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