-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathLayersTool.js
More file actions
2343 lines (2170 loc) · 105 KB
/
LayersTool.js
File metadata and controls
2343 lines (2170 loc) · 105 KB
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
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import $ from 'jquery'
import * as d3 from 'd3'
import Sortable from 'sortablejs'
import F_ from '../../Basics/Formulae_/Formulae_'
import L_ from '../../Basics/Layers_/Layers_'
import Map_ from '../../Basics/Map_/Map_'
import DataShaders from '../../Ancillary/DataShaders'
import LayerInfoModal from './LayerInfoModal/LayerInfoModal'
import Filtering from '../../Basics/Layers_/Filtering/Filtering'
import Help from '../../Ancillary/Help'
import CursorInfo from '../../Ancillary/CursorInfo'
import LegendTool from '../Legend/LegendTool.js'
import tippy from 'tippy.js'
import 'markjs'
import calls from '../../../pre/calls'
import * as tokml from '@maphubs/tokml'
import shpwrite from '@mapbox/shp-write'
import {
evaluate_cmap,
data as colormapData,
} from '../../../external/js-colormaps/js-colormaps.js'
import './LayersTool.css'
const helpKey = 'LayersTool'
//Add the tool markup if you want to do it this way
// prettier-ignore
var markup = [
"<div id='layersTool'>",
"<div id='layersToolHeader'>",
"<div id='filterLayers'>",
"<div class='left'>",
'<div id="title">Layers</div>',
Help.getComponent(helpKey),
"</div>",
"<div class='right'>",
'<div class="vector" type="vector" title="Hide/Show Vector Layers"><i class="mdi mdi-vector-square mdi-18px"></i></div>',
'<div class="vectortile" type="vectortile" title="Hide/Show VectorTile Layers"><i class="mdi mdi-grid mdi-18px"></i></div>',
'<div class="tile" type="tile" title="Hide/Show Raster Layers"><i class="mdi mdi-map-outline mdi-18px"></i></div>',
'<div class="query" type="query" title="Hide/Show Query Layers"><i class="mdi mdi-binoculars mdi-18px"></i></div>',
'<div class="data" type="data" title="Hide/Show Data Layers"><i class="mdi mdi-file-table mdi-18px"></i></div>',
'<div class="model" type="model" title="Hide/Show Model Layers"><i class="mdi mdi-cube-outline mdi-18px"></i></div>',
'<div class="visible" type="visible" title="Hide/Show Off Layers"><i class="mdi mdi-eye mdi-18px"></i></div>',
"</div>",
"</div>",
"<div id='searchLayers'>",
'<i class="mdi mdi-magnify mdi-18px"></i>',
"<input type='text' placeholder='Search Layers (# for tags)' />",
'<div id="clear"><i class="mdi mdi-close mdi-18px"></i></div>',
'<div id="expand"><i class="mdi mdi-arrow-expand-vertical mdi-18px"></i></div>',
'<div id="collapse"><i class="mdi mdi-arrow-collapse-vertical mdi-18px"></i></div>',
"</div>",
"</div>",
"<div id='layersToolContent'>",
"<ul id='layersToolList'>",
"</ul>",
"</div>",
"</div>",
].join('\n')
// These layers are a bit different and we need to account for that.
// Either they have no map data or not initial data
const quasiLayers = ['model', 'query']
const DEPTH_SIZE = 13
const INDENT_COLOR = 'var(--color-a)'
// The default color ramp used for image layer types
const IMAGE_DEFAULT_COLOR_RAMP = 'binary'
// The default color ramp used for tile layer types
const TILE_DEFAULT_COLOR_RAMP = 'viridis'
// The default color ramp used for velocity layer types
const VELOCITY_DEFAULT_COLOR_RAMP = 'rdylbu_r'
var LayersTool = {
height: 0,
width: 350,
vars: {},
MMGISInterface: null,
orderingHistory: [],
_maxDepth: 0,
initialize: function () {
//Get tool variables
this.vars = L_.getToolVars('layers')
// set custom width
if (this.vars.width) {
this.width = this.vars.width
}
},
finalize: function () {
//Order layers from url
if (L_.FUTURES.tools) {
for (let t of L_.FUTURES.tools) {
const tUrl = t.split('$')
if (tUrl[0] === 'LayersTool') {
LayersTool.orderingHistory = []
const orderHistory = tUrl[1].split('.')
orderHistory.forEach((o) => {
const oSplit = o.split('-')
LayersTool.orderingHistory.push([
parseInt(oSplit[0]),
parseInt(oSplit[1]),
parseInt(oSplit[2]),
])
})
break
}
}
}
if (LayersTool.orderingHistory.length > 0) {
LayersTool.make(null, true)
LayersTool.destroy()
}
},
make: function (t, fromInit) {
this.MMGISInterface = new interfaceWithMMGIS(fromInit)
},
destroy: function () {
this.MMGISInterface.separateFromMMGIS()
},
getUrlString: function () {
if (LayersTool.orderingHistory.length === 0) return ''
return LayersTool.orderingHistory
.map((hist) => `${hist[0]}-${hist[1]}-${hist[2]}`)
.join('.')
},
setHeader: function () {},
toggleHeader: function (elmIndex) {
var found = false
var done = false
var elmDepth = [0]
var wasOn = [false]
var currentHeaderIdx = 0
$('#layersToolList > li').each(function () {
if (done) return
var t = $(this)
if (t.attr('id') == elmIndex) {
found = true
elmDepth = [t.attr('depth')]
wasOn = [t.attr('childrenon') == 'true']
currentHeaderIdx = 0
t.attr('childrenon', wasOn[currentHeaderIdx] ? 'false' : 'true')
t.find('.headerChevron').toggleClass('mdi-chevron-right')
t.find('.headerChevron').toggleClass('mdi-chevron-down')
} else if (found) {
if (t.attr('depth') <= elmDepth[currentHeaderIdx]) {
if (currentHeaderIdx <= 0) done = true
else {
while (t.attr('depth') <= elmDepth[currentHeaderIdx]) {
elmDepth.pop()
wasOn.pop()
currentHeaderIdx--
if (currentHeaderIdx < 0) {
done = true
break
}
}
}
}
if (!done) {
const nextDepth =
parseInt(t.attr('depth')) >
parseInt(elmDepth[currentHeaderIdx])
// Hide if collapsing whole group or not every header up to the point was false
if (
currentHeaderIdx === 0
? wasOn[0] === true
: !wasOn.every((w) => w === false)
) {
// hide
if (nextDepth) t.attr('on', 'false')
t.css('overflow', 'hidden')
t.css('height', '0')
t.css('margin-top', '0px')
t.css('margin-bottom', '0px')
} else {
// show
if (t.attr('on') == 'true' || nextDepth) {
t.css('height', 'auto')
t.css('margin-top', '1px')
t.css('margin-bottom', '1px')
}
if (nextDepth) t.attr('on', 'true')
}
if (t.attr('type') == 'header') {
const childrenon = t.attr('childrenon') == 'true'
// Only expand subheader if we're opening
elmDepth.push(t.attr('depth'))
wasOn.push(!childrenon)
currentHeaderIdx++
const chevron = t.find('.headerChevron')
if (childrenon) {
// arrow down
if (chevron.hasClass('mdi-chevron-right'))
chevron.removeClass('mdi-chevron-right')
if (!chevron.hasClass('mdi-chevron-down'))
chevron.addClass('mdi-chevron-down')
} else {
// arrow right
if (chevron.hasClass('mdi-chevron-down'))
chevron.removeClass('mdi-chevron-down')
if (!chevron.hasClass('mdi-chevron-right'))
chevron.addClass('mdi-chevron-right')
}
}
}
}
})
},
populateCogScale: function (layerName) {
let layer = L_.asLayerUUID(layerName)
let units = ''
layer = L_.layers.data[layer]
if (L_.layers.layer[layer.name] === null) return
if (!layer.url.startsWith('stac-collection:') && layer.type !== 'image' && layer.type !== 'velocity') return
if (layer.cogTransform !== true && (layer.url.startsWith('stac-collection:') || layer.type === 'image')) return
if (layer.type === 'image' && (L_.layers.layer[layer.name].hasOwnProperty('georasters') && L_.layers.layer[layer.name].georasters[0].numberOfRasters !== 1)) return
// set units to proper unit property
if (layer.type === 'velocity') {
if (layer.kind === 'particles') {
units = layer.variables?.particles?.units ?? ''
} else {
units = layer.variables?.streamlines?.units ?? ''
}
} else {
units = layer.cogUnits
}
const dynamicLegendConf = []
const imgElement = document.getElementById(
`titlerCogColormapImage_${L_.asLayerUUID(layerName)}`
)
const canvasElement = document.createElement('canvas')
document.body.appendChild(canvasElement)
canvasElement.style.display = 'none'
canvasElement.width = 256
canvasElement.height = 1
const context = canvasElement.getContext('2d')
if (imgElement && layer.type === 'tile') {
context.drawImage(imgElement, 0, 0, 256, 1, 0, 0, 256, 1)
}
const min =
layer.currentCogMin == null ? (layer.cogMin == null ? layer.variables.streamlines.minVelocity : layer.cogMin) : layer.currentCogMin
const max =
layer.currentCogMax == null ? (layer.cogMax == null ? layer.variables.streamlines.maxVelocity : layer.cogMax) : layer.currentCogMax
for (let i = 0; i < 9; i++) {
let value =
Math.round(F_.linearScale([0, 8], [min, max], i) * 100) / 100
let label = `${
Math.round(F_.linearScale([0, 8], [min, max], i) * 100) / 100
}${units || ''}`
if (i !== 0 && i !== 8) {
// Match all id
$(`[id=tileCogLegend_${i}]`).html(label)
}
let color
if (imgElement && layer.type === 'tile') {
const c = context.getImageData(
parseInt((255 / 9) * i),
0,
1,
1
).data
color = `rgb(${c[0]}, ${c[1]}, ${c[2]})`
} else if (
layer.type === 'image' ||
layer.type === 'velocity' ||
!imgElement
) {
const layerColormap = ['tile', 'image'].includes(layer.type)
? layer.cogColormap
: layer?.variables?.streamlines?.colorScale
let { colormap, reverse } = LayersTool.findJSColormap(
layer,
layerColormap
)
let scaledPixelValue
if (min !== undefined && max !== undefined) {
// scale from 0 - 1
const range = max - min
scaledPixelValue = (value - min) / range
if (!(0 <= scaledPixelValue && scaledPixelValue <= 1)) {
if (scaledPixelValue <= 0) {
scaledPixelValue = 0
} else if (scaledPixelValue >= 1.0) {
scaledPixelValue = 1
}
}
} else {
// If cog transform option is not turned on,
scaledPixelValue = i / 9
label = ''
}
const hex = evaluate_cmap(scaledPixelValue, colormap, reverse)
const rgb = hex.join(',')
color = `rgb(${rgb})`
}
dynamicLegendConf.push({
color,
strokecolor: null,
shape: 'continuous',
value: label,
})
}
document.body.removeChild(canvasElement)
L_.layers.data[layer.name]._legend = dynamicLegendConf
$('#tileCogColormapMapLines').empty()
for (let i = 0; i < 9; i++) {
$('#tileCogColormapMapLines').append(
`<li style="height: ${(1 / 9) * 100}%;"></li>`
)
}
$('.tilerescalecogmin').val(min)
$('.tilerescalecogmax').val(max)
},
findJSColormap: function (layer, layerColormap) {
if (!['image', 'tile', 'velocity'].includes(layer.type)) return
let colormap
// Default to predefined values if the layer's colormap value is invalid
if (layer.type === 'image') {
colormap = layerColormap || IMAGE_DEFAULT_COLOR_RAMP
} else if (layer.type === 'tile') {
colormap = layerColormap || TILE_DEFAULT_COLOR_RAMP
} else if (layer.type === 'velocity') {
colormap = layerColormap || VELOCITY_DEFAULT_COLOR_RAMP
}
// js-colormaps data object only contains the non reversed color so we need to track if the color is reversed
let reverse = false
if (colormap.toLowerCase().endsWith('_r')) {
colormap = colormap.substring(0, colormap.length - 2)
reverse = true
}
let index = Object.keys(colormapData).findIndex((v) => {
return v.toLowerCase() === colormap.toLowerCase()
})
if (index > -1) {
colormap = Object.keys(colormapData)[index]
}
return { reverse, colormap }
},
}
//
function interfaceWithMMGIS(fromInit) {
this.separateFromMMGIS = function () {
separateFromMMGIS()
}
var tools = d3.select('#toolPanel')
//Clear it
tools.selectAll('*').remove()
//Add a semantic container
tools = tools.append('div').style('height', '100%')
if (fromInit) tools.style('display', 'none')
//Add the markup to tools or do it manually
tools.html(markup)
Help.finalize(helpKey)
let headerI = 0
LayersTool._maxDepth = 0
//This is where the layers list is created in the tool panel.
depthTraversal(L_.configData.layers, {}, 0)
function depthTraversal(node, parent, depth) {
LayersTool._maxDepth = Math.max(LayersTool._maxDepth, depth)
for (var i = 0; i < node.length; i++) {
let currentOpacity
let currentBrightness
let currentContrast
let currentSaturation
let currentBlend
//Build layerExport
var layerExport
switch (node[i].type) {
case 'vector':
case 'query':
// prettier-ignore
layerExport = [
/*
'<ul>',
L_.Coordinates.mainType != 'll' ? ['<li>',
'<div class="layersToolExportGeoJSON">',
`<div>Export GeoJSON (${L_.Coordinates.getMainTypeName()})</div>`,
'</div>',
'</li>'].join('\n') : '',
'<li>',
'<div class="layersToolExportSourceGeoJSON">',
`<div>Export GeoJSON ${L_.Coordinates.mainType != 'll' ? '(lonlat)' : '' }</div>`,
'</div>',
'</li>',
L_.Coordinates.mainType != 'll' ? ['<li>',
'<div class="layersToolExportKML">',
`<div>Export KML (${L_.Coordinates.getMainTypeName()})</div>`,
'</div>',
'</li>'].join('\n') : '',
'<li>',
'<div class="layersToolExportSourceKML">',
`<div>Export KML ${L_.Coordinates.mainType != 'll' ? '(lonlat)' : '' }</div>`,
'</div>',
'</li>',
'</ul>',
*/
'<ul>',
`<li class="layersToolExport">`,
`<div><i class='mdi mdi-download mdi-14px'></i><div>Export</div></div>`,
'<div>',
'<div>Format</div>',
'<select class="layersToolExportFormat dropdown">',
'<option value="geojson" selected>GeoJSON</option>',
'<option value="kml">KML</option>',
'<option value="shp">SHP</option>',
'</select>',
'</div>',
node[i]?.variables?.dynamicExtent === true ? ['<div>',
'<div>Extent</div>',
'<select class="layersToolExportExtent dropdown">',
'<option value="local" selected>Current Window Extent</option>',
'<option value="raw">Entire File</option>',
'</select>',
'</div>',].join('\n') : '',
L_.Coordinates.mainType != 'll' ? [
'<div>',
'<div>Coords</div>',
'<select class="layersToolExportCoords dropdown">',
'<option value="source" selected>Source Coordinates</option>',
`<option value="${L_.Coordinates.mainType}">Converted (${L_.Coordinates.mainType})</option>`,
'</select>',
'</div>'] .join('\n') : '',
'<div><div class="layersToolExportGo mmgisButton5">Export</div></div>',
`</li>`,
'</ul>',
].join('\n')
break
case 'data':
case 'tile':
layerExport = ''
// Add download URL for raster layers
if (node[i].hasOwnProperty('variables')) {
if (node[i].variables.hasOwnProperty('downloadURL')) {
layerExport = [
'<ul>',
'<li>',
'<div class="layersToolExportSourceGeoJSON">',
`<div><a href="` +
node[i].variables.downloadURL +
`" target="_blank">Download Data</a></div>`,
'</div>',
'</li>',
'</ul>',
].join('\n')
}
}
break
default:
layerExport = ''
}
// Build timeDisplay
var timeDisplay = ''
if (node[i].time != null) {
if (node[i].time.enabled == true) {
// prettier-ignore
timeDisplay = [
'<ul>',
'<li class="layerTimeTitle">',
'<div>Time</div>',
'</li>',
'<li>',
'<div>',
'<div>Start Time</div>',
'<label class="starttime ' +
F_.getSafeName(node[i].name) +
'">' +
node[i].time.start +
'</label>',
'</div>',
'</li>',
'<li>',
'<div>',
'<div>End Time</div>',
'<label class="endtime ' +
F_.getSafeName(node[i].name) +
'">' +
node[i].time.end +
'</label>',
'</div>',
'</li>',
(
node[i].time.refreshIntervalEnabled === true
) ?
[
'<li>',
'<div>',
'<div>Auto-Refreshes Every</div>',
'<label class="autoRefreshInterval ' +
F_.getSafeName(node[i].name) +
'">' +
(node[i].time.refreshIntervalAmount || 60) +
' Seconds</label>',
'</div>',
'</li>'
].join('\n')
: null,
'</ul>',
].join('\n')
}
}
//Build settings object
var settings
let additionalSettings = ''
switch (node[i].type) {
case 'vector':
case 'vectortile':
settings = getVectorLayerSettings(node[i].name)
break
case 'tile':
currentOpacity = L_.getLayerOpacity(node[i].name)
if (currentOpacity == null)
currentOpacity = L_.layers.opacity[node[i].name]
currentBrightness =
node[i]?.style?.brightness != null
? node[i].style.brightness
: 1
const defaultBrightness = currentBrightness
currentContrast =
node[i]?.style?.contrast != null
? node[i].style.contrast
: 1
const defaultContrast = currentContrast
currentSaturation =
node[i]?.style?.saturation != null
? node[i].style.saturation
: 1
const defaultSaturation = currentSaturation
currentBlend =
node[i]?.style?.blend != null
? node[i].style.blend
: 'none'
const defaultBlend = currentBlend
if (L_.layers.filters[node[i].name]) {
let f = L_.layers.filters[node[i].name]
currentBrightness =
f['brightness'] == null
? currentBrightness
: parseFloat(f['brightness'])
currentContrast =
f['contrast'] == null
? currentContrast
: parseFloat(f['contrast'])
currentSaturation =
f['saturate'] == null
? currentSaturation
: parseFloat(f['saturate'])
currentBlend =
f['mix-blend-mode'] == null
? currentBlend
: f['mix-blend-mode']
}
additionalSettings = ''
if (
node[i].cogTransform === true &&
typeof node[i].url === 'string' &&
node[i].url.split(':')[0] === 'stac-collection'
) {
if (window.mmgisglobal.WITH_TITILER === 'true') {
// prettier-ignore
additionalSettings = [
`<img id="titlerCogColormapImage_${node[i].name}" src="${window.location.origin}${(
window.location.pathname || ''
).replace(/\/$/g, '')}/titiler/colorMaps/${node[i].cogColormap}?format=png"></img>`,
].join('\n')
} else {
let { colormap, reverse } =
LayersTool.findJSColormap(
node[i],
node[i].cogColormap
)
additionalSettings = colormapData[
colormap
].colors.map((hex) => {
let rgb = hex
.map((v) => {
return Math.floor(v * 255)
})
.join(',')
return `<div style="background: rgb(${rgb}); width: 20px; height: 100%; margin: 0px; flex-grow: 1;"></div>`
})
if (reverse === true) {
additionalSettings.reverse()
}
additionalSettings = [
'<div id="titlerCogColormapCSS">',
additionalSettings.join('\n'),
'</div>',
].join('\n')
}
// prettier-ignore
additionalSettings = [
'<div class="layerSettingsTitle">',
'<div>COG Settings</div>',
`<div class="resetCog" title="Reset COG Settings" layername="${node[i].name}">`,
'<i class="mdi mdi-restore mdi-18px"></i>',
'</div>',
'</div>',
`<li class="tileCogMin">`,
'<div>',
'<div>Rescale Min Value</div>',
'<div>',
`<input class='tilerescalecogmin' style="width: 120px; border: none; height: 28px; margin: 1px 0px;" layername="${node[i].name}" parameter="min" type="number" value="${node[i].currentCogMin != null ? node[i].currentCogMin : node[i].cogMin}" default="0">`,
node[i].cogUnits != null ? `<div class='tileCogUnits'>${node[i].cogUnits}</div>`: '',
'</div>',
'</div>',
'</li>',
'<li id="tileCogLegend_1" class="tileCogLegend">-</li>',
'<li id="tileCogLegend_2" class="tileCogLegend">-</li>',
'<li id="tileCogLegend_3" class="tileCogLegend">-</li>',
'<li id="tileCogLegend_4" class="tileCogLegend">-</li>',
'<li id="tileCogLegend_5" class="tileCogLegend">-</li>',
'<li id="tileCogLegend_6" class="tileCogLegend">-</li>',
'<li id="tileCogLegend_7" class="tileCogLegend">-</li>',
`<li class="tileCogMax">`,
'<div>',
'<div>Rescale Max Value</div>',
'<div>',
`<input class='tilerescalecogmax' style="width: 120px; border: none; height: 28px; margin: 1px 0px;" layername="${node[i].name}" parameter="max" type="number" value="${node[i].currentCogMin != null ? node[i].currentCogMax : node[i].cogMax}" default="255">`,
node[i].cogUnits != null ? `<div class='tileCogUnits'>${node[i].cogUnits}</div>`: '',
'</div>',
'</div>',
'</li>',
'<div class="tileCogColor">',
`<li class="tileCogColormap">`,
`<div class="tileCogColormapMap">`,
additionalSettings,
`<ul id="tileCogColormapMapLines"></ul>`,
`</div>`,
'</li>',
'</div>'
].join('\n')
}
// prettier-ignore
settings = [
'<ul>',
'<li>',
'<div>',
'<div>Opacity</div>',
'<input class="transparencyslider slider2" layername="' + node[i].name + '" type="range" min="0" max="1" step="0.01" value="' + currentOpacity + '" default="' + L_.layers.opacity[node[i].name] + '">',
'</div>',
'</li>',
'<li>',
'<div>',
'<div>Brightness</div>',
'<input class="tilefilterslider slider2" filter="brightness" unit="%" layername="' + node[i].name + '" type="range" min="0" max="3" step="0.05" value="' + currentBrightness + '" default="' + defaultBrightness + '">',
'</div>',
'</li>',
'<li>',
'<div>',
'<div>Contrast</div>',
'<input class="tilefilterslider slider2" filter="contrast" unit="%" layername="' + node[i].name + '" type="range" min="0" max="4" step="0.05" value="' + currentContrast + '" default="' + defaultContrast + '">',
'</div>',
'</li>',
'<li>',
'<div>',
'<div>Saturation</div>',
'<input class="tilefilterslider slider2" filter="saturate" unit="%" layername="' + node[i].name + '" type="range" min="0" max="4" step="0.05" value="' + currentSaturation + '" default="' + defaultSaturation + '">',
'</div>',
'</li>',
'<li>',
'<div>',
'<div>Blend</div>',
'<select class="tileblender dropdown" layername="' + node[i].name + '" defaultBlend="' + defaultBlend + '">',
'<option value="unset"' + (currentBlend == 'none' ? ' selected' : '') + '>None</option>',
'<option value="color"' + (currentBlend == 'color' ? ' selected' : '') + '>Color</option>',
//'<option value="color-burn">Color Burn</option>',
//'<option value="color-dodge">Color Dodge</option>',
//'<option value="darken">Darken</option>',
//'<option value="difference">Difference</option>',
//'<option value="exclusion">Exclusion</option>',
//'<option value="hard-light">Hard Light</option>',
//'<option value="hue">Hue</option>',
//'<option value="lighten">Lighten</option>',
//'<option value="luminosity">Luminosity</option>',
//'<option value="multiply">Multiply</option>',
'<option value="overlay"' + (currentBlend == 'overlay' ? ' selected' : '') + '>Overlay</option>',
//'<option value="saturation">Saturation</option>',
//'<option value="screen">Screen</option>',
//'<option value="soft-light" ' + (currentBlend == 'soft-light' ? ' selected' : '') + '>Soft Light</option>',
'</select>',
'</div>',
'</li>',
additionalSettings,
/*
'<li>',
'<div>',
'<div>Hue</div>',
'<input class="tilefilterslider slider2" filter="hue-rotate" unit="deg" layername="' + node[i].name + '" type="range" min="0" max="3.60" step="0.1" value="0" default="0">',
'</div>',
'</li>',
'<li>',
'<div>',
'<div>Invert</div>',
'<input class="tilefilterslider slider2" filter="invert" unit="%" layername="' + node[i].name + '" type="range" min="0" max="1" step="0.05" value="0" default="0">',
'</div>',
'</li>',
*/
'</ul>'
].join('\n')
break
case 'data':
currentOpacity = L_.getLayerOpacity(node[i].name)
if (currentOpacity == null)
currentOpacity = L_.layers.opacity[node[i].name]
currentBlend = 'none'
if (L_.layers.filters[node[i].name]) {
let f = L_.layers.filters[node[i].name]
currentBlend =
f['mix-blend-mode'] == null
? 'none'
: f['mix-blend-mode']
}
additionalSettings = ''
const shader = F_.getIn(node[i], 'variables.shader')
if (shader && DataShaders[shader.type]) {
// prettier-ignore
additionalSettings = [
DataShaders[shader.type].getHTML(node[i].name, shader)
].join('\n')
}
// prettier-ignore
settings = [
'<ul>',
'<li>',
'<div>',
'<div>Opacity</div>',
'<input class="transparencyslider slider2" layername="' + node[i].name + '" type="range" min="0" max="1" step="0.01" value="' + currentOpacity + '" default="' + L_.layers.opacity[node[i].name] + '">',
'</div>',
'</li>',
'<li>',
'<div>',
'<div>Blend</div>',
'<select class="tileblender dropdown" layername="' + node[i].name + '">',
'<option value="unset"' + (currentBlend == 'none' ? ' selected' : '') + '>None</option>',
'<option value="color"' + (currentBlend == 'color' ? ' selected' : '') + '>Color</option>',
'<option value="overlay"' + (currentBlend == 'overlay' ? ' selected' : '') + '>Overlay</option>',
'</select>',
'</div>',
'</li>',
additionalSettings,
'</ul>'
].join('\n')
break
case 'model':
case 'query':
case 'velocity':
currentOpacity = L_.getLayerOpacity(node[i].name)
if (currentOpacity == null)
currentOpacity = L_.layers.opacity[node[i].name]
if (
node[i].kind === 'streamlines'
) {
if (window.mmgisglobal.WITH_TITILER === "true") {
// prettier-ignore
additionalSettings = [
`<img id="titlerCogColormapImage_${node[i].name}" src="${window.location.origin}${(
window.location.pathname || ''
).replace(/\/$/g, '')}/titiler/colorMaps/${node[i].variables.streamlines.colorScale.toLowerCase()}?format=png"></img>`,
].join('\n')
} else {
let { colormap, reverse } = LayersTool.findJSColormap(node[i], node[i].variables.streamlines.colorScale)
additionalSettings = (colormapData[colormap].colors).map(
(hex) => {
let rgb = hex.map(v => {return Math.floor(v * 255)}).join(',')
return `<div style="background: rgb(${rgb}); width: 20px; height: 100%; margin: 0px; flex-grow: 1;"></div>`;
}
)
if (reverse === true) {
additionalSettings.reverse()
}
additionalSettings = [
'<div id="titlerCogColormapCSS">',
additionalSettings.join('\n'),
'</div>',
].join('\n')
}
// prettier-ignore
additionalSettings = [
'<div class="layerSettingsTitle">',
'<div>Color Settings</div>',
`<div class="resetCog" title="Reset Color Settings" layername="${node[i].name}">`,
'<i class="mdi mdi-restore mdi-18px"></i>',
'</div>',
'</div>',
`<li class="tileCogMin">`,
'<div>',
'<div>Rescale Min Value</div>',
'<div>',
`<input class='tilerescalecogmin' style="width: 120px; border: none; height: 28px; margin: 1px 0px;" layername="${node[i].name}" parameter="min" type="number" value="${node[i].currentCogMin != null ? node[i].currentCogMin : node[i].variables?.streamlines?.minVelocity}" default="0">`,
node[i].variables?.streamlines?.units != null ? `<div class='tileCogUnits'>${node[i].variables?.streamlines?.units}</div>`: '',
'</div>',
'</div>',
'</li>',
'<li id="tileCogLegend_1" class="tileCogLegend">-</li>',
'<li id="tileCogLegend_2" class="tileCogLegend">-</li>',
'<li id="tileCogLegend_3" class="tileCogLegend">-</li>',
'<li id="tileCogLegend_4" class="tileCogLegend">-</li>',
'<li id="tileCogLegend_5" class="tileCogLegend">-</li>',
'<li id="tileCogLegend_6" class="tileCogLegend">-</li>',
'<li id="tileCogLegend_7" class="tileCogLegend">-</li>',
`<li class="tileCogMax">`,
'<div>',
'<div>Rescale Max Value</div>',
'<div>',
`<input class='tilerescalecogmax' style="width: 120px; border: none; height: 28px; margin: 1px 0px;" layername="${node[i].name}" parameter="max" type="number" value="${node[i].currentCogMin != null ? node[i].currentCogMax : node[i].variables?.streamlines?.maxVelocity}" default="255">`,
node[i].variables?.streamlines?.units != null ? `<div class='tileCogUnits'>${node[i].variables?.streamlines?.units}</div>`: '',
'</div>',
'</div>',
'</li>',
'<div class="tileCogColor">',
`<li class="tileCogColormap">`,
`<div class="tileCogColormapMap">`,
additionalSettings,
`<ul id="tileCogColormapMapLines"></ul>`,
`</div>`,
'</li>',
'</div>'
].join('\n')
}
// prettier-ignore
settings = [
'<ul>',
'<li>',
'<div>',
'<div>Opacity</div>',
'<input class="transparencyslider slider2" layername="' + node[i].name + '" type="range" min="0" max="1" step="0.01" value="' + currentOpacity + '" default="' + L_.layers.opacity[node[i].name] + '">',
'</div>',
'</li>',
additionalSettings,
].join('\n')
break
case 'image':
currentOpacity = L_.getLayerOpacity(node[i].name)
if (currentOpacity == null)
currentOpacity = L_.layers.opacity[node[i].name]
if (
node[i].cogTransform === true &&
typeof node[i].url === 'string' &&
L_.layers.layer[node[i].name].georasters &&
L_.layers.layer[node[i].name].georasters[0]
.numberOfRasters === 1
) {
if (window.mmgisglobal.WITH_TITILER === 'true') {
// prettier-ignore
additionalSettings = [
`<img id="titlerCogColormapImage_${node[i].name}" src="${window.location.origin}${(
window.location.pathname || ''
).replace(/\/$/g, '')}/titiler/colorMaps/${node[i].cogColormap}?format=png"></img>`,
].join('\n')
} else {
let { colormap, reverse } =
LayersTool.findJSColormap(
node[i],
node[i].cogColormap
)
additionalSettings = colormapData[
colormap
].colors.map((hex) => {
let rgb = hex
.map((v) => {
return Math.floor(v * 255)
})
.join(',')
return `<div style="background: rgb(${rgb}); width: 20px; height: 100%; margin: 0px; flex-grow: 1;"></div>`
})
if (reverse === true) {
additionalSettings.reverse()
}
additionalSettings = [
'<div id="titlerCogColormapCSS">',
additionalSettings.join('\n'),
'</div>',
].join('\n')
}
// prettier-ignore
additionalSettings = [
'<div class="layerSettingsTitle">',
'<div>COG Settings</div>',
`<div class="resetCog" title="Reset COG Settings" layername="${node[i].name}">`,
'<i class="mdi mdi-restore mdi-18px"></i>',
'</div>',
'</div>',
`<li class="tileCogMin">`,
'<div>',
'<div>Rescale Min Value</div>',
'<div>',
`<input class='tilerescalecogmin' style="width: 120px; border: none; height: 28px; margin: 1px 0px;" layername="${node[i].name}" parameter="min" type="number" value="${node[i].currentCogMin != null ? node[i].currentCogMin : node[i].cogMin}" default="0">`,
node[i].cogUnits != null ? `<div class='tileCogUnits'>${node[i].cogUnits}</div>`: '',
'</div>',
'</div>',
'</li>',
'<li id="tileCogLegend_1" class="tileCogLegend">-</li>',
'<li id="tileCogLegend_2" class="tileCogLegend">-</li>',
'<li id="tileCogLegend_3" class="tileCogLegend">-</li>',
'<li id="tileCogLegend_4" class="tileCogLegend">-</li>',
'<li id="tileCogLegend_5" class="tileCogLegend">-</li>',
'<li id="tileCogLegend_6" class="tileCogLegend">-</li>',
'<li id="tileCogLegend_7" class="tileCogLegend">-</li>',
`<li class="tileCogMax">`,
'<div>',
'<div>Rescale Max Value</div>',
'<div>',
`<input class='tilerescalecogmax' style="width: 120px; border: none; height: 28px; margin: 1px 0px;" layername="${node[i].name}" parameter="max" type="number" value="${node[i].currentCogMin != null ? node[i].currentCogMax : node[i].cogMax}" default="255">`,
node[i].cogUnits != null ? `<div class='tileCogUnits'>${node[i].cogUnits}</div>`: '',
'</div>',
'</div>',
'</li>',
'<div class="tileCogColor">',
`<li class="tileCogColormap">`,
`<div class="tileCogColormapMap">`,
additionalSettings,
`<ul id="tileCogColormapMapLines"></ul>`,
`</div>`,
'</li>',
'</div>'
].join('\n')
}
// prettier-ignore
settings = [
'<ul>',
'<li>',
'<div>',
'<div>Opacity</div>',
'<input class="transparencyslider slider2" layername="' + node[i].name + '" type="range" min="0" max="1" step="0.01" value="' + currentOpacity + '" default="' + L_.layers.opacity[node[i].name] + '">',
'</div>',
'</li>',
additionalSettings,
]
/*
let min = null, max = null
if (node[i].variables && node[i].variables.image) {
min = node[i].variables.image.defaults[1].min
max = node[i].variables.image.defaults[1].max
if (min !== null && max !== null) {
settings = [