From 1729abe777cf45c14384e099ff3680f573d72d51 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Thu, 6 Aug 2020 18:52:03 +1000 Subject: [PATCH] Fix bug with map transform not getting reset for map owner on change map --- src/components/map/MapInteraction.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/map/MapInteraction.js b/src/components/map/MapInteraction.js index ca95221..975bf59 100644 --- a/src/components/map/MapInteraction.js +++ b/src/components/map/MapInteraction.js @@ -74,9 +74,11 @@ function MapInteraction({ const stageTranslateRef = useRef({ x: 0, y: 0 }); // Reset transform when map changes + const previousMapIdRef = useRef(); useEffect(() => { const layer = mapLayerRef.current; - if (map && layer && !mapLoaded) { + const previousMapId = previousMapIdRef.current; + if (map && layer && previousMapId !== map.id) { const mapHeight = stageWidthRef.current * (map.height / map.width); const newTranslate = { x: 0, @@ -89,7 +91,8 @@ function MapInteraction({ setStageScale(1); } - }, [map, mapLoaded]); + previousMapIdRef.current = map && map.id; + }, [map]); const pinchPreviousDistanceRef = useRef(); const pinchPreviousOriginRef = useRef();