-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
257 lines (231 loc) · 9.92 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>Hike & Fly Peaks</title>
<script src='https://api.mapbox.com/mapbox-gl-js/v1.11.1/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v1.11.1/mapbox-gl.css' rel='stylesheet' />
<style type="text/css">
html {
font-family: sans-serif;
font-size: 0.8em;
}
th {
text-align: left;
}
#wrapper {
width: 100%;
}
#map {
height: 600px;
width: 100%;
}
.mapboxgl-popup-content h3 {
margin-top: 4px;
margin-bottom: 8px;
}
.mapboxgl-popup-content p {
margin-top: 0px;
margin-bottom: 8px;
}
</style>
</head>
<body>
<div id="header">
<h1>Alpine Hike & Fly Peaks</h1>
<select name="country">
<option value="austria">Austria</option>
<option value="liechtenstein">Liechtenstein</option>
<option value="slovenia">Slovenia</option>
<option value="switzerland" selected>Switzerland</option>
</select>
<p>Included are peaks with an elevation over 1000 m and launches (from XContest) within 350 m from the peak.</p>
<p>Colors: <span style="color: #4059AD;">●</span> No launches
| <span style="color: #FFDA20;">●</span> 1–3 launches
| <span style="color: #F46F22;">●</span> 3–9 launches
| <span style="color: #E92028;">●</span> 10+ launches</p>
</div>
<div id="wrapper">
<div id="map"></div>
</div>
<footer>
<p><strong>NOTE:</strong> This data analysis has its limitations. Only flights from XContest are considered. Only launches 350 m around the peak are included. Just because a peak is listed as having 0 flights does not mean that nobody launched from there, it just means that no flight from there was uploaded to XContest. Some peaks are dangerous to launch from and some peaks are in protected areas and are thus illegal to launch from. Please use your brain when picking a launch spot and make sure to inform yourself about local rules and regulations.</p>
<p>Contact: <a href="mailto:[email protected]">[email protected]</a> | <a href="https://github.com/dbrgn/hnf-peaks">Github</a> | Last data update: 2024-08-25</p>
</footer>
<script>
function ready(fn) {
if (document.readyState != 'loading'){
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
let countries = {
'switzerland': {
center: [8.496828420038582, 46.76733810404278],
zoom: 7,
},
'austria': {
center: [13.26, 47.2],
zoom: 7,
},
'slovenia': {
center: [14.6, 46.0],
zoom: 8,
},
'liechtenstein': {
center: [9.55, 47.1],
zoom: 10,
},
};
const RADIUS = 350;
ready(() => {
mapboxgl.accessToken = 'pk.eyJ1IjoiZGFuaWxvIiwiYSI6IkM2cVZZdkkifQ.KK_4WqiWBL_DhpjIfGPcLw';
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/danilo/citrnqoyx000h2jmg5qenf8ep',
center: countries.switzerland.center,
zoom: countries.switzerland.zoom,
});
let loaded = false;
const loadCountry = (country) => {
console.info(`Load country: ${country}`);
// Pan to new country
map
.setCenter(countries[country].center)
.zoomTo(countries[country].zoom);
// Update marker layer
if (loaded) {
map.removeLayer('circles');
map.removeLayer('markers');
}
const tier0 = '#4059AD'; // 0
const tier1 = '#FFDA20'; // 1-3
const tier2 = '#F46F22'; // 4-9
const tier3 = '#E92028'; // 10+
const metersRadius = 350;
map.addLayer({
id: 'circles',
source: `peaks_${country}`,
type: 'circle',
// https://stackoverflow.com/a/70458439/284318
paint: {
'circle-radius': [
'interpolate',
['exponential', 2],
['zoom'],
0, 0,
20, [
'/',
['/', metersRadius, 0.075],
['cos', ['*', ['get', 'lat'], ['/', Math.PI, 180]]],
],
],
'circle-color': '#444444',
'circle-opacity': 0.1,
},
});
map.addLayer({
id: 'markers',
source: `peaks_${country}`,
type: 'circle',
paint: {
// Set the label content to the
// feature's `name` property
//'text-field': ['get', 'title'],
'circle-radius': [
'interpolate', ['linear'], ['zoom'],
5, 2,
8, 3,
12, 6,
14, 18,
],
'circle-color': [
'match',
['get', 'flights'],
0, tier0,
1, tier1,
2, tier1,
3, tier1,
4, tier2,
5, tier2,
6, tier2,
7, tier2,
8, tier2,
9, tier2,
/* other */ tier3,
],
},
});
loaded = true;
// Show popup on click
map.on('click', 'markers', (e) => {
const coordinates = e.features[0].geometry.coordinates.slice();
const description = getDescription(e.features[0]);
new mapboxgl.Popup()
.setLngLat(coordinates)
.setHTML(description)
.addTo(map);
});
// Change the cursor to a pointer when the mouse is over the places layer
map.on('mouseenter', 'markers', function() {
map.getCanvas().style.cursor = 'pointer';
});
// Change it back to a pointer when it leaves
map.on('mouseleave', 'markers', function() {
map.getCanvas().style.cursor = '';
});
};
map.on('load', () => {
console.info('map loaded');
// Add data sources
map.addSource('peaks_switzerland', {
type: 'geojson',
data: 'geojson-switzerland-2024-08-25.json',
});
map.addSource('peaks_austria', {
type: 'geojson',
data: 'geojson-austria-2024-08-25.json',
});
map.addSource('peaks_slovenia', {
type: 'geojson',
data: 'geojson-slovenia-2024-08-25.json',
});
map.addSource('peaks_liechtenstein', {
type: 'geojson',
data: 'geojson-liechtenstein-2024-08-25.json',
});
// Show
loadCountry('switzerland');
});
const selector = document.querySelector('select[name="country"]');
selector.value = 'switzerland';
selector.addEventListener('change', (e) => {
const country = e.target.value;
if (countries[country] === undefined) {
console.error('Invalid country: ' + country);
return;
};
loadCountry(country);
});
});
// Function to create description from GeoJSON feature
function getDescription(feature) {
console.log(feature);
const p = feature.properties;
const coords = feature._geometry.coordinates;
let description = '<h3>' + p.title + '</h3>';
if (coords) {
description += '<p><a href="https://www.xcontest.org/world/en/flights-search/?filter%5Bpoint%5D=' + coords[0] + '+' + coords[1] + '&filter%5Bradius%5D=' + RADIUS + '&list%5Bsort%5D=pts&list%5Bdir%5D=down" target="_blank">XContest Search</a></p>';
}
description += '<strong>Elevation</strong><p>' + p.ele + ' m</p>';
description += '<strong>Flights</strong><p>' + p.flights + '</p>';
const topFlight = JSON.parse(p['top']);
if (topFlight['pilot'].length > 0) {
description += '<strong>Record holder</strong><p>' + topFlight.pilot + ' (' + topFlight.dist + ')</p>';
}
return description;
};
</script>
</body>
</html>