Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2469 - 1

2
namespace GMap.NET.WindowsPresentation
3
{
4
    using System.Collections.Generic;
5
    using System.Windows.Shapes;
6
 
7
    public class GMapPolygon : GMapMarker, IShapable
8
    {
9
        public readonly List<PointLatLng> Points = new List<PointLatLng>();
10
 
11
        public GMapPolygon(IEnumerable<PointLatLng> points)
12
        {
13
            Points.AddRange(points);
14
            RegenerateShape(null);
15
        }
16
 
17
        public override void Clear()
18
        {
19
            base.Clear();
20
            Points.Clear();
21
        }
22
 
23
        /// <summary>
24
        /// regenerates shape of polygon
25
        /// </summary>
26
        public virtual void RegenerateShape(GMapControl map)
27
        {
28
             if(map != null)
29
             {
30
                this.Map = map;
31
 
32
                if(Points.Count > 1)
33
                {
34
                   Position = Points[0];
35
 
36
                   var localPath = new List<System.Windows.Point>(Points.Count);
37
                   var offset = Map.FromLatLngToLocal(Points[0]);
38
                   foreach(var i in Points)
39
                   {
40
                      var p = Map.FromLatLngToLocal(i);
41
                      localPath.Add(new System.Windows.Point(p.X - offset.X, p.Y - offset.Y));
42
                   }
43
 
44
                   var shape = map.CreatePolygonPath(localPath);
45
 
46
                   if(this.Shape is Path)
47
                   {
48
                      (this.Shape as Path).Data = shape.Data;
49
                   }
50
                   else
51
                   {
52
                      this.Shape = shape;
53
                   }
54
                }
55
                else
56
                {
57
                   this.Shape = null;
58
                }
59
             }
60
        }
61
    }
62
}