如何在Mapbox Leaflet中放大标记点击事件? [英] How to zoom on marker click event in Mapbox Leaflet?
本文介绍了如何在Mapbox Leaflet中放大标记点击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在点击标记时放大标记。我正在使用Mapbox和传单。
I want to zoom on a marker when it is clicked. I am using Mapbox and leaflet.
我试过:
marker.on('click', function(e){
map.setView([e.lat, e.lng], 12);
});
但它给了我一些错误:
TypeError:t为null
TypeError: t is null
我甚至尝试过:
marker.on('click', function(e){
map.fitBounds(marker.getBounds());
});
推荐答案
要获得事件的纬度和经度,必须使用e.latlng: latlng reference 。使用此:
To get the latitude and longitude of the event, you must use e.latlng: latlng reference. Use this:
marker.on('click', function(e){
map.setView(e.latlng, 13);
});
这篇关于如何在Mapbox Leaflet中放大标记点击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文