背景:由于地图经常需要缩放至面的范围,有时候从geojson中获取到多个面进行缩放,特此写了一个方面,实现多个面组成一个多面并获取范围。
解决:
/**
* 获取整个区域extent
*/
function getPolygonsExtent(features) {
const coords = [];
features.forEach((f) => {
if (f.getGeometry().getType() === 'Polygon') {
coords.push(f.getGeometry().getCoordinates());
}
else if (f.getGeometry().getType() === 'MultiPolygon') {
f.getGeometry().getPolygons().forEach((polygon) => {
coords.push(polygon.getCoordinates());
});
}
});
const newMulityPolygon = new MultiPolygon(coords);
return newMulityPolygon.getExtent();
}
3396

被折叠的 条评论
为什么被折叠?



