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 ( fbbbf7...e24f38 )
by Florian
01:12
created

App.initFromPersist   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 27
rs 8.8571

1 Function

Rating   Name   Duplication   Size   Complexity  
A 0 3 1
1
/*jslint
2
*/
3
4
/*global
5
  $, google, Url, Lang, Lines, Markers, Conversion, Coordinates, trackMarker, showAlert,
6
  id2alpha, alpha2id,
7
  showLinkDialog,
8
  osmProvider, osmDeProvider, thunderforestProvider, opentopomapProvider,
9
  Attribution, Sidebar, ExternalLinks, Hillshading, Geolocation, NPA, CDDA, Freifunk, Okapi, Persist,
10
  DownloadGPX, API_KEY_THUNDERFOREST,
11
  restoreCoordinatesFormat,
12
  document
13
*/
14
15
16
var CLAT_DEFAULT = 51.163375;
17
var CLON_DEFAULT = 10.447683;
18
var ZOOM_DEFAULT = 12;
19
var ZOOM_DEFAULT_GEOCACHE = 15;
20
var MAPTYPE_DEFAULT = "OSM";
21
22
23
var App = {};
24
App.m_map = null;
25
26
27
App.init = function () {
28
    'use strict';
29
30
    Persist.init();
31
    Lang.init();
32
33
    if (!App.initFromUrl(Url.getParams())) {
34
        App.initFromPersist();
35
    }
36
};
37
38
39
App.initFromUrl = function (params) {
40
    'use strict';
41
42
    if (params.c === undefined &&
43
            params.z === undefined &&
44
            params.t === undefined &&
45
            params.m === undefined &&
46
            params.d === undefined &&
47
            params.f === undefined &&
48
            params.g === undefined) {
49
        return false;
50
    }
51
52
    var center = Url.parseCenter(params.c),
53
        zoom = this.repairZoom(parseInt(params.z, 10), (params.g === undefined)
54
            ? ZOOM_DEFAULT
55
            : ZOOM_DEFAULT_GEOCACHE),
56
        maptype = this.repairMaptype(params.t, MAPTYPE_DEFAULT),
57
        markerdata = Url.parseMarkers(params.m),
58
        defaultCenter = false,
59
        clat = 0,
60
        clng = 0;
61
62
    if (!center && markerdata.length > 0) {
63
        markerdata.map(function (m) {
64
            clat += m.coords.lat();
65
            clng += m.coords.lng();
66
        });
67
        center = new google.maps.LatLng(clat / markerdata.length, clng / markerdata.length);
68
    }
69
    if (!center) {
70
        center = new google.maps.LatLng(CLAT_DEFAULT, CLON_DEFAULT);
71
        defaultCenter = true;
72
    }
73
74
    App.m_map = this.createMap("themap", center, zoom, maptype);
75
76
    markerdata.map(function (m) {
77
        Markers.newMarker(m.coords, m.id, m.r, m.name, m.color);
78
    });
79
80
    Url.parseLines(params.d).map(function (m) {
81
        Lines.newLine(m.source, m.target);
82
    });
83
84
    App.restore(params.f, params.g);
85
86
    if (defaultCenter && params.g !== undefined) {
87
        Geolocation.whereAmI(false);
88
    }
89
90
    return true;
91
};
92
93
94
App.initFromPersist = function () {
95
    'use strict';
96
97
    var clat = this.repairLat(Persist.getFloat('clat', CLAT_DEFAULT)),
98
        clon = this.repairLon(Persist.getFloat('clon', CLON_DEFAULT)),
99
        defaultCenter = (clat === CLAT_DEFAULT && clon === CLON_DEFAULT),
100
        center = new google.maps.LatLng(clat, clon),
101
        zoom = this.repairZoom(Persist.getInt('zoom', ZOOM_DEFAULT), ZOOM_DEFAULT),
102
        maptype = this.repairMaptype(Persist.getValue('maptype', MAPTYPE_DEFAULT), MAPTYPE_DEFAULT);
103
104
105
    App.m_map = this.createMap("themap", center, zoom, maptype);
106
107
    Persist.parseMarkers().map(function (m) {
108
        Markers.newMarker(m.coords, m.id, m.r, m.name, m.color);
109
    });
110
111
    Persist.parseLines().map(function (m) {
112
        Lines.newLine(m.source, m.target);
113
    });
114
115
    App.restore(undefined);
116
117
    if (defaultCenter) {
118
        Geolocation.whereAmI();
119
    }
120
};
121
122
123
App.restore = function (features, geocache) {
124
    'use strict';
125
126
    if (geocache !== undefined) {
127
        Okapi.setShowCache(geocache);
128
    }
129
130
    Sidebar.restore(true);
131
132
    if (features === undefined) {
133
        Hillshading.restore(false);
134
        Okapi.restore(false);
135
        NPA.toggle(false);
136
        CDDA.toggle(false);
137
        Freifunk.toggle(false);
138
    } else {
139
        features = features.toLowerCase();
140
        Hillshading.toggle(features.indexOf('h') >= 0);
141
        Okapi.toggle(features.indexOf('g') >= 0);
142
        NPA.toggle(features.indexOf('n') >= 0);
143
        Freifunk.toggle(features.indexOf('f') >= 0);
144
    }
145
146
    restoreCoordinatesFormat("DM");
147
148
    if (geocache !== undefined) {
149
        Okapi.toggle(true);
150
    }
151
};
152
153
154
App.storeCenter = function () {
155
    'use strict';
156
157
    var c = App.m_map.getCenter();
158
    Persist.setValue('clat', c.lat());
159
    Persist.setValue('clon', c.lng());
160
};
161
162
163
App.storeZoom = function () {
164
    'use strict';
165
166
    Persist.setValue('zoom', App.m_map.getZoom());
167
};
168
169
170
App.storeMapType = function () {
171
    'use strict';
172
173
    Persist.setValue('maptype', App.m_map.getMapTypeId());
174
};
175
176
177
App.getFeaturesString = function () {
178
    'use strict';
179
180
    var s = "";
181
    if ($('#geocaches').is(':checked')) {
182
        s += "g";
183
    }
184
    if ($('#hillshading').is(':checked')) {
185
        s += "h";
186
    }
187
    if ($('#npa').is(':checked')) {
188
        s += "n";
189
    }
190
    if ($('#freifunk').is(':checked')) {
191
        s += "f";
192
    }
193
194
    return s;
195
};
196
197
198
App.getPermalink = function () {
199
    'use strict';
200
201
    var lat = App.m_map.getCenter().lat(),
202
        lng = App.m_map.getCenter().lng(),
203
        geocache = Okapi.popupCacheCode(),
204
        url = "https://flopp.net/" +
205
                "?c=" + lat.toFixed(6) + ":" + lng.toFixed(6) +
206
                "&z=" + App.m_map.getZoom() +
207
                "&t=" + App.m_map.getMapTypeId() +
208
                "&f=" + this.getFeaturesString() +
209
                "&m=" + Markers.toString() +
210
                "&d=" + Lines.getLinesText();
211
    if (geocache) {
212
        url += "&g=" + geocache;
213
    }
214
    return url;
215
};
216
217
App.generatePermalink = function () {
218
    'use strict';
219
220
    var link = this.getPermalink();
221
    showLinkDialog(link);
222
};
223
224
225
App.repairLat = function (x, d) {
226
    'use strict';
227
228
    if (Coordinates.validLat(x)) {
229
        return x;
230
    }
231
232
    return d;
233
};
234
235
236
App.repairLon = function (x, d) {
237
    'use strict';
238
239
    if (Coordinates.validLng(x)) {
240
        return x;
241
    }
242
243
    return d;
244
};
245
246
247
App.repairRadius = function (x, d) {
248
    'use strict';
249
250
    if (x === null || isNaN(x) || x < 0 || x > 100000000) {
251
        return d;
252
    }
253
254
    return x;
255
};
256
257
258
App.repairZoom = function (x, d) {
259
    'use strict';
260
261
    if (x === undefined || x === null || isNaN(x) || x < 1 || x > 20) {
262
        return d;
263
    }
264
265
    return x;
266
};
267
268
269
App.repairMaptype = function (t, d) {
270
    'use strict';
271
272
    var mapTypes = {
273
        OSM: 1,
274
        "OSM/DE": 1,
275
        OCM: 1,
276
        OUTD: 1,
277
        TOPO: 1,
278
        satellite: 1,
279
        hybrid: 1,
280
        roadmap: 1,
281
        terrain: 1
282
    };
283
284
    if (t !== undefined && mapTypes[t]) {
285
        return t;
286
    }
287
288
    return d;
289
};
290
291
292
App.createMap = function (id, center, zoom, maptype) {
293
    'use strict';
294
295
    var m = new google.maps.Map(
296
        document.getElementById(id),
297
        {
298
            zoom: zoom,
299
            center: center,
300
            scaleControl: true,
301
            streetViewControl: false,
302
            mapTypeControlOptions: {
303
                mapTypeIds: ['OSM', 'OSM/DE', 'OCM', 'OUTD', 'TOPO', google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.TERRAIN]
304
            },
305
            mapTypeId: google.maps.MapTypeId.ROADMAP
306
        }
307
    );
308
309
    m.mapTypes.set("OSM", osmProvider("OSM"));
310
    m.mapTypes.set("OSM/DE", osmDeProvider("OSM/DE"));
311
    m.mapTypes.set("OCM", thunderforestProvider("OCM", "cycle", API_KEY_THUNDERFOREST));
312
    m.mapTypes.set("OUTD", thunderforestProvider("OUTD", "outdoors", API_KEY_THUNDERFOREST));
313
    m.mapTypes.set("TOPO", opentopomapProvider("TOPO"));
314
    m.setMapTypeId(maptype);
315
316
    Attribution.init(m);
317
    Sidebar.init(m);
318
    ExternalLinks.init(m);
319
    Markers.init(m);
320
    Lines.init(m);
321
    Geolocation.init(m);
322
    Hillshading.init(m);
323
    NPA.init(m);
324
    CDDA.init(m);
325
    Freifunk.init(m);
326
    Okapi.init(m);
327
    DownloadGPX.init(m);
328
329
    google.maps.event.addListener(m, "center_changed", function () {
330
        App.storeZoom();
331
        App.storeCenter();
332
    });
333
    google.maps.event.addListener(m, "zoom_changed", function () {
334
        App.storeZoom();
335
        App.storeCenter();
336
    });
337
    google.maps.event.addListener(m, "maptypeid_changed", function () {
338
        App.storeMapType();
339
    });
340
341
    Attribution.forceUpdate();
342
343
    return m;
344
};
345
346
347
$(document).ready(function () {
348
    'use strict';
349
    App.init();
350
});
351