【发布时间】:2021-04-01 18:18:12
【问题描述】:
尝试覆盖正在工作的 geojson 数据,但我希望用户能够单击一个区域并弹出显示该区域的详细信息。使用传单网站上的示例
L.geoJSON(data, {
style: function (feature) {
return {color: feature.properties.color};
}
}).bindPopup(function (layer) {
return layer.feature.properties.description;
}).addTo(map);
我收到关于 layer.feature 不是 L.Layer 类型属性的错误。我也将 @types/leaflet 用于 angular/typescript 类型,但它没有在其中列出。
如何访问 geojson 的特性属性来绑定弹出窗口?或者说真的,我想做一个 onClick 事件来获取信息来设置表单数据。
提前致谢。
编辑 1: 所以我想出了一个可行的方法。
在准备好地图时调用的函数中,我将 layer 设置为键入 any 而不是键入 L.Layer,因为该属性直到运行时才存在。
this.geojson = L.geoJSON(this.data);
this.geojson.bindPopup((layer: any) => {
return layer.feature.properties ... ;
}
这将使用来自 geojson 数据的数据提供我正在寻找的弹出窗口。接下来将代替 bindPopup 使用事件来设置表单数据。
【问题讨论】:
标签: angular leaflet ngx-leaflet