1
1
import Controller from '@ember/controller' ;
2
2
import { assign } from '@ember/polyfills' ;
3
3
import { computed , action } from '@ember/object' ;
4
+ import { tracked } from '@glimmer/tracking' ;
4
5
import { inject as service } from '@ember/service' ;
5
6
import QueryParams from '@nycplanning/ember-parachute' ;
6
7
import config from 'labs-zola/config/environment' ;
@@ -87,6 +88,10 @@ export default class ApplicationController extends Controller.extend(
87
88
88
89
@service mainMap ;
89
90
91
+ @service metrics ;
92
+
93
+ @tracked layerGroupsStorage ;
94
+
90
95
// this action extracts query-param-friendly state of layer groups
91
96
// for various paramable layers
92
97
@action
@@ -98,6 +103,7 @@ export default class ApplicationController extends Controller.extend(
98
103
. sort ( ) ;
99
104
100
105
this . set ( 'layerGroups' , visibleLayerGroups ) ;
106
+ this . set ( 'layerGroupsStorage' , null ) ;
101
107
}
102
108
103
109
@action
@@ -106,6 +112,74 @@ export default class ApplicationController extends Controller.extend(
106
112
this . handleLayerGroupChange ( ) ;
107
113
}
108
114
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
+
109
183
@computed ( 'queryParamsState' )
110
184
get isDefault ( ) {
111
185
const state = this . queryParamsState || { } ;
0 commit comments