简体   繁体   English

无法使用 Leaflet 将弹出窗口绑定到多边形(geoJSON)

[英]Unable to bind popup to polygon (geoJSON) using Leaflet

I am trying to add to the generated polygon a message that will be displayed when the user clicks on it in Angular.我正在尝试向生成的多边形添加一条消息,当用户在 Angular 中单击它时将显示该消息。

I tried to create something based on the available materials on the Leftlet website, but I can't add the message to polygon.我尝试根据 Leftlet 网站上的可用材料创建一些东西,但我无法将消息添加到多边形。 I used an identical method, for geojson pointing to a point, and everything works without a problem.我使用了相同的方法,让geojson指向一个点,一切正常。

The materials I found, unfortunately, mostly show cases that work (eg, the geojson point).不幸的是,我发现的材料大多展示了有效的案例(例如,geojson 点)。

Geojson displays correctly on the map, the only problem is the lack of popup. Geojson 在 map 上正确显示,唯一的问题是缺少弹出窗口。

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

I just managed to solve the problem.我只是设法解决了这个问题。 All I had to do was change the map rendering option (preferCanvas).我所要做的就是更改 map 渲染选项(首选Canvas)。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM