-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForecastBar.vue
779 lines (683 loc) · 33.5 KB
/
ForecastBar.vue
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
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
<template>
<div id="app-forecast">
<template v-if="true"><!-- v-if="!mobile"-->
<div class="accordion position-absolute bottom-0 start-0 end-0 mh-50" id="accordionExample">
<div class="accordion-item">
<h2 class="accordion-header" id="headingOne">
<!--button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne"-->
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Forecast and Analysis of Mediterranean Sea - {{currentDataInformation}}
</button>
</h2>
<!--div id="collapseOne" class="accordion-collapse collapse" aria-labelledby="headingOne" data-bs-parent="#accordionExample"-->
<div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
<div class="accordion-body p-0">
<div class="container">
<!-- Feature selection -->
<div class="row p-1 align-items-center flex-nowrap">
<div class="col text-center">
<div class="btn-group" :key="data.name" :id="data.name" @click.prevent="dataClicked" v-for="data in dataTypes">
<button type="button" class="btn btn-sm btn-outline-dark" :class="[data.active ? 'active border': '']">{{data.name}}</button>
</div>
</div>
</div>
<!-- Data figures -->
<div class="row p-1 align-items-end flex-nowrap">
<!-- Arrow right (from carousel) -->
<!-- https://getbootstrap.com/docs/5.0/components/carousel/ -->
<button class="carousel-control-next" type="button" @click.prevent="nextTimeFigureClicked" data-bs-target="#carouselExampleControls" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
<!-- https://github.com/john015/vue-load-image -->
<div class="col btn btn-outline-light fig-col" :class="[fig.active ? 'active border border-dark': '']" :key="fig.id" :id="fig.id" @click.prevent="figureClicked" v-for="fig in figureInfo">
<figure class="figure m-0 position-relative">
<img :id="fig.id" :src="fig.url" :title="fig.date" :ref="el => onWMSImageLoadStart(el, fig)" @load="onWMSImageLoaded($event, fig)" @error="onWMSImageNotFound($event)" class="figure-img img-fluid rounded" :alt="fig.caption">
<div v-show="fig.isLoading" class="spinner-border text-dark" style="position: relative; margin-top: -60%; margin-inline: 20%" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<!--vue-load-image>
<template v-slot:image>
<img :src="fig.url" @error="onWMSImageNotFound($event)" class="figure-img img-fluid rounded" :alt="fig.caption">
</template>
<template v-slot:preloader>
<img class="figure-img img-fluid rounded" src="/geoportal/img/image-loader.gif" />
</template>
</vue-load-image-->
<figcaption class="figure-caption border">{{fig.caption}} <small class="text-end">({{fig.subcaption}})</small></figcaption>
</figure>
</div>
<!-- Arrow left (from carousel) -->
<!-- https://getbootstrap.com/docs/5.0/components/carousel/ -->
<button class="carousel-control-prev" type="button" @click.prevent="prevTimeFigureClicked" data-bs-target="#carouselExampleControls" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
</div>
<!-- Time scale selection -->
<div class="row p-1 align-items-center flex-nowrap">
<div class="col text-center">
<div class="btn-group" role="group" :key="timeScale.id" :id="timeScale.id" @click.prevent="timeScaleClicked" v-for="timeScale in getAvailableTimeScales">
<button v-if="timeScale.available" type="button" class="btn btn-sm btn-outline-dark" :class="[timeScale.active ? 'active border': '']">{{timeScale.name}}</button>
</div>
</div>
</div>
<!-- Source selection -->
<!-- Hidden because only CMEMS is setup -->
<div class="row p-1 align-items-center flex-nowrap" hidden>
<div class="col text-center">
<div class="btn-group" role="group" aria-label="Source selection" :key="source.id" :id="source.id" @click.prevent="sourceClicked" v-for="source in sources">
<button type="button" class="btn btn-sm btn-outline-dark" :class="[source.active ? 'active border': '']">{{source.id}}</button>
</div>
</div>
</div>
<!-- Attribution -->
<div class="row">
<div class="col text-center">
<div :key="source.id" v-for="source in sources">
<p class="fs-7" v-if="source.active">Attribution: {{source.attribution}}</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
</div>
</template>
<script>
import VueLoadImage from "VueLoadImage.vue";
// https://www.youtube.com/watch?v=6noJ0dlG7jM&ab_channel=Academind
// https://www.youtube.com/watch?v=FWQSuskE5UA&ab_channel=Academind
export default {
name: 'app-forecast',
created (){
window.addEventListener('resize', this.checkScreenRatio);
this.checkScreenRatio();
this.updateWMSURL();
},
mounted (){
// Once mounted, update the WMS url of map
this.$emit('changeWMSSource', this.getWMSInfo());
},
data () {
return {
currentDataInformation: "",
mobile: false,
currentDate: new Date(),
selectedDate: [false, false, true, false, false],
weekDays: ['Sunday','Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
catseaBBOX: [-1,36,9,44],
sources: {
'CMEMS-MED': {
id: 'CMEMS-MED',
attribution: "Mediterranean Sea Physics and Biogeochemistry Analysis and Forecast. Credits: E.U. Copernicus Marine Service Information",
productURL: "https://resources.marine.copernicus.eu/product-detail/MEDSEA_ANALYSISFORECAST_PHY_006_013/INFORMATION",
productURL2: "https://resources.marine.copernicus.eu/product-detail/MEDSEA_ANALYSISFORECAST_BGC_006_014/INFORMATION",
productURL3: "https://resources.marine.copernicus.eu/product-detail/MEDSEA_ANALYSISFORECAST_WAV_006_017/INFORMATION",
domainURL: "https://nrt.cmems-du.eu/thredds/wms",
active: true
},
'SOCIB-WMOP': {
id: 'SOCIB-WMOP',
attribution: "Western Mediterranean Operational Forecasting System. Credits: ICTS SOCIB",
productURL: "https://thredds.socib.es/thredds/catalog/operational_models/oceanographical/hydrodynamics/model_run_aggregation/wmop/catalog.html?dataset=operational_models/oceanographical/hydrodynamics/model_run_aggregation/wmop/wmop_best.ncd",
domainURL: "https://thredds.socib.es/thredds/wms/operational_models/oceanographical/hydrodynamics/model_run_aggregation/wmop/wmop_best.ncd",
catalog: "https://thredds.socib.es/thredds/catalog.html",
otherURL: "https://thredds.socib.es/lw4nc2/index-menu.html",
active: false
},
'SOCIB-SAPO': { // There are several forecasts: ib (illes balears), mallorca, menorca,
id: 'SOCIB-SAPO',
attribution: "Wave Forecast. Credits: ICTS SOCIB",
productURL: "https://thredds.socib.es/thredds/catalog/operational_models/oceanographical/wave/model_run_aggregation/sapo_ib/catalog.html?dataset=operational_models/oceanographical/wave/model_run_aggregation/sapo_ib/sapo_ib_best.ncd",
domainURL: "https://thredds.socib.es/thredds/wms/operational_models/oceanographical/wave/model_run_aggregation/sapo_ib/sapo_ib_best.ncd",
catalog: "https://thredds.socib.es/thredds/catalog.html",
otherURL: "https://thredds.socib.es/lw4nc2/index-menu.html",
active: false
} // TODO HERE....
},
//https://thredds.socib.es/thredds/wms/operational_models/oceanographical/wave/model_run_aggregation/sapo_ib/sapo_ib_best.ncd
// https://thredds.socib.es/lw4nc2/index-menu.html
// https://thredds.socib.es/thredds/wms/operational_models/oceanographical/hydrodynamics/model_run_aggregation/wmop/wmop_best.ncd?TRANSPARENT=true&FORMAT=image%2Fpng&LAYERS=salt&PROJECTION=EPSG%3A4326&ABOVEMAXCOLOR=extend&BELOWMINCOLOR=extend&STYLES=boxfill%2Frainbow&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&TIME=2021-10-18T15%3A00%3A00.000Z&SRS=EPSG%3A4326&COLORSCALERANGE=26.073683%2C38.58198&BBOX=5.625,33.75,11.25,39.375&WIDTH=256&HEIGHT=256
// https://thredds.socib.es/thredds/wms/operational_models/oceanographical/hydrodynamics/model_run_aggregation/wmop/wmop_best.ncd?TRANSPARENT=true&FORMAT=image%2Fpng&LAYERS=temp&COLORSCALERANGE=0%2C30&PROJECTION=EPSG%3A4326&NUMCOLORBANDS=50&ABOVEMAXCOLOR=extend&BELOWMINCOLOR=extend&STYLES=boxfill%2Fsst_36&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&SRS=EPSG%3A4326&BBOX=-16.4736328125,30.161865234375,19.4736328125,50.838134765625&WIDTH=1636&HEIGHT=941
// https://resources.marine.copernicus.eu/products
// https://resources.marine.copernicus.eu/product-detail/MEDSEA_ANALYSISFORECAST_PHY_006_013/INFORMATION
// https://view-cmems.mercator-ocean.fr/MEDSEA_ANALYSISFORECAST_PHY_006_013
// https://view-cmems.mercator-ocean.fr/MEDSEA_ANALYSISFORECAST_WAV_006_017
// ?service=WMS&version=1.3.0&request=GetCapabilities
// LEGEND
// TODO: ADD LEGEND. style is then transfered to legend.
// https://nrt.cmems-du.eu/thredds/wms/med-cmcc-cur-an-fc-qm?REQUEST=GetLegendGraphic&LAYER=sea_water_velocity&PALETTE=rainbow&COLORSCALERANGE=-0.5354787%2C0.92136043
dataTypes: {
"Sea surface velocity": {
name: 'Sea surface velocity',
url: 'med-cmcc-cur-an-fc',
layerName: 'sea_water_velocity',
timeScales: ['h', 'h3', 'h6', 'h12', 'd', 'd3', 'm'],
range: [0, 1.5],
units: 'm/s',
style: "boxfill%2Foccam",//"vector%2Foccam",
animation: {
layerNames: ['uo','vo'], // East, North
format: 'east_north',
type: 'velocity'
},
active: true
},
"Sea temperature": {
name: 'Sea temperature',
url: 'med-cmcc-tem-an-fc',
layerName: 'thetao',
timeScales: ['h', 'h3', 'h6', 'h12', 'd', 'd3', 'm'],
range: [10, 32],
units: 'ºC',
style: "boxfill%2Foccam",
active: false
},
"Salinity": {
name: 'Salinity',
url: 'med-cmcc-sal-an-fc',
layerName: 'so',
timeScales: ['h', 'h3', 'h6', 'h12', 'd', 'd3', 'm'],
range: [32, 41],
units: '‰',
style: "boxfill%2Foccam",
active: false
},
"Wave significant height": {
name: 'Wave significant height',
url: 'med-hcmr-wav-an-fc',
layerName: 'VHM0', // 'VMDR' for direction in degrees
timeScales: ['h', 'h3', 'h6', 'h12'],
range: [0, 6],
units: 'm',
style: "boxfill/alg",//occam_pastel-30",
animation: {
layerNames: ['VHM0', 'VMDR'], // Intensity, Angle
format: 'value_angle',
type: 'wave'
},
active: false,
},
"Wind wave significant height": {
name: 'Wind wave significant height',
url: 'med-hcmr-wav-an-fc',
layerName: 'VHM0_WW', // 'VMDR' for direction in degrees
timeScales: ['h', 'h3', 'h6', 'h12'],
range: [0, 6],
units: 'm',
style: "boxfill/sst_36", //occam_pastel-30",
animation: {
layerNames: ['VHM0_WW', 'VMDR_WW'], // Intensity, Angle
format: 'value_angle',
type: 'whiteWave'
},
active: false,
},
/*"Wave period": {
name: 'Wave period',
scientificName: 'Sea surface wave mean period from variance spectral density inverse frequency moment',
url: 'med-hcmr-wav-an-fc',
layerName: 'VTM10', // Check out other period measures
timeScales: ['h', 'h3', 'h6', 'h12'],
range: [0, 18],
units: 's',
style: "boxfill/sst_36", //occam_pastel-30",
active: false,
},*/
'Chlorophyll': {
name: 'Chlorophyll',
url: 'med-ogs-pft-an-fc',
layerName: 'chl',
timeScales: ['d', 'd3', 'm'],
range: [0.01, 1],
units: 'mg/m3',
style: 'boxfill%2Foccam',
active: false,// TODO BASE URL IS DIFFERENT
// https://nrt.cmems-du.eu/thredds/wms/med-ogs-pft-an-fc-d?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&TILED=true&COLORSCALERANGE=0.028321734%2C2.3005204&ELEVATION=-1.0182366371154785&LAYERS=chl&STYLES=boxfill%2Frainbow&TIME=2021-10-06T12%3A00%3A00.000Z&WIDTH=256&HEIGHT=256&CRS=EPSG%3A4326&BBOX=28.125%2C16.875%2C33.75%2C22.5
// https://thredds.socib.es/thredds/wms/operational_models/oceanographical/hydrodynamics/wmop_surface/2021/09/roms_wmop_surface_20210922.nc?service=WMS&version=1.3.0&request=GetCapabilities
},
},
// 15min, hourly, daily, monthly means
timeScales: {
'qm': {
id: 'qm',
name: '15-minutes instantaneous',
url: 'qm',
interval: [-30, -15, 0, 15, 30],
active: false
},
'h': {
id: 'h',
name: '1 hour',
url: 'h',
interval: [-2, -1, 0, 1, 2],
active: false
},
'h3': {
id: 'h3',
name: '3 hours',
url: 'h',
interval: [-6, -3, 0, 3, 6],
active: false
},
'h6': {
id: 'h6',
name: '6 hours',
url: 'h',
interval: [-12. -6, 0, 6, 12],
active: false
},
'h12': {
id: 'h12',
name: '12 hours',
url: 'h',
interval: [-24, -12, 0, 12, 24],
active: false
},
'd': {
id: 'd',
name: '1 day',
url: 'd',
interval: [-2, -1, 0, 1, 2],
active: true
},
'd3': {
id: 'd3',
name: '3 days',
interval: [-6, -3, 0, 3, 6],
url: 'd',
active: false
},
'm': {
id: 'm',
name: 'Montly mean',
url: 'm',
interval: [-5, -4, -3, -2, -1],
active: false
}
},
figureInfo: {},
layerInfoWMS: {},
//dataURL: "https://nrt.cmems-du.eu/thredds/wms/med-cmcc-cur-an-fc-d?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&LAYERS=sea_water_velocity&COLORSCALERANGE=-1%2C1&STYLES=boxfill%2Foccam&WIDTH=256&HEIGHT=256&CRS=CRS%3A84&BBOX=-1%2C36%2C9%2C44&TIME=2021-{MONTH}-{DAY}T12%253A00%253A00.000Z",
//baseURL: "https://nrt.cmems-du.eu/thredds/wms/{URLdataTypes}?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&LAYERS={LAYERNAME}&COLORSCALERANGE={MINRANGE}%2C{MAXRANGE}&STYLES=boxfill%2Foccam&WIDTH=256&HEIGHT=256&CRS=CRS%3A84&BBOX=-1%2C36%2C9%2C44&TIME=2021-{MONTH}-{DAY}T{HOURS}%253A{MINUTES}%253A00.000Z"
//https://nrt.cmems-du.eu/thredds/wms/med-ogs-pft-an-fc-m?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&TILED=true&COLORSCALERANGE=0.024503695%2C0.66972876&ELEVATION=-1.0182366371154785&LAYERS=chl&STYLES=boxfill%2Frainbow&TIME=2021-08-01T00%3A00%3A00.000Z&URL=https%3A%2F%2Fnrt.cmems-du.eu%2Fthredds%2Fwms%2Fmed-ogs-pft-an-fc-m&WIDTH=256&HEIGHT=256&CRS=EPSG%3A4326&BBOX=39.375%2C25.3125%2C42.1875%2C28.125
baseURL: "{DOMAIN}/{URLdataTypes}?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&LAYERS={LAYERNAME}&COLORSCALERANGE={MINRANGE}%2C{MAXRANGE}&ABOVEMAXCOLOR=extend&BELOWMINCOLOR=extend&STYLES={STYLE}&WIDTH=256&HEIGHT=256&CRS=CRS%3A84&BBOX={BBOX}&TIME={YEAR}-{MONTH}-{DAY}T{HOURS}:{MINUTES}:00.000Z"
}
},
methods: {
// USER HTML ACTIONS
checkScreenRatio: function(){
let ratio = window.innerHeight / window.innerWidth;
if (ratio < 1)
this.mobile = true;
else
this.mobile = false;
},
// Figure clicked
figureClicked: function (event) {
// Deselect date in GUI
this.selectedDate.forEach((e, index) => {
this.selectedDate[index] = false;
})
// Highlight selected date
this.selectedDate[event.currentTarget.id] = true;
this.updateWMSURL();
// Update WMS source in map component
this.$emit('changeWMSSource', this.getWMSInfo());
},
// Data type (SST, salinity, current)
dataClicked: function(event) {
// Select active data type
this.selectButtonInGroup(this.dataTypes, event.currentTarget.id)
// Change data type
this.updateWMSURL();
},
// Time scale
timeScaleClicked: function(event) {
// Select active time scale
this.selectButtonInGroup(this.timeScales, event.currentTarget.id)
// Change time scale
this.updateWMSURL();
},
// Source
sourceClicked: function(event) {
// Select active time scale
this.selectButtonInGroup(this.sources, event.currentTarget.id)
// Change time scale
this.updateWMSURL();
},
// Next / Previous time in Figures
nextTimeFigureClicked: function(event) {
// Time scale
let activeTimeScale = this.getActiveTimeScale();
// Add one to time interval
let interval = this.timeScales[activeTimeScale.id].interval;
let step = interval[interval.length - 1] - interval[interval.length - 2]; // Calculate step between last and before-last (newest dates)
interval.forEach((el,idx) => {interval[idx] = el + step});
this.timeScales[activeTimeScale.id].interval = interval;
// Update active date and date
// TODO: temporary solution -> if the selected date goes out of menu, it won't come back as selected
this.selectedDate.shift(1);
this.selectedDate.push(false);
// Change time interval
this.updateWMSURL();
},
prevTimeFigureClicked: function(event) {
// Time scale
let activeTimeScale = this.getActiveTimeScale();
// Remove one to time interval
let interval = this.timeScales[activeTimeScale.id].interval;
let step = interval[1] - interval[0]; // Calculate step between second and first (oldest dates)
interval.forEach((el,idx) => {interval[idx] = el - step})
this.timeScales[activeTimeScale.id].interval = interval;
// Update active date and date
// TODO: temporary solution -> if the selected date goes out of menu, it won't come back as selected
this.selectedDate.unshift(1);
this.selectedDate.pop();
this.selectedDate[0] = false;
// Change time interval
this.updateWMSURL();
},
// Select/deselect options
selectButtonInGroup: function(array, selKey){
Object.keys(array).forEach(key => array[key].active = false);
array[selKey].active = true;
},
// Returns active time scale
getActiveTimeScale: function(){
let activeTimeScale;
Object.keys(this.timeScales).forEach(key => { if (this.timeScales[key].active) activeTimeScale = this.timeScales[key] }); // Returns active data type
return activeTimeScale;
},
// INTERNAL METHODS
// Generate WMS url
updateWMSURL: function(){
let tmpURLData = this.baseURL;
// Get data source
let activeSource = this.sources[Object.keys(this.sources).find(key => this.sources[key].active)];
// Replace domain
tmpURLData = tmpURLData.replace('{DOMAIN}', activeSource.domainURL);
// Data type
let activeDataType; // = this.dataTypes.find(el => return el.active == true)
Object.keys(this.dataTypes).forEach(key => { if (this.dataTypes[key].active) activeDataType = this.dataTypes[key] }); // Returns active data type
// Show/Hide available time scales
Object.keys(this.timeScales).forEach(key => this.timeScales[key].available = activeDataType.timeScales.includes(key)); // Show/hide time scales in GUI
// TODO HERE: define this.timeScales.available
// HTML --> v-if: tScale.available
// TO0DO: WIND and Other sources:
// https://data.noaa.gov/dataset/?_tags_limit=0&sort=score+desc%2C+metadata_modified+desc&q=wind+forecast+hourly&res_format=WMS
// https://nowcoast.noaa.gov/help/#!section=wms-layer-ids
// https://resources.marine.copernicus.eu/product-detail/MEDSEA_ANALYSISFORECAST_BGC_006_014/INFORMATION
// Time scale
let activeTimeScale = this.getActiveTimeScale();
// Fix: sometimes activeTimeScale.interval loses the last item, no apparent reason. Maybe it is a vue bug. I haven't sorted it out
if (activeTimeScale.interval.length < this.selectedDate.length){
let step = activeTimeScale.interval[1] - activeTimeScale.interval[0];
activeTimeScale.interval.push(activeTimeScale.interval[activeTimeScale.interval.length -1] + step);
console.warn('timeScales lost one item in interval. It has been recovered.');
}
// WMS url parameters
tmpURLData = tmpURLData.replace('{URLdataTypes}', activeDataType.url + '-' + activeTimeScale.url);
tmpURLData = tmpURLData.replace('{LAYERNAME}', activeDataType.layerName);
tmpURLData = tmpURLData.replace('{MINRANGE}', activeDataType.range[0]);
tmpURLData = tmpURLData.replace('{MAXRANGE}', activeDataType.range[1]);
tmpURLData = tmpURLData.replace('{STYLE}', activeDataType.style);
// Time intervals
for (let i = 0; i < activeTimeScale.interval.length; i++){
let dd = new Date(this.currentDate);
dd.setMilliseconds(0);
dd.setSeconds(0);
let tmpURL = tmpURLData;
let caption = '';
let subcaption = '';
let dateSummary = '';
switch (activeTimeScale.url){
case 'qm':
// Set minimum time interval to 15 min
dd.setMinutes(Math.round(dd.getMinutes()/15)*15); // Rounds to closer 15min interval
dd.setMinutes(dd.getMinutes() + activeTimeScale.interval[i]);
caption = dd.getHours() + 'h:' + dd.getMinutes() + 'min';
subcaption = activeTimeScale.interval[i] + 'min';
dateSummary = caption + " " + subcaption;
break;
case 'h':
dd.setHours(dd.getHours() + activeTimeScale.interval[i]);
// Depends on data service. Again, check GetCapabilities?
if (activeDataType.url == "med-hcmr-wav-an-fc" || activeDataType.url == "med-ogs-pft-an-fc") // https://nrt.cmems-du.eu/thredds/wms/med-hcmr-wav-an-fc-h?request=GetCapabilities&service=WMS
dd.setMinutes(0)
else
dd.setMinutes(30); // https://nrt.cmems-du.eu/thredds/wms/med-cmcc-mld-an-fc-hts?request=GetCapabilities&service=WMS
caption = this.weekDays[dd.getDay()] + " " + dd.getDate() + " at " + dd.getHours() + ':00';
subcaption = activeTimeScale.interval[i] + 'h';
dateSummary = caption + "h, hourly mean";
break;
case 'd':
dd.setDate(dd.getDate() + activeTimeScale.interval[i]);
dd.setHours(12);
dd.setMinutes(0);
caption = this.weekDays[dd.getDay()] + " " + dd.getDate();
subcaption = 24*activeTimeScale.interval[i] + 'h';
dateSummary = caption + " " + this.monthNames[dd.getMonth()] + ' ' + dd.getUTCFullYear() +", daily mean";
break;
case 'm':
dd.setMonth(dd.getMonth() + activeTimeScale.interval[i])
// TODO: time intervals can be extracted from get capabilities?
// https://nrt.cmems-du.eu/thredds/wms/med-cmcc-tem-an-fc-m?request=GetCapabilities&service=WMS
if (activeDataType.name == 'Chlorophyll'){
dd.setDate(1);
dd.setHours(0);
dd.setMinutes(0);
} else {
dd.setDate(16); // or 15. check here: https://view.marine.copernicus.eu/ViewService/?record_id=66fb61fa-c911-4f7e-aec1-959627bbf2b3
dd.setHours(12); // or 00?
dd.setMinutes(0);
}
caption = this.monthNames[dd.getMonth()] + ' ' + dd.getUTCFullYear();
subcaption = 'Monthly average';
dateSummary = caption + " " + subcaption;
break;
}
// URL
tmpURL = tmpURL.replace("{YEAR}", dd.getFullYear().toString());
tmpURL = tmpURL.replace("{MONTH}", (dd.getMonth()+1).toString().padStart(2,"0"));
tmpURL = tmpURL.replace("{DAY}", dd.getDate().toString().padStart(2,"0"));
tmpURL = tmpURL.replace("{HOURS}", dd.getHours().toString().padStart(2,"0"));
tmpURL = tmpURL.replace("{MINUTES}", dd.getMinutes().toString().padStart(2,"0"));
// BBOX
tmpURL = tmpURL.replace("{BBOX}", JSON.stringify(this.catseaBBOX).replace('[', '').replace(']', ''));
// TODO: FIXING MONTHLY AVERAGE URL SHOULD BE DONE HERE. NOW IT IS DONE AT THE imgEl.onerror EVENT.
// Test the image WMS URL
// This is useful for monthyl average, because it can be on the 16th at 12h, 16th at 00h, 15th at 12h, 15th at 00h...
/*fetch(tmpURL)
.then((res) => {
if(res.status == 400){
}
})
.catch(console.error)*/
// Output
this.figureInfo[i] = {
'id': i,
'caption': caption,
'subcaption': subcaption,
'url': tmpURL,
'date': dd.toString(),
'active': this.selectedDate[i]//activeTimeScale.interval[i] == 0 ? true : false,
}
// Active source information
if (this.selectedDate[i]){
this.currentDataInformation = activeDataType.name + ", " + dateSummary + " (" + activeSource.id + ")";
// Openlayers WMS source information
// Fix hour difference (e.g. GMT+2) for ISOString function
dd.setHours(dd.getHours() - dd.getTimezoneOffset()/60);
// Layer source
this.layerInfoWMS = {
url: activeSource.domainURL + "/" + activeDataType.url + '-' + activeTimeScale.url,
attributions: activeSource.attribution,
params: {
'LAYERS': activeDataType.layerName,
'TIME': dd.toISOString(),
'COLORSCALERANGE': activeDataType.range,
'STYLES': activeDataType.style.replace('%2F', '/'),
'TRANSPARENT': true,
'UNITS': activeDataType.units
},
name: activeDataType.name,
tooltip: this.currentDataInformation,
cacheSize: 500,
zDirection: -1,
// Information for animation
exampleWMSURL: tmpURL, // TODO: remove without consequences?
animation: activeDataType.animation,
}
}
}
return this.figureInfo;
},
// INTERNAL EVENTS
// Image added and loading
onWMSImageLoadStart: function(imgEl, fig){
// If image already exists, but a property of it changed, this event is triggered
if (imgEl.width != 0 && imgEl.currentSrc == imgEl.src){
return;
}
//console.log("Loading image started");
fig.isLoading = true;
imgEl.style.opacity = 0.2;
},
// Image loaded, reset loadCount
onWMSImageLoaded: function (event, fig){
//console.log("Loading image ended");
let imgEl = event.currentTarget;
imgEl.loadCount = 0; // Control for recursivity
fig.isLoading = false;
imgEl.style.opacity = 1;
},
// Image not found (usually monthly mean)
onWMSImageNotFound: function(event){
let imgEl = event.currentTarget;
// Recursivity
imgEl.loadCount = imgEl.loadCount == undefined ? 1 : (imgEl.loadCount + 1); // Control for recursivity
// Active time scale should be monthly
let activeTimeScale = this.getActiveTimeScale();
if (imgEl.loadCount > 4 || activeTimeScale.id != 'm'){
imgEl.src = '../img/noData.png';
return;
}
let url = imgEl.src;
console.warn("WMS URL not valid. Trying other hours and minutes. Recursive load count: "+ imgEl.loadCount +" URL: " + url);
let time = this.getWMSParameter(url, 'TIME');
let date = new Date(time);
// Go back in time 12h
date.setHours(date.getHours() - 12); // Default date is 16th at 12h. Other possible dates are in the past (16th at 00h, 15th at 12h...)
// Replace img source. If it fails, it is recursive
imgEl.src = this.setWMSParameter(url, 'TIME', date.toISOString());
// Update consequent information
let figIndex = imgEl.id;
this.figureInfo[figIndex].url = imgEl.src;
if (this.selectedDate[figIndex]){
// Fix hour difference (e.g. GMT+2) for ISOString function
date.setHours(date.getHours() - date.getTimezoneOffset()/60);
this.layerInfoWMS.params['TIME'] = date.toISOString();
}
},
// Set WMS parameter
setWMSParameter: function(wmsURL, paramName, paramContent) {
// If parameter does not exist
if (wmsURL.indexOf(paramName + "=") == -1) {
console.log("Parameter ", paramName, " does not exist in WMS URL");
return wmsURL + '&' + paramName + '=' + paramContent;
}
let currentContent = this.getWMSParameter(wmsURL, paramName);
return wmsURL.replace(currentContent, paramContent);
},
// Get WMS parameter
getWMSParameter: function(wmsURL, paramName) {
// If parameter does not exist
if (wmsURL.indexOf(paramName + "=") == -1) {
console.log("Parameter ", paramName, " does not exist in WMS URL");
return '';
}
let tmpSTR = wmsURL.substr(wmsURL.indexOf(paramName + "="));
// If time is not the last parameter
if (tmpSTR.indexOf('&') != -1)
return tmpSTR.substring(paramName.length + 1, tmpSTR.indexOf('&'));
else
return tmpSTR.substring(paramName.length + 1, tmpSTR.length);
},
// Return WMS info for OpenLayers layer
getWMSInfo: function(){
return this.layerInfoWMS;
},
// PUBLIC METHODS
// Change WMS Style (called from App Manager. When legend is clicked, style changes)
changeWMSStyle: function(newStyle){
// Get active data type
let activeDataType; // = this.dataTypes.find(el => return el.active == true)
Object.keys(this.dataTypes).forEach(key => { if (this.dataTypes[key].active) activeDataType = this.dataTypes[key] }); // Returns active data type
// Change style
activeDataType.style = newStyle;
// Update the WMS url of the figures
this.updateWMSURL();
}
},
components: {
"vue-load-image": VueLoadImage
},
computed: {
// Returns available time scales for a data type
getAvailableTimeScales: function () {
let avTimeScales = Object.keys(this.timeScales)
.filter(key => this.timeScales[key].available)
.reduce((availableTimeScalesObj, key) => {availableTimeScalesObj[key] = this.timeScales[key]; return availableTimeScalesObj}, {});
// One available time scale should be active
let keys = Object.keys(avTimeScales);
for (let i = 0; i < keys.length; i++){
if (avTimeScales[keys[i]].active)
break;
else if (i == keys.length-1){
avTimeScales[keys[0]].active = true; // First time scale is active
this.selectButtonInGroup(this.timeScales, keys[i]); // Update timeScales
this.updateWMSURL(); // Update URLs
}
}
return avTimeScales;
},
}
}
</script>
<style scoped>
.accordion-item {
background-color: rgba(255, 255, 255, 0.8);
}
.figure-img {
max-height: 10em
}
.fig-col.active {
background-color: rgba(255, 255, 255, 0.6);
transform: 0.5s ease all;
}
.fig-col:not(active) {
border-color: rgba(0, 0, 0, 0.1);
}
.btn-outline-dark :not(active) {
background-color: rgba(255, 255, 255, 0.6);
}
.carousel-control-next-icon {
background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%2ffff'><path d='M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z'/></svg>");
}
.carousel-control-prev-icon {
background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%2ffff'><path d='M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z'/></svg>");
}
.carousel-control-next, .carousel-control-prev {
width: 7%;
top: 80px;
}
.fs-7 {
font-size: 0.8rem!important;
}
</style>