简体   繁体   中英

Leaflet.js popup and zoom

Is there a way to make a leaflet.js popup show up at specific zoom levels please, for example when map.getZoom() > 6 only. Hiding the popup or even setting its opacity to zero could also be viable options.

Thanks

Use the method/event handler map.on('zoomend') ( https://leafletjs.com/reference-1.4.0.html#map-zoomend ) to detect whenever the map finishes zooming. Then check the zoom value do see if you want to show the popup or not.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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