代码之家  ›  专栏  ›  技术社区  ›  Elton Santos

使用传单放大点击标记以了解更多操作

  •  0
  • Elton Santos  · 技术社区  · 6 年前

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

    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.fitbunds显示正常,但仍然不起作用:( 有人帮我吗?谢谢!

    1 回复  |  直到 6 年前
        1
  •  2
  •   Baptiste    6 年前

    你得为一个标记做点别的

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

    先拿马克笔 latlng 数组并创建 latLngBounds 带着它。你就可以适应这个界限了。

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