-
Notifications
You must be signed in to change notification settings - Fork 50
/
index.html
204 lines (177 loc) · 5.98 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
<!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>
</div>
<a href="https://github.com/geodienst/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:300];
// gather results
(
// query part for: “"seamark:light:sequence"=*”
node["seamark:light:sequence"]({{bbox}});
node["seamark:light:1:sequence"]({{bbox}});
way["seamark:light:sequence"]({{bbox}});
way["seamark:light:1:sequence"]({{bbox}});
// relation["seamark:light:sequence"]({{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.indexedfeaturelayer.js"></script>
<script src="leaflet.rangedmarker.js"></script>
<script src="leaflet.light.js"></script>
<script>
let map = L.map('seamap', {attributionControl: false})
.setView([54.2, 2.6], 6)
.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="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="https://carto.com/attribution/">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-full.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;
try {
sequence = L.Light.sequence(feat.properties.tags, '#FF0');
} catch (e) {
console.error('Error parsing sequence: %s', e, feat.properties.tags);
// Fallback sequence
sequence = L.Light.sequence({
'seamark:light:sequence': '1+(1)'
});
}
return 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.9,
fill: !!sequence.state(0),
fillColor: sequence.state(0)
});
}
}).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;
});
lights.then(layer => {
let draw = function(t) {
layer.eachVisibleLayer(marker => {
var state = false
try{
var state = marker.options.sequence.state(t);
marker.setColor(state ? (useRealColors ? state : '#FF0') : false);
} 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>