1,通過@turf/bbox
,獲取minX, minY, maxX, maxY(經緯度)
,再轉換成平面坐標,最后調用地圖的實例方法fitScreenCoordinates
1 const geojson = this.map.getSource(id)._data 2 const bound = bbox(geojson) 3 const min = this.map.project([bound[0], bound[1]]) 4 const max = this.map.project([bound[2], bound[3]]) 5 this.map.fitScreenCoordinates(min, max, this.map.getBearing())