0

I have a problem when I try make a zoom on marker, I got a error:

Uncaught TypeError: e.target.getBounds is not a function

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());
}

But when I do console.log it return correctly. What I'm wrong? My source code is here:

http://github.com/eltonsantos/analise_integrada

the map.fitBounds appear is ok, but still dont work :( Someone help me? thanks!

4

1 回答 1

3

您必须为单个标记做其他事情

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

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

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

于 2018-06-01T07:25:18.507 回答