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:
parent
13eb66570a
commit
502de00933
3 changed files with 221 additions and 4 deletions
12
main.js
12
main.js
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue