-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
241 lines (218 loc) · 7.79 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Wiesehahn's Dive Map</title>
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<link
href="https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.css"
rel="stylesheet"
/>
<script src="https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.js"></script>
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
.mapboxgl-popup-content {
font: 400 15px/22px 'Source Sans Pro', 'Helvetica Neue', sans-serif;
background-color: rgba(255, 255, 255, 0);
color: #ddf3ed;
}
.mapboxgl-popup-anchor-bottom > .mapboxgl-popup-tip { border-top-color: #ddf3ed5d; }
</style>
</head>
<body>
<style>
.overlay {
position: absolute;
top: 10px;
left: 10px;
}
.overlay button {
font: 600 12px/20px "Helvetica Neue", Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);
color: #333333;
display: inline-block;
margin: 0;
padding: 5px 10px;
cursor: pointer;
border-radius: 5px;
border: 3px solid #e6e6e6
}
.overlay button:hover {
background-color: #f2f2f2;
}
</style>
<div id="map"></div>
<div class="overlay">
<button id="overview">Overview</button>
</div>
<script>
mapboxgl.accessToken =
"pk.eyJ1Ijoid2llc2VoYWhuIiwiYSI6ImNqbW0wdXhnazBlYjAzdnBrcWtldnMwMXMifQ.DL1uJiohTfoRnGcC7kMsqA";// "pk.eyJ1Ijoid2llc2VoYWhuIiwiYSI6ImNreWxvNHN1ejM3eW4ydm4wZmk5NTVpNnoifQ.1LUJzdqzbd0hmjW89Zvt2w";
const map = new mapboxgl.Map({
container: "map", // container ID
style: "mb_exports/style.json", //"mapbox://styles/wiesehahn/ckyhc6j18ht2o15pc7zdt0pzv", // style URL
center: [120, 5], // starting position [lng, lat]
zoom: 4,
minZoom: 1,
maxZoom: 16,
});
map.on("load", () => {
// Load an image from an external URL.
map.loadImage(
"https://raw.githubusercontent.com/wiesehahn/divemap/0f508b538d7ff214161d7dc3ce00879a2580587d/assets/scuba-symbol.png",
(error, image) => {
if (error) throw error;
// Add the image to the map style.
map.addImage("dive-icon", image);
map.addSource("divespots", {
type: "geojson",
// Use a URL for the value for the `data` property.
data: "https://raw.githubusercontent.com/wiesehahn/divemap/main/divespots.geojson",
});
map.addSource("mapbox-dem", {
type: "raster-dem",
url: "mapbox://mapbox.mapbox-terrain-dem-v1",
});
map.setTerrain({
source: "mapbox-dem",
exaggeration: ["interpolate", ["linear"], ["zoom"], 0, 5, 10, 1],
});
map.addLayer({
id: "divespots-layer",
type: "symbol",
source: "divespots",
minzoom: 8,
layout: {
"icon-image": [
"match",
["get", "equipment"],
"scuba",
"dive-icon",
"", // none for any other type
],
"icon-size": [
"interpolate",
["linear"],
["zoom"],
// zoom is 8 (or less) -> size will be 0.05
8,
0.05,
// zoom is 15 (or greater) -> size will be 0.2
15,
0.2,
],
"icon-allow-overlap": true,
},
});
map.addLayer({
id: "sky",
type: "sky",
paint: {
// set up the sky layer to use a color gradient
"sky-type": "gradient",
// the sky will be lightest in the center and get darker moving radially outward
// this simulates the look of the sun just below the horizon
"sky-gradient": [
"interpolate",
["linear"],
["sky-radial-progress"],
0.8,
"rgba(135, 206, 235, 1.0)",
1,
"rgba(0,0,0,0.1)",
],
"sky-gradient-center": [0, 0],
"sky-gradient-radius": 90,
"sky-opacity": [
"interpolate",
["exponential", 0.1],
["zoom"],
5,
0,
22,
1,
],
},
});
}
);
// Center the map on the coordinates of any clicked circle from the 'circle' layer.
map.on("click", "divecenters-8z4elo copy 2", (e) => {
map.flyTo({
center: e.features[0].geometry.coordinates,
zoom: 10,
bearing: 30,
pitch: 30,
// These options control the flight curve, making it move
// slowly and zoom out almost completely before starting
// to pan.
speed: 1, // make the flying slow
curve: 0.5, // change the speed at which it zooms out
// this animation is considered essential with respect to prefers-reduced-motion
essential: true,
});
});
// Change the cursor to a pointer when the it enters a feature in the 'circle' layer.
map.on("mouseenter", "divecenters-8z4elo copy 2", () => {
map.getCanvas().style.cursor = "pointer";
});
// Change it back to a pointer when it leaves.
map.on("mouseleave", "divecenters-8z4elo copy 2", () => {
map.getCanvas().style.cursor = "";
});
// Create a popup, but don't add it to the map yet.
var popup = new mapboxgl.Popup({
closeButton: false,
closeOnClick: false,
});
map.on("mouseenter", "divecenters-8z4elo copy 2", function (e) {
// Change the cursor style as a UI indicator.
map.getCanvas().style.cursor = "pointer";
var coordinates = e.features[0].geometry.coordinates.slice();
var description = e.features[0].properties.island;
// Ensure that if the map is zoomed out such that multiple
// copies of the feature are visible, the popup appears
// over the copy being pointed to.
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
}
// Populate the popup and set its coordinates
// based on the feature found.
popup.setLngLat(coordinates).setHTML(description).addTo(map);
});
map.on("mouseleave", "divecenters-8z4elo copy 2", function () {
map.getCanvas().style.cursor = "";
popup.remove();
});
});
document.getElementById("overview").addEventListener("click", () => {
map.flyTo({
center: [123.83697133205874, 1.3468258144037293],
zoom: 4.383254165076805,
bearing: 0,
pitch: 0,
// These options control the flight curve, making it move
// slowly and zoom out almost completely before starting
// to pan.
speed: 1, // make the flying slow
curve: 0.5, // change the speed at which it zooms out
// this animation is considered essential with respect to prefers-reduced-motion
essential: true,
});
});
map.addControl(new mapboxgl.FullscreenControl());
</script>
</body>
</html>