1/* 2 * L.Control.Layers is a control to allow users to switch between different layers on the map. 3 4 https://raw.githubusercontent.com/Leaflet/Leaflet/v0.7.7/src/control/Control.Layers.js 5 */ 6 7osmcz.LayerSwitcher = L.Control.extend({ 8 options: { 9 collapsed: true, 10 position: 'topright', 11 autoZIndex: true 12 }, 13 14 initialize: function (baseLayers, overlays, panel, options) { 15 L.setOptions(this, options); 16 17 this._mode = 'basic'; // Layer switcher mode - basic or groups 18 19 this._layers = {}; // List of layers 20 this._groups = {}; // List of groups 21 this._groupsHeaders = {}; // List of groups headers 22 this._cntInGroup = {}; // Store number of layers per group 23 this._cntActiveInGroup = {}; // Store number of active layers per group 24 this._lastZIndex = 0; 25 this._handlingClick = false; 26 this._defaultLayer = null; // default layer - set from layer.options.osmczDefaultLayer 27 28 this._lastLayerId = 0; 29 this._layersIdMap = {}; // Mapping between internal layer ID and Leaflet object ID 30 31 this._panelContainer = panel; 32 33 34 // Restore mode from cookie - if exists 35 if (Cookies.get("_ls_mode")) { 36 this._mode = Cookies.get("_ls_mode"); 37 } 38 39 // Create priority groups first to preserve given groups order 40 if (options["priorityGroups"]) { 41 for (i in options["priorityGroups"]) { 42 this.addGroup(options["priorityGroups"][i]); 43 } 44 } 45 46 for (grp in baseLayers) { 47 for (layer in baseLayers[grp]) 48 this._addLayer(baseLayers[grp][layer], layer, false, grp); 49 } 50 51 for (grp in overlays) { 52 for (layer in overlays[grp]) 53 this._addLayer(overlays[grp][layer], layer, true, grp); 54 } 55 56 }, 57 58 onAdd: function (map) { 59 60 this._prepareLayout(); 61 this._update(); 62 63 map 64 .on('layeradd', this._onLayerChange, this) 65 .on('layerremove', this._onLayerChange, this); 66 67 return this._container; 68 }, 69 70 onRemove: function (map) { 71 map 72 .off('layeradd', this._onLayerChange, this) 73 .off('layerremove', this._onLayerChange, this); 74 }, 75 76 addBaseLayer: function (layer, name) { 77 this._addLayer(layer, name); 78 this._prepareLayout(); 79 this._update(); 80 return this; 81 }, 82 83 addOverlay: function (layer, name, group) { 84 this._addLayer(layer, name, true, group); 85 this._prepareLayout(); 86 this._update(); 87 return this; 88 }, 89 90 removeLayer: function (layer) { 91 var id = this._layersIdMap[L.stamp(layer)]; 92 var group = this._layers[id].group; 93 if (this._map.hasLayer(layer)) { 94 this._map.removeLayer(layer); 95 if (this._cntActiveInGroup[group] > 0) { 96 this._cntActiveInGroup[group]--; 97 } 98 } 99 delete this._layers[id]; 100 this._prepareLayout(); 101 this._update(); 102 return this; 103 }, 104 105 removeLayerByName: function (layerName) { 106 for (var layerId in this._layers) { 107 if (this._layers[layerId].name == layerName) { 108 this.removeLayer(this._layers[layerId].layer); 109 } 110 } 111 return this; 112 }, 113 114 115 expandGroup: function (group) { 116 // If no parameter set, use stored cookie 117 if (group == null && Cookies.get("_ls_expanded_groups") != null) { 118 var grpList = Cookies.get("_ls_expanded_groups").split("|"); 119 for (i in grpList) { 120 if (this._groups[grpList[i]]) { 121 this.expandGroup(grpList[i]); 122 } 123 } 124 } else { 125 if (this._groups[group]) { 126 if (this._groupsHeaders[group].getAttribute('aria-expanded') == null || 127 this._groupsHeaders[group].getAttribute('aria-expanded') == 'false') { 128 this._updateGroupCookie(group); 129 $("#" + this._groups[group].id).collapse("show"); 130 } 131 } 132 } 133 }, 134 135 collapseGroup: function (group) { 136 if (this._groups[group]) { 137 if (this._groupsHeaders[group].getAttribute('aria-expanded') == "true") { 138 this._updateGroupCookie(group); 139 $("#" + this._groups[group].id).collapse("hide"); 140 } 141 } 142 }, 143 144 expandAllGroups: function () { 145 for (group in this._groups) { 146 this.expandGroup(group); 147 } 148 }, 149 150 collapseAllGroups: function () { 151 for (group in this._groups) { 152 this.collapseGroup(group); 153 } 154 }, 155 156 addGroup: function (id) { 157 158 if (this._groups[id]) { 159 // Group already exists, nothing to do 160 return; 161 } 162 163 // Create a new group 164 165 function hashCode(str) { 166 var hash = 0; 167 if (str.length == 0) return hash; 168 for (i = 0; i < str.length; i++) { 169 char = str.charCodeAt(i); 170 hash = ((hash << 5) - hash) + char; 171 hash = hash & hash; // Convert to 32bit integer 172 } 173 return hash; 174 } 175 176 var className = 'leaflet-control-layers', 177 container = this._container, 178 form = this._form; 179 180 var uid = 'grp' + hashCode(id); 181 this._groupsHeaders[id] = this._addGroupHeader(id, uid, false); 182 183 var element = document.createElement('div');
184 element.id = uid; 185 element.className = 'collapse'; 186 187 this._groups[id] = element; 188 this._cntActiveInGroup[id] = 0; 189 }, 190 191 // Return current mode - basic or groups 192 getMode: function () { 193 return this._mode; 194 }, 195 196 // Check layers and return whether layer already exists or not. 197 layerExists: function (layerName) { 198 for (var layerId in this._layers) { 199 if (this._layers[layerId].name == layerName) { 200 return true; 201 } 202 } 203 return false; 204 }, 205 206 // ------------------------------------------------- 207 // Create header button 208 _addGroupHeader: function (name, target, expanded) { 209 var content, glHideRight, glHideBottom; 210 211 if (expanded) { 212 glHideRight = 'style="display:none"'; 213 } else { 214 glHideBottom = 'style="display:none"'; 215 } 216 217 var grpBase = document.createElement('div'); 218 grpBase.className = 'btn btn-default btn-block btn-xs'; 219 grpBase.setAttribute("data-toggle", "collapse"); 220 grpBase.setAttribute("data-target", '#' + target); 221 grpBase.setAttribute("onclick", "controls.layers._updateGroupCookie('" + name + "');"); 222 223 content = '<i class="glyphicon glyphicon-triangle-right pull-left" ' + glHideRight + '></i>'; 224 content += '<i class="glyphicon glyphicon-triangle-bottom pull-left" ' + glHideBottom + '></i>'; 225 content += name; 226 grpBase.innerHTML = content; 227 228 return grpBase; 229 }, 230 231 _prepareLayout: function () { 232 var className = 'leaflet-control-layers'; 233 234 if (!this._container) { 235 this._container = L.DomUtil.create('div', className); 236 237 //Makes this work on IE10 Touch devices by stopping it from firing a mouseout event when the touch is released 238 this._container.setAttribute('aria-haspopup', true); 239 240 if (!L.Browser.touch) { 241 L.DomEvent 242 .disableClickPropagation(this._container) 243 .disableScrollPropagation(this._container); 244 } else { 245 L.DomEvent.on(this._container, 'click', L.DomEvent.stopPropagation); 246 } 247 } 248 249 var container = this._container, 250 panelContainer = this._panelContainer; 251 252 253 // Init panel 254 var inCnt = []; 255 inCnt.push('<div id="map-layers-inner" class="sidebar-inner">'); 256// inCnt.push(' <button type="button" class="close"><span aria-hidden="true">×</span></button>'); 257 inCnt.push(' <div class="clearfix">'); 258 inCnt.push(' <div id="ls-info" class="btn-group inline navbar-default">'); 259 inCnt.push(' <a class="btn btn-header" data-toggle="collapse" data-target="#lsinfo" title="O vrstvách">Vrstvy <span class="glyphicon glyphicon-question-sign small"></a>'); 260 inCnt.push(' </div>'); 261 inCnt.push(' </div>'); 262 inCnt.push(' <div id="lsinfo" class="ls-info-body collapse">'); 263 inCnt.push(' <p class="text-center"><strong>Mapové vrstvy jsou to, co <em>OpenStreetMap</em> odliÅ¡uje.</strong></p>'); 264 inCnt.push(' <p class="text-justify">Jedna mapová databáze může být vykreslena v různých stylech a pro různé užitÃ. Jako mapa mÄsta, pro turistiku Äi lyžovánÃ.<br>NavÅ¡tivte naÅ¡i <a href="galerie">galerii.</a></p>'); 265 inCnt.push(' <p>Pod tlaÄÃtkem <span class="btn btn-default btn-xs glyphicon glyphicon-calendar disabled"></span> najdete dalšà vrstvy.</p>'); 266 inCnt.push(' <p class="text-center"><button class="btn btn-sm btn-info" data-toggle="collapse" data-target="#lsinfo" onclick=\'Cookies.set("_ls_info_hide", "yes", {expires: 90})\'>Skrýt</button></p>'); 267 inCnt.push(' </div>'); 268 inCnt.push(' <div id="map-layers-content">'); 269 inCnt.push(' </div>'); 270 inCnt.push('</div>'); 271 272 this._panelContainer.setContent(inCnt.join('')); 273 274 275 var form = this._form = L.DomUtil.create('form', className + '-list'); 276 277 L.DomEvent.on(panelContainer, 'hide', this._collapse2, this); 278 279 if (this.options.collapsed) { 280 if (!L.Browser.android) { 281 L.DomEvent 282 .on(container, 'click', this._expand, this) //osmcz 283 .on(container, 'mouseout', this._collapse, this); 284 } 285 286 if (!this._layersLink) { 287 this._layersLink = L.DomUtil.create('a', className + '-toggle', container); 288 this._layersLink.href = '#'; 289 this._layersLink.title = 'Layers'; 290 291 if (L.Browser.touch) { 292 L.DomEvent 293 .on(this._layersLink, 'click', L.DomEvent.stop) 294 .on(this._layersLink, 'click', this._expand, this); 295 } 296 else { 297 L.DomEvent.on(this._layersLink, 'focus', this._expand, this); 298 } 299 } 300 var link = this._layersLink; 301 302 //Work around for Firefox android issue https://github.com/Leaflet/Leaflet/issues/2033 303 L.DomEvent.on(form, 'click', function () { 304 setTimeout(L.bind(this._onInputClick, this), 0); 305 }, this); 306 307 this._map.on('click', this._collapse, this); 308 // TODO keyboard accessibility 309 } else { 310 this._expand(); 311 } 312 313 // Prepare layout 314 this._separatorMain = L.DomUtil.create('div', className + '-separator', form); 315 316 var clfix = document.createElement('div'); 317 clfix.className = "clearfix"; 318 319 // Main toolbar 320 var toolbar = document.createElement('div'); 321 toolbar.className = "btn-toolbar inline"; 322 toolbar.setAttribute('role', 'toolbar'); 323 324 // Collapse group 325 var collapseGroup = document.createElement('div'); 326 collapseGroup.className = "btn-group btn-group-xs"; 327 collapseGroup.setAttribute('role', 'group'); 328 collapseGroup.setAttribute('id', 'collapseGroup'); 329 330 // Expand all button 331 this._btnExpandAll = document.createElement('button'); 332 this._btnExpandAll.className = 'btn btn-secondary btn-default btn-xs'; 333 this._btnExpandAll.setAttribute('type', 'button'); 334 this._btnExpandAll.setAttribute('title', 'Rozbalit vÅ¡e'); 335 this._btnExpandAll.setAttribute('id', 'btnExpandAll'); 336 this._btnExpandAll.setAttribute("onclick", "controls.layers.expandAllGroups();"); 337 this._btnExpandAll.innerHTML = '<i class="glyphicon glyphicon-eject flip"></i>'; 338 339 // Collapse all button 340 this._btnCollapseAll = document.createElement('button'); 341 this._btnCollapseAll.className = 'btn btn-secondary btn-default btn-xs'; 342 this._btnCollapseAll.setAttribute('type', 'button'); 343 this._btnCollapseAll.setAttribute('title', 'Sbalit vÅ¡e'); 344 this._btnCollapseAll.setAttribute('id', 'btnCollapseAll'); 345 this._btnCollapseAll.setAttribute("onclick", "controls.layers.collapseAllGroups();"); 346 this._btnCollapseAll.innerHTML = '<i class="glyphicon glyphicon-eject" ></i>'; 347 348 // Fill collapse group 349 collapseGroup.appendChild(this._btnExpandAll); 350 collapseGroup.appendChild(this._btnCollapseAll); 351 352 // Settings button - dissabled for now - no content to show 353 this._btnSetting = document.createElement('button'); 354 this._btnSetting.className = 'btn btn-secondary btn-default btn-xs pull-right hidden'; 355 this._btnSetting.setAttribute('type', 'button'); 356 this._btnSetting.setAttribute('title', 'NastavenÃ'); 357 this._btnSetting.setAttribute('data-toggle', 'collapse'); 358 this._btnSetting.setAttribute('data-target', '#lssetup'); 359 this._btnSetting.innerHTML = '<i class="glyphicon glyphicon-cog" ></i>'; 360 361 // Mode switcher 362 var modeSwitchGroup = document.createElement('div'); 363 modeSwitchGroup.className = "btn-group btn-group-xs"; 364 modeSwitchGroup.setAttribute('role', 'group'); 365 modeSwitchGroup.setAttribute('id', 'modeSwitchGroup'); 366 modeSwitchGroup.setAttribute('data-toggle', 'buttons'); 367 368 // Basic button 369 var labelBasic = document.createElement('label'); 370 labelBasic.className = 'btn btn-default' + (this._mode == 'basic' ? ' active' : ''); 371 labelBasic.setAttribute('onclick', 'controls.layers._switchLayerMode("basic")'); 372 labelBasic.setAttribute('title', 'Základnà vrstvy'); 373 374 var inputBasic = document.createElement('input'); 375 inputBasic.className = 'btn-block'; 376 inputBasic.setAttribute('type', 'radio'); 377 inputBasic.setAttribute('name', 'layerMode'); 378 inputBasic.setAttribute('id', 'layerModeBasic'); 379 inputBasic.setAttribute('autocomplete', 'off'); 380 381 var nameBasic = document.createElement('span'); 382 nameBasic.className = 'glyphicon glyphicon-list'; 383 384 labelBasic.appendChild(inputBasic); 385 labelBasic.appendChild(nameBasic); 386 387 // Group button 388 var labelGroup = document.createElement('label'); 389 labelGroup.className = 'btn btn-default' + (this._mode == 'groups' ? ' active' : ''); 390 labelGroup.setAttribute('onclick', 'controls.layers._switchLayerMode("groups")'); 391 labelGroup.setAttribute('title', 'VÃce vrstev ve skupinách'); 392 393 var inputGroup = document.createElement('input'); 394 inputGroup.className = 'btn-block '; 395 inputGroup.setAttribute('type', 'radio'); 396 inputGroup.setAttribute('name', 'layerMode'); 397 inputGroup.setAttribute('id', 'layerModeGroup'); 398 inputGroup.setAttribute('autocomplete', 'off'); 399 400 var nameGroup = document.createElement('span'); 401 nameGroup.className = 'glyphicon glyphicon-calendar'; 402 403 labelGroup.appendChild(inputGroup); 404 labelGroup.appendChild(nameGroup); 405 406 modeSwitchGroup.appendChild(labelBasic); 407 modeSwitchGroup.appendChild(labelGroup); 408 409 toolbar.appendChild(modeSwitchGroup); 410 toolbar.appendChild(collapseGroup); 411 toolbar.appendChild(this._btnSetting); 412 this._form.appendChild(toolbar); 413 414 var lssetup = document.createElement('div'); 415 lssetup.className = "lssetup collapse"; 416 lssetup.setAttribute('id', 'lssetup'); 417 lssetup.innerHTML = '<h3>NastavenÃ</h3><div>Tady bude nÄjaké nastavenÃ.</div>'; 418 this._form.appendChild(lssetup); 419 420 this._separatorBtGroup = L.DomUtil.create('div', className + '-separator', form); 421 422 // Create layout for basic mode 423 var basicModeContainer = document.createElement('div'); 424 basicModeContainer.className = "clearfix"; 425 basicModeContainer.setAttribute('id', 'basicModeContainer'); 426 427 this._baseLayersList = L.DomUtil.create('div', className + '-base', basicModeContainer); 428 this._baseSeparator = L.DomUtil.create('div', className + '-separator', basicModeContainer); 429 this._overlaysList = L.DomUtil.create('div', className + '-overlays', basicModeContainer); 430 431 this._form.appendChild(basicModeContainer); 432 433 // Create layout for extended (group) mode 434 var groupsModeContainer = document.createElement('div'); 435 groupsModeContainer.className = "clearfix"; 436 groupsModeContainer.setAttribute('id', 'groupsModeContainer'); 437 438 for (var id in this._groups) { 439 groupsModeContainer.appendChild(this._groupsHeaders[id]); 440 groupsModeContainer.appendChild(this._groups[id]); 441 } 442 443 this._form.appendChild(groupsModeContainer); 444 445 //container.appendChild(form); 446 $('#map-layers-content').append(form); 447 448 // Hide group container by mode 449 if (this._mode == 'basic') { 450 $('#groupsModeContainer').hide(); 451 $('#layerModeBasic').attr('checked', true); 452 } else { 453 $('#basicModeContainer').hide(); 454 $('#layerModeGroup').attr('checked', true); 455 } 456 457 458// // Expand base overlays by default 459// this._overlaysListBase.className = 'collapse in'; 460 }, 461 462 _addLayer: function (layer, name, overlay, group) { 463 464 // Map layers to preserve layer order 465 this._lastLayerId++; 466 this._layersIdMap[L.stamp(layer)] = this._lastLayerId; 467 468 this._layers[this._lastLayerId] = { 469 layer: layer, 470 name: name, 471 overlay: overlay, 472 group: group 473 }; 474 475 if (group) { 476 this.addGroup(group); 477 } 478 479 if (!overlay && layer.options.osmczDefaultLayer) 480 this._defaultLayer = layer; 481
482 if (this.options.autoZIndex && layer.setZIndex) { 483 this._lastZIndex++; 484 layer.setZIndex(this._lastZIndex); 485 } 486 }, 487 488 _update: function () { 489 if (!this._container) { 490 return; 491 } 492 493 this._baseLayersList.innerHTML = ''; 494 this._overlaysList.innerHTML = ''; 495 496 for (var group in this._groups) { 497 this._groups[group].innerHTML = ''; 498 this._cntActiveInGroup[group] = 0; 499 for (var layer in this._layers) { 500 if (this._layers[layer].group == group) { 501 this._cntActiveInGroup[group]++; 502 } 503 } 504 this._cntInGroup[group] = this._cntActiveInGroup[group]; 505 } 506 507 var baseLayersPresent = false, 508 overlaysPresent = false, 509 i, obj; 510 511 for (i in this._layers) { 512 obj = this._layers[i]; 513 this._addItem(obj); 514 overlaysPresent = overlaysPresent || obj.overlay; 515 baseLayersPresent = baseLayersPresent || !obj.overlay; 516 } 517 518 if (this._mode == 'groups') { 519 this._baseSeparator.style.display = ''; 520 this._updateGroupHeaders(); 521 $('#basicModeContainer').hide(); 522 $('#groupsModeContainer').show(); 523 $('#btnExpandAll').show(); 524 $('#btnCollapseAll').show(); 525 $('#lsinfo').collapse("hide"); 526 } else { 527 this._baseSeparator.style.display = overlaysPresent && baseLayersPresent ? '' : 'none'; 528 $('#groupsModeContainer').hide(); 529 $('#basicModeContainer').show(); 530 $('#btnExpandAll').hide(); 531 $('#btnCollapseAll').hide(); 532 var infoCookie = Cookies.get("_ls_info_hide"); 533 if (!infoCookie || (infoCookie && infoCookie != "yes")) { 534 $('#lsinfo').collapse("show"); 535 } 536 } 537 }, 538 539 _onLayerChange: function (e) { 540 var obj = this._layers[this._layersIdMap[L.stamp(e.layer)]]; 541 542 if (!obj) { 543 return; 544 } 545 546 if (!this._handlingClick) { 547 this._update(); 548 } 549 550 var type = obj.overlay ? 551 (e.type === 'layeradd' ? 'overlayadd' : 'overlayremove') : 552 (e.type === 'layeradd' ? 'baselayerchange' : null); 553 554 if (type) { 555 this._map.fire(type, obj); 556 } 557 }, 558 559 // IE7 bugs out if you create a radio dynamically, so you have to do it this hacky way (see http://bit.ly/PqYLBe) 560 _createRadioElement: function (name, checked) { 561 562 var radioHtml = '<input type="radio" class="leaflet-control-layers-selector" name="' + name + '"'; 563 if (checked) { 564 radioHtml += ' checked="checked"'; 565 } 566 radioHtml += '/>'; 567 568 var radioFragment = document.createElement('div'); 569 radioFragment.innerHTML = radioHtml; 570 571 return radioFragment.firstChild; 572 }, 573 574 _addItem: function (obj) { 575 576 if (!obj.group) { 577 // requested group does not exists 578 return; 579 } 580 581 var label = document.createElement('label'), 582 input, 583 checked = this._map.hasLayer(obj.layer); 584 585 if (!checked) { 586 if (this._cntActiveInGroup[obj.group] > 0) { 587 this._cntActiveInGroup[obj.group]--; 588 } 589 } 590 591 var name = document.createElement('span'); 592 var innerContent = []; 593 if (obj.layer.options.removeBtn) { 594 innerContent.push('<span class="ellipsis removable" title="' + obj.name + '"> ' + obj.name + '</span>'); 595 innerContent.push('<a href="#" class="btn pull-right" title="Odebrat vrstvu"'); 596 innerContent.push('onclick="controls.layers.removeLayerByName(\'' + obj.name + '\');"'); 597 innerContent.push('>'); 598 innerContent.push('<span class="glyphicon glyphicon-trash text-danger" alt="X"></span></a>'); 599 innerContent.push('<div class="clearfix"></div>'); 600 } else { 601 innerContent.push('<span class="ellipsis" title="' + obj.name + '"> ' + obj.name + '</span>'); 602 } 603 604 name.innerHTML = innerContent.join(''); 605 606 if (obj.overlay) { 607 input = document.createElement('input'); 608 input.type = 'checkbox'; 609 input.className = 'leaflet-control-layers-selector'; 610 input.defaultChecked = checked; 611 name.className = 'lsOverlay'; 612 } else { 613 input = this._createRadioElement('leaflet-base-layers', checked); 614 } 615 616 input.setAttribute('id', 'lftid-' + L.stamp(obj.layer)); 617 input.layerId = this._layersIdMap[L.stamp(obj.layer)]; 618 619 L.DomEvent.on(input, 'click', this._onInputClick, this); 620 621 622 label.appendChild(input); 623 label.appendChild(name); 624 625 if (this._mode == 'basic') { 626 if (obj.layer.options.basic) { 627 var container = obj.overlay ? this._overlaysList : this._baseLayersList; 628 629 if (container) { 630 container.appendChild(label); 631 } 632 } 633 } else { 634 var container = this._groups[obj.group]; 635 636 if (container) { 637 container.appendChild(label); 638 } 639 } 640 641 642 return label; 643 }, 644 645 _onInputClick: function () { 646 var i, input, obj, 647 inputs = this._form.getElementsByTagName('input'),
648 inputsLen = inputs.length; 649 650 this._handlingClick = true; 651 652 for (i = 0; i < inputsLen; i++) { 653 input = inputs[i]; 654 obj = this._layers[input.layerId]; 655 656 if (!obj) { 657 continue; 658 } 659 660 if (input.checked && !this._map.hasLayer(obj.layer)) { 661 this._map.addLayer(obj.layer); 662 this._cntActiveInGroup[obj.group]++; 663 664 } else if (!input.checked && this._map.hasLayer(obj.layer)) { 665 this._map.removeLayer(obj.layer); 666 if (this._cntActiveInGroup[obj.group] > 0) { 667 this._cntActiveInGroup[obj.group]--; 668 } 669 670 } 671 } 672 673 this._handlingClick = false; 674 675 this._updateGroupHeaders(); 676 677 this._refocusOnMap(); 678 }, 679 680 _expand: function () { 681 this._panelContainer.show(); 682 $(this._container).hide(); 683 684 //L.DomUtil.addClass(this._container, 'leaflet-control-layers-expanded'); 685 }, 686 687 _collapse: function () { 688 //this._container.className = this._container.className.replace(' leaflet-control-layers-expanded', ''); 689 }, 690 691 _collapse2: function () { 692 $(this._container).show(); 693 }, 694 695 // Update Group headers to indicate, which group contains enabled layers 696 // Also hide empty groups 697 _updateGroupHeaders: function () { 698 for (group in this._cntActiveInGroup) { 699 if (this._cntActiveInGroup[group] == 0) { 700 this._groupsHeaders[group].setAttribute('group-active', 'false'); 701 } else { 702 this._groupsHeaders[group].setAttribute('group-active', 'true'); 703 } 704 705 if (this._cntInGroup[group] == 0) { 706 L.DomUtil.addClass(this._groupsHeaders[group], 'hidden'); 707 } else { 708 L.DomUtil.removeClass(this._groupsHeaders[group], 'hidden'); 709 } 710 } 711 }, 712 713 // Update cookie containig list of expanded groups so they can be restored next time 714 _updateGroupCookie: function (group) { 715 716 if (this._groups[group]) { 717 if (this._groupsHeaders[group].getAttribute('aria-expanded') == null || 718 this._groupsHeaders[group].getAttribute('aria-expanded') == "false") { 719 var expandCookie = Cookies.get("_ls_expanded_groups") == null ? group : Cookies.get("_ls_expanded_groups") + '|' + group; 720 Cookies.set("_ls_expanded_groups", expandCookie, {expires: 90}); 721 } else { 722 if (Cookies.get("_ls_expanded_groups") == null) { 723 return; 724 } else { 725 var cc = Cookies.get("_ls_expanded_groups").split("|"); 726 var expandCookie = []; 727 for (i in cc) { 728 if (cc[i] != group) { 729 expandCookie.push(cc[i]); 730 } 731 } 732 Cookies.set("_ls_expanded_groups", expandCookie.join("|"), {expires: 90}); 733 } 734 } 735 } 736 }, 737 738 _switchLayerMode: function (mode) { 739 if (mode && (mode == 'basic' || mode == 'groups')) { 740 this._mode = mode; 741 Cookies.set("_ls_mode", mode, {expires: 90}); 742 743 // Switch back to default layer when current base layer is not in basic layout 744 if (this._mode == 'basic') { 745 for (layerId in this._map._layers) { 746 var obj = this._layers[this._layersIdMap[layerId]]; 747 if (obj && !obj.overlay && !obj.layer.options.basic && this._defaultLayer) { 748 var lftid = L.stamp(this._defaultLayer); 749 $('#lftid-' + lftid).click(); 750 break; 751 } 752 } 753 } 754 755 this._update(); 756 } 757 } 758 759}); 760 761osmcz.layerSwitcher = function (baseLayers, overlays, panel, options) { 762 return new osmcz.LayerSwitcher(baseLayers, overlays, panel, options); 763};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.