-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
145 lines (126 loc) · 3.81 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Bikestations in Hamburg</title>
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<script src="https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.js"></script>
<link
href="https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.css"
rel="stylesheet"
/>
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
/* Center the loader */
#loader {
position: absolute;
left: 50%;
top: 50%;
z-index: 1;
width: 120px;
height: 120px;
margin: -76px 0 0 -76px;
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3498db;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
@-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<style>
.maplibregl-popup {
max-width: 200px;
}
</style>
<div id="loader"></div>
<div id="map"></div>
<script>
var map = new maplibregl.Map({
container: "map",
style:
"https://api.maptiler.com/maps/basic-v2/style.json?key=lyb2MoBOJXVDTlZsa91a",
center: [10.0204, 53.557],
zoom: 12,
});
map.on("load", async function () {
const getStations = async () => {
let stations = [];
let url =
"https://iot.hamburg.de/v1.0/Things?$filter=Datastreams/properties/serviceName%20eq%20%27HH_STA_StadtRad%27&$count=true&$expand=Locations,Datastreams($expand=Observations($orderby=phenomenonTime%20desc;$top=1),Sensor,ObservedProperty)&$top=17";
let resp = await fetch(url);
let json = await resp.json();
let nextLink = json["@iot.nextLink"];
stations = json.value;
while (nextLink) {
resp = await fetch(nextLink);
json = await resp.json();
nextLink = json["@iot.nextLink"];
stations.push(...json.value);
json.value.forEach((element) => {
if (element.Locations[0]) {
let stationBicycles =
element.Datastreams[0].Observations[0].result;
var bikeStation = [
element.Locations[0].location.geometry.coordinates[0],
element.Locations[0].location.geometry.coordinates[1],
];
var popup = new maplibregl.Popup({ offset: 25 }).setText(
element.description +
"\n\nVerfügbare Räder: " +
stationBicycles
);
var el = document.createElement("div");
el.id = "marker";
let stationColor = "#FF0000";
if (stationBicycles > 3) {
stationColor = "#00FF00";
} else if (stationBicycles >= 1) {
stationColor = "#ffa500";
}
var marker = new maplibregl.Marker({
color: stationColor,
})
.setLngLat(bikeStation)
.addTo(map)
.setPopup(popup);
}
});
}
document.getElementById("loader").style.display = "none";
return stations;
};
const stations = await getStations();
});
</script>
</body>
</html>