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

时间:2016-04-13 09:24:57

标签: javascript leaflet

使用Leaflet和leaflet.label,我如何添加图层的标签" my_layer"当地图的缩放大于10?并在缩放< = 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 ) {
      // ???      
   }
});

1 个答案:

答案 0 :(得分:1)

我认为有更好的解决方案,但如果没有其他标签,我会在Leaflet Popup Pane上使用display:none。使用jQuery:

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