Completed
Push — master ( 267db7...73d37d )
by Yannick
32:15
created

map.common.js ➔ terrainType   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
c 2
b 0
f 0
nc 5
dl 0
loc 17
rs 8.8571
nop 1
1
function getCookie(cname) {
2
    var name = cname + "=";
3
    var ca = document.cookie.split(';');
4
    for(var i=0; i<ca.length; i++) {
5
	var c = ca[i];
6
	while (c.charAt(0)==' ') c = c.substring(1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7
	if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8
    }
9
    return "";
10
}
11
12
function delCookie(cname) {
13
    document.cookie = cname + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';
14
}
15
16
function createCookie(name, value, days) {
17
    var date, expires;
18
    if (days) {
19
	date = new Date();
20
	date.setTime(date.getTime()+(days*24*60*60*1000));
21
	expires = "; expires="+date.toGMTString();
22
    } else {
23
	expires = "";
24
    }
25
    document.cookie = name+"="+value+expires+"; path=/";
26
}
27
28
function mapType(selectObj) {
29
    var idx = selectObj.selectedIndex;
30
    var atype = selectObj.options[idx].value;
31
    var type = atype.split('-');
32
    if (type[0] == 'Mapbox') {
33
	createCookie('MapType',type[0],9999);
34
	createCookie('MapTypeId',type[1],9999);
35
	if (getCookie('Map2D3DSync')) {
36
	    createCookie('MapType3D',type[0],9999);
37
	    createCookie('MapType3DId',type[1],9999);
38
	}
39
    } else {
40
	createCookie('MapType',atype,9999);
41
	if (getCookie('Map2D3DSync')) {
42
	    createCookie('MapType3D',atype,9999);
43
	}
44
    }
45
    window.location.reload();
46
}
47
function mapType3D(selectObj) {
48
    var idx = selectObj.selectedIndex;
49
    var atype = selectObj.options[idx].value;
50
    var type = atype.split('-');
51
    if (type[0] == 'Mapbox') {
52
	createCookie('MapType3D',type[0],9999);
53
	createCookie('MapType3DId',type[1],9999);
54
	if (getCookie('Map2D3DSync')) {
55
	    createCookie('MapType',type[0],9999);
56
	    createCookie('MapTypeId',type[1],9999);
57
	}
58
    } else {
59
	createCookie('MapType3D',atype,9999);
60
	if (getCookie('Map2D3DSync')) {
61
	    createCookie('MapType',atype,9999);
62
	}
63
    }
64
    window.location.reload();
65
}
66
function clickSyncMap2D3D(cb) {
67
    createCookie('Map2D3DSync',cb.checked,9999);
68
    if (cb.checked) {
69
	createCookie('MapType3D',getCookie('MapType'),9999);
70
	createCookie('MapType3DId',getCookie('MapTypeId'),9999);
71
    }
72
}
73
74
function terrainType(selectObj) {
75
    var idx = selectObj.selectedIndex;
76
    var atype = selectObj.options[idx].value;
77
    var type = atype.split('-');
78
    document.cookie =  'MapTerrain='+type+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
79
    createCookie('MapTerrain',type,9999);
80
    if (type == 'stk') {
81
	stkterrain();
82
    } else if (type == 'articdem') {
83
	articterrain();
84
    } else if (type == 'ellipsoid') {
85
	ellipsoidterrain();
86
    } else if (type == 'vrterrain') {
87
	vrtheworldterrain();
88
    }
89
    //window.location.reload();
90
}
91
92
function sattypes(selectObj) {
93
    var sattypes = [], sattype;
94
    for (var i=0, len=selectObj.options.length; i< len;i++) {
95
	sattype = selectObj.options[i];
96
	if (sattype.selected) {
97
	    sattypes.push(sattype.value);
98
	}
99
    }
100
    createCookie('sattypes',sattypes.join(),2);
101
    updateSat();
102
}
103
function airlines(selectObj) {
104
    var airs = [], air;
105
    for (var i=0, len=selectObj.options.length; i< len;i++) {
106
	air = selectObj.options[i];
107
	if (air.selected) {
108
	    airs.push(air.value);
109
	}
110
    }
111
    createCookie('filter_Airlines',airs.join(),2);
112
}
113
function airlinestype(selectObj) {
114
    var idx = selectObj.selectedIndex;
115
    var airtype = selectObj.options[idx].value;
116
    createCookie('filter_airlinestype',airtype,2);
117
}
118
function alliance(selectObj) {
119
    var idx = selectObj.selectedIndex;
120
    var alliance = selectObj.options[idx].value;
121
    createCookie('filter_alliance',alliance,2);
122
}
123
function identfilter() {
124
    var ident = $("#identfilter").value;
125
    createCookie('filter_ident',ident,2);
126
}
127
function mmsifilter() {
128
    var ident = $("#mmsifilter").value;
129
    createCookie('filter_mmsi',ident,2);
130
}
131
function removefilters() {
132
    // Get an array of all cookie names (the regex matches what we don't want)
133
    var cookieNames = document.cookie.split(/=[^;]*(?:;\s*|$)/);
134
    // Remove any that match the pattern
135
    for (var i = 0; i < cookieNames.length; i++) {
136
	if (/^filter_/.test(cookieNames[i])) {
137
	    delCookie(cookieNames[i]);
138
	}
139
    }
140
    window.location.reload();
141
}
142
function sources(selectObj) {
143
    var sources = [], source;
144
    for (var i=0, len=selectObj.options.length; i< len;i++) {
145
	source = selectObj.options[i];
146
	if (source.selected) {
147
	    sources.push(source.value);
148
	}
149
    }
150
    createCookie('filter_Sources',sources.join(),2);
151
}
152
153
154
function show2D() {
155
    createCookie('MapFormat','2d',10);
156
    if (document.getElementById("pointtype").className == 'tracker') {
157
	createCookie('MapTrackTracker',document.getElementById("pointident").className,1);
158
    } else if (document.getElementById("pointtype").className == 'marine') {
159
	createCookie('MapTrackMarine',document.getElementById("pointident").className,1);
160
    } else {
161
	createCookie('MapTrack',document.getElementById("pointident").className,1);
162
    }
163
    window.location.reload();
164
}
165
function show3D() {
166
    createCookie('MapFormat','3d',10);
167
    if (document.getElementById("pointtype").className == 'tracker') {
168
	createCookie('MapTrackTracker',document.getElementById("pointident").className,1);
169
    } else if (document.getElementById("pointtype").className == 'marine') {
170
	createCookie('MapTrackMarine',document.getElementById("pointident").className,1);
171
    } else {
172
	createCookie('MapTrack',document.getElementById("pointident").className,1);
173
    }
174
    window.location.reload();
175
}
176
function clickPolar(cb) {
177
    createCookie('polar',cb.checked,9999);
178
    window.location.reload();
179
}
180
function clickDisplayAirports(cb) {
181
    createCookie('displayairports',cb.checked,9999);
182
    window.location.reload();
183
}
184
function clickDisplayISS(cb) {
185
    createCookie('displayiss',cb.checked,9999);
186
    updateSat();
187
}
188
function clickDisplayMinimap(cb) {
189
    createCookie('displayminimap',cb.checked,9999);
190
    window.location.reload();
191
}
192
function clickShadows(cb) {
193
    createCookie('map3dnoshadows',cb.checked,9999);
194
    window.location.reload();
195
}
196
function clickSingleModel(cb) {
197
    createCookie('singlemodel',cb.checked,9999);
198
}
199
function clickUpdateRealtime(cb) {
200
    createCookie('updaterealtime',cb.checked,9999);
201
}
202
function clickVATSIM(cb) {
203
    createCookie('filter_ShowVATSIM',cb.checked,2);
204
}
205
function clickIVAO(cb) {
206
     createCookie('filter_ShowIVAO',cb.checked,2);
207
}
208
function clickphpVMS(cb) {
209
    createCookie('filter_ShowVMS',cb.checked,2);
210
}
211
function clickSBS1(cb) {
212
    createCookie('filter_ShowSBS1',cb.checked,2);
213
}
214
function clickAPRS(cb) {
215
    createCookie('filter_ShowAPRS',cb.checked,2);
216
}
217
function clickDisplayGroundStation(cb) {
218
    createCookie('show_GroundStation',cb.checked,2);
219
    window.location.reload();
220
}
221
function clickDisplayWeatherStation(cb) {
222
    createCookie('show_WeatherStation',cb.checked,2);
223
    window.location.reload();
224
}
225
function clickDisplayWeather(cb) {
226
    createCookie('show_Weather',cb.checked,2);
227
//    window.location.reload();
228
}
229
function clickDisplayLightning(cb) {
230
    createCookie('show_Lightning',cb.checked,2);
231
    window.location.reload();
232
}
233
function clickDisplayFires(cb) {
234
    createCookie('show_Fires',cb.checked,2);
235
    window.location.reload();
236
}
237
function clickDisplay2DBuildings(cb) {
238
    createCookie('Map2DBuildings',cb.checked,2);
239
    window.location.reload();
240
}
241
function unitdistance(selectObj) {
242
    var idx = selectObj.selectedIndex;
243
    var unit = selectObj.options[idx].value;
244
    createCookie('unitdistance',unit,9999);
245
}
246
function unitspeed(selectObj) {
247
    var idx = selectObj.selectedIndex;
248
    var unit = selectObj.options[idx].value;
249
    createCookie('unitspeed',unit,9999);
250
}
251
function unitaltitude(selectObj) {
252
    var idx = selectObj.selectedIndex;
253
    var unit = selectObj.options[idx].value;
254
    createCookie('unitaltitude',unit,9999);
255
}
256
function addarchive(begindate,enddate) {
257
    console.log('Add archive');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
258
    createCookie('archive',true,2);
259
    createCookie('archive_begin',begindate,2);
260
    createCookie('archive_end',enddate,2);
261
    createCookie('archive_speed',document.getElementById("archivespeed").value,2);
262
    window.location.reload();
263
}
264
function noarchive() {
265
    console.log('Exit archive!');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
266
    delCookie('archive');
267
    delCookie('archive_begin');
268
    delCookie('archive_end');
269
    delCookie('archive_speed');
270
    window.location.reload();
271
}
272
function msgbox(text,buttontext) {
273
	buttontext = buttontext || "OK";
274
	$("<div>" + text + "</div>").dialog({
275
	    dialogClass: "no-close",
276
	    buttons: [{
277
		text: buttontext,
278
		click: function() {
279
		    $( this ).dialog( "close" );
280
		    $(this).remove();
281
		}
282
	    }]
283
	});
284
}
285
function generateRandomPoint (latitude,longitude,height,diff,radius) {
286
287
	//console.log('height: '+height+' - diff: '+diff);
288
	radius = Math.random()*radius;
289
	latitude = latitude*(Math.PI/180.0);
290
	longitude = longitude*(Math.PI/180.0);
291
	
292
	const sinLat = 	Math.sin(latitude)
293
	const cosLat = 	Math.cos(latitude)
294
295
	/* go fixed distance in random direction*/
296
	const bearing = Math.random() * Math.PI*2
297
	const theta = radius/6371000
298
	const sinBearing = Math.sin(bearing)
299
	const cosBearing = Math.cos(bearing)
300
	const sinTheta = Math.sin(theta)
301
	const cosTheta = Math.cos(theta)
302
    
303
	latitude = Math.asin(sinLat*cosTheta+cosLat*sinTheta*cosBearing);
304
	longitude = longitude + Math.atan2( sinBearing*sinTheta*cosLat, cosTheta-sinLat*Math.sin(latitude ));
305
	/* normalize -PI -> +PI radians */
306
	longitude = ((longitude+(Math.PI*3))%(Math.PI*2))-Math.PI
307
	var h = height+(Math.random()*diff)
308
	//console.log('h: '+h);
309
	return {
310
	    latitude: latitude/(Math.PI/180.0),
311
	    longitude: longitude/(Math.PI/180.0),
312
	    height: h
313
	};
314
}
315
function getColor(colorStart,colorEnd,colorCount,step) {
316
	var alpha = (1.0/colorCount)*step;
317
	return {
318
	    r: colorStart[0]*alpha+(1-alpha)*colorEnd[0],
319
	    v: colorStart[1]*alpha+(1-alpha)*colorEnd[1],
320
	    b: colorStart[2]*alpha+(1-alpha)*colorEnd[2]
321
	};
322
}