Skip to content

Commit

Permalink
disable map scroll when map zoom Exceeding Zoom limits (#2444)
Browse files Browse the repository at this point in the history
  • Loading branch information
deyihu authored Oct 23, 2024
1 parent 2a1b227 commit aa3d78a
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/map/handler/Map.ScrollWheelZoom.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit aa3d78a

Please sign in to comment.