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

Dh4 toggle all layers off #1181

Merged
merged 5 commits into from
Apr 15, 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
74 changes: 74 additions & 0 deletions app/controllers/application.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Controller from '@ember/controller';
import { assign } from '@ember/polyfills';
import { computed, action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import QueryParams from '@nycplanning/ember-parachute';
import config from 'labs-zola/config/environment';
Expand Down Expand Up @@ -87,6 +88,10 @@ export default class ApplicationController extends Controller.extend(

@service mainMap;

@service metrics;

@tracked layerGroupsStorage;

// this action extracts query-param-friendly state of layer groups
// for various paramable layers
@action
Expand All @@ -98,6 +103,7 @@ export default class ApplicationController extends Controller.extend(
.sort();

this.set('layerGroups', visibleLayerGroups);
this.set('layerGroupsStorage', null);
}

@action
Expand All @@ -106,6 +112,74 @@ export default class ApplicationController extends Controller.extend(
this.handleLayerGroupChange();
}

@action
setAllLayerVisibilityToFalse() {
// save them so we can be able to reset them
const tempStorage = this.model.layerGroups
.filter(({ visible }) => visible)
.map(({ id }) => id)
.sort();

this.model.layerGroups
.filter(({ visible }) => visible)
.forEach((model) => this.toggleLayerVisibilityToFalse(model));
this.handleLayerGroupChange();

this.set('layerGroupsStorage', tempStorage);

gtag('event', 'search', {
event_category: 'Toggle Layer',
event_action: 'Toggle All Layers Off',
});

// GA
this.metrics.trackEvent('MatomoTagManager', {
category: 'Toggle Layer',
action: 'Toggle All Layers Off',
name: 'Toggle All Layers Off',
});
}

@action
undoSetAllLayerVisibilityToFalse() {
this.model.layerGroups.forEach((lg) => {
if (this.layerGroupsStorage.includes(lg.id)) {
lg.set('visible', true);
}
});

this.set('layerGroupsStorage', null);
this.handleLayerGroupChange();

gtag('event', 'search', {
event_category: 'Toggle Layer',
event_action: 'Undo Toggle All Layers Off',
});

// GA
this.metrics.trackEvent('MatomoTagManager', {
category: 'Toggle Layer',
action: 'Undo Toggle All Layers Off',
name: 'Undo Toggle All Layers Off',
});
}

@action
toggleLayerVisibilityToFalse(layer) {
layer.visible = false;
}

@computed('layerGroupsStorage', 'model.layerGroups')
get showToggleLayersBackOn() {
if (
this.model.layerGroups.filter(({ visible }) => visible).length === 0 &&
this.layerGroupsStorage
) {
return true;
}
return false;
}

@computed('queryParamsState')
get isDefault() {
const state = this.queryParamsState || {};
Expand Down
7 changes: 7 additions & 0 deletions app/styles/modules/_m-layer-palette.scss
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ $layer-palette-hover-color: rgba($dark-gray,0.08);
width: calc(100% - #{$layer-palette-padding*4});
}

//
// "Toggle All Map Layers Off" button
// --------------------------------------------------
.no-layers-button {
margin: $layer-palette-padding*3 $layer-palette-padding*2 $layer-palette-padding*2 $layer-palette-padding*2;
width: calc(100% - #{$layer-palette-padding*4});
}

//
// Indeterminate hider (hides element alongside unchecked checkbox)
Expand Down
3 changes: 3 additions & 0 deletions app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
@layerGroups={{this.model.layerGroupsObject}}
@isDefault={{this.isDefault}}
@resetQueryParams={{action this.setModelsToDefault}}
@setAllLayerVisibilityToFalse={{action this.setAllLayerVisibilityToFalse}}
@undoSetAllLayerVisibilityToFalse={{action this.undoSetAllLayerVisibilityToFalse}}
@handleLayerGroupChange={{action this.handleLayerGroupChange}}
@showToggleLayersBackOn={{this.showToggleLayersBackOn}}
/>
</div>
</div>
Expand Down
25 changes: 17 additions & 8 deletions app/templates/components/layer-palette.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@
{{/if}}
</button>
<div id="layers-menu" class="{{if this.closed "show-for-medium"}}">
{{#if this.showToggleLayersBackOn}}
<a
class="button gray small no-layers-button hide-for-print"
onclick={{action this.undoSetAllLayerVisibilityToFalse}}
data-test-reset-query-params="true">
<FaIcon @icon="undo" />
Toggle Layers Back On
</a>
{{else}}
<a
class="button gray small no-layers-button hide-for-print"
onclick={{action this.setAllLayerVisibilityToFalse}}
data-test-reset-query-params="true">
<FaIcon @icon="circle-xmark" @prefix="far" />
Toggle All Map Layers Off
</a>
{{/if}}
<LabsUiOverrides::LayerGroupsContainer
@handleToggle={{action this.handleLayerGroupToggle}}
@title="Zoning and Land Use" as |container|
Expand Down Expand Up @@ -323,13 +340,5 @@
</ul>
</container.layer-group-toggle>
</LabsUiOverrides::LayerGroupsContainer>
<a
class="button gray small reset-map-button hide-for-print"
disabled={{this.isDefault}}
onclick={{action this.resetQueryParams}}
data-test-reset-query-params="true">
<FaIcon @icon="undo" />
Reset Map Layers
</a>
</div>
{{yield}}
1 change: 1 addition & 0 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ module.exports = function (environment) {
'circle',
'dot-circle',
'square',
'circle-xmark',
],
'free-solid-svg-icons': [
'angle-up',
Expand Down
1 change: 1 addition & 0 deletions config/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = function () {
'circle',
'dot-circle',
'square',
'circle-xmark',
],
'free-solid-svg-icons': [
'angle-up',
Expand Down
Loading