mapbox将图层缩放到视口合适区域
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())