aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main.js20
1 files changed, 14 insertions, 6 deletions
diff --git a/main.js b/main.js
index b752e3e..28c885f 100644
--- a/main.js
+++ b/main.js
@@ -87,10 +87,7 @@ const extent = [110720, 6927136, 1159296, 7975712];
* https://www.lantmateriet.se/sv/om-lantmateriet/press/nyheter/lantmateriets-arbete-mot-oppna-data-i-full-gang/
*/
const baseMapSource = new WMTS({
- // XXX the 'layer' parameter should be passed in the options
- // dictionary (like style and version), but there is no setLayer()
- // method to switch from/to the toned down map
- url: 'https://minkarta.lantmateriet.se/map/topowebbcache?layer=topowebb',
+ url: undefined,
version: '1.0.0',
style: 'default',
matrixSet: '3006',
@@ -121,6 +118,7 @@ const view = new View({
constrainResolution: false,
});
+let baseMapLayer = 'topowebb';
(function() {
const params = new URLSearchParams(window.location.hash.substring(1));
const x = parseFloat(params.get('x'));
@@ -132,6 +130,11 @@ const view = new View({
if (!isNaN(z)) {
view.setZoom(z);
}
+
+ if (params.has('basemap')) {
+ baseMapLayer = params.get('basemap');
+ }
+ baseMapSource.setUrl(`https://minkarta.lantmateriet.se/map/topowebbcache?LAYER=${encodeURIComponent(baseMapLayer)}`);
})();
@@ -793,9 +796,14 @@ map.addLayer(vectorLayer);
label.setAttribute('for', input.id);
label.innerHTML = 'Nedtonad bakgrund karta';
+ input.checked = baseMapLayer === 'topowebb_nedtonad';
input.onchange = function(event) {
- const layer = event.target.checked ? 'topowebb_nedtonad' : 'topowebb';
- baseMapSource.setUrl('https://minkarta.lantmateriet.se/map/topowebbcache?LAYER=' + layer);
+ baseMapLayer = event.target.checked ? 'topowebb_nedtonad' : 'topowebb';
+ baseMapSource.setUrl(`https://minkarta.lantmateriet.se/map/topowebbcache?LAYER=${encodeURIComponent(baseMapLayer)}`);
+
+ const searchParams = new URLSearchParams(location.hash.substring(1));
+ searchParams.set('basemap', baseMapLayer);
+ location.hash = '#' + searchParams.toString();
};
})();
})();