From 03181c416510ce071df94beeba5e403fa3372449 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Fri, 2 Oct 2020 18:47:20 +1000 Subject: [PATCH] Added inset to map grid --- src/components/map/MapGrid.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/components/map/MapGrid.js b/src/components/map/MapGrid.js index 54bd306..1d43e55 100644 --- a/src/components/map/MapGrid.js +++ b/src/components/map/MapGrid.js @@ -28,18 +28,25 @@ function MapGrid({ map, strokeWidth }) { x: gridX ? 1 / gridX : 0, y: gridY ? 1 / gridY : 0, }; + const gridInset = map && map.grid.inset; const { mapWidth, mapHeight } = useContext(MapInteractionContext); - const lineSpacingX = mapWidth / gridX; - const lineSpacingY = mapHeight / gridY; + const insetWidth = (gridInset.bottomRight.x - gridInset.topLeft.x) * mapWidth; + const insetHeight = + (gridInset.bottomRight.y - gridInset.topLeft.y) * mapHeight; + + const lineSpacingX = insetWidth / gridX; + const lineSpacingY = insetHeight / gridY; + + const offsetX = gridInset.topLeft.x * mapWidth * -1; + const offsetY = gridInset.topLeft.y * mapHeight * -1; const [isImageLight, setIsImageLight] = useState(true); // When the map changes find the average lightness of its pixels useEffect(() => { if (mapLoadingStatus === "loaded") { - console.log("getting lightness"); setIsImageLight(getImageLightness(mapImage)); } }, [mapImage, mapLoadingStatus]); @@ -49,7 +56,7 @@ function MapGrid({ map, strokeWidth }) { lines.push( ); } @@ -65,7 +74,7 @@ function MapGrid({ map, strokeWidth }) { lines.push( ); }