添加和删除geojson层的传单标签

Add and remove Leaflet labels of a geojson layer

本文关键字:单标签 标签 删除 geojson 添加      更新时间:2024-05-24

使用传单和传单标签,当地图缩放大于10时,如何添加图层"my_layer"的标签?并且当缩放<10?非常感谢。

// ADD GEOJSON LAYER
my_layer = L.geoJson(data, {
    onEachFeature: onEachFeature        
    }
}).addTo(map);
// ZOOM OPTION
map.on('zoomend', function () {
   if (map.getZoom() > 10 ) {
      // ???      
   }
   if (map.getZoom() <= 10 ) {
      // ???      
   }
});

我认为有更好的解决方案,但如果没有其他标签,我会使用display:传单弹出窗格上没有。使用jQuery:

map.on('zoomend', function () {
   if (map.getZoom() > 10 ) {
      $('.leaflet-popup-pane).show();
   }
   if (map.getZoom() <= 10 ) {
      $('.leaflet-popup-pane).hide();    
   }
});
相关文章: