Skip to content

Commit c17f31f

Browse files
committed
【fix】bound 不合法不要设置bounds 减少不出图的几率
1 parent ae8a9ad commit c17f31f

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/common/mapping/WebMapV2.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,9 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
807807
];
808808
}
809809
}
810+
if (bounds && !this._isValidBounds(bounds)) {
811+
bounds = null;
812+
}
810813
this._addBaselayer({
811814
url: [requestUrl],
812815
layerID: layerId,
@@ -2758,6 +2761,28 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
27582761
return coor;
27592762
}
27602763

2764+
// 校验 bounds 是否为合法的经纬度范围(EPSG:4326)
2765+
// 不合法返回 false:值非数字/无穷、左>=右、下>=上、四个坐标都在 ±0.5 度内(认为退化为原点附近)、超出经纬度范围
2766+
_isValidBounds(bounds) {
2767+
if (!Array.isArray(bounds) || bounds.length !== 4) {
2768+
return false;
2769+
}
2770+
const [left, bottom, right, top] = bounds;
2771+
if (![left, bottom, right, top].every((v) => typeof v === 'number' && Number.isFinite(v))) {
2772+
return false;
2773+
}
2774+
if (left >= right || bottom >= top) {
2775+
return false;
2776+
}
2777+
if (Math.abs(left) > 180 || Math.abs(right) > 180 || Math.abs(bottom) > 90 || Math.abs(top) > 90) {
2778+
return false;
2779+
}
2780+
if (Math.abs(left) < 0.5 && Math.abs(right) < 0.5 && Math.abs(bottom) < 0.5 && Math.abs(top) < 0.5) {
2781+
return false;
2782+
}
2783+
return true;
2784+
}
2785+
27612786
_getMapCenter(mapInfo) {
27622787
// center
27632788
let center = mapInfo.center && [mapInfo.center.x, mapInfo.center.y];

0 commit comments

Comments
 (0)