From 32d68992b33d5001e7f68fa6ee737d6ee25c60fb Mon Sep 17 00:00:00 2001 From: songyumeng Date: Sun, 24 Dec 2023 01:18:11 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90fix=E3=80=91=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=80=BE=E6=96=9C=E6=97=B6scale=E4=B8=8D=E5=AF=B9=E7=9A=84?= =?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/mapboxgl/web-map/control/scale/ScaleViewModel.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/mapboxgl/web-map/control/scale/ScaleViewModel.js b/src/mapboxgl/web-map/control/scale/ScaleViewModel.js index 09841287..1fac3a6e 100644 --- a/src/mapboxgl/web-map/control/scale/ScaleViewModel.js +++ b/src/mapboxgl/web-map/control/scale/ScaleViewModel.js @@ -45,11 +45,12 @@ export default class ScaleViewModel extends mapboxgl.Evented { updateScale(map, options) { const maxWidth = (options && options.maxWidth) || 100; - const centerPoint = map.project(map.crs.getLngLatCenter()); - const left = map.unproject([centerPoint.x, centerPoint.y]); - let right = map.unproject([centerPoint.x + maxWidth, centerPoint.y]); + const y = map._container.clientHeight / 2; + const x = map._container.clientWidth / 2; + const left = map.unproject([x, y]); + let right = map.unproject([x + maxWidth, y]); if (right.lng === left.lng) { - right = map.unproject([centerPoint.x - maxWidth, centerPoint.y]); + right = map.unproject([x - maxWidth, y]); } const maxMeters = this._getDistance(left, right);