gpt4 book ai didi

javascript - 在鼠标单击时添加标记并删除 openlayers 中现有的标记?

转载 作者:行者123 更新时间:2023-11-28 01:49:22 25 4
gpt4 key购买 nike

我正在使用 Openlayers map 。我想要一项功能,当用户单击 map 时,应创建标记,但同时应删除或删除 map 上已有的现有标记,并且仅应显示最新的标记。

  var markers = new OpenLayers.Layer.Markers( "Markers" );
markers.id = "Markers";
me.OpenLayers.addLayer(markers);
/*myMarker = new OpenLayers.Marker(new OpenLayers.Marker( 56.512438257836,27.335700987698 ));
markers.addMarker(myMarker);*/

var size = new OpenLayers.Size(30,30);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var icon = new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png',size,offset);

//map.setCenter (lonLat, zoom);
me.OpenLayers.events.register("click", kijs_map_container, function(evt) {
var lonlat = me.OpenLayers.getLonLatFromViewPortPx(evt.xy).transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
$("#edit-field-jena-seta-map-openlayers-wkt").val('GEOMETRYCOLLECTION(POINT('+lonlat.lat+' '+lonlat.lon+'))');
var pos = me.OpenLayers.getLonLatFromPixel(evt.xy);
alert(baltic_long);
var marker = new OpenLayers.Marker(new OpenLayers.LonLat(baltic_lat, baltic_long),icon);
markers.addMarker(marker);
marker.events.register("click", marker, function(e){

});
//updateMaker(myMarker, pos);
});

最佳答案

在创建和添加新标记之前删除图层上的所有标记:

markers.clearMarkers(); 
markers.addMarker(marker);

参见clearMarkers了解更多详情。

关于javascript - 在鼠标单击时添加标记并删除 openlayers 中现有的标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19906473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com