最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - With OpenLayers, what is the correct way of removing a markers layer, and the popups? - Stack Overflow

programmeradmin4浏览0评论

LoadPin is a function to add a marker to a map. It initializes the layer on the first call. map is an openlayers map object.

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

AND, how do I remove the 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('.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));
}

LoadPin is a function to add a marker to a map. It initializes the layer on the first call. map is an openlayers map object.

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

AND, how do I remove the 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));
}
Share Improve this question edited Feb 12, 2014 at 6:31 tshepang 12.5k25 gold badges97 silver badges139 bronze badges asked Nov 3, 2010 at 20:54 GilShalitGilShalit 6,4639 gold badges51 silver badges73 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 10

You can remove individual markers from a marker layer with:

markers.removeMarker(marker);

Removing the entire layer, with markers should be achieved with:

markers.destroy();

You should be able to remove a popup with:

map.removePopup(popup);

where popup is the Popup object created earlier.

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

markerLayer.clearMarkers();

Try the any of below code i hope it will help you.

this.markerSource.removeFeature(this.iconFeature); 

or

this.markerSource.removeFeature(iconFeature);

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论