// add objects and zone around them void AddDemoZone(double areaRadius, PointLatLng center, List<PointAndInfo> objects) { var objectsInArea = from p in objects where MainMap.MapProvider.Projection.GetDistance(center, p.Point) <= areaRadius select new { Obj = p, Dist = MainMap.MapProvider.Projection.GetDistance(center, p.Point) }; if (objectsInArea.Any()) { var maxDistObject = (from p in objectsInArea orderby p.Dist descending select p).First(); // add objects to zone foreach (var o in objectsInArea) { GMapMarker it = new GMapMarker(o.Obj.Point); { it.ZIndex = 55; var s = new CustomMarkerDemo(this, it, o.Obj.Info + ", distance from center: " + o.Dist + "km."); it.Shape = s; } MainMap.Markers.Add(it); } // add zone circle { GMapMarker it = new GMapMarker(center); it.ZIndex = -1; Circle c = new Circle(); c.Center = center; c.Bound = maxDistObject.Obj.Point; c.Tag = it; c.IsHitTestVisible = false; UpdateCircle(c); Circles.Add(it); it.Shape = c; MainMap.Markers.Add(it); } } }
// calculates circle radius void UpdateCircle(Circle c) { var pxCenter = MainMap.FromLatLngToLocal(c.Center); var pxBounds = MainMap.FromLatLngToLocal(c.Bound); double a = (double)(pxBounds.X - pxCenter.X); double b = (double)(pxBounds.Y - pxCenter.Y); var pxCircleRadius = Math.Sqrt(a * a + b * b); c.Width = 55 + pxCircleRadius * 2; c.Height = 55 + pxCircleRadius * 2; (c.Tag as GMapMarker).Offset = new System.Windows.Point(-c.Width / 2, -c.Height / 2); }