【问题标题】:How to trigger native popup on Leaflet polygon如何在 Leaflet 多边形上触发本机弹出窗口
【发布时间】:2012-07-31 05:26:01
【问题描述】:

如何手动触发 Leaflet 多边形上的原生弹出窗口?

我可以像这样将原生弹出窗口绑定到每一层:

geojsonLayer.on("featureparse", function (e){
    // bind the native popup
    var popupContent = "popup content goes here";
    e.layer.bindPopup(popupContent);
});

我已经为每个多边形手动分配了一个 ID,以便以后可以像这样引用它们:

map._layers['poly0']

我试过像这样触发弹出窗口:

map._layers['poly0'].openPopup();

但这给了我这样的错误:

map._layers['poly0'].openPopup is not a function

知道我哪里出错了吗?

【问题讨论】:

标签: leaflet


【解决方案1】:

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

另外,请查看 Leaflet 0.4 发布公告:http://leaflet.cloudmade.com/2012/07/30/leaflet-0-4-released.html(请注意 GeoJSON API 已更改且不向后兼容,因此您还必须更新代码)

【讨论】:

    猜你喜欢
    • 2022-08-26
    • 1970-01-01
    • 1970-01-01
    • 2022-06-12
    • 2018-05-07
    • 1970-01-01
    • 1970-01-01
    • 2022-10-01
    • 2023-04-08
    相关资源
    最近更新 更多