Leaflet 如何使用lapper.pm将标记添加到多边形层?
添加直线和多边形没有问题,但当尝试在多边形层(“lyrPoly”)顶部添加标记时,它解释为我希望单击多边形(例如打开弹出窗口),而不是添加标记。我怎样才能避免这种情况?我正在使用lapper.pm添加标记、线串和多边形 这是标记的代码:Leaflet 如何使用lapper.pm将标记添加到多边形层?,leaflet,leaflet-geoman,leaflet.pm,Leaflet,Leaflet Geoman,Leaflet.pm,添加直线和多边形没有问题,但当尝试在多边形层(“lyrPoly”)顶部添加标记时,它解释为我希望单击多边形(例如打开弹出窗口),而不是添加标记。我怎样才能避免这种情况?我正在使用lapper.pm添加标记、线串和多边形 这是标记的代码: map.on('pm:create', function(e) { e.marker; var type = e.layerType, layer = e.l
map.on('pm:create', function(e) {
e.marker;
var type = e.layerType,
layer = e.layer;
$(document).ready(function() {
var jsnMarker = layer.toGeoJSON().geometry;
jsnMarker = {
type: "MultiPoint",
coordinates: [jsnMarker.coordinates]
};
})
});
在ajax函数中,我使用以下内容:
lyrMarker = L.geoJSON(jsnMarker, {
pointToLayer: function (feature, latlng) {
if(feature.properties.marker_type=="versionOne"){
return L.marker(latlng, {
icon: customIcon
})
}else if
(feature.properties.marker_type=="versionTwo"){
return L.marker(latlng, {
icon: otherIcon
})
} ,
onEachFeature: forEachMarker
});
对于多边形层,我有一个对应的“onEachFeature”函数,如下所示:
function forEachFeature(feature, layer) {
var att = feature.properties;
var popupContent =
"Popup-content" ;
layer.bindPopup(popupContent, {
offset: [0, -120]
});
layer.on("click", function (e) {
lyrPoly.setStyle(style); //resets layer colors
layer.setStyle(highlight); //highlights selected.
});
};
将标记添加到背景/底图可以正常工作,但不能添加到多边形层。为什么会这样?什么是好的解决方案?我不想将标记添加到多边形所在的同一层,但要避免多边形“碍事”
我曾经有过在添加标记模式下使多边形层
交互:false
的想法,但没有成功 如果启用了绘图模式,则更新单击事件并进行测试:
function forEachFeature(feature, layer) {
var att = feature.properties;
var popupContent =
"Popup-content" ;
layer.bindPopup(popupContent, {
offset: [0, -120]
});
layer.on("click", function (e) {
if(!map.pm.Draw.Marker.enabled()){
lyrPoly.setStyle(style); //resets layer colors
layer.setStyle(highlight); //highlights selected.
}
});
};
更新
要禁用弹出打开事件,请在文件顶部添加以下代码。在创建带有弹出窗口的图层之前:
L.Layer.include({
_openPopup: function (e) {
var layer = e.layer || e.target;
//This IF is new
if(map.pm.Draw.Marker.enabled()){
return;
}
if (!this._popup) {
return;
}
if (!this._map) {
return;
}
// prevent map click
L.DomEvent.stop(e);
// if this inherits from Path its a vector and we can just
// open the popup at the new location
if (layer instanceof L.Path) {
this.openPopup(e.layer || e.target, e.latlng);
return;
}
// otherwise treat it like a marker and figure out
// if we should toggle it open/closed
if (this._map.hasLayer(this._popup) && this._popup._source === layer) {
this.closePopup();
} else {
this.openPopup(layer, e.latlng);
}
},
});
示例:如果启用了绘图模式,则更新单击事件并进行测试:
function forEachFeature(feature, layer) {
var att = feature.properties;
var popupContent =
"Popup-content" ;
layer.bindPopup(popupContent, {
offset: [0, -120]
});
layer.on("click", function (e) {
if(!map.pm.Draw.Marker.enabled()){
lyrPoly.setStyle(style); //resets layer colors
layer.setStyle(highlight); //highlights selected.
}
});
};
更新
要禁用弹出打开事件,请在文件顶部添加以下代码。在创建带有弹出窗口的图层之前:
L.Layer.include({
_openPopup: function (e) {
var layer = e.layer || e.target;
//This IF is new
if(map.pm.Draw.Marker.enabled()){
return;
}
if (!this._popup) {
return;
}
if (!this._map) {
return;
}
// prevent map click
L.DomEvent.stop(e);
// if this inherits from Path its a vector and we can just
// open the popup at the new location
if (layer instanceof L.Path) {
this.openPopup(e.layer || e.target, e.latlng);
return;
}
// otherwise treat it like a marker and figure out
// if we should toggle it open/closed
if (this._map.hasLayer(this._popup) && this._popup._source === layer) {
this.closePopup();
} else {
this.openPopup(layer, e.latlng);
}
},
});
示例:是,如果样式不变,则使用此选项。但是弹出窗口仍然出现,并且标记没有被放置。还有什么想法吗?我更新了答案,请别忘了检查答案哦,我的上帝,太棒了-很有效!!!我很想拥抱你。:)是的,如果样式不变,则使用此选项。但是弹出窗口仍然出现,并且标记没有被放置。还有什么想法吗?我更新了答案,请别忘了检查答案哦,我的上帝,太棒了-很有效!!!我很想拥抱你。:)