Skip to content

Commit

Permalink
Merge pull request #222 from RENCI/issue214
Browse files Browse the repository at this point in the history
Issue214 - Update sidebar layer tray to toggle raster layers like the control panel.
  • Loading branch information
lstillwe authored Sep 12, 2024
2 parents 1abc314 + d1d78fc commit b1dfaa9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
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

0 comments on commit b1dfaa9

Please sign in to comment.