-
Notifications
You must be signed in to change notification settings - Fork 26
/
eo-timeseries-explorer.js
757 lines (653 loc) · 20.7 KB
/
eo-timeseries-explorer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
/**
* @license
* Copyright 2021 Justin Braaten
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// #############################################################################
// ### IMPORT MODULES ###
// #############################################################################
// RGB time series charting module: https://github.com/jdbcode/ee-rgb-timeseries
var rgbTs = require(
'users/jstnbraaten/modules:rgb-timeseries/rgb-timeseries.js');
// #############################################################################
// ### GET URL PARAMS ###
// #############################################################################
var initRun = 'false';
var runUrl = ui.url.get('run', initRun);
ui.url.set('run', runUrl);
var initSensor = 'Sentinel-2 SR';
var sensorUrl = ui.url.get('sensor', initSensor);
ui.url.set('sensor', sensorUrl);
var initLon = -121.68804;
var lonUrl = ui.url.get('lon', initLon);
ui.url.set('lon', lonUrl);
var initLat = 36.46517;
var latUrl = ui.url.get('lat', initLat);
ui.url.set('lat', latUrl);
var initIndex = 'NBR';
var indexUrl = ui.url.get('index', initIndex);
ui.url.set('index', indexUrl);
var initRgb = 'SWIR1/NIR/GREEN';
var rgbUrl = ui.url.get('rgb', initRgb);
ui.url.set('rgb', rgbUrl);
var initDuration = 12;
var durationUrl = ui.url.get('duration', initDuration);
ui.url.set('duration', durationUrl);
var initCloud = 30;
var cloudUrl = ui.url.get('cloud', initCloud);
ui.url.set('cloud', cloudUrl);
var initChipWidth = 2;
var chipWidthUrl = ui.url.get('chipwidth', initChipWidth);
ui.url.set('chipwidth', chipWidthUrl);
// #############################################################################
// ### DEFINE UI ELEMENTS ###
// #############################################################################
// Style.
var CONTROL_PANEL_WIDTH = '280px';
var CONTROL_PANEL_WIDTH_HIDE = '141px';
var textFont = {fontSize: '12px'};
var headerFont = {
fontSize: '13px', fontWeight: 'bold', margin: '4px 8px 0px 8px'};
var sectionFont = {
fontSize: '16px', color: '#808080', margin: '16px 8px 0px 8px'};
var infoFont = {fontSize: '11px', color: '#505050'};
// Control panel.
var controlPanel = ui.Panel({
style: {position: 'top-left', width: CONTROL_PANEL_WIDTH_HIDE,
maxHeight: '90%'
}});
// Info panel.
var infoElements = ui.Panel(
{style: {shown: false, margin: '0px -8px 0px -8px'}});
// Element panel.
var controlElements = ui.Panel(
{style: {shown: false, margin: '0px -8px 0px -8px'}});
// Instruction panel.
var instr = ui.Label('Click on a location',
{fontSize: '15px', color: '#303030', margin: '0px 0px 6px 0px'});
// Show/hide info panel button.
var infoButton = ui.Button(
{label: 'About ❯', style: {margin: '0px 4px 0px 0px'}});
// Show/hide control panel button.
var controlButton = ui.Button(
{label: 'Options ❯', style: {margin: '0px 0px 0px 0px'}});
// Info/control button panel.
var buttonPanel = ui.Panel(
[infoButton, controlButton],
ui.Panel.Layout.Flow('horizontal'),
{stretch: 'horizontal', margin: '0px 0px 0px 0px'});
// Options label.
var optionsLabel = ui.Label('Options', sectionFont);
optionsLabel.style().set('margin', '16px 8px 2px 8px');
// Information label.
var infoLabel = ui.Label('About', sectionFont);
// Information text.
var aboutLabel = ui.Label(
'This app shows a time series chart and image chips for selected ' +
'datasets and locations for images collected within two years of today. Time series ' +
'point colors are defined by RGB assignment to selected bands where ' +
'intensity is based on the area-weighted mean pixel value within a radius ' +
'around the clicked point in the map (30 m for Sentinel-2, 45 m for Landsat-8/9).',
infoFont);
var appCodeLink = ui.Label({
value: 'App source code',
style: {fontSize: '11px', color: '#505050', margin: '-4px 8px 0px 8px'},
targetUrl: 'https://github.com/jdbcode/ee-rgb-timeseries/blob/main/eo-timeseries-explorer.js'
});
// Sensor selection.
var sensorLabel = ui.Label({value: 'Sensor selection', style: headerFont});
var sensorList = ['Sentinel-2 SR', 'Sentinel-2 TOA',
'Landsat-8/9 SR', 'Landsat-8/9 TOA'];
var sensorSelect = ui.Select({
items: sensorList, placeholder: ui.url.get('sensor'),
value: ui.url.get('sensor'), style: {stretch: 'horizontal'}
});
var sensorPanel = ui.Panel([sensorLabel, sensorSelect], null, {stretch: 'horizontal'});
// Y-axis index selection.
var indexLabel = ui.Label('Y-axis index', headerFont);
var indexList = ['NBR', 'NDVI', 'Blue', 'Green', 'Red',
'NIR', 'SWIR1', 'SWIR2'];
var indexSelect = ui.Select(
{items: indexList, value: ui.url.get('index'), style: {stretch: 'horizontal'}});
var indexPanel = ui.Panel(
[indexLabel, indexSelect], null, {stretch: 'horizontal'});
// RGB bands selection.
var rgbLabel = ui.Label({value: 'RGB visualization', style: headerFont});
var rgbList = ['SWIR1/NIR/GREEN', 'RED/GREEN/BLUE', 'NIR/RED/GREEN',
'NIR/SWIR1/RED'];
var rgbSelect = ui.Select({
items: rgbList, placeholder: ui.url.get('rgb'),
value: ui.url.get('rgb'), style: {stretch: 'horizontal'}
});
var rgbPanel = ui.Panel([rgbLabel, rgbSelect], null, {stretch: 'horizontal'});
// Duration.
var durationLabel = ui.Label(
{value: 'Duration (months prior)', style: headerFont});
var durationSlider = ui.Slider({
min: 1, max: 24 , value: parseInt(ui.url.get('duration')),
step: 1, style: {stretch: 'horizontal'}
});
var durationPanel = ui.Panel(
[durationLabel, durationSlider], null, {stretch: 'horizontal'});
// Cloud threshold.
var cloudLabel = ui.Label(
{value: 'Cloud threshold % (exclude >)', style: headerFont});
var cloudSlider = ui.Slider({
min: 0, max: 100 , value: parseInt(ui.url.get('cloud')),
step: 1, style: {stretch: 'horizontal'}
});
var cloudPanel = ui.Panel(
[cloudLabel, cloudSlider], null, {stretch: 'horizontal'});
// Region buffer.
var regionWidthLabel = ui.Label(
{value: 'Image chip width (km)', style: headerFont});
var regionWidthSlider = ui.Slider({
min: 1, max: 10 , value: parseInt(ui.url.get('chipwidth')),
step: 1, style: {stretch: 'horizontal'}
});
var regionWidthPanel = ui.Panel(
[regionWidthLabel, regionWidthSlider], null, {stretch: 'horizontal'});
// A message to wait for image chips to load.
var waitMsgImgPanel = ui.Label({
value: '⚙️' + ' Processing, please wait.',
style: {
stretch: 'horizontal',
textAlign: 'center',
backgroundColor: '#d3d3d3'
}
});
// Panel to hold the chart.
var chartPanel = ui.Panel({style: {height: '25%'}});
// Holder for image cards.
var imgCardPanel = ui.Panel({
layout: ui.Panel.Layout.flow('horizontal', true),
style: {width: '897px', backgroundColor: '#d3d3d3'}
});
// Map widget.
var map = ui.Map();
// Map/chart panel
var mapChartSplitPanel = ui.Panel(ui.SplitPanel({
firstPanel: map, //
secondPanel: chartPanel,
orientation: 'vertical',
wipe: false,
}));
// Map/chart and image card panel
var splitPanel = ui.SplitPanel(mapChartSplitPanel, imgCardPanel);
// Submit changes button.
var submitButton = ui.Button({
label: 'Submit changes',
style: {stretch: 'horizontal', shown: false}
});
// #############################################################################
// ### DEFINE INITIALIZING CONSTANTS ###
// #############################################################################
// Set color of the circle to show on map and images where clicked
var AOI_COLOR = 'ffffff'; //'b300b3';
var COORDS = null;
var CLICKED = false;
// Set region reduction and chart params.
var OPTIONAL_PARAMS = {
reducer: ee.Reducer.mean(),
scale: 20,
crs: 'EPSG:4326',
chartParams: {
pointSize: 11,
legend: {position: 'none'},
hAxis: {title: 'Date', titleTextStyle: {italic: false, bold: true}},
vAxis: {
title: indexSelect.getValue(),
titleTextStyle: {italic: false, bold: true}
},
explorer: {axis: 'horizontal'}
}
};
var sensorInfo = {
'Landsat-8/9 SR': {
id: 'LANDSAT/LC08/C02/T1_L2',
scale: 30,
aoiRadius: 45,
index: {
NBR: 'NBR',
NDVI: 'NDVI',
Blue: 'SR_B2',
Green: 'SR_B3',
Red: 'SR_B4',
NIR: 'SR_B5',
SWIR1: 'SR_B6',
SWIR2: 'SR_B7'
},
rgb: {
'SWIR1/NIR/GREEN': {
bands: ['SR_B6', 'SR_B5', 'SR_B3'],
min: [0.01, 0.01 , 0.01],
max: [0.47, 0.47, 0.47],
gamma: [1, 1, 1]
},
'RED/GREEN/BLUE': {
bands: ['SR_B4', 'SR_B3', 'SR_B2'],
min: [0.05, 0.05, 0.05],
max: [0.25, 0.25, 0.25],
gamma: [1.3, 1.3, 1.3]
},
'NIR/RED/GREEN': {
bands: ['SR_B5', 'SR_B4', 'SR_B3'],
min: [0.01, 0.01, 0.01],
max: [0.47, 0.47, 0.47],
gamma: [1, 1, 1]
},
'NIR/SWIR1/RED': {
bands: ['SR_B5', 'SR_B6', 'SR_B3'],
min: [0.01, 0.01, 0.01],
max: [0.47, 0.47, 0.47],
gamma: [1, 1, 1]
}
}
},
'Landsat-8/9 TOA': {
id: 'LANDSAT/LC08/C02/T1_TOA',
scale: 30,
aoiRadius: 45,
index: {
NBR: 'NBR',
NDVI: 'NDVI',
Blue: 'B2',
Green: 'B3',
Red: 'B4',
NIR: 'B5',
SWIR1: 'B6',
SWIR2: 'B7'
},
rgb: {
'SWIR1/NIR/GREEN': {
bands: ['B6', 'B5', 'B3'],
min: [0.01, 0.01 , 0.01],
max: [0.47, 0.47, 0.47],
gamma: [1, 1, 1]
},
'RED/GREEN/BLUE': {
bands: ['B4', 'B3', 'B2'],
min: [0.01, 0.01, 0.01],
max: [0.25, 0.25, 0.25],
gamma: [1.3, 1.3, 1.3]
},
'NIR/RED/GREEN': {
bands: ['B5', 'B4', 'B3'],
min: [0.01, 0.01 , 0.01],
max: [0.47, 0.47, 0.47],
gamma: [1, 1, 1]
},
'NIR/SWIR1/RED': {
bands: ['B5', 'B6', 'B3'],
min: [0.01, 0.01 , 0.01],
max: [0.47, 0.47, 0.47],
gamma: [1, 1, 1]
}
}
},
'Sentinel-2 SR': {
id: 'COPERNICUS/S2_SR_HARMONIZED',
scale: 20,
aoiRadius: 30,
index: {
NBR: 'NBR',
NDVI: 'NDVI',
Blue: 'B2',
Green: 'B3',
Red: 'B4',
NIR: 'B8',
SWIR1: 'B11',
SWIR2: 'B12'
},
rgb: {
'SWIR1/NIR/GREEN': {
bands: ['B11', 'B8', 'B3'],
min: [100, 100 , 100],
max: [4700, 4700, 4700],
gamma: [1, 1, 1]
},
'RED/GREEN/BLUE': {
bands: ['B4', 'B3', 'B2'],
min: [100, 100, 100],
max: [2500, 2500, 2500],
gamma: [1.3, 1.3, 1.3]
},
'NIR/RED/GREEN': {
bands: ['B8', 'B4', 'B3'],
min: [100, 100 , 100],
max: [4700, 4700, 4700],
gamma: [1, 1, 1]
},
'NIR/SWIR1/RED': {
bands: ['B8', 'B11', 'B3'],
min: [100, 100 , 100],
max: [4700, 4700, 4700],
gamma: [1, 1, 1]
}
}
},
'Sentinel-2 TOA': {
id: 'COPERNICUS/S2_HARMONIZED',
scale: 20,
aoiRadius: 30,
index: {
NBR: 'NBR',
NDVI: 'NDVI',
Blue: 'B2',
Green: 'B3',
Red: 'B4',
NIR: 'B8',
SWIR1: 'B11',
SWIR2: 'B12'
},
rgb: {
'SWIR1/NIR/GREEN': {
bands: ['B11', 'B8', 'B3'],
min: [100, 100 , 100],
max: [4700, 4700, 4700],
gamma: [1, 1, 1]
},
'RED/GREEN/BLUE': {
bands: ['B4', 'B3', 'B2'],
min: [100, 100, 100],
max: [2500, 2500, 2500],
gamma: [1.2, 1.2, 1.2]
},
'NIR/RED/GREEN': {
bands: ['B8', 'B4', 'B3'],
min: [100, 100 , 100],
max: [4700, 4700, 4700],
gamma: [1, 1, 1]
},
'NIR/SWIR1/RED': {
bands: ['B8', 'B11', 'B3'],
min: [100, 100 , 100],
max: [4700, 4700, 4700],
gamma: [1, 1, 1]
}
}
}
};
// #############################################################################
// ### DEFINE FUNCTIONS ###
// #############################################################################
/**
* Ccloud masks OLI images.
*/
function prepOliSr(img) {
var opticalBands = img.select('SR_B.').multiply(0.0000275).add(-0.2);
img = img.addBands(opticalBands, null, true);
var nbr = img.normalizedDifference(['SR_B5', 'SR_B7']).rename(['NBR']);
var ndvi = img.normalizedDifference(['SR_B5', 'SR_B4']).rename('NDVI');
return addDate(img.addBands(ee.Image.cat(nbr, ndvi)));
}
function prepOliToa(img) {
var nbr = img.normalizedDifference(['B5', 'B7']).rename(['NBR']);
var ndvi = img.normalizedDifference(['B5', 'B4']).rename('NDVI');
return addDate(img.addBands(ee.Image.cat(nbr, ndvi)));
}
/**
* Add NDVI band Sentinel-2.
*/
function addBandsS2(img) {
var nbr = img.normalizedDifference(['B8', 'B12']).rename(['NBR']);
var ndvi = img.normalizedDifference(['B8', 'B4']).rename('NDVI');
return img.addBands(ee.Image.cat(nbr, ndvi));
}
/**
* Add date property.
*/
function addDate(img) {
var date = img.date().format('YYYY-MM-dd');
return img.set('date', date);
}
/**
* Gathers all Landsat into a collection.
*/
function getLandsatCollection(aoi, startDate, endDate, cloudthresh, id) {
var id8 = id;
var id9 = id.replace('LC08', 'LC09');
var oli8Col = ee.ImageCollection(id8)
.filterBounds(aoi)
.filterDate(startDate, endDate)
.filter(ee.Filter.lt('CLOUD_COVER', cloudthresh));
var oli9Col = ee.ImageCollection(id9)
.filterBounds(aoi)
.filterDate(startDate, endDate)
.filter(ee.Filter.lt('CLOUD_COVER', cloudthresh));
var oliCol = oli8Col.merge(oli9Col).sort('system:time_start');
if (id8 == 'LANDSAT/LC08/C02/T1_TOA') {
oliCol = oliCol.map(prepOliToa);
} else {
oliCol = oliCol.map(prepOliSr);
}
return oliCol;
}
/**
* Join S2 SR and S2 cloudless.
*/
function getS2SrCldCol(aoi, startDate, endDate, cloudthresh, id) {
var s2SrCol = ee.ImageCollection(id)
.filterBounds(aoi)
.filterDate(startDate, endDate)
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', cloudthresh));
return s2SrCol.map(addBandsS2).map(addDate);
}
/**
* Clears image cards from the image card panel.
*/
function clearImgs() {
imgCardPanel.clear();
}
/**
* Displays image cards to the card panel.
*/
function displayBrowseImg(col, aoiBox, aoiCircle) {
clearImgs();
waitMsgImgPanel.style().set('shown', true);
imgCardPanel.add(waitMsgImgPanel);
var visParams = sensorInfo[sensorSelect.getValue()]['rgb'][rgbSelect.getValue()];
var dates = col.aggregate_array('date').sort();
dates.evaluate(function(dates) {
waitMsgImgPanel.style().set('shown', false);
dates.forEach(function(date) {
var img = col.filter(ee.Filter.eq('date', date)).first();
var aoiImg = ee.Image().byte()
.paint(ee.FeatureCollection(ee.Feature(aoiCircle)), 1, 2)
.visualize({palette: AOI_COLOR});
var thumbnail = ui.Thumbnail({
image: img.visualize(visParams).blend(aoiImg),
params: {
region: aoiBox,
dimensions: '200',
crs: 'EPSG:3857',
format: 'PNG'
}
});
var imgCard = ui.Panel([
ui.Label(date,
{margin: '4px 4px -6px 8px', fontSize: '13px', fontWeight: 'bold'}),
thumbnail
], null, {margin: '4px 0px 0px 4px' , width: 'px'});
imgCardPanel.add(imgCard);
});
});
}
/**
* Generates chart and adds image cards to the image panel.
*/
function renderGraphics(coords) {
var sensor = sensorSelect.getValue();
// Get the selected RGB combo vis params.
var visParams = sensorInfo[sensorSelect.getValue()]['rgb'][rgbSelect.getValue()];
// Get the clicked point and buffer it.
var point = ee.Geometry.Point(coords);
var aoiCircle = point.buffer(sensorInfo[sensor]['aoiRadius']);
var aoiBox = point.buffer(regionWidthSlider.getValue()*1000/2);
// Clear previous point from the Map.
map.layers().forEach(function(el) {
map.layers().remove(el);
});
// Add new point to the Map.
map.addLayer(aoiCircle, {color: AOI_COLOR});
map.centerObject(aoiCircle, 14);
// Get collection options.
var cloudThresh = cloudSlider.getValue();
var datasetId = sensorInfo[sensor]['id'];
var endDate = new Date();
var startDate = ee.Date(endDate)
.advance(-parseInt(durationSlider.getValue()), 'months');
// Build the collection.
var col;
if(sensor == 'Sentinel-2 SR' | sensor == 'Sentinel-2 TOA') {
col = getS2SrCldCol(aoiBox, startDate, endDate, cloudThresh, datasetId);
} else if(sensor == 'Landsat-8/9 SR' | sensor == 'Landsat-8/9 TOA') {
col = getLandsatCollection(aoiBox, startDate, endDate, cloudThresh, datasetId);
}
col = ee.ImageCollection(col.distinct('date')).sort('system:time_start');
// Display the image chip time series.
displayBrowseImg(col, aoiBox, aoiCircle);
OPTIONAL_PARAMS['chartParams']['vAxis']['title'] = indexSelect.getValue();
OPTIONAL_PARAMS['scale'] = sensorInfo[sensorSelect.getValue()]['scale'];
// Render the time series chart.
rgbTs.rgbTimeSeriesChart(col, aoiCircle,
sensorInfo[sensorSelect.getValue()]['index'][indexSelect.getValue()],
sensorInfo[sensorSelect.getValue()]['rgb'][rgbSelect.getValue()],
chartPanel, OPTIONAL_PARAMS);
}
/**
* Handles map clicks.
*/
function handleMapClick(coords) {
CLICKED = true;
COORDS = [coords.lon, coords.lat];
ui.url.set('run', 'true');
ui.url.set('lon', COORDS[0]);
ui.url.set('lat', COORDS[1]);
renderGraphics(COORDS);
}
/**
* Handles submit button click.
*/
function handleSubmitClick() {
renderGraphics(COORDS);
submitButton.style().set('shown', false);
}
/**
* Sets URL params.
*/
function setParams() {
ui.url.set('sensor', sensorSelect.getValue());
ui.url.set('index', indexSelect.getValue());
ui.url.set('rgb', rgbSelect.getValue());
ui.url.set('duration', durationSlider.getValue());
ui.url.set('cloud', cloudSlider.getValue());
ui.url.set('chipwidth', regionWidthSlider.getValue());
}
/**
* Show/hide the submit button.
*/
function showSubmitButton() {
if(CLICKED) {
submitButton.style().set('shown', true);
}
}
/**
* Handles options changes.
*/
function optionChange() {
showSubmitButton();
setParams();
}
/**
* Show/hide the control panel.
*/
var controlShow = false;
function controlButtonHandler() {
if(controlShow) {
controlShow = false;
controlElements.style().set('shown', false);
controlButton.setLabel('Options ❯');
} else {
controlShow = true;
controlElements.style().set('shown', true);
controlButton.setLabel('Options ❮');
}
if(infoShow | controlShow) {
controlPanel.style().set('width', CONTROL_PANEL_WIDTH);
} else {
controlPanel.style().set('width', CONTROL_PANEL_WIDTH_HIDE);
}
}
/**
* Show/hide the control panel.
*/
var infoShow = false;
function infoButtonHandler() {
if(infoShow) {
infoShow = false;
infoElements.style().set('shown', false);
infoButton.setLabel('About ❯');
} else {
infoShow = true;
infoElements.style().set('shown', true);
infoButton.setLabel('About ❮');
}
if(infoShow | controlShow) {
controlPanel.style().set('width', CONTROL_PANEL_WIDTH);
} else {
controlPanel.style().set('width', CONTROL_PANEL_WIDTH_HIDE);
}
}
// #############################################################################
// ### SETUP UI ELEMENTS ###
// #############################################################################
infoElements.add(infoLabel);
infoElements.add(aboutLabel);
infoElements.add(appCodeLink);
controlElements.add(optionsLabel);
controlElements.add(sensorPanel);
controlElements.add(indexPanel);
controlElements.add(rgbPanel);
controlElements.add(durationPanel);
controlElements.add(cloudPanel);
controlElements.add(regionWidthPanel);
controlElements.add(submitButton);
controlPanel.add(instr);
controlPanel.add(buttonPanel);
controlPanel.add(infoElements);
controlPanel.add(controlElements);
map.add(controlPanel);
infoButton.onClick(infoButtonHandler);
controlButton.onClick(controlButtonHandler);
sensorSelect.onChange(optionChange);
rgbSelect.onChange(optionChange);
indexSelect.onChange(optionChange);
durationSlider.onChange(optionChange);
cloudSlider.onChange(optionChange);
regionWidthSlider.onChange(optionChange);
submitButton.onClick(handleSubmitClick);
map.onClick(handleMapClick);
map.style().set('cursor', 'crosshair');
map.setOptions('SATELLITE');
map.setControlVisibility(
{layerList: false, fullscreenControl: false, zoomControl: false});
//map.centerObject(ee.Geometry.Point([-122.91966, 44.24135]), 14);
ui.root.clear();
ui.root.add(splitPanel);
if(ui.url.get('run')) {
CLICKED = true;
COORDS = [ui.url.get('lon'), ui.url.get('lat')];
renderGraphics(COORDS);
}