This repository has been archived by the owner on May 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
95 lines (86 loc) · 3.12 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hamburger Treppen Karten / Stairs Map</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<meta name="theme-color" content="#3388ff">
<link rel="icon" href="./favicon.ico">
<link href="https://api.mapbox.com/mapbox-gl-js/v2.13.0/mapbox-gl.css" rel="stylesheet">
<script src="https://api.mapbox.com/mapbox-gl-js/v2.13.0/mapbox-gl.js"></script>
<script src="./steps-hamburg.min.js"></script>
<style>
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
</style>
</head>
<body style="margin: 0; padding: 0;">
<div id="map"></div>
<script>
mapboxgl.accessToken = '<MAPBOX-ACCESS-TOKEN-HERE>';
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/dark-v10',
center: [9.993682, 53.551086],
zoom: 14,
})
.addControl(new mapboxgl.NavigationControl())
.addControl(new mapboxgl.GeolocateControl())
.addControl(new mapboxgl.ScaleControl())
.addControl(new mapboxgl.FullscreenControl());
map.on("load", () => {
map.addSource("steps", {
type: "geojson",
data: StepsHamburg,
});
map.addLayer({
id: "steps",
type: "line",
source: "steps",
layout: {
"line-join": "round",
"line-cap": "round",
},
paint: {
"line-color": "#3388ff",
"line-width": 4,
},
});
// Add pop-up
map.on("click", "steps", (e) => {
const properties = e.features[0].properties;
var description = "";
if (properties.name) {
description += "<h3>" + properties.name + "</h3>";
}
description += "<pre>";
for (const [key, value] of Object.entries(properties)) {
if (["@id", "highway"].includes(key)) {
continue;
}
description += `${key}: ${value}\n`;
}
description +=
'</pre><p>Data: <a href="https://www.openstreetmap.org/' +
properties["@id"] +
'" target="_blank">OpenStreetMap</a> / <a href="https://opendatacommons.org/licenses/odbl/1-0/" target="_blank">ODbL</a></p>';
new mapboxgl.Popup()
.setLngLat(e.lngLat)
.setHTML(description)
.addTo(map);
});
// Cursor when the mouse is over the layer.
map.on("mouseenter", "steps", () => {
map.getCanvas().style.cursor = "pointer";
});
map.on("mouseleave", "steps", () => {
map.getCanvas().style.cursor = "";
});
});
</script>
</body>
</html>