From e08dc60f5f64f7ffc9ea019ae16d222b825a4f97 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Mon, 27 Apr 2020 17:40:36 +1000 Subject: [PATCH] Cleaned map interaction props and changed drawing interaction handle --- src/components/map/Map.js | 4 +--- src/components/map/MapDrawing.js | 27 +++++++++++++++++++++------ src/components/map/MapInteraction.js | 17 +++++------------ 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/components/map/Map.js b/src/components/map/Map.js index b81d7cb..3cdf25b 100644 --- a/src/components/map/Map.js +++ b/src/components/map/Map.js @@ -221,15 +221,13 @@ function Map({ {map && mapImage} {map && mapDrawing} {map && mapTokens} - {allowTokenChange && ( <> { + const map = document.querySelector(".map"); + map.addEventListener("mousedown", handleStart); + map.addEventListener("mousemove", handleMove); + map.addEventListener("mouseup", handleStop); + map.addEventListener("touchstart", handleStart); + map.addEventListener("touchmove", handleMove); + map.addEventListener("touchend", handleStop); + + return () => { + map.removeEventListener("mousedown", handleStart); + map.removeEventListener("mousemove", handleMove); + map.removeEventListener("mouseup", handleStop); + map.removeEventListener("touchstart", handleStart); + map.removeEventListener("touchmove", handleMove); + map.removeEventListener("touchend", handleStop); + }; + }); + const hoveredShapeRef = useRef(null); useEffect(() => { function pointsToPath(points) { @@ -205,12 +226,6 @@ function MapDrawing({
handleMove(e, false), }, cursorChecker: () => { - return selectedTool === "pan" && map ? "move" : "default"; + return isEnabled && map ? "move" : "default"; }, }) .on("doubletap", (event) => { event.preventDefault(); - if (selectedTool === "pan") { + if (isEnabled) { setTranslateAndScale({ x: 0, y: 0 }, 1); } }); @@ -70,7 +63,7 @@ function MapInteraction({ return () => { mapInteract.unset(); }; - }, [selectedTool, map]); + }, [isEnabled, map]); // Reset map transform when map changes useEffect(() => {