Hi Raquibur,
Just as you have mentioned, the SimpleMarkerOverlay.GetMarkersForDrawing does return all the markers every time. This is due to some internal usage issues.
You can get markers in a specific extent by writing an extension method for SimpleMarkerOverlay, here is a sample that may be of help:
public static class SimpleMarkerOverlayExtension
{
public static GeoCollection<Marker> GetMarkersInExtent(this SimpleMarkerOverlay overlay, RectangleShape extent)
{
double minX = extent.UpperLeftPoint.X;
double maxX = extent.LowerRightPoint.X;
double minY = extent.LowerRightPoint.Y;
double maxY = extent.UpperLeftPoint.Y;
var markersInExtent = overlay.Markers
.Where(marker => marker.Position.X <= maxX
&& marker.Position.X >= minX
&& marker.Position.Y <= maxY
&& marker.Position.Y >= minY);
GeoCollection<Marker> result = new GeoCollection<Marker>();
foreach (var marker in markersInExtent)
{
result.Add(marker);
}
return result;
}
}
Then you can call the method like this:
private void TestSimpleMarkerOverlay()
{
SimpleMarkerOverlay simpleMarkerOverlay = new SimpleMarkerOverlay();
simpleMarkerOverlay.Markers.Add(new Marker(0, 0));
simpleMarkerOverlay.Markers.Add(new Marker(20, 20));
int count1 = simpleMarkerOverlay.GetMarkersInExtent(new RectangleShape(-1, 1, 1, -1)).Count;
int count2 = simpleMarkerOverlay.GetMarkersInExtent(new RectangleShape(19, 21, 21, 19)).Count;
int count3 = simpleMarkerOverlay.GetMarkersInExtent(new RectangleShape(-180, 90, 90, -180)).Count;
}
And then you’ll notice that count1 equals to 1, count2 equals to 1 and count3 equals to 2.
Regards,
Tsui