Skip to content

Commit

Permalink
add zoom to layer
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Jun 25, 2024
1 parent 0f6aac2 commit 55f456d
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/pages/viewer/components/Layers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import { MapContext, ModalContext } from "../contexts";
import LegendSymbol from "./LegendSymbol";
import { Button } from "react-bulma-components";

function flyToLayer(map, layer) {
if (map && layer && layer.source) {
let bounds = map.getSource(layer.source).bounds;
map.fitBounds(bounds);
map.zoomOut();
}
}

function Layer({ node }) {
const { map, layers, lazy, config, visibleLayers } = useContext(MapContext);
const layer = layers[node.data.id];
Expand Down Expand Up @@ -38,11 +46,18 @@ function Layer({ node }) {
}, [layer, lazy])

return (
<div onClick={updateVisibility} style={{ flexGrow: 1, display: 'flex', alignItems: 'center' }}>
<i className={icon}></i>
<div style={{ width: '17px', height: '17px', margin: '0 0.5rem' }}>{legend}</div>
<div>{node.data.name}</div>
</div>
<>
<div onClick={updateVisibility} style={{ flexGrow: 1, display: 'flex', alignItems: 'center' }}>
<i className={icon}></i>
<div style={{ width: '17px', height: '17px', margin: '0 0.5rem' }}>{legend}</div>
<div>{node.data.name}</div>
</div>
{config && config.zoom_to_extend && map && layer && layer.isVisible && layer.source && (
<div>
<Button size="small" text onClick={() => flyToLayer(map, layer)}><i className="fas fa-expand"></i></Button>
</div>
)}
</>
);
}

Expand Down

0 comments on commit 55f456d

Please sign in to comment.