From 230b5b53460982ef888d309725f027ea29b29bb6 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 21 Aug 2021 16:46:15 -0700 Subject: Fix map switches --- modern/src/map/Map.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'modern/src/map/Map.js') diff --git a/modern/src/map/Map.js b/modern/src/map/Map.js index c2861ed..3afa48d 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); }; -- cgit v1.2.3