Skip to content

Commit

Permalink
support fly to, bbox and is open
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Jul 22, 2024
1 parent c9ae0af commit 01e7768
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/pages/viewer/components/LayersVTree.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<a onClick={toggle}>
Expand All @@ -74,7 +80,17 @@ function Group({ data, isOpen, toggle }) {
</Icon>
</a>
<div className="node-name">{data.name}</div>
<ComponentDropdown data={data} />
<ComponentDropdown data={data}>
{fly && data.bbox && (
<MenuItem>
<a onClick={fly}>
<Icon>
<i className="fas fa-expand"></i>
</Icon>
</a>
</MenuItem>
)}
</ComponentDropdown>
</>
);
}
Expand Down Expand Up @@ -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,
},
Expand Down
10 changes: 10 additions & 0 deletions src/pages/viewer/components/MapContextProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -148,6 +157,7 @@ export default function MapContextProvider({ mapSlug, children }) {
mapContainerRef,
updateVisibility,
flyToLayer,
flyToBounds,
setActiveBasemap,
};

Expand Down

0 comments on commit 01e7768

Please sign in to comment.