Leaflet ::根据缩放级别更改图标 [英] Leaflet :: Changing icon based on zoom level
本文介绍了Leaflet ::根据缩放级别更改图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更改图标高度&宽度基于传单的缩放级别?
How do I go about changing an icon height & width based on Leaflet zoom level?
我正在使用Leaflet api v0.7.5
I'm using Leaflet api v0.7.5
推荐答案
将L.Marker.setIcon
方法与地图的zoomend
事件一起使用,即:
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);
}
})
此外,请注意不赞成使用传单0.7.5.建议您切换到1.0.0-rc3(在撰写本文时,这是最新版本).
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).
这篇关于Leaflet ::根据缩放级别更改图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文