forked from geodienst/lighthousemap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
279 lines (243 loc) · 8.6 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Lights at sea</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-M2wvCLH6DSRazYeZRIm1JnYyh22purTM+FDB5CsyxtQJYeKq83arPe5wgbNmcFXGqiSH2XR8dT/fJISVA1r/zQ=="
crossorigin="" />
<style>
html,
body {
margin: 0;
padding: 0;
height: 100%;
font: 12px/16px sans-serif;
color: white;
}
#seamap {
width: 100%;
height: 100%;
}
#controls {
position: fixed;
bottom: 0;
left: 0;
z-index: 1000;
}
#seamap .leaflet-control-attribution,
#controls {
margin: 10px;
font-size: 12px;
color: #ccc;
background: none;
text-shadow: 0px 0px 2px black;
}
#seamap .leaflet-control-attribution a {
color: inherit;
text-decoration: underline;
}
</style>
</head>
<body>
<div id="seamap"></div>
<div id="controls">
<label>
<input name="real-colors" type="checkbox">
Show real colors
</label>
<label>
<input name="real-distances" type="checkbox">
Show real distance
</label>
</div>
<a href="https://github.com/ErgEnn/lighthousemap"><img
style="position: absolute; top: 0; right: 0; border: 0; z-index: 1000"
src="https://camo.githubusercontent.com/52760788cde945287fbb584134c4cbc2bc36f904/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f77686974655f6666666666662e706e67"
alt="Fork me on GitHub"
data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png"></a>
<script id="seamap-query" type="text/x-overpass">
[out:json][timeout:7200];
// gather results
(
// query part for: “"seamark:light:sequence"=*”
node["seamark:light:colour"]({{bbox}});
way["seamark:light:colour"]({{bbox}});
relation["seamark:light:colour"]({{bbox}});
node["seamark:light:1:colour"]({{bbox}});
way["seamark:light:1:colour"]({{bbox}});
relation["seamark:light:1:colour"]({{bbox}});
);
// print results
out body;
>;
out skel qt;
</script>
<script id="seamap-wikidata-query" type="text/x-sparql">
SELECT ?item ?itemLabel ?location ?height ?focalHeight ?sequence
WHERE
{
?item wdt:P31 wd:Q39715.
?item wdt:P625 ?location.
OPTIONAL {
?item wdt:P2048 ?height.
?item wdt:P2923 ?focalHeight.
?item wdt:P1030 ?sequence.
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
</script>
<script src="https://unpkg.com/[email protected]/dist/leaflet-src.js"></script>
<script src="https://unpkg.com/[email protected]/osmtogeojson.js"
integrity="sha384-O1DMEF/gKYhLsICYtozkRWjEr9OfkZzVawUjyOPtevnKB2S1BegNJO0R251Pfuwz" crossorigin=""></script>
<script src="https://unpkg.com/[email protected]/rbush.js"></script>
<script src="https://unpkg.com/@turf/[email protected]/turf.min.js"></script>
<script src="leaflet.semicircle.js"></script>
<script src="leaflet.indexedfeaturelayer.js"></script>
<script src="leaflet.rangedmarker.js"></script>
<script src="leaflet.light.js"></script>
<script>
let map = L.map('seamap', { attributionControl: false })
.setView([58.6, 25], 8)
.addControl(L.control.attribution({
position: 'bottomright',
prefix: 'Made by <a href="https://www.geodienst.xyz/">Geodienst</a>'
}));
L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png', {
detectRetina: true,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>'
}).addTo(map);
let bounds = map.getBounds();
function bbox(bounds) {
let ne = bounds.getNorthEast();
let sw = bounds.getSouthWest();
return [sw.lat, sw.lng, ne.lat, ne.lng]
}
//let query = document.getElementById('seamap-query').textContent
// .replace(/\{\{bbox\}\}/g, bbox(bounds).join(','));
// // Query the entire world
// bounds = [-90, -180, 90, 180]
// let query = document.getElementById('seamap-query').textContent
// .replace(/\{\{bbox\}\}/g, bounds.join(','));
//let url = 'https://www.overpass-api.de/api/interpreter?data=' + encodeURIComponent(query);
url = 'data-full2.json'; // For testing
//url = 'data.json'; // For testing
let data = fetch(url)
.then(req => req.json())
.then(json => osmtogeojson(json))
.then(json => ({
type: json.type,
features: json.features.map(feature => {
return feature.geometry.type == 'Polygon'
? Object.assign({}, feature, { geometry: turf.centroid(feature).geometry })
: feature;
})
}));
let lights = data.then(geojson => {
return L.indexedGeoJSON(null, {
pointToLayer: function (feat, latlng) {
let sequence;
if (feat.properties.tags['seamark:light:colour']) {
try {
sequence = L.Light.sequence(feat.properties.tags, Math.random(), '#FF0');
} catch (e) {
console.error('Error parsing sequence: %s', e, feat.properties.tags);
// Fallback sequence
sequence = L.Light.sequence({
'seamark:light:sequence': '1+(1)'
}, Math.random());
}
return new L.SectorGroup([new L.Light(latlng, {
interactive: false,
title: feat.properties.tags['name'],
radius: (parseFloat(feat.properties.tags['seamark:light:range'], 10) || 1) * 1852,
sequence: sequence,
stroke: false,
fillOpacity: 0.5,
fill: !!sequence.state(0),
fillColor: sequence.state(0)
})]);
} else if (feat.properties.tags['seamark:light:1:colour']) {
var i = 1;
let layr = [];
let seqOffset = Math.random();
while (feat.properties.tags['seamark:light:' + i + ':colour']) {
let data = {
"seamark:light:character": feat.properties.tags['seamark:light:' + i + ':character'],
"seamark:light:colour": feat.properties.tags['seamark:light:' + i + ':colour'],
"seamark:light:sequence": feat.properties.tags['seamark:light:' + i + ':sequence'],
"seamark:light:period": feat.properties.tags['seamark:light:' + i + ':period'],
"seamark:light:group": feat.properties.tags['seamark:light:' + i + ':group'],
"seamark:light:range": feat.properties.tags['seamark:light:' + i + ':range'],
"seamark:light:sector_start": feat.properties.tags['seamark:light:' + i + ':sector_start'],
"seamark:light:sector_end": feat.properties.tags['seamark:light:' + i + ':sector_end'],
}
try {
sequence = L.Light.sequence(data, seqOffset, '#FF0');
} catch (e) {
console.error('Error parsing sequence: %s', e, data);
// Fallback sequence
sequence = L.Light.sequence({
'seamark:light:sequence': '1+(1)'
}, seqOffset);
}
let start = (parseFloat(data['seamark:light:sector_start']) + 180) % 360;
let stop = (parseFloat(data['seamark:light:sector_end']) + 180) % 360;
if (stop < start) stop = stop + 360;
let l = new L.Light(latlng, {
interactive: false,
title: feat.properties.tags['name'],
radius: (parseFloat(data['seamark:light:range']) || 1) * 1852,
realDistance: (parseFloat(data['seamark:light:range']) || 1) * 1852,
sequence: sequence,
stroke: false,
fillOpacity: 0.5,
fill: !!sequence.state(0),
fillColor: sequence.state(0),
startAngle: start,
stopAngle: stop,
});
layr.push(l);
i++;
}
return new L.SectorGroup(layr);
}
}
}).addTo(map).addData(geojson);
});
let useRealColors = true;
document.querySelector('input[name=real-colors]').checked = useRealColors;
document.querySelector('input[name=real-colors]').addEventListener('change', function (e) {
useRealColors = this.checked;
});
let useRealDistances = true;
document.querySelector('input[name=real-distances]').checked = useRealColors;
document.querySelector('input[name=real-distances]').addEventListener('change', function (e) {
useRealDistances = this.checked;
});
lights.then(layer => {
let draw = function (t) {
layer.eachVisibleLayer(layerGroup => {
if (layerGroup.feature.properties.type == 'node')
layerGroup.eachLayer(marker => {
var state = false
try {
var state = marker.options.sequence.state(t);
marker.setColor(state ? (useRealColors ? state : '#FF0') : false);
marker.setUseRealDistance(useRealDistances);
} catch (e) {
console.error(e)
}
})
});
};
let update = function (t) {
draw(t / 1000);
requestAnimationFrame(update);
};
update(0);
}).catch(e => console.error(e));
lights.catch(e => console.error(e));
</script>
</body>
</html>