aboutsummaryrefslogtreecommitdiff
path: root/src/static/main.js
diff options
context:
space:
mode:
authoruser <user@node5.net>2024-05-20 19:51:41 +0200
committeruser <user@node5.net>2024-05-20 19:51:41 +0200
commitf0626b175d21230dc68ecd83e2726ec7e7daae5a (patch)
treebee47010f3374fd53395f62a9067f4e41762c000 /src/static/main.js
parent4c03c8e4514d40dff2a3736c7f04a89a7e21843a (diff)
user input categories, refactor, remove zombie code
Diffstat (limited to 'src/static/main.js')
-rw-r--r--src/static/main.js79
1 files changed, 53 insertions, 26 deletions
diff --git a/src/static/main.js b/src/static/main.js
index a920476..be136a4 100644
--- a/src/static/main.js
+++ b/src/static/main.js
@@ -11,14 +11,40 @@ var markers = L.featureGroup().addTo(map);
var polygons = L.featureGroup().addTo(map);
var heatmap = L.featureGroup().addTo(map);
+const CategoryField = document.getElementById('Category');
+
+const DefaultSearchValue = "supermarket";
+var Categories = []
+
var overlayMaps = {
- "Supermarket icons": markers,
- "Nearest supermarket polygons": polygons,
- "Stores heatmap": heatmap
+ "POI markers": markers,
+ "Nearest POI polygons": polygons,
+// "POI heatmap": heatmap
};
var layerControl = L.control.layers({},overlayMaps).addTo(map);
+function runQueryAfterLoad() {
+ fetchAll(CategoryField.value);
+}
+
+async function fetchCategories() {
+ const response = await fetch("categories");
+ try {
+ categories = await response.json();
+ const CategoriesDataList = document.getElementById('CategoriesDataList');
+ categories.forEach(function(item){
+ var option = document.createElement('option');
+ option.value = item;
+ option.innerHTML = item;
+ CategoriesDataList.appendChild(option);
+ });
+ CategoryField.pattern = categories.join('|');
+ } catch (error) {
+ alert(`Failed to fetch categories, are you online?\n${error.message}`)
+ }
+}
+
async function fetchChains() {
const response = await fetch("chains");
known_store_chains = await response.json();
@@ -33,7 +59,25 @@ async function fetchChains() {
iconAnchor: [8, 8],
});
}
- fetchAll()
+
+ const queryString = window.location.search;
+ const urlParams = new URLSearchParams(queryString);
+ const urlParam = urlParams.get('Category')
+ const fieldValue = CategoryField.value
+ // Retains saved value from input field on reload
+ if (urlParam)
+ {
+ fetchAll(urlParam);
+ CategoryField.value = urlParam;
+
+ } else if (fieldValue !== "")
+ {
+ fetchAll(fieldValue);
+ } else
+ {
+ CategoryField.value = DefaultSearchValue;
+ fetchAll(DefaultSearchValue);
+ }
}
@@ -64,8 +108,8 @@ function addShop(shop) {
}
-async function fetchAll() {
- const response = await fetch("all.json");
+async function fetchAll(Category) {
+ const response = await fetch(`all.json?Category=${Category}`)
const shops = await response.json();
shops.forEach((shop) => addShop(shop));
}
@@ -76,23 +120,6 @@ async function fetchShopHeatmap() {
var heat = L.heatLayer(shops, {radius: 30}).addTo(heatmap);
}
-
-async function fetch_voronoi_polygons() {
- const response = await fetch("voronoi_polygons.json");
- const voronoi_polygons = await response.json();
- voronoi_polygons.forEach((polygon) => addPolygon(polygon));
-}
-
-function update(){
- if (map.getZoom() >= 14){
- //console.log('update')
- }
-}
-
-map.on('moveend', function() {
- update()
-});
-
-fetchChains()
-
-fetchShopHeatmap();
+fetchChains();
+fetchCategories();
+//fetchShopHeatmap();