-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
59 lines (55 loc) · 1.88 KB
/
index.html
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<html>
<head>
<title>Restaurants</title>
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ=="
crossorigin=""
/>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<div style="display: flex; height: 100vh">
<div style="flex: 20%; overflow-y: auto">
<div id="loading">loading...</div>
<div id="diets"></div>
<div id="pois"></div>
</div>
<div id="map" style="flex: 80%"></div>
</div>
</body>
<script
src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-BB3hKbKWOc9Ez/TAwyWxNXeoV9c1v6FIeYiBieIWkpLjauysF18NzgR1MBNBXf8/KABdlkX68nAhlwcDFLGPCQ=="
crossorigin=""
></script>
<script src="index.js"></script>
<script>
(async () => {
const { pois, latitude, longitude } = await this.getRestaurantsAroundMe();
document.getElementById("loading").innerHTML = "";
const { map, markers } = this.initMap({ pois, latitude, longitude });
const diets = this.extractDiets(pois);
const dietsHtml = diets
.map((d) => `<span class="">${d.at(0)} (${d.at(1)})</span>`)
.join(` | `);
document.getElementById(`diets`).innerHTML += dietsHtml;
pois.forEach((poi) => {
if (!poi.name) return;
const div = document.createElement("div");
const a = document.createElement("a");
a.innerHTML = poi.name;
div.appendChild(a);
a.addEventListener("click", () => {
const leafletMarker = markers.get(poi);
if (leafletMarker) {
leafletMarker.openPopup();
map.fitBounds(L.latLngBounds([leafletMarker.getLatLng()]));
}
});
document.getElementById(`pois`).appendChild(div);
});
})();
</script>
</html>