From 4c6a6ce7ecdb98734cc52a44dccbf90342c36933 Mon Sep 17 00:00:00 2001 From: user Date: Sat, 28 Dec 2024 23:45:00 +0100 Subject: JS - Toggle layers with URL parameters --- src/static/main.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/static/main.js') diff --git a/src/static/main.js b/src/static/main.js index 3ef9cf1..102862f 100644 --- a/src/static/main.js +++ b/src/static/main.js @@ -7,9 +7,23 @@ L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { let known_store_chains; let icons = {}; -var markers = L.featureGroup().addTo(map); -var polygons = L.featureGroup().addTo(map); -var heatmap = L.featureGroup().addTo(map); +var markers = L.featureGroup() +var polygons = L.featureGroup() +var heatmap = L.featureGroup() + +const queryString = window.location.search; +const urlParams = new URLSearchParams(queryString); +if (!urlParams.has('markers') || urlParams.get('markers') == "1") { + markers.addTo(map); +} +if (!urlParams.has('polygons') || urlParams.get('polygons') == "1") { + polygons.addTo(map); +} +if (!urlParams.has('heatmap') || urlParams.get('heatmap') == "1") { + heatmap.addTo(map); +} + + const CategoryField = document.getElementById('Category'); const CountryField = document.getElementById('Country'); -- cgit v1.2.3