【问题标题】:Unable to bind popup to polygon (geoJSON) using Leaflet无法使用 Leaflet 将弹出窗口绑定到多边形(geoJSON)
【发布时间】:2022-08-26 06:31:38
【问题描述】:

我正在尝试向生成的多边形添加一条消息,当用户在 Angular 中单击它时将显示该消息。

我尝试根据 Leftlet 网站上的可用材料创建一些东西,但我无法将消息添加到多边形。我使用了相同的方法,让 geojson 指向一个点,一切正常。

不幸的是,我发现的材料大多展示了有效的案例(例如,geojson 点)。

Geojson 在地图上正确显示,唯一的问题是缺少弹出窗口。

L.geoJSON(geojsonFeature,
            {
                style: function(feature) {
                    return {
                        \"color\": \"#78c679\",
                        \"weight\": 5,
                        \"opacity\": 0.9
                    }
                },
                onEachFeature: (feature, layer)=>{
                    layer.bindPopup(\'Test message\');
                }
            }
        ).addTo(this.map);

    标签: angular leaflet polygon geojson


    【解决方案1】:

    我只是设法解决了这个问题。我所要做的就是更改地图渲染选项(preferCanvas)。

    this.map = L.map('map', {
            center: center,
            maxZoom: 19,
            zoom: 17,
            layers: [osm],
            preferCanvas: true
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-14
      • 1970-01-01
      • 2021-05-14
      相关资源
      最近更新 更多