From de6d3aa5dc0ca81484cd21e54f9da516298deb1a Mon Sep 17 00:00:00 2001
From: dominik-korsa <29484605+dominik-korsa@users.noreply.github.com>
Date: Wed, 23 Jul 2025 00:44:13 +0200
Subject: [PATCH] Use ZoomPanEmitter/Subscriber instead of a context for
aligning the view
---
src/components/map/ZoomPanWrapper.js | 60 +++++++++----------
.../map/object-renderers/TrackRenderer.js | 8 +--
src/contexts/ZoomPanContext.js | 4 --
src/hooks/useZoomPubSub.js | 18 +++++-
4 files changed, 48 insertions(+), 42 deletions(-)
delete mode 100644 src/contexts/ZoomPanContext.js
diff --git a/src/components/map/ZoomPanWrapper.js b/src/components/map/ZoomPanWrapper.js
index b28b95b..2a5295e 100644
--- a/src/components/map/ZoomPanWrapper.js
+++ b/src/components/map/ZoomPanWrapper.js
@@ -3,7 +3,6 @@ import './ZoomPanWrapper.css';
import Constants from '../../helpers/constants';
import { useZoomPanSubscriber, viewBox$, clientRect$, camera$ } from '../../hooks/useZoomPubSub';
import {mapRotation$} from '../../services/mapRotationService';
-import ZoomPanContext from "../../contexts/ZoomPanContext";
import AngleHelper from "../../helpers/angleHelper";
export default function ZoomPanWrapper({children}) {
@@ -91,8 +90,19 @@ export default function ZoomPanWrapper({children}) {
scheduleCameraUpdate();
}, [scheduleCameraUpdate]);
- // Subscribe to any external "center" calls
- useZoomPanSubscriber(centerOn);
+ const alignView = (angleDeg) => {
+ // Find such relative rotation in the range [-45, 45] degrees that aligns the track
+ // with y rotation angleDeg to the X or Y screen axis.
+ const angleDifference = -angleDeg - cameraRef.current.rotation;
+ let deltaAngle = AngleHelper.normalizeDegAngle(angleDifference, 90);
+ if (deltaAngle > 45) deltaAngle -= 90;
+
+ cameraRef.current.rotation += deltaAngle;
+ scheduleCameraUpdate();
+ };
+
+ // Subscribe to any external `center` and `alignView` calls
+ useZoomPanSubscriber(centerOn, alignView);
const onWheel = (e) => {
const { left, top } = clientRectRef.current;
@@ -149,35 +159,21 @@ export default function ZoomPanWrapper({children}) {
isMouseDownRef.current = false;
};
- // `event` could be used in the future to perform the rotation around the click position
- const alignView = (angleDeg, _event) => {
- // Find such relative rotation in the range [-45, 45] degrees that aligns the track
- // with y rotation angleDeg to the X or Y screen axis.
- const angleDifference = -angleDeg - cameraRef.current.rotation;
- let deltaAngle = AngleHelper.normalizeDegAngle(angleDifference, 90);
- if (deltaAngle > 45) deltaAngle -= 90;
-
- cameraRef.current.rotation += deltaAngle;
- scheduleCameraUpdate();
- };
-
return (
-