aboutsummaryrefslogtreecommitdiff
path: root/modern/src/map/switcher/switcher.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-08-21 16:12:32 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-08-21 16:12:32 -0700
commitbe69f7ea8f58b65cfe164ac77ec5feb74755fb76 (patch)
treefff3971932d3bd1361bb66d7e32e93c9f76837e7 /modern/src/map/switcher/switcher.js
parent946b6d807dc7625b02d4bd48de8da8682e3a3584 (diff)
downloadtrackermap-web-be69f7ea8f58b65cfe164ac77ec5feb74755fb76.tar.gz
trackermap-web-be69f7ea8f58b65cfe164ac77ec5feb74755fb76.tar.bz2
trackermap-web-be69f7ea8f58b65cfe164ac77ec5feb74755fb76.zip
Support MapTiler maps
Diffstat (limited to 'modern/src/map/switcher/switcher.js')
-rw-r--r--modern/src/map/switcher/switcher.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/modern/src/map/switcher/switcher.js b/modern/src/map/switcher/switcher.js
index e9076aa6..014a35e0 100644
--- a/modern/src/map/switcher/switcher.js
+++ b/modern/src/map/switcher/switcher.js
@@ -5,12 +5,17 @@ export class SwitcherControl {
this.beforeSwitch = beforeSwitch;
this.afterSwitch = afterSwitch;
this.onDocumentClick = this.onDocumentClick.bind(this);
+ this.variables = {};
}
getDefaultPosition() {
return 'top-right';
}
+ setVariable(key, value) {
+ this.variables[key] = value;
+ }
+
onAdd(map) {
this.map = map;
this.controlContainer = document.createElement('div');
@@ -25,14 +30,16 @@ export class SwitcherControl {
styleElement.type = 'button';
styleElement.innerText = style.title;
styleElement.classList.add(style.title.replace(/[^a-z0-9-]/gi, '_'));
- styleElement.dataset.uri = JSON.stringify(style.uri);
+ styleElement.dataset.uri = style.uri;
styleElement.addEventListener('click', (event) => {
const { srcElement } = event;
if (srcElement.classList.contains('active')) {
return;
}
this.beforeSwitch();
- this.map.setStyle(JSON.parse(srcElement.dataset.uri));
+ let uri = srcElement.dataset.uri;
+ Object.entries(this.variables).forEach(([key, value]) => uri = uri.replaceAll(`\$\{${key}\}`, value));
+ this.map.setStyle(uri);
this.afterSwitch();
this.mapStyleContainer.style.display = 'none';
this.styleButton.style.display = 'block';