With OpenLayers, what is the correct way to remove layer markers and pop-ups?

LoadPin is a function of adding a marker to a map. It initializes the layer on the first call. map - map object with an open layer.

But using map.removeLayer ("markers") or "Markers" does not remove markers from the map. I saw a mention of the annihilation operation to do this, but I cannot find it.

And how to remove popups?

var markers = null function LoadPin(LL, name, description) { var size = new OpenLayers.Size(36, 47); var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h); var icon = new OpenLayers.Icon('http://www.waze.co.il/images/home.png', size, offset); if (markers == null) { markers = new OpenLayers.Layer.Markers("Markers"); map.addLayer(markers); } var marker = new OpenLayers.Marker(LL, icon) markers.addMarker(marker); var bounds = markers.getDataExtent(); map.zoomToExtent(bounds); map.addPopup(new OpenLayers.Popup.FramedCloud("test", LL, null, "<div style='font-family:Arial,sans-serif;font-size:0.8em;'>" + name + "<br>" + description + "</div>", anchor = null, true, null)); } 
+4
source share
2 answers

You can remove individual markers from the marker level with

 markers.removeMarker(marker); 

Removing the entire marker layer should be achieved with:

 markers.destroy(); 

You can remove the popup using

 map.removePopup(popup); 

where popup is the popup created earlier.

+9
source

I know this post is outdated, but to remove all markers from the marker layer list:

 markerLayer.clearMarkers(); 
+10
source

All Articles