forked from SerenityOS/user-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
157 lines (137 loc) · 4.89 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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>SerenityOS User Map</title>
<link rel="shortcut icon" href="https://serenityos.org/favicon.ico" />
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
crossorigin=""
/>
<script
src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
crossorigin=""
></script>
<script
src="https://cdn.jsdelivr.net/gh/dj0001/Leaflet.timezones@c4f81012e5025b0133b3f06110b92427eac0118e/L.timezones.js"
integrity="sha512-tVofT+jp87w25dni8POKxzfk9ha8YHydkGQ1RSJVL/yG8zvSX/IGBz8K4cidliE4sfNuhMT23rYPYcLwRFf+Ag=="
crossorigin=""
></script>
<style>
* {
box-sizing: border-box;
}
body {
position: fixed;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#map {
width: 100%;
height: 100%;
}
.leaflet-popup-content {
text-align: center;
}
.leaflet-popup-content h1 {
font-size: 1.5rem;
font-weight: bold;
margin: 0.5rem;
}
.leaflet-marker-icon:not(.contributor) {
filter: grayscale(1) brightness(1.2);
}
</style>
</head>
<body>
<div id="map">
<div class="leaflet-control-container">
<div class="leaflet-top leaflet-right">
<div class="leaflet-control-attribution leaflet-control">
<span id="user-count">0</span> users are already registered |
<a
href="https://github.com/SerenityOS/user-map"
title="Contribute to this map"
>Contribute</a
>
</div>
</div>
</div>
</div>
<script>
fetch("people.json")
.then((response) => response.json())
.then((data) => {
var map = L.map("map").setView([0.0, 0.0], 2);
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution:
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
}).addTo(map);
L.timezones
.setStyle({
color: "#2dc1fc",
weight: 4,
})
.addTo(map);
for (const user of data) {
const container = document.createElement("div");
const heading = document.createElement("h1");
heading.innerText = user.nick;
container.appendChild(heading);
for (const [label, link] of Object.entries(user.links)) {
const anchor = document.createElement("a");
anchor.innerText = label;
anchor.href = link;
anchor.target = "_blank";
container.appendChild(anchor);
container.appendChild(document.createElement("br"));
}
const icon = new L.Icon.Default();
icon.options.className = user.contributor ? "contributor" : "";
L.marker(user.coordinates, { icon })
.addTo(map)
.bindPopup(() => {
// see https://stackoverflow.com/a/38671346/14457064
const userBounds = L.latLngBounds(
user.coordinates,
user.coordinates,
);
for (const overlay of Object.values(map._layers)) {
if (overlay._layers) {
for (const feature of Object.values(overlay._layers)) {
let bounds;
if (feature.getBounds) {
bounds = feature.getBounds();
} else if (feature._latlng) {
bounds = L.latLngBounds(
feature._latlng,
feature._latlng,
);
}
if (bounds && userBounds.intersects(bounds)) {
const paragraph =
container.getElementsByTagName("p")[0] ??
document.createElement("p");
paragraph.innerText = `${new Date().toLocaleString(
"sv",
{ timeZone: feature.feature.properties.tz_name1st },
)} (${feature.feature.properties.time_zone})`;
container.appendChild(paragraph);
return container;
}
}
}
}
return container;
});
}
document.getElementById("user-count").innerText = String(data.length);
});
</script>
</body>
</html>