From aa3d78afcb23355b9f8df5922adb03a75d821ec2 Mon Sep 17 00:00:00 2001 From: hu de yi Date: Wed, 23 Oct 2024 16:41:44 +0800 Subject: [PATCH] disable map scroll when map zoom Exceeding Zoom limits (#2444) --- src/map/handler/Map.ScrollWheelZoom.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/map/handler/Map.ScrollWheelZoom.ts b/src/map/handler/Map.ScrollWheelZoom.ts index c1cc1bd723..42a0b40bef 100644 --- a/src/map/handler/Map.ScrollWheelZoom.ts +++ b/src/map/handler/Map.ScrollWheelZoom.ts @@ -1,4 +1,4 @@ -import { isNil } from '../../core/util'; +import { isNil, isNumber } from '../../core/util'; import { addDomEvent, removeDomEvent, getEventContainerPoint, preventDefault, stopPropagation } from '../../core/util/dom'; import Handler from '../../handler/Handler'; import Map from '../Map'; @@ -65,6 +65,23 @@ class MapScrollWheelZoomHandler extends Handler { removeDomEvent(this.target._containerDOM, 'wheel', this._onWheelScroll); } + //@internal + _currentZoomCanScroll(value: number) { + if (isNumber(value)) { + const map = this.target; + const zoom = map.getZoom(); + const minZoom = map.getMinZoom(); + const maxZoom = map.getMaxZoom(); + if (zoom === minZoom && value > 0) { + return false; + } + if (zoom === maxZoom && value < 0) { + return false; + } + } + return true; + } + //@internal _onWheelScroll(evt) { const map = this.target; @@ -119,6 +136,9 @@ class MapScrollWheelZoomHandler extends Handler { this._delta = 0; } this._delta -= value; + if (!this._currentZoomCanScroll(value)) { + return; + } if (!this._zooming && this._delta) { const map = this.target; this._zoomOrigin = origin;