-
Notifications
You must be signed in to change notification settings - Fork 6
/
club-map.js
88 lines (75 loc) · 2.22 KB
/
club-map.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { html, render, makeComponent } from "./makeComponent.js";
import L from "leaflet";
const onConstruct = (host) => {
const state = {};
host.useState(state);
};
const onConnected = (host) => {
const el = host.shadowRoot.querySelector("#leaflet-map");
const map = L.map(el, {
drawControl: true,
zoomControl: false, // Disable default zoom control
center: [30.683, 9.099], // Set initial center point
zoom: 2, // Set an initial zoom level
minZoom: 2, // Set minimum zoom-out level
maxBounds: [
[-90, -180], // Southwest corner of the bounding box
[90, 180], // Northeast corner of the bounding box
],
});
L.control.zoom({ position: "topright" }).addTo(map);
L.tileLayer("https://tile.openstreetmap.de/{z}/{x}/{y}.png", {
attribution:
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
}).addTo(map);
(async () => {
let clubs = await fetch(
`https://api2.hackclub.com/v0.1/Club Applications/Clubs Dashboard`
).then((res) => res.json());
clubs.forEach(({ fields: x }) => {
if (!x.Status || x.Status === "inactive") return;
if (!(x?.Latitude && x?.Longitude)) return;
const style = `
transform-origin: left top;
height: 20px;
border-radius: 50%;
`;
const icon = new L.divIcon({
html: `<img style="${style}" src="https://assets.hackclub.com/icon-rounded.png"/>`,
className: "clear",
});
let marker = new L.marker([x.Latitude, x.Longitude], { icon }).addTo(map);
marker.bindPopup(`<b>${x?.Venue}</b>`);
});
})();
};
const styles = html`
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
crossorigin=""
/>
<style>
#leaflet-map {
width: 100%;
height: 100vh;
}
.leaflet-container {
font-family: "Phantom Sans";
}
.leaflet-popup-close-button {
display: none;
}
</style>
`;
const template = (host) => html`
${styles}
<div id="leaflet-map"></div>
`;
makeComponent({
name: "club-map",
template,
onConstruct,
onConnected,
});