diff options
Diffstat (limited to 'modern/src/map/switcher/switcher.js')
-rw-r--r-- | modern/src/map/switcher/switcher.js | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/modern/src/map/switcher/switcher.js b/modern/src/map/switcher/switcher.js index e9076aa6..cb7326f4 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'); @@ -32,7 +37,11 @@ export class SwitcherControl { return; } this.beforeSwitch(); - this.map.setStyle(JSON.parse(srcElement.dataset.uri)); + let uri = JSON.parse(srcElement.dataset.uri); + if (typeof uri === 'string') { + 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'; |