如何缩放地图框传单中的标记单击事件

How to zoom on marker click event in Mapbox Leaflet?

本文关键字:单中 事件 单击 何缩放 缩放 地图      更新时间:2023-09-26

我想在单击标记时放大它。我正在使用Mapbox和传单。

我试过了:

marker.on('click', function(e){
    map.setView([e.lat, e.lng], 12);
});

但它给了我一些错误:

TypeError:t为空

我甚至尝试过:

marker.on('click', function(e){
    map.fitBounds(marker.getBounds());
});

要获取事件的纬度和经度,必须使用e.latlng:latlng引用。使用此:

marker.on('click', function(e){
    map.setView(e.latlng, 13);
});

尝试

marker.on('click', function(e){
    map.setView([e.latlng.lat, e.latlng.lng], 12);
});