From 01e77686d9acf78462d93202fafb0f69fecce194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Cant=C3=B9?= Date: Mon, 22 Jul 2024 10:29:39 +0200 Subject: [PATCH] support fly to, bbox and is open --- src/pages/viewer/components/LayersVTree.jsx | 20 +++++++++++++++++-- .../viewer/components/MapContextProvider.jsx | 10 ++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/pages/viewer/components/LayersVTree.jsx b/src/pages/viewer/components/LayersVTree.jsx index 9d33f36..4647f38 100644 --- a/src/pages/viewer/components/LayersVTree.jsx +++ b/src/pages/viewer/components/LayersVTree.jsx @@ -66,6 +66,12 @@ function Layer({ data }) { } function Group({ data, isOpen, toggle }) { + const { flyToBounds } = useContext(MapContext); + + const fly = useMemo(() => { + return flyToBounds ? () => flyToBounds(data.bbox) : null; + }, [data.bbox, flyToBounds]); + return ( <> @@ -74,7 +80,17 @@ function Group({ data, isOpen, toggle }) {
{data.name}
- + + {fly && data.bbox && ( + + + + + + + + )} + ); } @@ -157,7 +173,7 @@ const getNodeData = (node, nestingLevel, isSmallScreen) => ({ : (Math.round(node.name.length / 80) + 1) * 30, id: node.id.toString(), // mandatory isLeaf: !node.children, - isOpenByDefault: true, // mandatory + isOpenByDefault: node.is_open, // mandatory name: node.name, nestingLevel, }, diff --git a/src/pages/viewer/components/MapContextProvider.jsx b/src/pages/viewer/components/MapContextProvider.jsx index 26a25d4..5c058cc 100644 --- a/src/pages/viewer/components/MapContextProvider.jsx +++ b/src/pages/viewer/components/MapContextProvider.jsx @@ -138,6 +138,15 @@ export default function MapContextProvider({ mapSlug, children }) { }; }, [config]); + const flyToBounds = useMemo(() => { + if (!config.zoom_to_extend) { + return null; + } + return (bounds) => { + map.current.fitBounds(bounds); + }; + }, [config]); + const setActiveBasemap = (current, next) => { map.current.setLayoutProperty(current, "visibility", "none"); map.current.setLayoutProperty(next, "visibility", "visible"); @@ -148,6 +157,7 @@ export default function MapContextProvider({ mapSlug, children }) { mapContainerRef, updateVisibility, flyToLayer, + flyToBounds, setActiveBasemap, };