[英]is there a way to resize marker icons depending on zoom level in leaflet?
[英]Which is the best way to resize custom marker icons depending on zoom level in leaflet?
我需要根據 leaflet 中的縮放級別調整一些自定義標記的大小。 'zoomend' function 僅適用於圓形。
map.on('zoomend', function() {
)
var currentZoom = map.getZoom();
myMarker.setRadius(currentZoom );
});
解決方案:
var myIcon= L.Icon.extend({
options: {
iconUrl: 'icon.png',
iconSize: [7.5, 7.5],
iconAnchor: [0, 0]
}
});
var ic = new myIcon({iconSize: [7.5, 7.5]});
var marker = L.marker([-15.7745457, -48.3575684], {icon: ic}).addTo(map);
map.on('zoomend', function() {
var actualZoom = map.getZoom();
var newSize = 60/((20 - actualZoom )*2);
var resizedIcon = new myIcon({iconSize: [newSize ,newSize ]});
marker.setIcon(resizedIcon );
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.