Skip to content

Commit 57665c9

Browse files
Merge pull request #1181 from NYCPlanning/DH4-toggle-all-layers-off
Dh4 toggle all layers off
2 parents 41c5b37 + daf2a7b commit 57665c9

File tree

6 files changed

+103
-8
lines changed

6 files changed

+103
-8
lines changed

app/controllers/application.js

+74
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Controller from '@ember/controller';
22
import { assign } from '@ember/polyfills';
33
import { computed, action } from '@ember/object';
4+
import { tracked } from '@glimmer/tracking';
45
import { inject as service } from '@ember/service';
56
import QueryParams from '@nycplanning/ember-parachute';
67
import config from 'labs-zola/config/environment';
@@ -87,6 +88,10 @@ export default class ApplicationController extends Controller.extend(
8788

8889
@service mainMap;
8990

91+
@service metrics;
92+
93+
@tracked layerGroupsStorage;
94+
9095
// this action extracts query-param-friendly state of layer groups
9196
// for various paramable layers
9297
@action
@@ -98,6 +103,7 @@ export default class ApplicationController extends Controller.extend(
98103
.sort();
99104

100105
this.set('layerGroups', visibleLayerGroups);
106+
this.set('layerGroupsStorage', null);
101107
}
102108

103109
@action
@@ -106,6 +112,74 @@ export default class ApplicationController extends Controller.extend(
106112
this.handleLayerGroupChange();
107113
}
108114

115+
@action
116+
setAllLayerVisibilityToFalse() {
117+
// save them so we can be able to reset them
118+
const tempStorage = this.model.layerGroups
119+
.filter(({ visible }) => visible)
120+
.map(({ id }) => id)
121+
.sort();
122+
123+
this.model.layerGroups
124+
.filter(({ visible }) => visible)
125+
.forEach((model) => this.toggleLayerVisibilityToFalse(model));
126+
this.handleLayerGroupChange();
127+
128+
this.set('layerGroupsStorage', tempStorage);
129+
130+
gtag('event', 'search', {
131+
event_category: 'Toggle Layer',
132+
event_action: 'Toggle All Layers Off',
133+
});
134+
135+
// GA
136+
this.metrics.trackEvent('MatomoTagManager', {
137+
category: 'Toggle Layer',
138+
action: 'Toggle All Layers Off',
139+
name: 'Toggle All Layers Off',
140+
});
141+
}
142+
143+
@action
144+
undoSetAllLayerVisibilityToFalse() {
145+
this.model.layerGroups.forEach((lg) => {
146+
if (this.layerGroupsStorage.includes(lg.id)) {
147+
lg.set('visible', true);
148+
}
149+
});
150+
151+
this.set('layerGroupsStorage', null);
152+
this.handleLayerGroupChange();
153+
154+
gtag('event', 'search', {
155+
event_category: 'Toggle Layer',
156+
event_action: 'Undo Toggle All Layers Off',
157+
});
158+
159+
// GA
160+
this.metrics.trackEvent('MatomoTagManager', {
161+
category: 'Toggle Layer',
162+
action: 'Undo Toggle All Layers Off',
163+
name: 'Undo Toggle All Layers Off',
164+
});
165+
}
166+
167+
@action
168+
toggleLayerVisibilityToFalse(layer) {
169+
layer.visible = false;
170+
}
171+
172+
@computed('layerGroupsStorage', 'model.layerGroups')
173+
get showToggleLayersBackOn() {
174+
if (
175+
this.model.layerGroups.filter(({ visible }) => visible).length === 0 &&
176+
this.layerGroupsStorage
177+
) {
178+
return true;
179+
}
180+
return false;
181+
}
182+
109183
@computed('queryParamsState')
110184
get isDefault() {
111185
const state = this.queryParamsState || {};

app/styles/modules/_m-layer-palette.scss

+7
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ $layer-palette-hover-color: rgba($dark-gray,0.08);
131131
width: calc(100% - #{$layer-palette-padding*4});
132132
}
133133

134+
//
135+
// "Toggle All Map Layers Off" button
136+
// --------------------------------------------------
137+
.no-layers-button {
138+
margin: $layer-palette-padding*3 $layer-palette-padding*2 $layer-palette-padding*2 $layer-palette-padding*2;
139+
width: calc(100% - #{$layer-palette-padding*4});
140+
}
134141

135142
//
136143
// Indeterminate hider (hides element alongside unchecked checkbox)

app/templates/application.hbs

+3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
@layerGroups={{this.model.layerGroupsObject}}
3131
@isDefault={{this.isDefault}}
3232
@resetQueryParams={{action this.setModelsToDefault}}
33+
@setAllLayerVisibilityToFalse={{action this.setAllLayerVisibilityToFalse}}
34+
@undoSetAllLayerVisibilityToFalse={{action this.undoSetAllLayerVisibilityToFalse}}
3335
@handleLayerGroupChange={{action this.handleLayerGroupChange}}
36+
@showToggleLayersBackOn={{this.showToggleLayersBackOn}}
3437
/>
3538
</div>
3639
</div>

app/templates/components/layer-palette.hbs

+17-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@
99
{{/if}}
1010
</button>
1111
<div id="layers-menu" class="{{if this.closed "show-for-medium"}}">
12+
{{#if this.showToggleLayersBackOn}}
13+
<a
14+
class="button gray small no-layers-button hide-for-print"
15+
onclick={{action this.undoSetAllLayerVisibilityToFalse}}
16+
data-test-reset-query-params="true">
17+
<FaIcon @icon="undo" />
18+
Toggle Layers Back On
19+
</a>
20+
{{else}}
21+
<a
22+
class="button gray small no-layers-button hide-for-print"
23+
onclick={{action this.setAllLayerVisibilityToFalse}}
24+
data-test-reset-query-params="true">
25+
<FaIcon @icon="circle-xmark" @prefix="far" />
26+
Toggle All Map Layers Off
27+
</a>
28+
{{/if}}
1229
<LabsUiOverrides::LayerGroupsContainer
1330
@handleToggle={{action this.handleLayerGroupToggle}}
1431
@title="Zoning and Land Use" as |container|
@@ -323,13 +340,5 @@
323340
</ul>
324341
</container.layer-group-toggle>
325342
</LabsUiOverrides::LayerGroupsContainer>
326-
<a
327-
class="button gray small reset-map-button hide-for-print"
328-
disabled={{this.isDefault}}
329-
onclick={{action this.resetQueryParams}}
330-
data-test-reset-query-params="true">
331-
<FaIcon @icon="undo" />
332-
Reset Map Layers
333-
</a>
334343
</div>
335344
{{yield}}

config/environment.js

+1
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ module.exports = function (environment) {
382382
'circle',
383383
'dot-circle',
384384
'square',
385+
'circle-xmark',
385386
],
386387
'free-solid-svg-icons': [
387388
'angle-up',

config/icons.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = function () {
55
'circle',
66
'dot-circle',
77
'square',
8+
'circle-xmark',
89
],
910
'free-solid-svg-icons': [
1011
'angle-up',

0 commit comments

Comments
 (0)