Leaflet :: Changing icon based on zoom level [closed]

怎甘沉沦 提交于 2020-01-07 06:43:10

问题


How do I go about changing an icon height & width based on Leaflet zoom level?

I'm using Leaflet api v0.7.5


回答1:


Use the L.Marker.setIcon method together with the map's zoomend event, i.e.:

var marker = L.marker(…).addTo(map);
var bigIcon = L.icon(…);
var smallIcon = L.icon(…);

map.on('zoomend', function(ev){
  if (map.getZoom() > 16) {
    marker.setIcon(bigIcon);
  } else {
    marker.setIcon(smallIcon);
  }
})

Also, note that Leaflet 0.7.5 is deprecated. You are encouraged to switch to 1.0.0-rc3 (which is the latest available at the time of this writing).



来源:https://stackoverflow.com/questions/39696033/leaflet-changing-icon-based-on-zoom-level

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!