maptalks获取图层中所有几何体,并获取 Circle 类型的最小范围
if (!targetLayer) {
console.error('目标图层未找到');
} else {
const geometries = targetLayer.getGeometries(); // 获取所有几何体
let minLon = Infinity, maxLon = -Infinity;
let minLat = Infinity, maxLat = -Infinity;
geometries.forEach(geometry => {
if (geometry instanceof maptalks.Circle) { // 判断是否为 Circle 类型
const ring = geometry.getCoordinates(); // 取外环坐标
const { x, y } = ring
minLon = Math.min(minLon, x);
maxLon = Math.max(maxLon, x);
minLat = Math.min(minLat, y);
maxLat = Math.max(maxLat, y);
}
});
if (minLon !== Infinity) {
['95.4843107785941', '5.293242647908599', '98.67882483424289', '8.1788864486889']
const extent = [minLon, minLat, maxLon, maxLat]
// this.map.fitExtent(extent, { padding: [100, 100] });
this.map.fitExtent(extent);
}
}