我想在点击标记时放大标记。我正在使用Mapbox和传单。
我试过了:
marker.on('click', function(e){
map.setView([e.lat, e.lng], 12);
});
但它给了我一些错误:
TypeError:t为null
我甚至尝试过:
marker.on('click', function(e){
map.fitBounds(marker.getBounds());
});
答案 0 :(得分:9)
要获取事件的纬度和经度,您必须使用e.latlng:latlng reference。使用此:
marker.on('click', function(e){
map.setView(e.latlng, 13);
});
答案 1 :(得分:2)
尝试
marker.on('click', function(e){
map.setView([e.latlng.lat, e.latlng.lng], 12);
});