Improve URL layer enabling

This commit is contained in:
Chandler Swift 2024-09-02 13:58:45 -05:00
parent 42351844b4
commit ff8da54892
Signed by: chandlerswift
GPG key ID: A851D929D52FB93F

19
main.js
View file

@ -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,9 +129,26 @@ 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