Mapbox GL JS getBounds()/fitBounds()

前端 未结 5 1680
自闭症患者
自闭症患者 2020-12-13 17:44

I\'m using Mapbox GL JS v0.14.2 and I\'ve searched high and low through the documentation and very little is clear about this.

If you use the standard JS API, it\'s

5条回答
  •  长情又很酷
    2020-12-13 17:59

    If you want to fit map to markers, you can create bounds that contains all markers.

    var bounds = new mapboxgl.LngLatBounds();
    
    markers.features.forEach(function(feature) {
        bounds.extend(feature.geometry.coordinates);
    });
    
    map.fitBounds(bounds);
    

提交回复
热议问题