Add customLayer URL param

This includes a switch to `qs` for querystring parsing, since the
browser builtin won't automatically extract out objects inside arrays.
This commit is contained in:
Chandler Swift 2024-10-19 18:45:53 -05:00
parent 13eb66570a
commit 502de00933
Signed by: chandlerswift
GPG key ID: A851D929D52FB93F
3 changed files with 221 additions and 4 deletions

12
main.js
View file

@ -17,6 +17,8 @@ import GeoJSON from 'ol/format/GeoJSON.js';
import {Style} from 'ol/style.js';
import Icon from 'ol/style/Icon.js';
import qs from 'qs';
import pin from './generic-pin.svg?url';
// from https://openlayers.org/en/latest/examples/popup.html
@ -127,8 +129,8 @@ for (let category of layerCategories) {
document.querySelector("aside").appendChild(catDiv);
}
const urlParams = new URLSearchParams(window.location.search);
const urlLayers = urlParams.getAll('layer');
const urlParams = qs.parse(window.location.search, { ignoreQueryPrefix: true });
const urlLayers = urlParams.layer ?? [];
for (let category of layerCategories) {
for (let layer of category.layers) {
@ -218,6 +220,12 @@ function newCustomLayer(name, sourceURL, colorString) {
customLayerDiv.querySelector("ul").appendChild(li);
}
if (urlParams.customLayer) {
for (let customLayer of urlParams.customLayer) {
newCustomLayer(customLayer['name'], customLayer['url'], customLayer['color'])
}
}
let location_set = false;
if (urlLayers.length > 0) {