Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2287 - 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
 
16
        public GMapRoute(IEnumerable<PointLatLng> points)
17
        {
18
            Points.AddRange(points);
19
            RegenerateShape(null);
20
        }
21
 
22
        public override void Clear()
23
        {
24
            base.Clear();
25
            Points.Clear();
26
        }
27
 
28
        /// <summary>
29
        /// regenerates shape of route
30
        /// </summary>
31
        public virtual void RegenerateShape(GMapControl map)
32
        {
33
            if (map != null)
34
            {
35
                this.Map = map;
36
 
37
                if(Points.Count > 1)
38
                {
39
                   Position = Points[0];
40
 
41
                   var localPath = new List<System.Windows.Point>(Points.Count);
42
                   var offset = Map.FromLatLngToLocal(Points[0]);
43
                   foreach(var i in Points)
44
                   {
45
                      var p = Map.FromLatLngToLocal(i);
46
                      localPath.Add(new System.Windows.Point(p.X - offset.X, p.Y - offset.Y));
47
                   }
48
 
49
                   var shape = map.CreateRoutePath(localPath);
50
 
51
                   if(this.Shape is Path)
52
                   {
53
                      (this.Shape as Path).Data = shape.Data;
54
                   }
55
                   else
56
                   {
57
                      this.Shape = shape;
58
                   }
59
                }
60
                else
61
                {
62
                   this.Shape = null;
63
                }
64
            }
65
        }
66
    }
67
}