Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2499 | - | 1 | |
2 | namespace GMap.NET.WindowsPresentation |
||
3 | { |
||
4 | using System.Collections.Generic; |
||
5 | using System.Windows.Shapes; |
||
6 | |||
7 | public interface IShapable |
||
8 | { |
||
9 | void RegenerateShape(GMapControl map); |
||
10 | } |
||
11 | |||
12 | public class GMapRoute : GMapMarker, IShapable |
||
13 | { |
||
14 | public readonly List<PointLatLng> Points = new List<PointLatLng>(); |
||
15 | public System.Windows.Media.Brush _brush = System.Windows.Media.Brushes.Magenta; |
||
16 | public GMapRoute(IEnumerable<PointLatLng> points, System.Windows.Media.Brush brush) |
||
17 | { |
||
18 | if (brush != null) |
||
19 | _brush = brush; |
||
20 | Points.AddRange(points); |
||
21 | RegenerateShape(null); |
||
22 | } |
||
23 | |||
24 | |||
25 | |||
26 | public override void Clear() |
||
27 | { |
||
28 | base.Clear(); |
||
29 | Points.Clear(); |
||
30 | } |
||
31 | |||
32 | /// <summary> |
||
33 | /// regenerates shape of route |
||
34 | /// </summary> |
||
35 | public virtual void RegenerateShape(GMapControl map) |
||
36 | { |
||
37 | if (map != null) |
||
38 | { |
||
39 | this.Map = map; |
||
40 | |||
41 | if(Points.Count > 1) |
||
42 | { |
||
43 | Position = Points[0]; |
||
44 | |||
45 | var localPath = new List<System.Windows.Point>(Points.Count); |
||
46 | var offset = Map.FromLatLngToLocal(Points[0]); |
||
47 | foreach(var i in Points) |
||
48 | { |
||
49 | var p = Map.FromLatLngToLocal(i); |
||
50 | localPath.Add(new System.Windows.Point(p.X - offset.X, p.Y - offset.Y)); |
||
51 | } |
||
52 | |||
53 | var shape = map.CreateRoutePath(localPath,false,_brush); |
||
54 | |||
55 | if(this.Shape is Path) |
||
56 | { |
||
57 | (this.Shape as Path).Data = shape.Data; |
||
58 | } |
||
59 | else |
||
60 | { |
||
61 | this.Shape = shape; |
||
62 | } |
||
63 | } |
||
64 | else |
||
65 | { |
||
66 | this.Shape = null; |
||
67 | } |
||
68 | } |
||
69 | } |
||
70 | } |
||
71 | } |