Improve URL layer enabling
This commit is contained in:
parent
42351844b4
commit
ff8da54892
19
main.js
19
main.js
|
@ -105,7 +105,7 @@ for (let category of layerCategories) {
|
|||
for (let layer of category.layers) {
|
||||
const li = document.createElement("li");
|
||||
li.innerHTML = `
|
||||
<label><input type="checkbox" ${layer.enabled ? "checked" : ""}> ${layer.name}</label>
|
||||
<label><input type="checkbox"> ${layer.name}</label>
|
||||
`;
|
||||
li.querySelector("input").addEventListener("change", function(e){
|
||||
if (e.target.checked) {
|
||||
|
@ -129,10 +129,27 @@ for (let category of layerCategories) {
|
|||
}
|
||||
if (layer.enabled) {
|
||||
map.addLayer(layer.layer);
|
||||
// I'm a bit rusty on the definitions, but this might be O(n^2), and definitely wouldn't have to be.
|
||||
// Keep checkbox state in sync
|
||||
for (const label of document.querySelectorAll("aside label")) {
|
||||
if (label.innerText.trim() == layer.name) {
|
||||
label.querySelector("input[type=checkbox]").checked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let location_set = false;
|
||||
|
||||
if (urlLayers.length > 0) {
|
||||
location_set = true;
|
||||
map.once('loadend', function() {
|
||||
const layers = map.getLayers();
|
||||
map.getView().fit(layers.item(layers.getLength() - 1).getSource().getExtent(), {padding: [20, 20, 20, 20]});
|
||||
});
|
||||
}
|
||||
|
||||
function objectToTable(o) {
|
||||
// TODO: hack hack hack
|
||||
let table = `<table style="margin: 0.5em; border-collapse: collapse;">`;
|
||||
|
|
Loading…
Reference in a new issue