From c5cf330238be49c1829172351566e1cf513220b9 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Thu, 9 Aug 2018 20:20:03 -0400 Subject: [PATCH] map: Add a button to set the state of all children of a LayerGroup --- src/map.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/map.js b/src/map.js index 13c2b17..4315e59 100644 --- a/src/map.js +++ b/src/map.js @@ -227,7 +227,22 @@ function render_layer_toggles(event) { input.type = 'checkbox'; input.className = "expand"; label.appendChild(document.createElement('span')); + layer_toggle(layer, label); // 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('click', event => { + console.log("test"); + layer.getLayers().forEach(subLayer => { + subLayer.setVisible(event.target.checked); + subLayer.toggle_element.querySelector("input").checked = + event.target.checked; + }); + }); + let container = label.appendChild(document.createElement('div')); container.className = 'collapsible-content'; layer.getLayers().forEach(