【问题标题】:Leaflet.js popup and zoomLeaflet.js 弹出和缩放
【发布时间】:2019-03-20 22:41:27
【问题描述】:

有没有办法让leaflet.js 弹出窗口显示在特定的缩放级别,例如仅当map.getZoom() > 6 时。隐藏弹出窗口甚至将其不透明度设置为零也是可行的选择。

谢谢

【问题讨论】:

    标签: leaflet


    【解决方案1】:

    使用方法/事件处理程序map.on('zoomend') (https://leafletjs.com/reference-1.4.0.html#map-zoomend) 来检测地图何时完成缩放。然后检查缩放值,看看是否要显示弹出窗口。

    map.on('zoomend', function(){
      if(map.getZoom() > 6){
        showPopup();//your function here
      } 
    });
    

    【讨论】:

    • 我想我明白了。这就是我的代码现在大致的样子。我没有像marker.bindPopup 这样的东西让我卡住了。 L.geoJson(data, {pointToLayer: function (feature, latlng) {//some code goes here})}, onEachFeature: onEachMarker }) function onEachMarker(feature, layer) { layer.on({popupopen: onPopupOpen,}); layer.bindPopup(myPopup, customOptions) } function onPopupOpen(e) { if ( map.getMaxZoom() < 6 ) { this.closePopup(); } }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 2016-12-21
    • 1970-01-01
    相关资源
    最近更新 更多