From b2266f45098da16496fae72adbcfd877b385ee91 Mon Sep 17 00:00:00 2001 From: luoxiao Date: Fri, 10 Jan 2025 17:41:35 +0800 Subject: [PATCH] =?UTF-8?q?[fix]webmap=E5=8E=9F=E7=82=B9=E5=AF=B9=E6=AF=94?= =?UTF-8?q?=E5=88=86=E8=BE=A8=E7=8E=87=E5=AF=B9=E6=AF=94=E5=B0=8F=E6=95=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/mapping/WebMapV2.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/common/mapping/WebMapV2.js b/src/common/mapping/WebMapV2.js index 883834547..808c3c045 100644 --- a/src/common/mapping/WebMapV2.js +++ b/src/common/mapping/WebMapV2.js @@ -705,14 +705,17 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa } return this._isSameOrigin(origin) && this._isSameResolutions(resolutions, tileSize); } + numberEqual(num1, num2, precision = 10E-6) { + return Math.abs(+num1 - +num2) <= precision; + } _isSameOrigin(origin) { const extent = this.map.getCRS().getExtent(); - return origin[0].toFixed(2) === extent[0].toFixed(2) && origin[1].toFixed(2) === extent[3].toFixed(2); + return this.numberEqual(origin[0], extent[0]) && this.numberEqual(origin[1], extent[3]); } _isSameResolutions(resolutions, tileSize, mapTileSize = 512) { const mapResolutions = this._getMapResolutions(); const conversion = mapTileSize / tileSize; - return resolutions.every((item, i) => (item).toFixed(6) === (conversion * mapResolutions[i]).toFixed(6)); + return resolutions.every((item, i) => this.numberEqual(item, conversion * mapResolutions[i])); } _getMapResolutions() { return this._getResolutionsByExtent({extent: this.map.getCRS().getExtent(), tileSize: 512})