|
1
|
|
|
/*jslint |
|
2
|
|
|
indent: 4 |
|
3
|
|
|
*/ |
|
4
|
|
|
|
|
5
|
|
|
/*global |
|
6
|
|
|
$, google, Lines, Markers, Conversion, Cookies, Coordinates, trackMarker, mytrans, showAlert, |
|
7
|
|
|
id2alpha, alpha2id, |
|
8
|
|
|
showProjectionDialog, showLinkDialog, |
|
9
|
|
|
osmProvider, osmDeProvider, ocmProvider, thunderforestOutdoorsProvider, opentopomapProvider |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
//var boundariesLayer = null; |
|
13
|
|
|
//var boundariesLayerShown = false; |
|
14
|
|
|
var map = null; |
|
15
|
|
|
var copyrightDiv = null; |
|
16
|
|
|
var theMarkers = new Markers(); |
|
17
|
|
|
|
|
18
|
|
|
var CLAT_DEFAULT = 51.163375; |
|
19
|
|
|
var CLON_DEFAULT = 10.447683; |
|
20
|
|
|
var ZOOM_DEFAULT = 12; |
|
21
|
|
|
var MAPTYPE_DEFAULT = "OSM"; |
|
22
|
|
|
var RADIUS_DEFAULT = 0; |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
function enterEditMode(id) { |
|
26
|
|
|
'use strict'; |
|
27
|
|
|
|
|
28
|
|
|
trackMarker('edit'); |
|
29
|
|
|
var m = theMarkers.getById(id); |
|
30
|
|
|
|
|
31
|
|
|
$('#edit_name' + m.getAlpha()).val(m.getName()); |
|
32
|
|
|
$('#edit_coordinates' + m.getAlpha()).val(Coordinates.toString(m.getPosition())); |
|
33
|
|
|
$('#edit_circle' + m.getAlpha()).val(m.getRadius()); |
|
34
|
|
|
|
|
35
|
|
|
$('#dynview' + id).hide(); |
|
36
|
|
|
$('#dynedit' + id).show(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
function leaveEditMode(id, takenew) { |
|
41
|
|
|
'use strict'; |
|
42
|
|
|
|
|
43
|
|
|
if (takenew) { |
|
44
|
|
|
var m = theMarkers.getById(id), |
|
45
|
|
|
name = $('#edit_name' + m.getAlpha()).val(), |
|
46
|
|
|
name_ok = /^([a-zA-Z0-9-_]*)$/.test(name), |
|
47
|
|
|
s_coordinates = $('#edit_coordinates' + m.getAlpha()).val(), |
|
48
|
|
|
coordinates = Coordinates.fromString(s_coordinates), |
|
49
|
|
|
s_radius = $('#edit_circle' + m.getAlpha()).val(), |
|
50
|
|
|
radius = Conversion.getInteger(s_radius, 0, 100000000000), |
|
51
|
|
|
errors = []; |
|
52
|
|
|
|
|
53
|
|
|
if (!name_ok) { |
|
54
|
|
|
errors.push(mytrans("sidebar.markers.error_badname").replace(/%1/, name)); |
|
55
|
|
|
} |
|
56
|
|
|
if (!coordinates) { |
|
57
|
|
|
errors.push(mytrans("sidebar.markers.error_badcoordinates").replace(/%1/, s_coordinates)); |
|
58
|
|
|
} |
|
59
|
|
|
if (radius === null) { |
|
60
|
|
|
errors.push(mytrans("sidebar.markers.error_badradius").replace(/%1/, s_radius)); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if (errors.length > 0) { |
|
64
|
|
|
showAlert(mytrans("dialog.error"), errors.join("<br /><br />")); |
|
65
|
|
|
} else { |
|
66
|
|
|
m.setNamePositionRadius(name, coordinates, radius); |
|
67
|
|
|
$('#dynview' + id).show(); |
|
68
|
|
|
$('#dynedit' + id).hide(); |
|
69
|
|
|
} |
|
70
|
|
|
} else { |
|
71
|
|
|
$('#dynview' + id).show(); |
|
72
|
|
|
$('#dynedit' + id).hide(); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
function createMarkerDiv(id) { |
|
78
|
|
|
'use strict'; |
|
79
|
|
|
|
|
80
|
|
|
var alpha = id2alpha(id), |
|
81
|
|
|
iconw = 33, |
|
82
|
|
|
iconh = 37, |
|
83
|
|
|
offsetx = (id % 26) * iconw, |
|
84
|
|
|
offsety = Math.floor(id / 26) * iconh; |
|
85
|
|
|
|
|
86
|
|
|
return "<div id=\"dyn" + id + "\">" + |
|
87
|
|
|
"<table id=\"dynview" + id + "\" style=\"width: 100%; vertical-align: middle;\">\n" + |
|
88
|
|
|
" <tr>\n" + |
|
89
|
|
|
" <td rowspan=\"3\" style=\"vertical-align: top\">\n" + |
|
90
|
|
|
" <span style=\"width:" + iconw + "px; height:" + iconh + "px; float: left; display: block; background-image: url(img/markers.png); background-repeat: no-repeat; background-position: -" + offsetx + "px -" + offsety + "px;\"> </span>\n" + |
|
91
|
|
|
" </td>\n" + |
|
92
|
|
|
" <td style=\"text-align: center\"><i class=\"fa fa-map-marker\"></i></td>\n" + |
|
93
|
|
|
" <td id=\"view_name" + alpha + "\" colspan=\"2\">marker</td>\n" + |
|
94
|
|
|
" </tr>\n" + |
|
95
|
|
|
" <tr>\n" + |
|
96
|
|
|
" <td style=\"text-align: center\"><i class=\"fa fa-globe\"></i></td>\n" + |
|
97
|
|
|
" <td id=\"view_coordinates" + alpha + "\" colspan=\"2\">N 48° 00.123 E 007° 51.456</td>\n" + |
|
98
|
|
|
" </tr>\n" + |
|
99
|
|
|
" <tr>\n" + |
|
100
|
|
|
" <td style=\"text-align: center\"><i class=\"fa fa-circle-o\"></i></td>\n" + |
|
101
|
|
|
" <td id=\"view_circle" + alpha + "\">16100 m</td>\n" + |
|
102
|
|
|
" <td>\n" + |
|
103
|
|
|
" <div class=\"btn-group\" style=\"padding-bottom: 2px; padding-top: 2px; float: right\">\n" + |
|
104
|
|
|
" <button class=\"my-button btn btn-mini btn-warning\" data-i18n=\"[title]sidebar.markers.edit_marker\" type=\"button\" onclick=\"enterEditMode(" + id + ");\"><i class=\"fa fa-edit\"></i></button>\n" + |
|
105
|
|
|
" <button class=\"my-button btn btn-mini btn-danger\" data-i18n=\"[title]sidebar.markers.delete_marker\" type=\"button\" onClick=\"theMarkers.removeById(" + id + ")\"><i class=\"fa fa-trash-o\"></i></button>\n" + |
|
106
|
|
|
" <button class=\"my-button btn btn-mini btn-info\" data-i18n=\"[title]sidebar.markers.move_to\" type=\"button\" onClick=\"theMarkers.goto(" + id + ")\"><i class=\"fa fa-search\"></i></button>\n" + |
|
107
|
|
|
" <button class=\"my-button btn btn-mini btn-warning\" data-i18n=\"[title]sidebar.markers.center\" type=\"button\" onClick=\"theMarkers.center(" + id + ")\"><i class=\"fa fa-crosshairs\"></i></button>\n" + |
|
108
|
|
|
" <button class=\"my-button btn btn-mini btn-success\" data-i18n=\"[title]sidebar.markers.project\" type=\"button\" onClick=\"projectFromMarker(" + id + ")\"><i class=\"fa fa-location-arrow\"></i></button>\n" + |
|
109
|
|
|
" </div>\n" + |
|
110
|
|
|
" </td>\n" + |
|
111
|
|
|
" </tr>\n" + |
|
112
|
|
|
"</table>\n" + |
|
113
|
|
|
"<table id=\"dynedit" + id + "\" style=\"display: none; width: 100%; vertical-align: middle;\">\n" + |
|
114
|
|
|
" <tr>\n" + |
|
115
|
|
|
" <td rowspan=\"4\" style=\"vertical-align: top\"><span style=\"width:" + iconw + "px; height:" + iconh + "px; float: left; display: block; background-image: url(img/markers.png); background-repeat: no-repeat; background-position: -" + offsetx + "px -" + offsety + "px;\"> </span>\n" + |
|
116
|
|
|
" <td style=\"text-align: center; vertical-align: middle;\"><i class=\"icon-map-marker\"></i></td>\n" + |
|
117
|
|
|
" <td><input id=\"edit_name" + alpha + "\" data-i18n=\"[title]sidebar.markers.name;[placeholder]sidebar.markers.name_placeholder\" class=\"form-control input-block-level\" type=\"text\" style=\"margin-bottom: 0px;\" value=\"n/a\" /></td>\n" + |
|
118
|
|
|
" </tr>\n" + |
|
119
|
|
|
" <tr>\n" + |
|
120
|
|
|
" <td style=\"text-align: center; vertical-align: middle;\"><i class=\"icon-globe\"></i></td>\n" + |
|
121
|
|
|
" <td><input id=\"edit_coordinates" + alpha + "\" data-i18n=\"[title]sidebar.markers.coordinates;[placeholder]sidebar.markers.coordinates_placeholder\" class=\"form-control input-block-level\" type=\"text\" style=\"margin-bottom: 0px;\" value=\"n/a\" /></td>\n" + |
|
122
|
|
|
" </tr>\n" + |
|
123
|
|
|
" <tr>\n" + |
|
124
|
|
|
" <td style=\"text-align: center; vertical-align: middle;\"><i class=\"icon-circle-blank\"></i></td>\n" + |
|
125
|
|
|
" <td><input id=\"edit_circle" + alpha + "\" data-i18n=\"[title]sidebar.markers.radius;[placeholder]sidebar.markers.radius_placeholder\" class=\"form-control input-block-level\" type=\"text\" style=\"margin-bottom: 0px;\" value=\"n/a\" /></td>\n" + |
|
126
|
|
|
" </tr>\n" + |
|
127
|
|
|
" <tr>\n" + |
|
128
|
|
|
" <td colspan=\"2\" style=\"text-align: right\">\n" + |
|
129
|
|
|
" <button class=\"btn btn-small btn-primary\" type=\"button\" onclick=\"javascript: leaveEditMode(" + id + ", true);\" data-i18n=\"dialog.ok\">OK</button>\n" + |
|
130
|
|
|
" <button class=\"btn btn-small\" type=\"button\" onclick=\"leaveEditMode(" + id + ", false);\" data-i18n=\"dialog.cancel\">CANCEL</button>\n" + |
|
131
|
|
|
" </td>\n" + |
|
132
|
|
|
" </tr>\n" + |
|
133
|
|
|
"</table>" + |
|
134
|
|
|
"</div>"; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
|
|
138
|
|
|
function newMarker(coordinates, id, radius, name) { |
|
139
|
|
|
'use strict'; |
|
140
|
|
|
|
|
141
|
|
|
if (radius < 0) { |
|
142
|
|
|
radius = RADIUS_DEFAULT; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
if (id < 0 || id >= theMarkers.getSize() || !theMarkers.getById(id).isFree()) { |
|
146
|
|
|
id = theMarkers.getFreeId(); |
|
147
|
|
|
} |
|
148
|
|
|
if (id < 0) { |
|
149
|
|
|
showAlert( |
|
150
|
|
|
mytrans("dialog.error"), |
|
151
|
|
|
mytrans("dialog.toomanymarkers_error.content").replace(/%1/, theMarkers.getSize()) |
|
152
|
|
|
); |
|
153
|
|
|
return null; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
var alpha = id2alpha(id), |
|
157
|
|
|
marker, |
|
158
|
|
|
div, |
|
159
|
|
|
nextid; |
|
160
|
|
|
|
|
161
|
|
|
if (!name || name === "") { |
|
162
|
|
|
name = "marker_" + alpha; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
marker = theMarkers.getById(id); |
|
166
|
|
|
marker.initialize(map, name, coordinates, radius); |
|
167
|
|
|
div = createMarkerDiv(id); |
|
168
|
|
|
|
|
169
|
|
|
nextid = theMarkers.getNextUsedId(id); |
|
170
|
|
|
if (nextid < 0) { |
|
171
|
|
|
$('#dynMarkerDiv').append(div); |
|
172
|
|
|
} else { |
|
173
|
|
|
$(div).insertBefore('#dyn' + nextid); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
$('#edit_name' + alpha).keydown(function (e) { |
|
177
|
|
|
if (e.which === 27) { |
|
178
|
|
|
leaveEditMode(id, false); |
|
179
|
|
|
} else if (e.which === 13) { |
|
180
|
|
|
leaveEditMode(id, true); |
|
181
|
|
|
} |
|
182
|
|
|
}); |
|
183
|
|
|
|
|
184
|
|
|
$('#edit_coordinates' + alpha).keydown(function (e) { |
|
185
|
|
|
if (e.which === 27) { |
|
186
|
|
|
leaveEditMode(id, false); |
|
187
|
|
|
} else if (e.which === 13) { |
|
188
|
|
|
leaveEditMode(id, true); |
|
189
|
|
|
} |
|
190
|
|
|
}); |
|
191
|
|
|
|
|
192
|
|
|
$('#edit_circle' + alpha).keydown(function (e) { |
|
193
|
|
|
if (e.which === 27) { |
|
194
|
|
|
leaveEditMode(id, false); |
|
195
|
|
|
} else if (e.which === 13) { |
|
196
|
|
|
leaveEditMode(id, true); |
|
197
|
|
|
} |
|
198
|
|
|
}); |
|
199
|
|
|
|
|
200
|
|
|
$('#btnmarkers2').show(); |
|
201
|
|
|
$('#btnmarkersdelete1').removeAttr('disabled'); |
|
202
|
|
|
$('#btnmarkersdelete2').removeAttr('disabled'); |
|
203
|
|
|
|
|
204
|
|
|
marker.update(); |
|
205
|
|
|
theMarkers.saveMarkersList(); |
|
206
|
|
|
Lines.updateLinesMarkerAdded(); |
|
207
|
|
|
|
|
208
|
|
|
return marker; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
|
|
212
|
|
|
function projectFromMarker(id) { |
|
213
|
|
|
'use strict'; |
|
214
|
|
|
|
|
215
|
|
|
trackMarker('project'); |
|
216
|
|
|
|
|
217
|
|
|
var mm = theMarkers.getById(id), |
|
218
|
|
|
oldpos = mm.getPosition(); |
|
219
|
|
|
|
|
220
|
|
|
showProjectionDialog( |
|
221
|
|
|
function (data1, data2) { |
|
222
|
|
|
var angle = Conversion.getFloat(data1, 0, 360), |
|
223
|
|
|
dist = Conversion.getFloat(data2, 0, 100000000000), |
|
224
|
|
|
newpos, |
|
225
|
|
|
newmarker; |
|
226
|
|
|
|
|
227
|
|
|
if (angle === null) { |
|
228
|
|
|
showAlert( |
|
229
|
|
|
mytrans("dialog.error"), |
|
230
|
|
|
mytrans("dialog.projection.error_bad_bearing").replace(/%1/, data1) |
|
231
|
|
|
); |
|
232
|
|
|
return; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
if (dist === null) { |
|
236
|
|
|
showAlert( |
|
237
|
|
|
mytrans("dialog.error"), |
|
238
|
|
|
mytrans("dialog.projection.error_bad_distance").replace(/%1/, data2) |
|
239
|
|
|
); |
|
240
|
|
|
return; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
newpos = Coordinates.projection_geodesic(oldpos, angle, dist); |
|
244
|
|
|
newmarker = newMarker(newpos, -1, RADIUS_DEFAULT, null); |
|
245
|
|
|
if (newmarker) { |
|
246
|
|
|
showAlert( |
|
247
|
|
|
mytrans("dialog.information"), |
|
248
|
|
|
mytrans("dialog.projection.msg_new_marker").replace(/%1/, newmarker.getAlpha()) |
|
249
|
|
|
); |
|
250
|
|
|
} |
|
251
|
|
|
} |
|
252
|
|
|
); |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
|
|
256
|
|
|
function storeCenter() { |
|
257
|
|
|
'use strict'; |
|
258
|
|
|
|
|
259
|
|
|
var c = map.getCenter(); |
|
260
|
|
|
Cookies.set('clat', c.lat(), {expires: 30}); |
|
261
|
|
|
Cookies.set('clon', c.lng(), {expires: 30}); |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
|
|
265
|
|
|
function storeZoom() { |
|
266
|
|
|
'use strict'; |
|
267
|
|
|
|
|
268
|
|
|
Cookies.set('zoom', map.getZoom(), {expires: 30}); |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
|
|
272
|
|
|
function getFeaturesString() { |
|
273
|
|
|
'use strict'; |
|
274
|
|
|
|
|
275
|
|
|
var s = ""; |
|
276
|
|
|
//if ($('#boundaries').is(':checked')) { s += "b"; } |
|
277
|
|
|
if ($('#geocaches').is(':checked')) { s += "g"; } |
|
278
|
|
|
if ($('#hillshading').is(':checked')) { s += "h"; } |
|
279
|
|
|
if ($('#npa').is(':checked')) { s += "n"; } |
|
280
|
|
|
if ($('#freifunk').is(':checked')) { s += "f"; } |
|
281
|
|
|
|
|
282
|
|
|
return s; |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
|
|
286
|
|
|
function getPermalink() { |
|
287
|
|
|
'use strict'; |
|
288
|
|
|
|
|
289
|
|
|
var lat = map.getCenter().lat(), |
|
290
|
|
|
lng = map.getCenter().lng(); |
|
291
|
|
|
|
|
292
|
|
|
return "http://flopp.net/" + |
|
293
|
|
|
"?c=" + lat.toFixed(6) + ":" + lng.toFixed(6) + |
|
294
|
|
|
"&z=" + map.getZoom() + |
|
295
|
|
|
"&t=" + map.getMapTypeId() + |
|
296
|
|
|
"&f=" + getFeaturesString() + |
|
297
|
|
|
"&m=" + theMarkers.toString() + |
|
298
|
|
|
"&d=" + Lines.getLinesText(); |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
function generatePermalink() { |
|
302
|
|
|
'use strict'; |
|
303
|
|
|
|
|
304
|
|
|
var link = getPermalink(); |
|
305
|
|
|
showLinkDialog(link); |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
|
|
309
|
|
|
function updateCopyrights() { |
|
310
|
|
|
'use strict'; |
|
311
|
|
|
|
|
312
|
|
|
var newMapType = map.getMapTypeId(), |
|
313
|
|
|
isGoogleMap = true, |
|
314
|
|
|
copyright = ""; |
|
315
|
|
|
|
|
316
|
|
|
Cookies.set('maptype', newMapType, {expires: 30}); |
|
317
|
|
|
|
|
318
|
|
|
if (newMapType === "OSM" || newMapType === "OSM/DE") { |
|
319
|
|
|
isGoogleMap = false; |
|
320
|
|
|
copyright = "Map data (C) by <a href=\"http://www.openstreetmap.org/\">OpenStreetMap.org</a> and its contributors; <a href=\"http://opendatacommons.org/licenses/odbl/\">Open Database License</a>"; |
|
321
|
|
|
} else if (newMapType === "OCM") { |
|
322
|
|
|
isGoogleMap = false; |
|
323
|
|
|
copyright = "Map data (C) by <a href=\"http://www.openstreetmap.org/\">OpenStreetMap.org</a> and its contributors; <a href=\"http://opendatacommons.org/licenses/odbl/\">Open Database License</a>, tiles (C) by <a href=\"http://opencyclemap.org\">OpenCycleMap.org</a>"; |
|
324
|
|
|
} else if (newMapType === "OUTD") { |
|
325
|
|
|
isGoogleMap = false; |
|
326
|
|
|
copyright = "Map data (C) by <a href=\"http://www.openstreetmap.org/\">OpenStreetMap.org</a> and its contributors; <a href=\"http://opendatacommons.org/licenses/odbl/\">Open Database License</a>, tiles (C) by <a href=\"http://www.thunderforest.com/outdoors/\">Thunderforest</a>"; |
|
327
|
|
|
} else if (newMapType === "TOPO") { |
|
328
|
|
|
isGoogleMap = false; |
|
329
|
|
|
copyright = "Map data (C) by <a href=\"http://www.openstreetmap.org/\">OpenStreetMap.org</a> and its contributors; <a href=\"http://opendatacommons.org/licenses/odbl/\">Open Database License</a>, height data by SRTM, tiles (C) by <a href=\"http://www.opentopomap.org/\">OpenTopoMap</a>"; |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
if (copyrightDiv) { |
|
333
|
|
|
copyrightDiv.innerHTML = copyright; |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
if (isGoogleMap) { |
|
337
|
|
|
$(".gmnoprint a, .gmnoprint span, .gm-style-cc").css("display", "block"); |
|
338
|
|
|
$("a[href*='maps.google.com/maps']").show(); |
|
339
|
|
|
map.setOptions({streetViewControl: true}); |
|
340
|
|
|
} else { |
|
341
|
|
|
// hide logo for non-g-maps |
|
342
|
|
|
$("a[href*='maps.google.com/maps']").hide(); |
|
343
|
|
|
// hide term-of-use for non-g-maps |
|
344
|
|
|
$(".gmnoprint a, .gmnoprint span, .gm-style-cc").css("display", "none"); |
|
345
|
|
|
map.setOptions({streetViewControl: false}); |
|
346
|
|
|
} |
|
347
|
|
|
} |
|
348
|
|
|
|
|
349
|
|
|
|
|
350
|
|
|
function repairLat(x, d) { |
|
351
|
|
|
'use strict'; |
|
352
|
|
|
|
|
353
|
|
|
if (x === null || isNaN(x) || x < -90 || x > +90) { |
|
354
|
|
|
return d; |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
return x; |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
|
|
361
|
|
|
function repairLon(x, d) { |
|
362
|
|
|
'use strict'; |
|
363
|
|
|
|
|
364
|
|
|
if (x === null || isNaN(x) || x < -180 || x > +180) { |
|
365
|
|
|
return d; |
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
return x; |
|
369
|
|
|
} |
|
370
|
|
|
|
|
371
|
|
|
|
|
372
|
|
|
function repairRadius(x, d) { |
|
373
|
|
|
'use strict'; |
|
374
|
|
|
|
|
375
|
|
|
if (x === null || isNaN(x) || x < 0 || x > 100000000) { |
|
376
|
|
|
return d; |
|
377
|
|
|
} |
|
378
|
|
|
|
|
379
|
|
|
return x; |
|
380
|
|
|
} |
|
381
|
|
|
|
|
382
|
|
|
|
|
383
|
|
|
function repairZoom(x, d) { |
|
384
|
|
|
'use strict'; |
|
385
|
|
|
|
|
386
|
|
|
if (x === null || isNaN(x) || x < 1 || x > 20) { |
|
387
|
|
|
return d; |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
|
|
return x; |
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
|
|
|
|
394
|
|
|
function repairMaptype(t, d) { |
|
395
|
|
|
'use strict'; |
|
396
|
|
|
|
|
397
|
|
|
if (t === "OSM" || t === "OSM/DE" || t === "OCM" || t === "OUTD" || t === "TOPO" || |
|
398
|
|
|
t === "satellite" || t === "hybrid" || t === "roadmap" || t === "terrain") { |
|
399
|
|
|
return t; |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
|
|
return d; |
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
|
|
|
|
406
|
|
|
function parseMarkersFromUrl(urlarg) { |
|
407
|
|
|
'use strict'; |
|
408
|
|
|
|
|
409
|
|
|
var markers = [], |
|
410
|
|
|
data; |
|
411
|
|
|
|
|
412
|
|
|
// ID:COODRS:R(:NAME)?|ID:COORDS:R(:NAME)? |
|
413
|
|
|
// COORDS=LAT:LON or DEG or DMMM |
|
414
|
|
|
if (urlarg.indexOf("*") >= 0) { |
|
415
|
|
|
data = urlarg.split('*'); |
|
416
|
|
|
} else { |
|
417
|
|
|
/* sep is '|' */ |
|
418
|
|
|
data = urlarg.split('|'); |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
data.map(function (dataitem) { |
|
422
|
|
|
dataitem = dataitem.split(':'); |
|
423
|
|
|
if (dataitem.length < 3 || dataitem.length > 5) { |
|
424
|
|
|
return; |
|
425
|
|
|
} |
|
426
|
|
|
|
|
427
|
|
|
var m = { |
|
428
|
|
|
alpha: dataitem[0], |
|
429
|
|
|
id: alpha2id(dataitem[0]), |
|
430
|
|
|
name: null, |
|
431
|
|
|
coords: null, |
|
432
|
|
|
r: 0 |
|
433
|
|
|
}, |
|
434
|
|
|
index = 1, |
|
435
|
|
|
lat, |
|
436
|
|
|
lon; |
|
437
|
|
|
|
|
438
|
|
|
if (m.id < 0) { |
|
439
|
|
|
return; |
|
440
|
|
|
} |
|
441
|
|
|
|
|
442
|
|
|
lat = parseFloat(dataitem[index]); |
|
443
|
|
|
lon = parseFloat(dataitem[index + 1]); |
|
444
|
|
|
if (lat !== null && -90 <= lat && lat <= 90 && |
|
445
|
|
|
lon !== null && -180 <= lon && lon <= 180) { |
|
446
|
|
|
index += 2; |
|
447
|
|
|
m.coords = new google.maps.LatLng(lat, lon); |
|
448
|
|
|
} else { |
|
449
|
|
|
m.coords = Coordinates.fromString(dataitem[index]); |
|
450
|
|
|
index += 1; |
|
451
|
|
|
} |
|
452
|
|
|
if (!m.coords) { |
|
453
|
|
|
return; |
|
454
|
|
|
} |
|
455
|
|
|
|
|
456
|
|
|
m.r = parseFloat(dataitem[index]); |
|
457
|
|
|
if (m.r === null || m.r < 0 || m.r > 100000000000) { |
|
458
|
|
|
m.r = 0; |
|
459
|
|
|
} |
|
460
|
|
|
index = index + 1; |
|
461
|
|
|
|
|
462
|
|
|
if (index < dataitem.length) { |
|
463
|
|
|
if (/^([a-zA-Z0-9-_]*)$/.test(dataitem[index])) { |
|
464
|
|
|
m.name = dataitem[index]; |
|
465
|
|
|
} |
|
466
|
|
|
} |
|
467
|
|
|
|
|
468
|
|
|
markers.push(m); |
|
469
|
|
|
}); |
|
470
|
|
|
|
|
471
|
|
|
return markers; |
|
472
|
|
|
} |
|
473
|
|
|
|
|
474
|
|
|
|
|
475
|
|
|
function parseCenterFromUrl(urlarg) { |
|
476
|
|
|
'use strict'; |
|
477
|
|
|
|
|
478
|
|
|
var data = urlarg.split(':'), |
|
479
|
|
|
lat, |
|
480
|
|
|
lon; |
|
481
|
|
|
|
|
482
|
|
|
if (data.length === 1) { |
|
483
|
|
|
return Coordinates.fromString(data[0]); |
|
484
|
|
|
} |
|
485
|
|
|
|
|
486
|
|
|
if (data.length === 2) { |
|
487
|
|
|
lat = parseFloat(data[0]); |
|
488
|
|
|
lon = parseFloat(data[1]); |
|
489
|
|
|
if (lat >= -90 && lat <= 90 && lon >= -180 && lon <= 180) { |
|
490
|
|
|
return new google.maps.LatLng(lat, lon); |
|
491
|
|
|
} |
|
492
|
|
|
} |
|
493
|
|
|
|
|
494
|
|
|
return null; |
|
495
|
|
|
} |
|
496
|
|
|
|
|
497
|
|
|
|
|
498
|
|
|
function initialize(xcenter, xzoom, xmap, xfeatures, xmarkers, xlines, xgeocache) { |
|
499
|
|
|
'use strict'; |
|
500
|
|
|
|
|
501
|
|
|
var center = null; |
|
|
|
|
|
|
502
|
|
|
var atDefaultCenter = false; |
|
|
|
|
|
|
503
|
|
|
var zoom = parseInt(xzoom, 10); |
|
504
|
|
|
var maptype = xmap; |
|
505
|
|
|
|
|
506
|
|
|
// parse markers |
|
507
|
|
|
var markerdata = parseMarkersFromUrl(xmarkers); |
|
508
|
|
|
var markercenter = null; |
|
509
|
|
|
var clat = 0; |
|
510
|
|
|
var clon = 0; |
|
511
|
|
|
if (markerdata.length > 0) { |
|
512
|
|
|
markerdata.map(function (m) { |
|
513
|
|
|
clat += m.coords.lat(); |
|
514
|
|
|
clon += m.coords.lng(); |
|
515
|
|
|
}); |
|
516
|
|
|
markercenter = new google.maps.LatLng(clat / markerdata.length, clon / markerdata.length); |
|
517
|
|
|
} |
|
518
|
|
|
|
|
519
|
|
|
var loadfromcookies = false; |
|
520
|
|
|
if (xcenter && xcenter !== '') { |
|
521
|
|
|
center = parseCenterFromUrl(xcenter); |
|
522
|
|
|
} else if (markercenter) { |
|
523
|
|
|
center = markercenter; |
|
524
|
|
|
} else { |
|
525
|
|
|
loadfromcookies = true; |
|
526
|
|
|
|
|
527
|
|
|
/* try to read coordinats from cookie */ |
|
528
|
|
|
clat = get_cookie_float('clat', CLAT_DEFAULT); |
|
529
|
|
|
clon = get_cookie_float('clon', CLON_DEFAULT); |
|
530
|
|
|
if (clat == CLAT_DEFAULT && clon == CLON_DEFAULT) { |
|
531
|
|
|
atDefaultCenter = true; |
|
|
|
|
|
|
532
|
|
|
} |
|
533
|
|
|
|
|
534
|
|
|
clat = repairLat(clat, CLAT_DEFAULT); |
|
535
|
|
|
clon = repairLon(clon, CLON_DEFAULT); |
|
536
|
|
|
center = new google.maps.LatLng(clat, clon); |
|
537
|
|
|
|
|
538
|
|
|
zoom = get_cookie_int('zoom', ZOOM_DEFAULT); |
|
539
|
|
|
maptype = get_cookie_string('maptype', MAPTYPE_DEFAULT); |
|
540
|
|
|
} |
|
541
|
|
|
|
|
542
|
|
|
if (!center) { |
|
543
|
|
|
center = new google.maps.LatLng(CLAT_DEFAULT, CLON_DEFAULT); |
|
544
|
|
|
atDefaultCenter = true; |
|
545
|
|
|
} |
|
546
|
|
|
|
|
547
|
|
|
zoom = repairZoom(zoom, ZOOM_DEFAULT); |
|
548
|
|
|
maptype = repairMaptype(maptype, MAPTYPE_DEFAULT); |
|
549
|
|
|
|
|
550
|
|
|
var myOptions = { |
|
551
|
|
|
zoom: zoom, |
|
552
|
|
|
center: center, |
|
553
|
|
|
scaleControl: true, |
|
554
|
|
|
streetViewControl: false, |
|
555
|
|
|
mapTypeControlOptions: { mapTypeIds: ['OSM', 'OSM/DE', 'OCM', 'OUTD', 'TOPO', google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.TERRAIN] }, |
|
556
|
|
|
mapTypeId: google.maps.MapTypeId.ROADMAP }; |
|
557
|
|
|
|
|
558
|
|
|
map = new google.maps.Map(document.getElementById("themap"), myOptions); |
|
559
|
|
|
|
|
560
|
|
|
map.mapTypes.set("OSM", osmProvider("OSM")); |
|
561
|
|
|
map.mapTypes.set("OSM/DE", osmDeProvider("OSM/DE")); |
|
562
|
|
|
map.mapTypes.set("OCM", ocmProvider("OCM")); |
|
563
|
|
|
map.mapTypes.set("OUTD", thunderforestOutdoorsProvider("OUTD")); |
|
564
|
|
|
map.mapTypes.set("TOPO", opentopomapProvider("TOPO")); |
|
565
|
|
|
map.setMapTypeId(maptype); |
|
566
|
|
|
|
|
567
|
|
|
Sidebar.init(map); |
|
|
|
|
|
|
568
|
|
|
ExternalLinks.init(map); |
|
|
|
|
|
|
569
|
|
|
Lines.init(map); |
|
570
|
|
|
Geolocation.init(map); |
|
|
|
|
|
|
571
|
|
|
Hillshading.init(map); |
|
|
|
|
|
|
572
|
|
|
NPA.init(map); |
|
|
|
|
|
|
573
|
|
|
CDDA.init(map); |
|
|
|
|
|
|
574
|
|
|
Freifunk.init(map); |
|
|
|
|
|
|
575
|
|
|
|
|
576
|
|
|
//boundariesLayer = new google.maps.ImageMapType({ |
|
577
|
|
|
// getTileUrl: function(coord, zoom) { |
|
578
|
|
|
// if (6 <= zoom && zoom <= 16) |
|
579
|
|
|
// { |
|
580
|
|
|
// return tileUrl("http://korona.geog.uni-heidelberg.de/tiles/adminb/?x=%x&y=%y&z=%z", ["dummy"], coord, zoom); |
|
581
|
|
|
// } |
|
582
|
|
|
// else |
|
583
|
|
|
// { |
|
584
|
|
|
// return null; |
|
585
|
|
|
// } |
|
586
|
|
|
// }, |
|
587
|
|
|
// tileSize: new google.maps.Size(256, 256), |
|
588
|
|
|
// name: "adminb", |
|
589
|
|
|
// alt: "Administrative Boundaries", |
|
590
|
|
|
// maxZoom: 16 }); |
|
591
|
|
|
|
|
592
|
|
|
// Create div for showing copyrights. |
|
593
|
|
|
copyrightDiv = document.createElement("div"); |
|
594
|
|
|
copyrightDiv.id = "map-copyright"; |
|
595
|
|
|
copyrightDiv.style.fontSize = "11px"; |
|
596
|
|
|
copyrightDiv.style.fontFamily = "Arial, sans-serif"; |
|
597
|
|
|
copyrightDiv.style.margin = "0 2px 2px 0"; |
|
598
|
|
|
copyrightDiv.style.whiteSpace = "nowrap"; |
|
599
|
|
|
copyrightDiv.style.background = "#FFFFFF"; |
|
600
|
|
|
map.controls[google.maps.ControlPosition.BOTTOM_RIGHT].push(copyrightDiv); |
|
601
|
|
|
|
|
602
|
|
|
map.setCenter(center, zoom); |
|
603
|
|
|
|
|
604
|
|
|
google.maps.event.addListener(map, "center_changed", function() { storeZoom(); storeCenter(); okapi_schedule_load_caches(); }); |
|
605
|
|
|
google.maps.event.addListener(map, "zoom_changed", function() { storeZoom(); storeCenter(); okapi_schedule_load_caches(); }); |
|
606
|
|
|
google.maps.event.addListener(map, "maptypeid_changed", function(){ updateCopyrights()}); |
|
607
|
|
|
|
|
608
|
|
|
if (loadfromcookies) { |
|
609
|
|
|
var raw_ids = Cookies.get('markers'); |
|
610
|
|
|
if (raw_ids != undefined) { |
|
611
|
|
|
var ids = raw_ids.split(':'); |
|
612
|
|
|
for (var i = 0; i != ids.length; ++i) { |
|
613
|
|
|
var id = parseInt(ids[i], 10); |
|
614
|
|
|
if (id === null || id < 0 || id >= 26*10) continue; |
|
|
|
|
|
|
615
|
|
|
|
|
616
|
|
|
var raw_data = Cookies.get('marker' + id); |
|
617
|
|
|
if (raw_data == undefined) continue; |
|
|
|
|
|
|
618
|
|
|
|
|
619
|
|
|
var data = raw_data.split(':') |
|
620
|
|
|
if (data.length != 3 && data.length != 4) continue; |
|
|
|
|
|
|
621
|
|
|
|
|
622
|
|
|
var lat = parseFloat(data[0]); |
|
623
|
|
|
if (lat < -90 || lat > 90) continue; |
|
|
|
|
|
|
624
|
|
|
var lon = parseFloat(data[1]); |
|
625
|
|
|
if (lon < -180 || lon > 180) continue; |
|
|
|
|
|
|
626
|
|
|
var r = parseFloat(data[2]); |
|
627
|
|
|
if (r < 0 || r > 100000000000) continue; |
|
|
|
|
|
|
628
|
|
|
|
|
629
|
|
|
var name = null; |
|
630
|
|
|
if (data.length == 4) { |
|
631
|
|
|
if (/^([a-zA-Z0-9-_]*)$/.test(data[3])) { |
|
632
|
|
|
name = data[3]; |
|
633
|
|
|
} |
|
634
|
|
|
} |
|
635
|
|
|
|
|
636
|
|
|
newMarker(new google.maps.LatLng(lat, lon), id, r, name); |
|
637
|
|
|
} |
|
638
|
|
|
} |
|
639
|
|
|
|
|
640
|
|
|
var raw_lines = Cookies.get('lines'); |
|
641
|
|
|
if (raw_lines != undefined) { |
|
642
|
|
|
var linesarray = raw_lines.split('*'); |
|
643
|
|
|
for (var i = 0; i < linesarray.length; ++i) { |
|
|
|
|
|
|
644
|
|
|
var line = linesarray[i].split(':'); |
|
645
|
|
|
if (line.length != 2) continue; |
|
|
|
|
|
|
646
|
|
|
|
|
647
|
|
|
var id1 = alpha2id(line[0]); |
|
648
|
|
|
if (id1 != -1 && theMarkers.getById(id1).isFree()) { |
|
649
|
|
|
id1 = -1; |
|
650
|
|
|
} |
|
651
|
|
|
var id2 = alpha2id(line[1]); |
|
652
|
|
|
if (id2 != -1 && theMarkers.getById(id2).isFree()) { |
|
653
|
|
|
id2 = -1; |
|
654
|
|
|
} |
|
655
|
|
|
|
|
656
|
|
|
Lines.newLine(id1, id2); |
|
657
|
|
|
} |
|
658
|
|
|
} |
|
659
|
|
|
} else { |
|
660
|
|
|
for (var i = 0; i < markerdata.length; ++i) { |
|
|
|
|
|
|
661
|
|
|
newMarker(markerdata[i].coords, markerdata[i].id, markerdata[i].r, markerdata[i].name); |
|
662
|
|
|
} |
|
663
|
|
|
|
|
664
|
|
|
var raw_lines = xlines; |
|
|
|
|
|
|
665
|
|
|
if (raw_lines != null) { |
|
666
|
|
|
/* be backwards compatible */ |
|
667
|
|
|
if (raw_lines.length == 3 |
|
668
|
|
|
&& raw_lines[0] >= 'A' && raw_lines[0] <= 'Z' |
|
669
|
|
|
&& raw_lines[1] == '*' |
|
670
|
|
|
&& raw_lines[2] >= 'A' && raw_lines[2] <= 'Z') { |
|
671
|
|
|
raw_lines = raw_lines[0] + ':' + raw_lines[2]; |
|
672
|
|
|
} |
|
673
|
|
|
|
|
674
|
|
|
var linesarray = raw_lines.split('*'); |
|
|
|
|
|
|
675
|
|
|
for (var i = 0; i < linesarray.length; ++i) { |
|
|
|
|
|
|
676
|
|
|
var line = linesarray[i].split(':'); |
|
|
|
|
|
|
677
|
|
|
if (line.length != 2) continue; |
|
|
|
|
|
|
678
|
|
|
|
|
679
|
|
|
var id1 = alpha2id(line[0]); |
|
|
|
|
|
|
680
|
|
|
if (id1 != -1 && theMarkers.getById(id1).isFree()) { |
|
681
|
|
|
id1 = -1; |
|
682
|
|
|
} |
|
683
|
|
|
var id2 = alpha2id(line[1]); |
|
|
|
|
|
|
684
|
|
|
if (id2 != -1 && theMarkers.getById(id2).isFree()) { |
|
685
|
|
|
id2 = -1; |
|
686
|
|
|
} |
|
687
|
|
|
|
|
688
|
|
|
Lines.newLine(id1, id2); |
|
689
|
|
|
} |
|
690
|
|
|
} |
|
691
|
|
|
} |
|
692
|
|
|
|
|
693
|
|
|
okapi_show_cache = xgeocache; |
|
|
|
|
|
|
694
|
|
|
Sidebar.restore(true); |
|
|
|
|
|
|
695
|
|
|
if (xfeatures == '[default]') { |
|
696
|
|
|
Hillshading.restore(false); |
|
|
|
|
|
|
697
|
|
|
//restoreBoundaries(false); |
|
698
|
|
|
restoreGeocaches(false); |
|
699
|
|
|
NPA.toggle(false); |
|
|
|
|
|
|
700
|
|
|
CDDA.toggle(false); |
|
|
|
|
|
|
701
|
|
|
Freifunk.toggle(false); |
|
|
|
|
|
|
702
|
|
|
} else { |
|
703
|
|
|
Hillshading.toggle(xfeatures.indexOf('h') >= 0 || xfeatures.indexOf('H') >= 0); |
|
704
|
|
|
//toggleBoundaries(xfeatures.indexOf('b') >= 0 || xfeatures.indexOf('B') >= 0); |
|
705
|
|
|
okapi_toggle_load_caches(xfeatures.indexOf('g') >= 0 || xfeatures.indexOf('G') >= 0); |
|
706
|
|
|
NPA.toggle(xfeatures.indexOf('n') >= 0 || xfeatures.indexOf('N') >= 0); |
|
707
|
|
|
Freifunk.toggle(xfeatures.indexOf('f') >= 0 || xfeatures.indexOf('F') >= 0); |
|
708
|
|
|
} |
|
709
|
|
|
restoreCoordinatesFormat(0); |
|
710
|
|
|
|
|
711
|
|
|
if (xgeocache != "") { |
|
712
|
|
|
okapi_toggle_load_caches(true); |
|
713
|
|
|
atDefaultCenter = false; |
|
|
|
|
|
|
714
|
|
|
} |
|
715
|
|
|
|
|
716
|
|
|
// update copyrights + gmap-stuff now, once the map is fully loaded, and in 1s - just to be sure! |
|
717
|
|
|
updateCopyrights(); |
|
718
|
|
|
google.maps.event.addListenerOnce(map, 'idle', function(){ updateCopyrights(); }); |
|
719
|
|
|
setTimeout(function(){ updateCopyrights(); }, 1000); |
|
720
|
|
|
|
|
721
|
|
|
//if (atDefaultCenter) { |
|
722
|
|
|
// Geolocation.whereAmI(); |
|
723
|
|
|
//} |
|
724
|
|
|
} |
|
725
|
|
|
|