Created
November 6, 2016 19:22
-
-
Save odoe/147532e719b5860f867d81c75267f113 to your computer and use it in GitHub Desktop.
Ghetto JSAPI layerlist toggle in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function layerList(layers) { | |
const list = layers.reduce((ul, layer) => { | |
const li = document.createElement('li'); | |
const toggle = document.createElement('input'); | |
toggle.type = 'checkbox'; | |
toggle.checked = layer.visible; | |
layer.watch('visible', () => toggle.checked = layer.visible); | |
toggle.addEventListener('change', () => layer.visible = !layer.visible); | |
const label = document.createElement('span'); | |
label.innerHTML = layer.title; | |
li.appendChild(toggle); | |
li.appendChild(label); | |
ul.appendChild(li); | |
return ul; | |
}, document.createElement('ul')); | |
return list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yummy vanilla