[英]How to zoom on marker click event in Mapbox Leaflet?
I want to zoom on a marker when it is clicked. 我想在点击标记时放大标记。 I am using Mapbox and leaflet. 我正在使用Mapbox和传单。
I tried: 我试过了:
marker.on('click', function(e){
map.setView([e.lat, e.lng], 12);
});
But it gives me some kind of error: 但它给了我一些错误:
TypeError: t is null TypeError:t为null
I even tried: 我甚至尝试过:
marker.on('click', function(e){
map.fitBounds(marker.getBounds());
});
To get the latitude and longitude of the event, you must use e.latlng: latlng reference . 要获取事件的纬度和经度,必须使用e.latlng: latlng引用 。 Use this: 用这个:
marker.on('click', function(e){
map.setView(e.latlng, 13);
});
Try 尝试
marker.on('click', function(e){
map.setView([e.latlng.lat, e.latlng.lng], 12);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.