GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 4f9b41...6f45f0 )
by Florian
01:15
created

map.js ➔ parseLinesFromCookies   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 26
rs 8.8571

1 Function

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