From 00ba1a5fc1d72f0e4aab8200e31d130a60b07b8a Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Fri, 17 Jul 2020 13:04:06 +1000 Subject: [PATCH] Fixed map showing the a new maps state when loading --- src/components/map/MapInteraction.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/map/MapInteraction.js b/src/components/map/MapInteraction.js index 8b82335..32e4723 100644 --- a/src/components/map/MapInteraction.js +++ b/src/components/map/MapInteraction.js @@ -40,7 +40,7 @@ function MapInteraction({ const mapSource = useDataSource(mapSourceMap, defaultMapSources); const [mapSourceImage, mapSourceImageStatus] = useImage(mapSource); - // Create a map source that only update when the image is fully loaded + // Create a map source that only updates when the image is fully loaded const [loadedMapSourceImage, setLoadedMapSourceImage] = useState(); useEffect(() => { if (mapSourceImageStatus === "loaded") { @@ -48,6 +48,17 @@ function MapInteraction({ } }, [mapSourceImage, mapSourceImageStatus]); + // Map loaded taking in to account different resolutions + const [mapLoaded, setMapLoaded] = useState(false); + useEffect(() => { + if (map === null) { + setMapLoaded(false); + } + if (mapSourceImageStatus === "loaded") { + setMapLoaded(true); + } + }, [mapSourceImageStatus, map]); + const [stageWidth, setStageWidth] = useState(1); const [stageHeight, setStageHeight] = useState(1); const [stageScale, setStageScale] = useState(1); @@ -285,7 +296,7 @@ function MapInteraction({ > - {children} + {mapLoaded && children}