Skip to content

Commit

Permalink
Fix NavigationControl compass regression (#5205)
Browse files Browse the repository at this point in the history
* Fix NavigationControl compass regression

* Corrected string quotation style

* Changed the check for TouchEvent availability

* Changed TouchEvent check to not require window

* Revised based on review feedback.

* Added CHANGELOG entry
  • Loading branch information
raboczi authored Dec 15, 2024
1 parent f1a70c0 commit 414e474
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
### 🐞 Bug fixes
- Fix globe custom layers being supplied incorrect matrices after projection transition to mercator ([#5150](https://github.com/maplibre/maplibre-gl-js/pull/5150))
- Fix custom 3D models disappearing during projection transition ([#5150](https://github.com/maplibre/maplibre-gl-js/pull/5150))
- Fix regression in NavigationControl compass on Firefox and Safari browsers ([#5205](https://github.com/maplibre/maplibre-gl-js/pull/5205))
- _...Add new stuff here..._

## 5.0.0-pre.9
Expand Down
34 changes: 24 additions & 10 deletions src/ui/handler/drag_move_state_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,38 @@ export class MouseOrTouchMoveStateManager implements DragMoveStateManager<MouseE
private oneFingerTouchMoveStateManager = new OneFingerTouchMoveStateManager()
) {}

_executeRelevantHandler(e: MouseEvent | TouchEvent, onMouseEvent: (MouseEvent) => any, onTouchEvent: (TouchEvent) => any) {
if (e instanceof MouseEvent) return onMouseEvent(e);
if (typeof TouchEvent !== 'undefined' && e instanceof TouchEvent) return onTouchEvent(e);
}

startMove(e: MouseEvent | TouchEvent) {
if (e instanceof MouseEvent) this.mouseMoveStateManager.startMove(e);
if (e instanceof TouchEvent) this.oneFingerTouchMoveStateManager.startMove(e);
this._executeRelevantHandler(e,
e => this.mouseMoveStateManager.startMove(e),
e => this.oneFingerTouchMoveStateManager.startMove(e));
}

endMove(e?: MouseEvent | TouchEvent) {
if (e instanceof MouseEvent) this.mouseMoveStateManager.endMove(e);
if (e instanceof TouchEvent) this.oneFingerTouchMoveStateManager.endMove(e);
this._executeRelevantHandler(e,
e => this.mouseMoveStateManager.endMove(e),
e => this.oneFingerTouchMoveStateManager.endMove(e));
}

isValidStartEvent(e: MouseEvent | TouchEvent) {
if (e instanceof MouseEvent) return this.mouseMoveStateManager.isValidStartEvent(e);
if (e instanceof TouchEvent) return this.oneFingerTouchMoveStateManager.isValidStartEvent(e);
return this._executeRelevantHandler(e,
e => this.mouseMoveStateManager.isValidStartEvent(e),
e => this.oneFingerTouchMoveStateManager.isValidStartEvent(e));
}

isValidMoveEvent(e: MouseEvent | TouchEvent) {
if (e instanceof MouseEvent) return this.mouseMoveStateManager.isValidMoveEvent(e);
if (e instanceof TouchEvent) return this.oneFingerTouchMoveStateManager.isValidMoveEvent(e);
return this._executeRelevantHandler(e,
e => this.mouseMoveStateManager.isValidMoveEvent(e),
e => this.oneFingerTouchMoveStateManager.isValidMoveEvent(e));
}

isValidEndEvent(e?: MouseEvent | TouchEvent) {
if (e instanceof MouseEvent) return this.mouseMoveStateManager.isValidEndEvent(e);
if (e instanceof TouchEvent) return this.oneFingerTouchMoveStateManager.isValidEndEvent(e);
return this._executeRelevantHandler(e,
e => this.mouseMoveStateManager.isValidEndEvent(e),
e => this.oneFingerTouchMoveStateManager.isValidEndEvent(e));
}
}

0 comments on commit 414e474

Please sign in to comment.