使用 OpenLayers,删除标记层和弹出窗口的正确方法是什么?
LoadPin 是一个向地图添加标记的函数。它在第一次调用时初始化该层。 map 是一个 openlayers 地图对象。
但使用 map.removeLayer("markers") 或 "Markers" 不会从地图上删除标记。我看到提到要执行此操作的销毁操作,但找不到。
并且,如何删除弹出窗口?
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));
}
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));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过以下方式从标记图层中删除单个标记:
删除带有标记的整个图层应通过以下方式实现:
您应该能够通过以下方式删除弹出窗口:
其中 popup 是之前创建的 Popup 对象。
You can remove individual markers from a marker layer with:
Removing the entire layer, with markers should be achieved with:
You should be able to remove a popup with:
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:
尝试以下任何代码,希望对您有所帮助。
或者
Try the any of below code i hope it will help you.
or