在我的传单代码中,我添加了标记(图像)和矢量图像(多边形)。我需要两者都有一个上下文菜单,但在标记的情况下,上下文菜单是可见的,但对于多边形则不可见。谁能为此提供解决方案,下面是多边形的代码?
x = L.polygon([latpos,longpos],[latpos+1*scale,longpos+1*scale],[latpos+1*scale,longpos+3*scale],[latpos,longpos+2*scale],[latpos-1*scale,longpos+3*scale],[latpos-1*scale,longpos+1*scale]],{
fillColor:'black',
color:'red',
fillopacity:1.0,
fillOpacity:1.0,
contextmenu: true,
contextmenuInheritItems: false,
contextmenuItems: [{
text: 'Show coordinates',
callback: showCoordinates
}, {
text: 'Center map here',
callback: centerMap
}, '-', {
text: 'Zoom in',
callback: zoomIn
}, {
text: 'Zoom out',
callback: zoomOut
}]
}).addTo(map);
function showCoordinates (e) {
alert(e.latlng);
}
function centerMap (e) {
map.panTo(e.latlng);
}
function zoomIn (e) {
map.zoomIn();
}
function zoomOut (e) {
map.zoomOut();
}
您可以使用上下文菜单的传单插件LeafletContextMenu