Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue214 - Update sidebar layer tray to toggle raster layers like the control panel. #222

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/trays/layers/layer-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const LayerCard = ({ index, layer }) => {
const {
getLayerIcon,
swapLayers,
toggleLayerVisibility,
toggleLayerVisibility2,
} = useLayers();
const expanded = useToggleState(false);
const isVisible = layer.state.visible;
Expand Down Expand Up @@ -72,7 +72,7 @@ export const LayerCard = ({ index, layer }) => {
<Switch
size="sm"
checked={ isVisible }
onChange={ () => toggleLayerVisibility(layer.id) }
onChange={ () => toggleLayerVisibility2(layer.id) }
className="action-button"
/>
<DeleteLayerButton layerId={ layer.id }/>
Expand Down
50 changes: 50 additions & 0 deletions src/context/map-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,33 @@ export const LayersProvider = ({ children }) => {
]);
};

const toggleLayerVisibility2 = id => {
const newLayers = [...defaultModelLayers];
const index = newLayers.findIndex(l => l.id === id);
if (index === -1) {
console.error('Could not locate layer', id);
return;
}

// if this is an observation layer remove all observation layers/dialogs from the map
removeObservations(id);

const alteredLayer = newLayers[index];
alteredLayer.state.visible = !alteredLayer.state.visible;

// if we are toggle a raster layer, turn off the other raster layers
// if this is a observation layer, just leave the raster layers alone
let invisibleLayers = getAllRasterLayersInvisible();
if (alteredLayer.properties.product_type === "obs") {
invisibleLayers = [...newLayers];
}
setDefaultModelLayers([
...invisibleLayers.slice(0, index),
{ ...alteredLayer },
...invisibleLayers.slice(index + 1),
]);
};

const getAllLayersInvisible = () => {
const currentLayers = [...defaultModelLayers];

Expand Down Expand Up @@ -189,6 +216,28 @@ export const LayersProvider = ({ children }) => {
return alteredLayers;
};

// get ADCIRC raster layers as invisible
const getAllRasterLayersInvisible = () => {
const currentLayers = [...defaultModelLayers];
const alteredLayers = currentLayers
.map((layer) => {
const opacity = layer.state.opacity;
if (layer.properties.product_type !== "obs") {
return {
...layer,
state: {visible: false, opacity: opacity}
};
}
else {
return {
...layer
};
}
});

return alteredLayers;
};

const swapLayers = (i, j) => {
// ensure our pair has i < j
const [a, b] = [i, j].sort();
Expand Down Expand Up @@ -287,6 +336,7 @@ export const LayersProvider = ({ children }) => {
setHurricaneTrackLayers,
toggleHurricaneLayerVisibility,
toggleLayerVisibility,
toggleLayerVisibility2,
getAllLayersInvisible,
getAllHurricaneLayersInvisible,
selectedObservations, setSelectedObservations,
Expand Down