如何解决检查重复标记传单geoman
我正在尝试检查每个geojson功能是否为标记。如果要删除放置的图层,请再次初始化绘图标记。
如果位置不同,我将其添加到要素图层中。
问题在于eachLayer始终返回true,因为它遍历所有图层,并且始终返回true,因为标记已添加到要素中。所以它总是重复。
const num = 1115487.2644548;
const len = String(parseInt(num)).length
const two = len-2;
console.log(num/10**two); // without testing the len > 2
这是摆弄,我很忘了添加重要的代码。 https://jsfiddle.net/2ftmy0bu/2/
解决方法
将您的代码更改为:
// listen to when a new layer is created
map.on('pm:create',function(e) {
//should only place one marker each time
// check if the layer with the same latlng exists
var eq = features.getLayers().find(function(layer){
if(layer instanceof L.Marker) {
return layer.getLatLng().equals(e.layer.getLatLng())
}else{
return false;
}
}) !== undefined;
if(!eq) {
console.log('not equal')
features.addLayer(e.layer);
map.pm.disableDraw('Marker')
//if marker is placed on the map and it is not placed on same place as another marker
} else if(eq) {
console.log('equal')
//if marker is placed on the map over another marker,remove marker,then init draw marker again.
map.removeLayer(e.layer);
map.pm.enableDraw('Marker',{
snappable: true,snapDistance: 20,finishOn: 'click' || 'mousedown',});
// TODO: I think you don't want this
// features.addLayer(e.layer);
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。