Skip to content

Add shortcut to toggle overlay layer visibility #11290

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2413,6 +2413,7 @@ en:
osm_data: "Toggle OpenStreetMap data"
minimap: "Toggle minimap"
highlight_edits: "Highlight unsaved edits"
overlays: "Toggle all overlays"
selecting:
title: "Selecting features"
select_one: "Select a single feature"
Expand Down
5 changes: 5 additions & 0 deletions data/shortcuts.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@
"shortcuts": ["P"],
"text": "shortcuts.browsing.enable.streetlevel"
},
{
"modifiers": ["⇧"],
"shortcuts": ["O"],
"text": "shortcuts.browsing.display_options.overlays"
},
{
"shortcuts": ["background.minimap.key"],
"text": "shortcuts.browsing.display_options.minimap"
Expand Down
34 changes: 34 additions & 0 deletions modules/ui/sections/overlay_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { uiSection } from '../section';

export function uiSectionOverlayList(context) {

let _overlaysHidden = false;
let _savedOverlays = [];

var section = uiSection('overlay-list', context)
.label(() => t.append('background.overlays'))
.disclosureContent(renderDisclosureContent);
Expand Down Expand Up @@ -37,6 +40,10 @@ export function uiSectionOverlayList(context) {

function updateLayerSelections(selection) {
function active(d) {
if (_overlaysHidden) {
// If overlays are hidden, ensure checkboxes remain checked on rerender
return _savedOverlays.includes(d);
}
return context.background().showsLayer(d);
}

Expand Down Expand Up @@ -112,6 +119,33 @@ export function uiSectionOverlayList(context) {
.call(drawListItems, 'checkbox', chooseOverlay, function(d) { return !d.isHidden() && d.overlay; });
}

/**
* Toggles overlays on/off
*/
function toggleAllOverlays(){
let overlays = context.background().overlayLayerSources();
let overlayContainer = d3_select('.disclosure-wrap-overlay_list');

if (!_overlaysHidden){
overlays.forEach(d => {
if (context.background().showsLayer(d)) {
_savedOverlays.push(d);
context.background().toggleOverlayLayer(d);
}
});
overlayContainer.classed('disabled-panel', true);
} else {
_savedOverlays.forEach(d => {
context.background().toggleOverlayLayer(d);
});
_savedOverlays = [];
overlayContainer.classed('disabled-panel', false);
}
_overlaysHidden = !_overlaysHidden;
};

context.keybinding().on('⇧O', toggleAllOverlays);

context.map()
.on('move.overlay_list',
_debounce(function() {
Expand Down