gpt4 book ai didi

javascript - 使用传单放大单击标记以执行更多操作

转载 作者:行者123 更新时间:2023-12-01 02:00:30 24 4
gpt4 key购买 nike

当我尝试缩放标记时遇到问题,出现错误:

未捕获类型错误:e.target.getBounds 不是函数

var rotas = L.geoJSON(paradas, {
onEachFeature: onEachFeature
}).addTo(map);

function onEachFeature(feature, layer){
layer.on('click', function(e){
$('.orange').html(feature.properties.nome);
$('.city').html(feature.properties.imagem);
$('.event').html(feature.properties.descricao);

console.log(e.target);
zoomToFeature(e)
});

}

function zoomToFeature(e) {
console.log("pass here")
map.fitBounds(e.target.getBounds());
}

但是当我执行 console.log 时它会正确返回。我有什么错吗?我的源代码在这里:

http://github.com/eltonsantos/analise_integrada

map.fitBounds 出现正常,但仍然不起作用:(谁来帮帮我?谢谢!

最佳答案

您必须为单个标记执行其他操作

function zoomToFeature(e)
{
var latLngs = [e.target.getLatLng()];
var markerBounds = L.latLngBounds(latLngs);
map.fitBounds(markerBounds);
}

首先获取标记latlng数组并用它创建一个latLngBounds。然后您就可以适应这个界限。

工作示例:https://jsfiddle.net/8282emwn/175/

关于javascript - 使用传单放大单击标记以执行更多操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50636019/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com