map: Allow for nested LayerGroups in layer toggles
This commit is contained in:
parent
131d6f2e30
commit
cdad5f7da8
@ -43,6 +43,6 @@ html, body {
|
||||
.collapsible-content {
|
||||
margin-left: 0.8em;
|
||||
}
|
||||
.collapsible-content label {
|
||||
.collapsible-content > label {
|
||||
display: block;
|
||||
}
|
||||
|
27
src/map.js
27
src/map.js
@ -210,10 +210,9 @@ function plotPacketPaths(packets) {
|
||||
});
|
||||
}
|
||||
|
||||
function layer_toggle(layer, parentElement) {
|
||||
function layer_toggle(layer) {
|
||||
if (layer.toggle_element === undefined) {
|
||||
layer.toggle_element = parentElement.appendChild(
|
||||
document.createElement('label'));
|
||||
layer.toggle_element = document.createElement('label');
|
||||
|
||||
let checkbox = layer.toggle_element.appendChild(
|
||||
document.createElement('input'));
|
||||
@ -228,27 +227,23 @@ function layer_toggle(layer, parentElement) {
|
||||
return layer.toggle_element;
|
||||
}
|
||||
|
||||
function render_layer_toggles(event, element) {
|
||||
event.map.getLayers().getArray()
|
||||
.filter(layer => layer.get('title') !== undefined)
|
||||
.forEach(layer => {
|
||||
function layer_toggles(layer, parentElement) {
|
||||
if (layer instanceof LayerGroup) {
|
||||
if (layer.group_toggle === undefined) {
|
||||
let label = layer.group_toggle = element.appendChild(
|
||||
let label = layer.group_toggle = parentElement.appendChild(
|
||||
document.createElement('label'));
|
||||
let input = label.appendChild(document.createElement('input'));
|
||||
input.type = 'checkbox';
|
||||
input.className = "expand";
|
||||
label.appendChild(document.createElement('span'));
|
||||
|
||||
layer_toggle(layer, label); // whole LayerGroup
|
||||
label.appendChild(layer_toggle(layer)); // whole LayerGroup
|
||||
|
||||
let child_toggle_element = label.appendChild(
|
||||
document.createElement('input'));
|
||||
child_toggle_element.type = 'checkbox';
|
||||
child_toggle_element.checked = true;
|
||||
child_toggle_element.addEventListener('change', event => {
|
||||
console.log("test");
|
||||
layer.getLayers().forEach(subLayer => {
|
||||
subLayer.setVisible(event.target.checked);
|
||||
subLayer.toggle_element.querySelector("input").checked =
|
||||
@ -259,13 +254,19 @@ function render_layer_toggles(event, element) {
|
||||
let container = label.appendChild(document.createElement('div'));
|
||||
container.className = 'collapsible-content';
|
||||
layer.getLayers().forEach(
|
||||
sublayer => layer_toggle(sublayer, container));
|
||||
subLayer => layer_toggles(subLayer, container));
|
||||
return label;
|
||||
}
|
||||
}
|
||||
else {
|
||||
layer_toggle(layer, element);
|
||||
parentElement.appendChild(layer_toggle(layer));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function render_layer_toggles(event, element) {
|
||||
event.map.getLayers().getArray()
|
||||
.filter(layer => layer.get('title') !== undefined)
|
||||
.forEach(layer => layer_toggles(layer, element));
|
||||
}
|
||||
|
||||
(function makeLayerToogleControl() {
|
||||
|
Loading…
Reference in New Issue
Block a user