aboutsummaryrefslogtreecommitdiff
path: root/src/static/main.js
blob: 24d0edff403c241dd20246ec955854f4e212c0e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var map = L.map('map').setView([55.68, 12.57], 13);
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
    maxZoom: 19,
    attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);


function addMarker(shop) {
    L.marker([shop.lat, shop.long], {title: shop.name, }).addTo(map);
}

function addPolygon(polygon) {
    L.polygon(polygon, {color: 'red'}).addTo(map);

    console.log(polygon.coordinates)
}


async function fetchShops() {
  const response = await fetch("supermarkets.json");
  const shops = await response.json();
  shops.forEach((shop) => addMarker(shop));
}

fetchShops()

async function fetch_voronoi_polygons() {
  const response = await fetch("voronoi_polygons.json");
  const voronoi_polygons = await response.json();
  voronoi_polygons.forEach((polygon) => addPolygon(polygon));
}
fetch_voronoi_polygons()