Hello,
I am using WinformsMap & SimpleMarkerOverlay in my ASP.NET windows application to display a marker on a map. On different location selection ie. by providing new longitude & latitude, I am displaying new marker on the map. But before the Add marker call, I am clearing old marker from the map. I tried two different ways but could not achieve it. Below are the two approaches.
1# Clear Marker
SimpleMarkerOverlay markerOverlay = (SimpleMarkerOverlay)winformsMap1.Overlays["MarkerOverlay"];
if (markerOverlay != null && markerOverlay.Markers.Count > 0)
{
markerOverlay.Markers.Clear();
}
winformsMap1.Refresh();
2# Remove Marker
SimpleMarkerOverlay markerOverlay = (SimpleMarkerOverlay)winformsMap1.Overlays["MarkerOverlay"];
if (markerOverlay != null && markerOverlay.Markers.Count > 0)
{
foreach (var item in markerOverlay.Markers)
{
markerOverlay.Markers.Remove(item);
}
winformsMap1.Refresh();
}
Please suggest the exact way by which I can clear the older marker from the map.
Regards,
Ravi
Markers not getting cleared
Hi Ravi,
It looks the API don’t works well here, I will discuss that with our developers.
Here is how to clear the markers from map:
SimpleMarkerOverlay markerOverlay = (SimpleMarkerOverlay)winformsMap1.Overlays[“MarkerOverlay”];
if (markerOverlay != null && markerOverlay.Markers.Count > 0)
{
foreach (var item in markerOverlay.Markers)
{
item.Dispose();
}
}
winformsMap1.Refresh();
Regards,
Don
Hello Don,
Fantastic. It’s working & clearing old markers. Thanks a lot. But to my surprise while debugging the code, after execution of above code, marker counts still persists that is 1 or 2. But fortunately old markers are not displayed on map. Thanks a lot.
Regards,
Ravi
Hi Ravi,
I am glad to hear that works for you.
You can try call markerOverlay.Markers.Clear(); after dispose all markers.
I think that will make marker count back to 0.
Regards,
Don