1- import get from 'lodash.get ' ;
1+ import defaultsDeep from 'lodash.defaultsdeep ' ;
22
33import no2 from './layer-no2' ;
44import no2Diff from './layer-no2-diff' ;
@@ -18,7 +18,7 @@ import waterGlSpm from './layer-wq-gl-spm';
1818import detectionPlane from './layer-detection-plane' ;
1919import agTogo from './layer-togo-ag' ;
2020
21- const layers = [
21+ const layerOverrides = [
2222 no2 ,
2323 no2Diff ,
2424 co2 ,
@@ -38,196 +38,30 @@ const layers = [
3838 agTogo
3939] ;
4040
41- export default layers ;
42-
43- const layersBySpotlight = {
44- be : [ 'no2' , 'no2-diff' , 'co2' , 'co2-diff' , 'nightlights-hd' , 'nightlights-viirs' , 'slowdown' , 'recovery' , 'detection-plane' ] ,
45- du : [ 'no2' , 'no2-diff' , 'co2' , 'co2-diff' , 'nightlights-hd' , 'nightlights-viirs' , 'slowdown' , 'recovery' ] ,
46- gh : [ 'no2' , 'no2-diff' , 'co2' , 'co2-diff' , 'nightlights-hd' , 'nightlights-viirs' , 'slowdown' , 'recovery' ] ,
47- la : [ 'no2' , 'no2-diff' , 'co2' , 'co2-diff' , 'nightlights-hd' , 'nightlights-viirs' , 'agriculture' , 'slowdown' , 'detection-ship' , 'detection-plane' , 'recovery' ] ,
48- sf : [ 'no2' , 'no2-diff' , 'co2' , 'co2-diff' , 'nightlights-hd' , 'nightlights-viirs' , 'agriculture' , 'slowdown' , 'recovery' , 'detection-ship' , 'detection-plane' , 'water-chlorophyll' , 'water-spm' ] ,
49- tk : [ 'no2' , 'no2-diff' , 'co2' , 'co2-diff' , 'nightlights-hd' , 'nightlights-viirs' , 'recovery' , 'detection-plane' ] ,
50- ny : [ 'no2' , 'no2-diff' , 'co2' , 'co2-diff' , 'nightlights-hd' , 'nightlights-viirs' , 'slowdown' , 'detection-ship' , 'detection-plane' , 'water-chlorophyll' , 'water-spm' , 'recovery' ] ,
51- togo : [ 'togo-ag' ] ,
52- wble : [ 'water-wq-gl-chl' , 'water-wq-gl-spm' ]
53- } ;
54-
55- const layerOverridesBySpotlight = {
56- be : {
57- 'nightlights-viirs' : handleNightlightsViirs ,
58- 'detection-plane' : ( l , spotlightId ) =>
59- handleInferenceTimeseries ( l , spotlightId , {
60- domain : [ '2020-01-09' , '2020-01-12' , '2020-01-14' , '2020-02-10' , '2020-02-18' , '2020-03-12' , '2020-03-13' , '2020-03-19' , '2020-04-11' , '2020-05-05' , '2020-05-14' ]
61- } )
62-
63- } ,
64- du : {
65- 'nightlights-viirs' : handleNightlightsViirs
66- } ,
67- gh : {
68- 'nightlights-viirs' : handleNightlightsViirs
69- } ,
70- la : {
71- 'nightlights-viirs' : handleNightlightsViirs ,
72- 'detection-multi' : ( l , spotlightId ) =>
73- handleInferenceTimeseries ( l , spotlightId , {
74- domain : [ '2020-01-02' , '2020-02-13' ]
75- } ) ,
76- 'detection-ship' : ( l , spotlightId ) =>
77- handleInferenceTimeseries ( l , spotlightId , {
78- domain : [ '2020-01-01' , '2020-01-06' , '2020-01-07' , '2020-01-09' , '2020-01-10' , '2020-01-12' , '2020-01-13' , '2020-01-14' , '2020-01-17' , '2020-01-18' , '2020-01-19' , '2020-01-22' , '2020-01-23' , '2020-01-24' , '2020-01-27' , '2020-01-28' , '2020-01-29' , '2020-01-30' , '2020-01-31' , '2020-02-02' , '2020-02-03' , '2020-02-27' , '2020-02-29' , '2020-03-03' , '2020-03-08' , '2020-03-15' , '2020-03-21' , '2020-03-22' , '2020-03-27' , '2020-04-23' , '2020-04-24' , '2020-05-01' , '2020-05-02' , '2020-05-03' , '2020-05-04' , '2020-05-05' , '2020-05-06' , '2020-05-07' , '2020-05-08' , '2020-05-09' , '2020-05-11' , '2020-05-12' , '2020-05-13' , '2020-05-14' , '2020-05-15' , '2020-05-16' , '2020-05-17' , '2020-05-19' , '2020-05-20' , '2020-05-21' ]
79- } ) ,
80- 'detection-plane' : ( l , spotlightId ) =>
81- handleInferenceTimeseries ( l , spotlightId , {
82- domain : [ '2020-01-10' , '2020-01-14' , '2020-02-01' , '2020-02-03' , '2020-03-22' , '2020-04-15' , '2020-04-21' , '2020-05-04' , '2020-05-05' ]
83- } )
84- } ,
85- sf : {
86- 'nightlights-viirs' : handleNightlightsViirs ,
87- 'detection-ship' : ( l , spotlightId ) =>
88- handleInferenceTimeseries ( l , spotlightId , {
89- domain : [ '2020-01-02' , '2020-01-03' , '2020-01-05' , '2020-01-07' , '2020-01-10' , '2020-01-11' , '2020-01-12' , '2020-01-13' , '2020-01-14' , '2020-01-17' , '2020-01-18' , '2020-01-23' , '2020-01-27' , '2020-01-30' , '2020-01-31' , '2020-05-01' , '2020-05-03' , '2020-05-04' , '2020-05-05' , '2020-05-06' , '2020-05-07' , '2020-05-08' , '2020-01-02' , '2020-01-03' , '2020-01-05' , '2020-01-07' , '2020-01-10' , '2020-01-11' , '2020-01-12' , '2020-01-13' , '2020-01-14' , '2020-01-17' , '2020-01-18' , '2020-01-22' , '2020-01-23' , '2020-01-27' , '2020-01-30' , '2020-01-31' , '2020-02-03' , '2020-02-27' , '2020-02-29' , '2020-03-03' , '2020-03-08' , '2020-03-10' , '2020-03-11' , '2020-04-21' , '2020-05-01' , '2020-05-03' , '2020-05-04' , '2020-05-05' , '2020-05-06' , '2020-05-07' , '2020-05-08' , '2020-05-09' , '2020-05-15' , '2020-05-16' , '2020-05-17' , '2020-05-19' , '2020-05-20' , '2020-05-21' ]
90- } ) ,
91- 'water-chlorophyll' : ( l , spotlightId ) => {
92- return {
93- ...l ,
94- domain : [ '2020-03-02' , '2020-04-03' , '2020-04-19' , '2020-05-04' , '2020-05-05' , '2020-05-19' , '2020-05-21' , '2020-05-24' , '2020-06-01' , '2020-06-03' , '2020-06-06' , '2020-06-13' , '2020-06-18' , '2020-06-21' , '2020-06-22' , '2020-06-23' , '2020-06-26' , '2020-06-28' , '2020-07-01' , '2020-07-03' , '2020-07-06' , '2020-07-08' , '2020-07-13' ]
95- } ;
96- } ,
97- 'water-spm' : ( l , spotlightId ) => {
98- return {
99- ...l ,
100- domain : [ '2020-03-02' , '2020-04-03' , '2020-04-19' , '2020-05-04' , '2020-05-05' , '2020-05-21' , '2020-05-24' , '2020-05-28' , '2020-06-01' , '2020-06-03' , '2020-06-06' , '2020-06-13' , '2020-06-21' , '2020-06-22' , '2020-06-23' , '2020-06-25' , '2020-06-28' , '2020-07-01' , '2020-07-03' ]
101- } ;
102- } ,
103- 'detection-plane' : ( l , spotlightId ) =>
104- handleInferenceTimeseries ( l , spotlightId , {
105- domain : [ '2020-01-11' , '2020-01-12' , '2020-01-13' , '2020-02-06' , '2020-02-07' , '2020-02-10' , '2020-02-15' , '2020-02-18' , '2020-02-20' , '2020-03-09' , '2020-03-10' , '2020-03-12' , '2020-03-19' , '2020-04-02' , '2020-04-03' , '2020-04-07' , '2020-04-15' , '2020-04-22' , '2020-05-04' , '2020-05-05' , '2020-05-07' , '2020-05-19' ]
106- } )
107- } ,
108- tk : {
109- 'nightlights-viirs' : handleNightlightsViirs ,
110- 'water-chlorophyll' : ( l , spotlightId ) => {
111- return {
112- ...l ,
113- domain : [ '2018-01-03' , '2018-01-10' , '2018-01-17' , '2018-01-24' , '2018-01-31' , '2018-02-14' , '2018-02-21' , '2018-03-07' , '2018-03-14' , '2018-03-28' , '2018-04-04' , '2018-04-11' , '2018-04-18' , '2018-04-25' , '2018-05-02' , '2018-05-09' , '2018-05-16' , '2018-05-30' , '2018-06-20' , '2018-06-27' , '2018-07-04' , '2018-07-11' , '2018-07-18' , '2018-07-25' , '2018-08-01' , '2018-08-08' , '2018-08-22' , '2018-09-05' , '2018-09-12' , '2018-09-19' , '2018-09-26' , '2018-10-03' , '2018-10-17' , '2018-10-24' , '2018-11-07' , '2018-11-14' , '2018-11-21' , '2018-11-28' , '2018-12-12' , '2018-12-19' , '2018-12-26' , '2019-01-02' , '2019-01-09' , '2019-01-16' , '2019-01-23' , '2019-01-30' , '2019-02-13' , '2019-02-27' , '2019-03-06' , '2019-03-13' , '2019-03-20' , '2019-03-27' , '2019-04-03' , '2019-04-10' , '2019-05-08' , '2019-05-15' , '2019-05-22' , '2019-05-29' , '2019-06-12' , '2019-06-19' , '2019-07-24' , '2019-07-31' , '2019-08-07' , '2019-08-14' , '2019-08-21' , '2019-08-28' , '2019-09-04' , '2019-09-11' , '2019-09-25' , '2019-10-02' , '2019-10-09' , '2019-10-23' , '2019-10-30' , '2019-11-06' , '2019-11-13' , '2019-11-20' , '2019-11-27' , '2019-12-11' , '2019-12-18' , '2019-12-25' , '2020-01-01' , '2020-01-08' , '2020-01-15' , '2020-01-29' , '2020-02-05' , '2020-02-19' , '2020-02-26' , '2020-03-04' , '2020-03-18' , '2020-03-25' , '2020-04-01' , '2020-04-08' , '2020-04-15' , '2020-04-29' , '2020-05-06' , '2020-05-13' , '2020-05-20' , '2020-06-03' , '2020-06-10' , '2020-06-13' , '2020-07-25' , '2020-08-01' , '2020-08-08' , '2020-08-15' ] ,
114- source : {
115- ...l . source ,
116- tiles : l . source . tiles . map ( t => t . replace ( '&rescale=-100%2C100' , '' ) )
117- }
118- } ;
119- } ,
120- 'detection-plane' : ( l , spotlightId ) =>
121- handleInferenceTimeseries ( l , spotlightId , {
122- domain : [ '2020-01-19' , '2020-02-01' , '2020-02-05' , '2020-03-18' , '2020-03-19' , '2020-04-09' , '2020-04-10' , '2020-05-02' ]
123- } )
124- } ,
125- ny : {
126- 'nightlights-viirs' : handleNightlightsViirs ,
127- 'water-chlorophyll' : ( l , spotlightId ) => {
128- return {
129- ...l ,
130- domain : [ '2020-01-01' , '2020-01-08' , '2020-01-15' , '2020-01-22' , '2020-01-29' , '2020-02-05' , '2020-02-12' , '2020-02-19' , '2020-02-26' , '2020-03-04' , '2020-03-11' , '2020-03-18' , '2020-03-25' , '2020-04-01' , '2020-04-08' , '2020-04-15' , '2020-04-22' , '2020-04-29' , '2020-05-06' , '2020-05-13' , '2020-05-20' , '2020-05-27' , '2020-06-03' , '2020-06-10' , '2020-06-17' , '2020-06-24' , '2020-07-01' , '2020-07-08' , '2020-07-15' , '2020-07-22' , '2020-07-29' , '2020-08-05' , '2020-08-12' , '2020-09-02' , '2020-09-09' , '2020-09-16' , '2020-09-23' , '2020-09-30' ]
131- } ;
132- } ,
133- 'detection-ship' : ( l , spotlightId ) =>
134- handleInferenceTimeseries ( l , spotlightId , {
135- domain : [ '2020-01-02' , '2020-01-09' , '2020-01-11' , '2020-01-16' , '2020-01-17' , '2020-01-19' , '2020-01-23' , '2020-01-24' , '2020-01-30' , '2020-05-02' , '2020-05-05' , '2020-01-02' , '2020-01-09' , '2020-01-11' , '2020-01-16' , '2020-01-17' , '2020-01-19' , '2020-01-20' , '2020-01-21' , '2020-01-22' , '2020-01-23' , '2020-01-24' , '2020-01-30' , '2020-02-02' , '2020-02-03' , '2020-02-29' , '2020-03-08' , '2020-03-18' , '2020-03-22' , '2020-03-27' , '2020-05-02' , '2020-05-05' , '2020-05-09' , '2020-05-10' , '2020-05-13' , '2020-05-14' , '2020-05-16' , '2020-05-19' , '2020-05-20' , '2020-05-21' ]
136- } ) ,
137- 'water-spm' : ( l , spotlightId ) => {
138- return {
139- ...l ,
140- domain : [ '2020-01-01' , '2020-01-08' , '2020-01-15' , '2020-01-22' , '2020-01-29' , '2020-02-05' , '2020-02-12' , '2020-02-19' , '2020-02-26' , '2020-03-04' , '2020-03-11' , '2020-03-18' , '2020-03-25' , '2020-04-01' , '2020-04-08' , '2020-04-15' , '2020-04-22' , '2020-04-29' , '2020-05-06' , '2020-05-13' , '2020-05-20' , '2020-05-27' , '2020-06-03' , '2020-06-10' , '2020-06-17' , '2020-06-24' , '2020-07-01' , '2020-07-08' , '2020-07-15' , '2020-07-22' , '2020-07-29' , '2020-08-05' , '2020-08-12' , '2020-09-02' , '2020-09-09' , '2020-09-16' , '2020-09-23' , '2020-09-30' ]
141- } ;
142- } ,
143- 'nightlights-hd' : ( l , spotlightId ) => {
144- return {
145- ...l ,
146- // For NY, nightlights goes till June
147- domain : [ l . domain [ 0 ] , '2020-06-01' ]
148- } ;
149- } ,
150- 'detection-plane' : ( l , spotlightId ) =>
151- handleInferenceTimeseries ( l , spotlightId , {
152- domain : [ '2020-01-16' , '2020-01-20' , '2020-02-17' , '2020-02-19' , '2020-03-09' , '2020-03-15' , '2020-04-06' , '2020-04-15' , '2020-05-05' , '2020-05-14' ]
153- } )
154- }
155- } ;
41+ // Store the layer data.
42+ const layersDataBySpotlight = { } ;
15643
15744export function getSpotlightLayers ( spotlightId ) {
158- const layersToUse = layersBySpotlight [ spotlightId ] || [ ] ;
159-
160- // Filter by the layers to include &
161- // Replace the {site} property on the layers
162- return layers
163- . filter ( ( l ) => layersToUse . includes ( l . id ) )
164- . map ( ( layer ) => {
165- let l = handleSpotlightId ( layer , spotlightId ) ;
166-
167- // Apply override function if it exists
168- const overrideFn = get ( layerOverridesBySpotlight , [ spotlightId , l . id ] ) ;
169- l = overrideFn ? overrideFn ( l , spotlightId ) : l ;
170-
171- return l ;
172- } ) ;
45+ return layersDataBySpotlight [ spotlightId ] ;
17346}
17447
17548export function getGlobalLayers ( ) {
176- const layersToUse = [ 'no2' , 'no2-diff' , 'co2' , 'co2-diff' , 'gibs-population' , 'agriculture' ] ;
177- return layers . filter ( ( l ) => layersToUse . includes ( l . id ) ) ;
49+ return layersDataBySpotlight . global ;
17850}
17951
180- // // // // // // // // // // // // // // // // // // // // // // // // // // //
181- // // // // // // // // // // // // // // // // // // // // // // // // // // //
182- // Layer helper functions below.
183-
184- function handleSpotlightId ( l , spotlightId ) {
185- // If we're dealing with a layer with a standard source, replace the
186- // spotlightId in the source tiles. Other layers will be handled by the
187- // override functions.
188- const tiles = get ( l , 'source.tiles' ) ;
189- return tiles
190- ? {
191- ...l ,
192- source : {
193- ...l . source ,
194- tiles : tiles . map ( ( t ) => t . replace ( '{spotlightId}' , spotlightId ) )
195- }
196- }
197- : l ;
198- }
52+ export const storeSpotlightLayers = ( spotlightId , layers ) => {
53+ if ( spotlightId === 'global' ) {
54+ layersDataBySpotlight [ spotlightId ] = layers ;
55+ return ;
56+ }
19957
200- function handleNightlightsViirs ( l , spotlightId ) {
201- const spotlightName = spotlightId === 'du' || spotlightId === 'gh'
202- ? 'EUPorts'
203- : spotlightId ;
58+ // Overrides to the layer settings.
59+ const spotLayers = layers
60+ . map ( ( layer ) => {
61+ const overrides = layerOverrides . find ( l => l . id === layer . id ) || { } ;
20462
205- return {
206- ...l ,
207- source : {
208- ...l . source ,
209- tiles : l . source . tiles . map ( ( t ) =>
210- t . replace ( '{spotlightName}' , spotlightName )
211- )
212- }
213- } ;
214- }
63+ return defaultsDeep ( layer , overrides ) ;
64+ } ) ;
21565
216- function handleInferenceTimeseries ( l , spotlightId , options ) {
217- return {
218- ...l ,
219- domain : options . domain ,
220- source : {
221- ...l . source ,
222- vector : {
223- ...l . source . vector ,
224- data : l . source . vector . data . replace ( '{spotlightId}' , spotlightId )
225- } ,
226- raster : {
227- ...l . source . raster ,
228- tiles : l . source . raster . tiles
229- . map ( t => t . replace ( '{spotlightId}' , spotlightId ) )
230- }
231- }
232- } ;
233- }
66+ layersDataBySpotlight [ spotlightId ] = spotLayers ;
67+ } ;
0 commit comments