Fix bug with map transform not getting reset for map owner on change map

This commit is contained in:
Mitchell McCaffrey 2020-08-06 18:52:03 +10:00
parent 93a09db707
commit 1729abe777

View File

@ -74,9 +74,11 @@ function MapInteraction({
const stageTranslateRef = useRef({ x: 0, y: 0 }); const stageTranslateRef = useRef({ x: 0, y: 0 });
// Reset transform when map changes // Reset transform when map changes
const previousMapIdRef = useRef();
useEffect(() => { useEffect(() => {
const layer = mapLayerRef.current; 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 mapHeight = stageWidthRef.current * (map.height / map.width);
const newTranslate = { const newTranslate = {
x: 0, x: 0,
@ -89,7 +91,8 @@ function MapInteraction({
setStageScale(1); setStageScale(1);
} }
}, [map, mapLoaded]); previousMapIdRef.current = map && map.id;
}, [map]);
const pinchPreviousDistanceRef = useRef(); const pinchPreviousDistanceRef = useRef();
const pinchPreviousOriginRef = useRef(); const pinchPreviousOriginRef = useRef();