From 775409f83d77eb4f98fbcac9419b99721f5c7815 Mon Sep 17 00:00:00 2001 From: user Date: Sun, 7 Apr 2024 18:08:45 +0200 Subject: derive colors from database, verify icons are in sync --- src/static/main.js | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'src/static') diff --git a/src/static/main.js b/src/static/main.js index c37c92b..82d474e 100644 --- a/src/static/main.js +++ b/src/static/main.js @@ -10,14 +10,12 @@ let icons = {}; async function fetchChains() { const response = await fetch("chains"); known_store_chains = await response.json(); - icons["Unknown"] = L.icon({ iconUrl: 'icons/Unknown.png', iconSize: [10, 16], iconAnchor: [16, 16], }); - - for (let known_store_chain of known_store_chains) { + for (let known_store_chain in known_store_chains) { icons[known_store_chain] = L.icon({ iconUrl: `icons/${known_store_chain}.png`, iconAnchor: [8, 8], @@ -28,24 +26,19 @@ async function fetchChains() { function addPolygon(store) { - console.log(store) let color; - if (store.brand === 'Rema 1000'){ - color = 'blue'; - } else if (store.brand === 'Netto'){ - color = 'yellow' + if (known_store_chains.hasOwnProperty(store.brand)) { + color = known_store_chains[store.brand]; + } else { + color = 'grey'; } - else if (store.brand === 'Coop 365discount'){ - color = 'green'; - }else{ - color = 'red'} L.polygon(store.polygon, {color: color}).addTo(map); } function addShop(shop) { let icon; - if (known_store_chains.includes(shop.brand)){ + if (known_store_chains.hasOwnProperty(shop.brand)){ icon = icons[shop.brand]; } else { icon = icons["Unknown"]; -- cgit v1.2.3