Leaflet gets all polylines added to map
P粉358281574
P粉358281574 2023-08-18 13:18:02
0
1
360

Once you've added one or more polylines with clickable actions on your map, and want to use the measure tool PolylineMeasure, those polylines will exist in some way. How can I get all created polylines in a map to disable clickability, just like you can with polylines directly you can click with marker on the map.

L.polyline(latlngs, {clickable: false}).addTo(map);
P粉358281574
P粉358281574

reply all (1)
P粉138711794

Polyline disable in Leaflet

You need to traverse all layers, you can use theeachLayer functionto achieve this. And remove theclick event listener. Just use the.off functionlike this:layer.off('click');In my code below it will remove the line from eachpolylineRemoveevent listener.

The following is the code:

// 我假设'map'是您的L.Map实例。 map.eachLayer(function(layer) { if (layer instanceof L.Polyline) { // 从该折线中移除点击事件监听器。 layer.off('click'); } });
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!