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 ( 0bfeeb...7b7241 )
by Florian
01:16
created

App.getFeaturesString   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

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