javascript - Leaflet - openPopup() 不显示 geoJSON
问题描述
我正在尝试将弹出窗口绑定到 geoJSON 层上的标记。为此,我使用了 onEachFeature 函数:
var onEachFeature = function(feature, layer) {
layer.bindPopup("hello",
{closeButton:false,
autoClose: false,
closeOnClick: false,
className: "popup-custom"}).openPopup();
}
这不会导致弹出显示。弹出窗口已创建,但我需要单击标记以显示它。在不单击标记的情况下使弹出窗口可见,我缺少什么?
我没有使用 pointToLayer 函数,因为我也在使用过滤器功能过滤特征并使用请求来自定义弹出窗口和标记(弹出窗口绑定实际上是在回调函数中)。
解决方案
您会得到一个 geojsonlayer 作为结果,然后您可以打开每个图层的弹出窗口:
var geojsonLayer = L.geoJSON(data, {
onEachFeature : onEachFeature
}).addTo(map);
geojsonLayer.eachLayer(function(layer){
layer.openPopup();
});
推荐阅读
- html - 我如何获取网页网址并将其填写在 Matlab 中
- c# - EntityFrameworkCore - 使用来自 http 正文的接收对象过滤现有数据
- php - GD 无法创建 JPG
- linux - libcurl 中不支持或禁用协议“https”-如何检查当前版本的 libcurl
- powerbi - 带有过滤器的最后日期未在 Powerbi 中显示所有日期
- flutter - Flutter TextButton onPrimary 替代品
- swift - scrollToRow(...animated:false) 导致故障
- flutter - 如何在颤动中获取具有相同ID的所有文档快照
- python - 使机器人重新发送具有所有属性的嵌入
- javascript - 关于范围界定和提升的新手问题?