2017-03-16 59 views
0

我目前正在使用gmap.net使用多边形创建特定的半径。我目前已经为半径做了一个多边形,但是现在我遇到了我想要创建多面体标记的问题,但只显示了多边形内的标记。这可能吗?Gmap.net只显示多边​​形内的标记

_polygonOverlay = new GMapOverlay("destination"); 
_gMap.Overlays.Add(_polygonOverlay); 

private void CreateCircle(PointLatLng destination, double radius) 
    { 
     List<PointLatLng> radiusPoint = new List<PointLatLng>(); 

     double seg = Math.PI * 2/40; 

     for (int i = 0; i < 40; i++) 
     { 
      double theta = seg * i; 
      double latitude = destination.Lat + Math.Cos(theta) * radius; 
      double longitude = destination.Lng + Math.Sin(theta) * radius; 

      PointLatLng cirlePoint = new PointLatLng(latitude, longitude); 

      radiusPoint.Add(cirlePoint); 
     } 
     GMapPolygon radiusCircle = new GMapPolygon(radiusPoint, "radius"); 
     _polygonOverlay.Polygons.Add(radiusCircle); 
    } 

private void CreateMarkers() 
     { 
      _polygonOverlay.Markers.Add(new GMarkerGoogle(new PointLatLng(xxx, xxx), GMarkerGoogleType.blue)); 
      _polygonOverlay.Markers.Add(new GMarkerGoogle(new PointLatLng(xxx, xxx), GMarkerGoogleType.blue)); 
      _polygonOverlay.Markers.Add(new GMarkerGoogle(new PointLatLng(xxx, xxx), GMarkerGoogleType.blue)); 
     } 

下面是我创建一个圆的代码(仍然需要一些工作)和一些标记的小样本。

由于已经提前是

+0

添加一些代码。因为这个问题太广泛了。 –

+0

添加了一些我希望这有助于理解的代码 – MrAndre

回答

0

既然你正在处理一个圈,你应该能够简单地从圆心检查标记的距离。如果距离大于半径,请勿将其添加到叠加层。

GMap可让您访问确定此信息的必要方法。做这样的事情:

//Assuming p1 is your marker and p2 is your circle center coordinate 
double markerDist = GMap.NET.MapProviders.EmptyProvider.Instance.Projection.GetDistance(p1.Position, p2); 

if(markerDist <= circleRadius) 
{ 
    //Add the marker to the overlay 
}