Leaflet 如何在传单多边形上触发本机弹出窗口

Leaflet 如何在传单多边形上触发本机弹出窗口,leaflet,Leaflet,如何手动触发传单多边形上的本机弹出窗口? 我可以将本机弹出窗口绑定到每个层,如下所示: geojsonLayer.on("featureparse", function (e){ // bind the native popup var popupContent = "popup content goes here"; e.layer.bindPopup(popupContent); }); map._layers['poly0'] map._layers['poly

如何手动触发传单多边形上的本机弹出窗口?

我可以将本机弹出窗口绑定到每个层,如下所示:

geojsonLayer.on("featureparse", function (e){
    // bind the native popup
    var popupContent = "popup content goes here";
    e.layer.bindPopup(popupContent);
});
map._layers['poly0']
map._layers['poly0'].openPopup();
map._layers['poly0'].openPopup is not a function
我已经手动为每个多边形指定了一个ID,以便以后可以像这样引用它们:

geojsonLayer.on("featureparse", function (e){
    // bind the native popup
    var popupContent = "popup content goes here";
    e.layer.bindPopup(popupContent);
});
map._layers['poly0']
map._layers['poly0'].openPopup();
map._layers['poly0'].openPopup is not a function
我尝试过像这样触发弹出窗口:

geojsonLayer.on("featureparse", function (e){
    // bind the native popup
    var popupContent = "popup content goes here";
    e.layer.bindPopup(popupContent);
});
map._layers['poly0']
map._layers['poly0'].openPopup();
map._layers['poly0'].openPopup is not a function
但这给了我这样一个错误:

geojsonLayer.on("featureparse", function (e){
    // bind the native popup
    var popupContent = "popup content goes here";
    e.layer.bindPopup(popupContent);
});
map._layers['poly0']
map._layers['poly0'].openPopup();
map._layers['poly0'].openPopup is not a function

知道我哪里出了问题吗?

矢量层openPopup最近才出现在最新版本中,以前没有


另外,请查看传单0.4发布公告:(注意GeoJSON API已更改,并且它不向后兼容,因此您还必须更新代码)

我在这里回答了我自己的问题: