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

Allow to make a layer exclusively visible by pressing ctrl when changing visibility #4061

Merged
merged 5 commits into from
May 8, 2019
Merged
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ class DatasetSettings extends React.PureComponent<DatasetSettingsProps> {
</Tooltip>
);

setVisibilityForAllLayers = (isVisible: boolean) => {
const { layers } = this.props.datasetConfiguration;
Object.keys(layers).forEach(otherLayerName =>
this.props.onChangeLayer(otherLayerName, "isDisabled", !isVisible),
);
};

isLayerExclusivelyVisible = (layerName: string): boolean => {
const { layers } = this.props.datasetConfiguration;
return Object.keys(layers).every(otherLayerName => {
const { isDisabled } = layers[otherLayerName];
return layerName === otherLayerName ? !isDisabled : isDisabled;
});
};

getColorSettings = (
[layerName, layer]: [string, DatasetLayerConfiguration],
layerIndex: number,
Expand All @@ -96,7 +111,20 @@ class DatasetSettings extends React.PureComponent<DatasetSettingsProps> {
<div style={{ display: "inline-block", marginRight: 8 }}>
<Switch
size="small"
onChange={val => this.props.onChangeLayer(layerName, "isDisabled", !val)}
onChange={(val, event) => {
if (!event.ctrlKey) {
this.props.onChangeLayer(layerName, "isDisabled", !val);
return;
}
// If ctrl is pressed, toggle between "all layers visible" and
// "only selected layer visible".
if (this.isLayerExclusivelyVisible(layerName)) {
this.setVisibilityForAllLayers(true);
} else {
this.setVisibilityForAllLayers(false);
this.props.onChangeLayer(layerName, "isDisabled", false);
}
}}
checked={!isDisabled}
/>
</div>
Expand Down