-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
362 lines (311 loc) · 11.1 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<!DOCTYPE html>
<html>
<head>
<title>direction</title>
<meta charset="UTF-8" />
<meta name="keywords" content="direction,viewpoint,bench,openstreetmap,osm" />
<meta name="description" content="shows the direction of osm objects as semicircle" />
<meta name="author" content="Harald Hartmann" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico" />
<link rel="icon" type="image/png" href="images/favicon.png" sizes="16x16">
<link rel="stylesheet" href="leaflet.css" />
<link rel="stylesheet" href="Control.Geocoder.css" />
<script src="jquery-3.2.1.min.js"></script>
<script src="leaflet.js"></script>
<script src="leaflet.semicircle.js"></script>
<script src="leaflet.permalink.js"></script>
<script src="Control.Geocoder.js"></script>
<style>
body {
padding: 0;
margin: 0;
}
html,
body,
#map {
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
///
/// tileLayers
///
var openTopoMap = L.tileLayer("http://{s}.tile.opentopomap.org/{z}/{x}/{y}.png", {
minZoom: 12,
maxZoom: 16,
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Kartendarstellung: © <a href="http://opentopomap.org/">OpenTopoMap</a>'
});
var osmMapnik = L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
minZoom: 12,
maxZoom: 16,
attribution: 'Map data © OpenStreetMap contributors'
});
var osmMapnikBlackWhite = L.tileLayer("http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png", {
minZoom: 12,
maxZoom: 16,
attribution: 'Map data © OpenStreetMap contributors'
});
var baseLayers = {
"OpenTopoMap": openTopoMap,
"OpenStreetMap": osmMapnik,
"OpenStreetMap Grau": osmMapnikBlackWhite
};
var viewpoints = new L.layerGroup();
var benchs = new L.layerGroup();
var huntingstands = new L.layerGroup();
var entrances = new L.layerGroup();
var surveillances = new L.layerGroup();
var advertising = new L.layerGroup();
var trafficsign = new L.layerGroup();
var overlayLayers = {
"viewpoint": viewpoints,
"bench": benchs,
"hunting stand": huntingstands,
"entrance (cave, adit)": entrances,
"surveillance": surveillances,
"advertising": advertising,
"traffic sign": trafficsign
};
///
/// prepare and initialize map
///
var mappos = L.Permalink.getMapLocation();
var map = L.map('map', {
layers: [openTopoMap, viewpoints],
center: mappos.center,
zoom: mappos.zoom
});
map.attributionControl.setPrefix(
'<a href="http://leafletjs.com" title="A JS library for interactive maps">Leaflet</a> | <a href="https://github.com/osmtools/direction" title="Repository and Readme on GitHub">GitHub</a> | <a id="permalink" href="">Permalink</a>');
//map.locate({setView: true, maxZoom: 15});
L.Permalink.setup(map);
L.control.layers(baseLayers, overlayLayers, {
collapsed: false
}).addTo(map);
L.control.scale().addTo(map);
L.Control.geocoder({
position: 'topleft'
}).addTo(map);
var debug = false;
var osmIds = {};
var defaultRadius = 150;
var defaultSegmentAngle = 45;
///
/// functions
///
function callJosm(type, id, newLayer) {
$.get('http://127.0.0.1:8111/load_object?new_layer=' + newLayer + '&objects=' + type + id);
}
function getOsmType(element, abbr) {
abbr = abbr === undefined ? false : abbr;
return abbr ? element.type.charAt(0) : element.type;
}
function popupContent(element, debuginfo) {
return debug ? ('Art der Richtung: ' + debuginfo + '<br>') : '' +
'osm ID: <a href="https://www.openstreetmap.org/' + getOsmType(element) + '/' + element.id + '">' + getOsmType(element, true) + element.id + '</a><br>' +
'<a href="javascript:callJosm(' + getOsmType(element, true) + element.id + ',false)">JOSM</a> (<a href="javascript:callJosm(' + getOsmType(element, true) + element.id + ',true)">neue Ebene</a>)' +
"<pre><code>" + JSON.stringify(element.tags, null, 2).toString() + "</code></pre>";
}
function getDirectionFromCardinal(cardinal) {
var direction = 0;
switch (cardinal) {
case 'N':
direction = 0;
break;
case 'NNE':
direction = 22;
break;
case 'NE':
direction = 45;
break;
case 'ENE':
direction = 67;
break;
case 'E':
direction = 90;
break;
case 'ESE':
direction = 112;
break;
case 'SE':
direction = 135;
break;
case 'SSE':
direction = 157;
break;
case 'S':
direction = 180;
break;
case 'SSW':
direction = 202;
break;
case 'SW':
direction = 225;
break;
case 'WSW':
direction = 247;
break;
case 'W':
direction = 270;
break;
case 'WNW':
direction = 292;
break;
case 'NW':
direction = 315;
break;
case 'NNW':
direction = 337;
break;
default:
direction = -1;
}
return direction;
}
///
/// overpass Query
///
function getOverpassQuery(mapBounds) {
var overpassUrl = 'https://overpass-api.de/api/interpreter?data=';
overpassUrl += '[out:json][timeout:30];';
overpassUrl += '(';
//overpassUrl += 'node["direction"]({{bbox}});';
overpassUrl += 'node["tourism"="viewpoint"]({{bbox}});';
overpassUrl += 'way["tourism"="viewpoint"]({{bbox}});';
overpassUrl += 'node["amenity"="bench"]({{bbox}});';
overpassUrl += 'node["amenity"="hunting_stand"]({{bbox}});';
overpassUrl += 'node["natural"="cave_entrance"]({{bbox}});';
overpassUrl += 'node["man_made"="adit"]({{bbox}});';
overpassUrl += 'node["camera:direction"]({{bbox}});';
overpassUrl += 'node["advertising"]({{bbox}});';
overpassUrl += 'node[traffic_sign][direction][direction!~"^(forward|backward)$"]({{bbox}});';
overpassUrl += ')';
overpassUrl += ';out body center qt;';
var overpassQuery = overpassUrl.replace(/{{bbox}}/g,
mapBounds.getSouthWest().lat + "," +
mapBounds.getSouthWest().lng + "," +
mapBounds.getNorthEast().lat + "," +
mapBounds.getNorthEast().lng);
return overpassQuery;
}
//
//
//
function loadPois() {
$.getJSON(getOverpassQuery(map.getBounds()), function(data) {
$.each(data.elements, function(index, element) {
if ('tags' in element) {
if (!(element.id in osmIds)) {
osmIds[element.id] = true;
var lat, lon;
if (element.type === 'node') {
lat = element.lat;
lon = element.lon;
} else if (element.type === 'way') {
lat = element.center.lat;
lon = element.center.lon;
}
var layers = new Array();
if (element.tags.tourism === "viewpoint") layers.push(viewpoints);
if (element.tags.amenity === "bench") layers.push(benchs);
if (element.tags.amenity === "hunting_stand") layers.push(huntingstands);
if (element.tags.natural === "cave_entrance") layers.push(entrances);
if (element.tags.man_made === "adit") layers.push(entrances);
if (element.tags.man_made === "surveillance") layers.push(surveillances);
if (element.tags.advertising) layers.push(advertising);
if (element.tags.traffic_sign) layers.push(trafficsign);
if (layers.length == 0) layers.push(map);
layers.forEach(function(layer) {
var radius = defaultRadius;
// move camera:direction to direction
if ('camera:direction' in element.tags) {
element.tags.direction = element.tags["camera:direction"];
}
if ('direction' in element.tags) {
var directions = element.tags.direction.split(/; ?/);
directions.forEach(function(direction) {
if (/^(0-359|0-360)$/.test(direction)) {
L.circle([lat, lon], {
radius: radius,
color: "#008000",
fillColor: "#008000",
fillOpacity: 0.6
}).bindPopup(popupContent(element, '360°')).addTo(layer);
} else if (/^\d{1,3}-\d{1,3}$/.test(direction)) {
var angles = direction.split('-');
var startAngle = parseInt(angles[0]);
var stopAngle = parseInt(angles[1]);
var size = stopAngle - startAngle + (stopAngle < startAngle ? 360 : 0);
var segmentDirection = (startAngle + stopAngle + (stopAngle < startAngle ? 360 : 0)) / 2;
L.semiCircle([lat, lon], {
radius: radius,
color: "#008000",
fillColor: "#008000",
fillOpacity: 0.6
}).setDirection(segmentDirection, size).bindPopup(popupContent(element, 'x-y: startAngle(' + startAngle + ') - stopAngle(' + stopAngle + ') - direction(' + segmentDirection +
') - size(' + size + ')')).addTo(layer);
} else if (/^\d{1,3}$/.test(direction)) {
L.semiCircle([lat, lon], {
radius: radius,
color: "#FFA500",
fillColor: "#FFA500",
fillOpacity: 0.6
}).setDirection(parseInt(direction), defaultSegmentAngle).bindPopup(popupContent(element, 'x: direction(' + direction + '), size(' + defaultSegmentAngle + ')')).addTo(layer);
} else if (/^[NESW]{1,3}$/.test(direction)) {
var circleDirection = getDirectionFromCardinal(direction);
L.semiCircle([lat, lon], {
radius: radius,
color: "#FFA500",
fillColor: "#FFA500",
fillOpacity: 0.6
}).setDirection(circleDirection, defaultSegmentAngle).bindPopup(popupContent(element, 'NEWS: direction(' + circleDirection + ')')).addTo(layer);
} else if (/[NESW]{1,3}-[NESW]{1,3}/.test(direction)) {
var cardinals = direction.split('-');
var startAngle = parseInt(getDirectionFromCardinal(cardinals[0]));
var stopAngle = parseInt(getDirectionFromCardinal(cardinals[1]));
var size = stopAngle - startAngle + (stopAngle < startAngle ? 360 : 0);
var segmentDirection = (startAngle + stopAngle + (stopAngle < startAngle ? 360 : 0)) / 2;
L.semiCircle([lat, lon], {
radius: radius,
color: "#008000",
fillColor: "#008000",
fillOpacity: 0.6
}).setDirection(segmentDirection, size).bindPopup(popupContent(element, 'NESW-NESW: startAngle(' + startAngle + ') - stopAngle(' + stopAngle + ') - direction(' +
segmentDirection + ') - size(' + size + ')')).addTo(layer);
} else {
L.circle([lat, lon], {
radius: radius,
color: "#AD00AD",
fillColor: "#AD00AD"
}).bindPopup(popupContent(element, "direction, but not parsable, could also be false-positive!")).addTo(layer);
}
});
} else {
L.circle([lat, lon], {
radius: radius,
color: "#ff0000",
fillColor: "#ff0000"
}).bindPopup(popupContent(element, "no direction")).addTo(layer);
}
});
}
}
});
});
};
var moveEnd = function() {
loadPois();
$("#permalink").attr("href", location.href);
};
map.on('moveend', moveEnd);
loadPois();
</script>
</body>
</html>