-
Notifications
You must be signed in to change notification settings - Fork 55
/
legend.js
750 lines (690 loc) · 24.7 KB
/
legend.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
import Awesomplete from 'awesomplete';
import {
Component, Button, Element as El, ToggleGroup, dom, Input
} from '../ui';
import imageSource from './legend/imagesource';
import Overlays from './legend/overlays';
import VisibleOverlays from './legend/visibleOverlays';
import LayerProperties from './legend/overlayproperties';
import PopupMenu from '../ui/popupmenu';
const Legend = function Legend(options = {}) {
const {
cls: clsSettings = '',
style: styleSettings = {},
autoHide = 'never',
expanded = true,
contentCls,
contentStyle,
turnOnLayersControl = false,
name = 'legend',
labelOpacitySlider = '',
visibleLayersControl = false,
turnOffLayersControl = false,
useGroupIndication = true,
searchLayersControl = false,
searchLayersMinLength = 2,
searchLayersLimit = 10,
searchLayersParameters = ['name', 'title'],
searchLayersPlaceholderText = 'Sök lager'
} = options;
let {
visibleLayersViewActive = false
} = options;
const keyCodes = {
9: 'tab',
27: 'esc',
37: 'left',
39: 'right',
13: 'enter',
38: 'up',
40: 'down'
};
let viewer;
let target;
let awesomplete;
let mainContainerCmp;
let overlaysCmp;
let visibleOverlaysCmp;
let mainContainerEl;
const backgroundLayerButtons = [];
let toggleGroup;
let layerSwitcherEl;
let addLayerButton;
let closeButton;
let layerButton;
let layerButtonEl;
let layerSwitcherCmp;
let isExpanded;
let toolsCmp;
const cls = `${clsSettings} control bottom-right box flex row o-legend`.trim();
const style = dom.createStyle(Object.assign({}, { width: 'auto', overflow: 'unset' }, styleSettings));
const popupMenuItems = [];
let popupMenu;
const setTabIndex = function setTabIndex() {
let idx = -1;
if (isExpanded) {
idx = 0;
}
for (let i = 0; i < document.getElementById(mainContainerCmp.getId()).getElementsByTagName('button').length; i += 1) {
// Skip if it's slidenav button and not expanded otherwise set tab index
if (document.getElementById(mainContainerCmp.getId()).getElementsByTagName('button')[i].tabIndex !== -99) {
if (document.getElementById(mainContainerCmp.getId()).getElementsByTagName('button')[i].closest('.collapse') !== null) {
if (document.getElementById(mainContainerCmp.getId()).getElementsByTagName('button')[i].closest('.collapse').className.indexOf('expanded') !== -1) {
document.getElementById(mainContainerCmp.getId()).getElementsByTagName('button')[i].tabIndex = idx;
}
}
}
}
};
const addBackgroundButton = function addBackgroundButton(layer) {
const styleName = layer.get('styleName') || 'default';
const icon = viewer.getStyle(styleName) ? imageSource(viewer.getStyle(styleName)) : 'img/png/farg.png';
const backgroundLayerButton = Button({
icon,
cls: 'round smallest border icon-small icon-bg',
title: layer.get('title'),
state: layer.get('visible') ? 'active' : undefined,
methods: {
active: () => layer.setVisible(true),
initial: () => layer.setVisible(false)
},
click() {
const overlayComponent = visibleLayersControl && visibleLayersViewActive ? visibleOverlaysCmp : overlaysCmp;
if (overlayComponent.slidenav.getState() === 'initial') {
const slided = document.getElementById(overlayComponent.slidenav.getId()).classList.contains('slide-secondary');
if (this.getState() === 'active' && !slided) {
const layerProperties = LayerProperties({ layer, viewer, parent: this });
overlayComponent.slidenav.setSecondary(layerProperties);
overlayComponent.slidenav.slideToSecondary();
} else if (slided) {
overlayComponent.slidenav.slideToMain();
}
}
}
});
layer.on('change:visible', () => {
if (layer.getVisible() === true) {
backgroundLayerButton.setState('active');
} else {
backgroundLayerButton.setState('initial');
}
});
backgroundLayerButtons.push(backgroundLayerButton);
};
const addBackgroundButtons = function addBackgroundButtons(layers) {
layers.forEach((layer) => {
addBackgroundButton(layer);
});
};
const getTargetHeight = () => target.offsetHeight;
const calcMaxHeight = function calcMaxHeight(size) {
const topMargin = 64;
const bottomMargin = 32;
const maxHeight = size - topMargin - bottomMargin;
return maxHeight;
};
const updateMaxHeight = function updateMaxHeight() {
mainContainerEl.style.maxHeight = `${calcMaxHeight(getTargetHeight())}px`;
};
const turnOffAllLayers = function turnOffAllLayers() {
const layers = viewer.getLayersByProperty('visible', true);
layers.forEach((el) => {
if (!(['none', 'background'].includes(el.get('group')))) {
el.setVisible(false);
}
});
};
const turnOnAllLayers = function turnOnAllLayers() {
const layers = viewer.getLayers();
layers.forEach((el) => {
if (!(['none', 'background'].includes(el.get('group')))) {
const group = viewer.getGroups().find((item) => item.name === el.get('group'));
if (typeof group !== 'undefined') {
if (!group.exclusive) {
el.setVisible(true);
}
} else {
el.setVisible(true);
}
}
});
};
const divider = El({
cls: 'divider margin-x-small',
style: {
'border-width': '2px',
'margin-bottom': '5px',
'margin-top': '5px'
}
});
const turnOffLayersButton = Button({
cls: 'round compact icon-small margin-x-smaller',
title: 'Släck alla lager',
click() {
viewer.dispatch('active:turnofflayers');
},
style: {
'align-self': 'center',
'padding-right': '6px'
},
icon: '#ic_visibility_off_24px',
iconStyle: {
fill: '#7a7a7a'
}
});
const showVisibleLayersButton = Button({
cls: 'compact icon-smaller margin-x-small hidden',
title: 'Visa endast tända lager',
click() {
viewer.dispatch('active:togglevisibleLayers');
},
style: {
'align-self': 'right',
'padding-right': '6px'
},
icon: '#ic_close_fullscreen_24px',
iconStyle: {
fill: '#4a4a4a'
}
});
const showAllVisibleLayersButton = Button({
cls: 'compact icon-smaller margin-x-small hidden',
title: 'Visa alla lager',
click() {
viewer.dispatch('active:togglevisibleLayers');
},
style: {
'align-self': 'right',
'padding-right': '6px'
},
icon: '#ic_open_in_full_24px',
iconStyle: {
fill: '#4a4a4a'
}
});
const setVisibleLayersViewActive = function setVisibleLayersViewActive(active) {
if (!visibleLayersControl) return;
visibleLayersViewActive = active;
if (visibleLayersViewActive) {
document.getElementById(overlaysCmp.getId()).classList.add('hidden');
document.getElementById(visibleOverlaysCmp.getId()).classList.remove('hidden');
document.getElementById(showAllVisibleLayersButton.getId()).classList.remove('hidden');
document.getElementById(showVisibleLayersButton.getId()).classList.add('hidden');
visibleOverlaysCmp.dispatch('readOverlays');
document.getElementById(toolsCmp.getId()).classList.add('hidden');
} else {
document.getElementById(overlaysCmp.getId()).classList.remove('hidden');
document.getElementById(visibleOverlaysCmp.getId()).classList.add('hidden');
document.getElementById(showAllVisibleLayersButton.getId()).classList.add('hidden');
document.getElementById(showVisibleLayersButton.getId()).classList.remove('hidden');
if (toolsCmp.getComponents().length > 0) {
document.getElementById(toolsCmp.getId()).classList.remove('hidden');
}
}
};
const toggleShowVisibleLayers = function toggleShowVisibleLayers() {
setVisibleLayersViewActive(!visibleLayersViewActive);
};
const turnOnLayersButton = Button({
cls: 'round compact icon-small margin-x-smaller',
title: 'Tänd alla lager utom bakgrundslager',
click() {
viewer.dispatch('active:turnonlayers');
},
style: {
'align-self': 'center',
'padding-right': '6px'
},
icon: '#ic_visibility_24px',
iconStyle: {
fill: '#7a7a7a'
}
});
const addPopupMenuItems = function addPopupMenuItems(button, cmp) {
if (addLayerButton.getState() === 'hidden') {
cmp.addButtonToTools(addLayerButton);
addLayerButton.setState('initial');
}
popupMenuItems.push(button);
};
const popupMenuList = Component({
render() {
this.addComponents(popupMenuItems);
let html = `<ul id="${this.getId()}">`;
popupMenuItems.forEach((item) => {
html += `<li class="padding-x-small">${item.render()}</li>`;
});
html += '</ul>';
return html;
}
});
const createPopupMenu = function createPopupMenu() {
const relDiv = document.createElement('div');
const absDiv = document.createElement('div');
relDiv.classList.add('relative');
relDiv.style.display = 'contents';
absDiv.classList.add('absolute');
const addLayerButtonEl = document.getElementById(addLayerButton.getId());
const onUnfocus = (e) => {
if (!addLayerButtonEl.contains(e.target)) {
popupMenu.setVisibility(false);
}
};
popupMenu = PopupMenu({ onUnfocus, cls: 'button-popup' });
addLayerButtonEl.insertAdjacentElement('beforebegin', relDiv);
relDiv.appendChild(absDiv);
absDiv.appendChild(dom.html(popupMenu.render()));
relDiv.addEventListener('click', () => { popupMenu.setVisibility(false); });
popupMenu.setContent(popupMenuList.render());
popupMenuList.dispatch('render');
if (popupMenuItems.length > 1) {
popupMenu.setVisibility(true);
} else {
popupMenu.setVisibility(false);
popupMenuItems[0].dispatch('click');
}
};
const togglePopupMenu = function togglePopupMenu() {
if (!popupMenu) {
createPopupMenu();
} else if (popupMenuItems.length > 1) {
popupMenu.toggleVisibility();
} else {
popupMenu.setVisibility(false);
popupMenuItems[0].dispatch('click');
}
};
addLayerButton = Button({
cls: 'round compact primary icon-small margin-x-smaller o-tooltip',
click() {
togglePopupMenu();
},
style: {
'align-self': 'center'
},
icon: '#o_add_24px',
ariaLabel: 'Lägg till lager',
title: 'Lägg till lager',
tabIndex: -1,
validStates: ['initial', 'hidden'],
state: 'hidden'
});
const layerSearchInput = Input({
cls: 'o-search-layer-field placeholder-text-smaller smaller',
style: { height: '1.5rem', margin: 0, width: '100%' },
placeholderText: searchLayersPlaceholderText,
value: ''
});
const toggleVisibility = function toggleVisibility() {
if (isExpanded) {
layerSwitcherEl.classList.add('fade-out');
layerSwitcherEl.classList.remove('fade-in');
layerButtonEl.classList.add('fade-in');
layerButtonEl.classList.remove('fade-out');
closeButton.setState('hidden');
} else {
layerSwitcherEl.classList.remove('fade-out');
layerSwitcherEl.classList.add('fade-in');
layerButtonEl.classList.remove('fade-out');
layerButtonEl.classList.add('fade-in');
closeButton.setState('initial');
}
layerButtonEl.classList.toggle('faded');
layerSwitcherEl.classList.toggle('faded');
isExpanded = !isExpanded;
setTabIndex();
};
const onMapClick = function onMapClick() {
if (autoHide === 'always' && isExpanded) {
toggleVisibility();
} else if (autoHide === 'mobile' && isExpanded) {
const size = viewer.getSize();
if (size === 'm' || size === 's' || size === 'xs') {
toggleVisibility();
}
}
};
/** There are several different ways to handle selected search result.
*/
function selectHandler(evt) {
const label = evt.text.label;
if (name) {
// Todo
const layer = viewer.getLayer(label);
const layerGroup = layer.get('group');
const groupExclusive = (viewer.getGroup(layerGroup) && (viewer.getGroup(layerGroup).exclusive || viewer.getGroup(layerGroup).name === 'background'));
if (groupExclusive) {
const layers = viewer.getLayersByProperty('group', layerGroup);
layers.forEach(l => l.setVisible(false));
}
layer.setVisible(true);
document.getElementsByClassName('o-search-layer-field')[0].value = '';
} else {
console.error('Search options are missing');
}
}
function clearSearchResults() {
awesomplete.list = [];
}
function onClearSearch() {
document.getElementById(`${closeButton.getId()}`).addEventListener('click', () => {
clearSearchResults();
document.getElementById(`${layerSearchInput.getId()}`).classList.remove('o-search-true');
document.getElementById(`${layerSearchInput.getId()}`).classList.add('o-search-false');
document.getElementsByClassName('o-search-layer-field')[0].value = '';
});
}
function bindUIActions() {
if (searchLayersControl) {
document.getElementById(`${layerSearchInput.getId()}`).addEventListener('awesomplete-selectcomplete', selectHandler);
document.getElementsByClassName('o-search-layer-field')[0].addEventListener('input', () => {
if (document.getElementsByClassName('o-search-layer-field')[0].value && document.getElementById(`${layerSearchInput.getId()}`).classList.contains('o-search-false')) {
document.getElementById(`${layerSearchInput.getId()}`).classList.remove('o-search-false');
document.getElementById(`${layerSearchInput.getId()}`).classList.add('o-search-true');
onClearSearch();
} else if (!(document.getElementsByClassName('o-search-layer-field')[0].value) && document.getElementById(`${layerSearchInput.getId()}`).classList.contains('o-search-true')) {
document.getElementById(`${layerSearchInput.getId()}`).classList.remove('o-search-true');
document.getElementById(`${layerSearchInput.getId()}`).classList.add('o-search-false');
}
});
}
}
function renderList(suggestion, input) {
let opts = {};
let html = input === '' ? suggestion.value : suggestion.value.replace(RegExp(Awesomplete.$.regExpEscape(input), 'gi'), '<mark>$&</mark>');
html = `<div class="suggestion">${html}</div>`;
opts = {
innerHTML: html,
'aria-selected': 'false'
};
return Awesomplete.$.create('li', opts);
}
/*
The label property in Awesomplete is used to store the feature id. This way the properties
of each feature in the search response will be available in event handling.
The complete properties are stored in a tempory db called searchDb. This is a workaround
for a limit in Awesomplete that can only store data in the fields label and text.
The data-category attribute is used to make a layer division in the sugguestion list.
*/
function initAutocomplete() {
const input = document.getElementsByClassName('o-search-layer-field')[0];
function shorten(text, searchword) {
let returnValue = text;
if (text.length > 20) {
returnValue = `...${text.substring(text.indexOf(searchword) - 3, text.indexOf(searchword) + searchword.length + 3).trim()}...`;
}
return returnValue;
}
function makeRequest(obj) {
const layersArr = viewer.getLayers();
const hitArr = [];
layersArr.forEach((layer) => {
if (layer.get('group') !== 'none') {
let found = false;
const label = layer.get('name');
let value = label;
if (label.toLowerCase().search(obj.value.toLowerCase()) !== -1 && searchLayersParameters.includes('name')) {
found = true;
}
if (typeof layer.get('title') !== 'undefined' && searchLayersParameters.includes('title')) {
value = layer.get('title');
if (value.toLowerCase().search(obj.value.toLowerCase()) !== -1) {
found = true;
}
}
if (typeof layer.get('abstract') !== 'undefined' && searchLayersParameters.includes('abstract') && !found) {
value = layer.get('abstract');
if (value.toLowerCase().search(obj.value.toLowerCase()) !== -1) {
found = true;
}
if (typeof layer.get('title') === 'undefined') {
value = `Titel saknas (${shorten(value, obj.value)})`;
} else {
value = `${layer.get('title')} (${shorten(value, obj.value)})`;
}
}
if (found) {
const dataItem = {};
dataItem.label = label;
dataItem.value = value;
hitArr.push(dataItem);
}
}
});
awesomplete.list = hitArr;
awesomplete.evaluate();
}
if (typeof input !== 'undefined') {
awesomplete = new Awesomplete('.o-search-layer-field', {
minChars: searchLayersMinLength,
autoFirst: false,
sort: false,
maxItems: searchLayersLimit,
item: renderList,
filter(suggestion, userInput) {
const { value: suggestionValue } = suggestion;
return suggestionValue.toLowerCase().includes(userInput.toLowerCase()) ? suggestionValue : false;
}
});
awesomplete.ul.style.maxHeight = `${calcMaxHeight(getTargetHeight()) / 2}px`;
input.parentNode.classList.add('black');
input.parentNode.classList.add('grow');
input.addEventListener('keyup', (e) => {
const keyCode = e.keyCode;
if (input.value.length >= searchLayersMinLength) {
if (keyCode in keyCodes) {
// empty
} else {
makeRequest(input);
}
}
});
}
}
function getState() {
return {
expanded: isExpanded,
visibleLayersViewActive
};
}
function restoreState(params) {
if (params && params.legend) {
const legendState = params.legend;
if (legendState.expanded != null && legendState.expanded !== isExpanded) {
toggleVisibility();
}
if (legendState.visibleLayersViewActive != null) {
setVisibleLayersViewActive(legendState.visibleLayersViewActive);
}
}
}
return Component({
name,
getLayerSwitcherCmp() {
return layerSwitcherCmp;
},
getState() {
return getState();
},
restoreState(params) {
restoreState(params);
},
getuseGroupIndication() { return useGroupIndication; },
getOverlaysCollapse() { return overlaysCmp.overlaysCollapse; },
getOverlays() { return overlaysCmp; },
setVisibleLayersViewActive,
addButtonToTools(button, buttonGroup) {
if (buttonGroup === 'addLayerButton') {
addPopupMenuItems(button, this);
} else {
const toolsEl = document.getElementById(toolsCmp.getId());
toolsEl.classList.remove('hidden');
if (toolsCmp.getComponents().length > 0) {
toolsEl.style.justifyContent = 'space-between';
toolsEl.insertBefore(dom.html(divider.render()), toolsEl.firstChild);
toolsEl.insertBefore(dom.html(button.render()), toolsEl.firstChild);
} else {
const node = document.createElement('div');
if (typeof button.getValue === 'function') {
node.classList.add('grow');
toolsEl.appendChild(node);
node.appendChild(dom.html(button.render()));
} else {
toolsEl.appendChild(dom.html(button.render()));
}
}
toolsCmp.addComponent(button);
button.onRender();
}
},
onInit() {
this.on('render', this.onRender);
},
onAdd(evt) {
viewer = evt.target;
if (turnOffLayersControl) {
viewer.on('active:turnofflayers', turnOffAllLayers);
}
if (turnOnLayersControl) {
viewer.on('active:turnonlayers', turnOnAllLayers);
}
viewer.on('active:togglevisibleLayers', toggleShowVisibleLayers);
const backgroundLayers = viewer.getLayersByProperty('group', 'background').reverse();
addBackgroundButtons(backgroundLayers);
toggleGroup = ToggleGroup({
components: backgroundLayerButtons,
cls: 'spacing-horizontal-small'
});
this.render();
this.dispatch('render');
viewer.getMap().on('click', onMapClick);
},
hide() {
document.getElementById(mainContainerCmp.getId()).classList.add('hidden');
document.getElementById(layerButton.getId()).classList.add('hidden');
},
unhide() {
document.getElementById(mainContainerCmp.getId()).classList.remove('hidden');
document.getElementById(layerButton.getId()).classList.remove('hidden');
},
onRender() {
const layerControlCmps = [];
if (turnOnLayersControl) layerControlCmps.push(turnOnLayersButton);
if (turnOffLayersControl) layerControlCmps.push(turnOffLayersButton);
const layerControl = El({
cls: 'flex justify-end align-center no-shrink',
components: layerControlCmps
});
mainContainerEl = document.getElementById(mainContainerCmp.getId());
layerButtonEl = document.getElementById(layerButton.getId());
layerSwitcherEl.addEventListener('collapse:toggle', (e) => {
e.preventDefault();
e.stopPropagation();
toggleVisibility();
});
window.addEventListener('resize', updateMaxHeight);
if (layerControlCmps.length > 0) this.addButtonToTools(layerControl);
if (searchLayersControl) this.addButtonToTools(layerSearchInput);
initAutocomplete();
bindUIActions();
setTabIndex();
setVisibleLayersViewActive(visibleLayersViewActive);
restoreState(viewer.getUrlParams());
},
render() {
const size = viewer.getSize();
isExpanded = !size && expanded;
target = document.getElementById(viewer.getMain().getId());
const maxHeight = calcMaxHeight(getTargetHeight());
overlaysCmp = Overlays({
viewer, cls: contentCls, style: contentStyle, labelOpacitySlider
});
visibleOverlaysCmp = VisibleOverlays({
viewer, cls: `${contentCls} hidden`, style: contentStyle, labelOpacitySlider
});
const baselayerCmps = [toggleGroup];
toolsCmp = El({
cls: 'flex padding-small no-shrink hidden',
tooltipText: 'Lagerbytare',
style: {
'background-color': '#fff',
'justify-content': 'flex-end',
height: '40px'
}
});
const closeButtonState = isExpanded ? 'initial' : 'hidden';
closeButton = Button({
cls: 'icon-smaller small round grey-lightest',
icon: '#ic_close_24px',
state: closeButtonState,
validStates: ['initial', 'hidden'],
ariaLabel: 'Stäng',
click() {
toggleVisibility();
}
});
const legendControlDivider = El({
cls: `divider margin-x-small ${!visibleLayersControl && 'hidden'}`,
style: {
height: '100%',
'border-width': '2px'
}
});
const legendControlCmps = [];
legendControlCmps.push(legendControlDivider);
legendControlCmps.push(showVisibleLayersButton);
legendControlCmps.push(showAllVisibleLayersButton);
legendControlCmps.push(closeButton);
const legendControlCmp = El({
cls: 'grow flex justify-end align-center no-shrink',
components: legendControlCmps
});
baselayerCmps.push(legendControlCmp);
const baselayersCmp = El({
cls: 'flex padding-small no-shrink',
style: {
'background-color': '#fff',
height: '50px',
'border-top': '1px solid #dbdbdb',
'border-radius': '0.5rem'
},
components: baselayerCmps
});
const mainContainerComponents = [overlaysCmp, visibleOverlaysCmp, toolsCmp, baselayersCmp];
mainContainerCmp = El({
cls: 'flex column relative width-100',
components: mainContainerComponents,
style: {
'max-height': `${maxHeight}px`
}
});
const layerSwitcherCls = isExpanded ? '' : ' faded';
layerSwitcherCmp = El({
name: 'layerSwitcher',
style,
cls: `${cls}${layerSwitcherCls}`,
components: [mainContainerCmp],
target
});
layerSwitcherCmp.render();
layerSwitcherEl = document.getElementById(layerSwitcherCmp.getId());
const layerButtonCls = isExpanded ? ' faded' : '';
layerButton = Button({
icon: '#ic_layers_24px',
tooltipText: 'Lager',
tooltipPlacement: 'west',
cls: `control icon-small medium round absolute light bottom-right${layerButtonCls}`,
click() {
if (!isExpanded) {
overlaysCmp.dispatch('expand');
toggleVisibility();
}
}
});
this.addComponent(layerButton);
const el = dom.html(layerButton.render());
target.appendChild(el);
}
});
};
export default Legend;