aboutsummaryrefslogtreecommitdiff
path: root/modern
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-08-21 16:46:15 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-08-21 16:46:15 -0700
commit230b5b53460982ef888d309725f027ea29b29bb6 (patch)
treef5aca22f65c534e110ca017039b2f341f60c7df7 /modern
parent75e62d6f56bffb8d4fd18ce7d2d9077821095c85 (diff)
downloadtrackermap-web-230b5b53460982ef888d309725f027ea29b29bb6.tar.gz
trackermap-web-230b5b53460982ef888d309725f027ea29b29bb6.tar.bz2
trackermap-web-230b5b53460982ef888d309725f027ea29b29bb6.zip
Fix map switches
Diffstat (limited to 'modern')
-rw-r--r--modern/src/map/Map.js30
-rw-r--r--modern/src/map/switcher/switcher.js8
2 files changed, 21 insertions, 17 deletions
diff --git a/modern/src/map/Map.js b/modern/src/map/Map.js
index c2861ed5..3afa48df 100644
--- a/modern/src/map/Map.js
+++ b/modern/src/map/Map.js
@@ -40,21 +40,23 @@ const updateReadyValue = (value) => {
const initMap = async () => {
if (ready) return;
- const background = await loadImage('images/background.svg');
- map.addImage('background', await prepareIcon(background), {
- pixelRatio: window.devicePixelRatio,
- });
- await Promise.all(deviceCategories.map(async (category) => {
- const results = [];
- ['green', 'red', 'gray'].forEach((color) => {
- results.push(loadImage(`images/icon/${category}.svg`).then((icon) => {
- map.addImage(`${category}-${color}`, prepareIcon(background, icon, palette.common[color]), {
- pixelRatio: window.devicePixelRatio,
- });
- }));
+ if (!map.hasImage('background')) {
+ const background = await loadImage('images/background.svg');
+ map.addImage('background', await prepareIcon(background), {
+ pixelRatio: window.devicePixelRatio,
});
- await Promise.all(results);
- }));
+ await Promise.all(deviceCategories.map(async (category) => {
+ const results = [];
+ ['green', 'red', 'gray'].forEach((color) => {
+ results.push(loadImage(`images/icon/${category}.svg`).then((icon) => {
+ map.addImage(`${category}-${color}`, prepareIcon(background, icon, palette.common[color]), {
+ pixelRatio: window.devicePixelRatio,
+ });
+ }));
+ });
+ await Promise.all(results);
+ }));
+ }
updateReadyValue(true);
};
diff --git a/modern/src/map/switcher/switcher.js b/modern/src/map/switcher/switcher.js
index 643b6ec0..a3805f6b 100644
--- a/modern/src/map/switcher/switcher.js
+++ b/modern/src/map/switcher/switcher.js
@@ -30,15 +30,17 @@ export class SwitcherControl {
styleElement.type = 'button';
styleElement.innerText = style.title;
styleElement.classList.add(style.title.replace(/[^a-z0-9-]/gi, '_'));
- styleElement.dataset.uri = style.uri;
+ styleElement.dataset.uri = JSON.stringify(style.uri);
styleElement.addEventListener('click', (event) => {
const { srcElement } = event;
if (srcElement.classList.contains('active')) {
return;
}
this.beforeSwitch();
- let uri = srcElement.dataset.uri;
- Object.entries(this.variables).forEach(([key, value]) => uri = uri.replaceAll(`$\{${key}}`, value));
+ 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';