-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathGeoTemConfig.js
483 lines (462 loc) · 12.7 KB
/
GeoTemConfig.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
/*
* GeoTemConfig.js
*
* Copyright (c) 2012, Stefan Jänicke. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
/**
* @class GeoTemConfig
* Global GeoTemCo Configuration File
* @author Stefan Jänicke ([email protected])
* @release 1.0
* @release date: 2012-07-27
* @version date: 2012-07-27
*/
var GeoTemConfig = {
incompleteData : true, // show/hide data with either temporal or spatial metadata
inverseFilter : true, // if inverse filtering is offered
mouseWheelZoom : true, // enable/disable zoom with mouse wheel on map & timeplot
language : 'en', // default language of GeoTemCo
allowFilter : true, // if filtering should be allowed
highlightEvents : true, // if updates after highlight events
selectionEvents : true, // if updates after selection events
//colors for several datasets; rgb1 will be used for selected objects, rgb0 for unselected
colors : [{
r1 : 255,
g1 : 101,
b1 : 0,
r0 : 253,
g0 : 229,
b0 : 205
}, {
r1 : 144,
g1 : 26,
b1 : 255,
r0 : 230,
g0 : 225,
b0 : 255
}, {
r1 : 0,
g1 : 217,
b1 : 0,
r0 : 213,
g0 : 255,
b0 : 213
}, {
r1 : 240,
g1 : 220,
b1 : 0,
r0 : 247,
g0 : 244,
b0 : 197
}]
}
GeoTemConfig.ie = false;
GeoTemConfig.ie8 = false;
GeoTemConfig.independentMapId = 0;
GeoTemConfig.independentTimeId = 0;
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
GeoTemConfig.ie = true;
var ieversion = new Number(RegExp.$1);
if (ieversion == 8) {
GeoTemConfig.ie8 = true;
}
}
GeoTemConfig.getIndependentId = function(target){
if( target == 'map' ){
return ++GeoTemConfig.independentMapId;
}
if( target == 'time' ){
return ++GeoTemConfig.independentTimeId;
}
return 0;
};
GeoTemConfig.setHexColor = function(hex,index,fill){
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
if( fill ){
GeoTemConfig.colors[index].r0 = parseInt(result[1], 16);
GeoTemConfig.colors[index].g0 = parseInt(result[2], 16);
GeoTemConfig.colors[index].b0 = parseInt(result[3], 16);
}
else {
GeoTemConfig.colors[index].r1 = parseInt(result[1], 16);
GeoTemConfig.colors[index].g1 = parseInt(result[2], 16);
GeoTemConfig.colors[index].b1 = parseInt(result[3], 16);
}
}
GeoTemConfig.setRgbColor = function(r,g,b,index,fill){
if( fill ){
GeoTemConfig.colors[index].r0 = r;
GeoTemConfig.colors[index].g0 = g;
GeoTemConfig.colors[index].b0 = b;
}
else {
GeoTemConfig.colors[index].r1 = r;
GeoTemConfig.colors[index].g1 = g;
GeoTemConfig.colors[index].b1 = b;
}
}
GeoTemConfig.configure = function(urlPrefix) {
GeoTemConfig.urlPrefix = urlPrefix;
GeoTemConfig.path = GeoTemConfig.urlPrefix + "images/";
}
GeoTemConfig.applySettings = function(settings) {
$.extend(this, settings);
};
GeoTemConfig.getColor = function(id){
if( GeoTemConfig.colors.length <= id ){
GeoTemConfig.colors.push({
r1 : Math.floor((Math.random()*255)+1),
g1 : Math.floor((Math.random()*255)+1),
b1 : Math.floor((Math.random()*255)+1),
r0 : 230,
g0 : 230,
b0 : 230
});
}
return GeoTemConfig.colors[id];
};
GeoTemConfig.getString = function(field) {
if ( typeof Tooltips[GeoTemConfig.language] == 'undefined') {
GeoTemConfig.language = 'en';
}
return Tooltips[GeoTemConfig.language][field];
}
/**
* returns the actual mouse position
* @param {Event} e the mouseevent
* @return the top and left position on the screen
*/
GeoTemConfig.getMousePosition = function(e) {
if (!e) {
e = window.event;
}
var body = (window.document.compatMode && window.document.compatMode == "CSS1Compat") ? window.document.documentElement : window.document.body;
return {
top : e.pageY ? e.pageY : e.clientY,
left : e.pageX ? e.pageX : e.clientX
};
}
/**
* returns the json object of the file from the given url
* @param {String} url the url of the file to load
* @return json object of given file
*/
GeoTemConfig.getJson = function(url) {
var data;
$.ajax({
url : url,
async : false,
dataType : 'json',
success : function(json) {
data = json;
}
});
return data;
}
GeoTemConfig.mergeObjects = function(set1, set2) {
var inside = [];
var newSet = [];
for (var i = 0; i < set1.length; i++) {
inside.push([]);
newSet.push([]);
for (var j = 0; j < set1[i].length; j++) {
inside[i][set1[i][j].index] = true;
newSet[i].push(set1[i][j]);
}
}
for (var i = 0; i < set2.length; i++) {
for (var j = 0; j < set2[i].length; j++) {
if (!inside[i][set2[i][j].index]) {
newSet[i].push(set2[i][j]);
}
}
}
return newSet;
}
/**
* returns the xml dom object of the file from the given url
* @param {String} url the url of the file to load
* @return xml dom object of given file
*/
GeoTemConfig.getKml = function(url,asyncFunc) {
var data;
var async = false;
if( asyncFunc ){
async = true;
}
$.ajax({
url : url,
async : async,
dataType : 'xml',
success : function(xml) {
if( asyncFunc ){
asyncFunc(xml);
}
else {
data = xml;
}
}
});
if( !async ){
return data;
}
}
/**
* returns a Date and a SimileAjax.DateTime granularity value for a given XML time
* @param {String} xmlTime the XML time as String
* @return JSON object with a Date and a SimileAjax.DateTime granularity
*/
GeoTemConfig.getTimeData = function(xmlTime) {
if (!xmlTime)
return;
var dateData;
try {
var bc = false;
if (xmlTime.startsWith("-")) {
bc = true;
xmlTime = xmlTime.substring(1);
}
var timeSplit = xmlTime.split("T");
var timeData = timeSplit[0].split("-");
for (var i = 0; i < timeData.length; i++) {
parseInt(timeData[i]);
}
if (bc) {
timeData[0] = "-" + timeData[0];
}
if (timeSplit.length == 1) {
dateData = timeData;
} else {
var dayData;
if (timeSplit[1].indexOf("Z") != -1) {
dayData = timeSplit[1].substring(0, timeSplit[1].indexOf("Z") - 1).split(":");
} else {
dayData = timeSplit[1].substring(0, timeSplit[1].indexOf("+") - 1).split(":");
}
for (var i = 0; i < timeData.length; i++) {
parseInt(dayData[i]);
}
dateData = timeData.concat(dayData);
}
} catch (exception) {
return null;
}
var date, granularity;
if (dateData.length == 6) {
granularity = SimileAjax.DateTime.SECOND;
date = new Date(Date.UTC(dateData[0], dateData[1] - 1, dateData[2], dateData[3], dateData[4], dateData[5]));
} else if (dateData.length == 3) {
granularity = SimileAjax.DateTime.DAY;
date = new Date(Date.UTC(dateData[0], dateData[1] - 1, dateData[2]));
} else if (dateData.length == 2) {
granularity = SimileAjax.DateTime.MONTH;
date = new Date(Date.UTC(dateData[0], dateData[1] - 1, 1));
} else if (dateData.length == 1) {
granularity = SimileAjax.DateTime.YEAR;
date = new Date(Date.UTC(dateData[0], 0, 1));
}
if (timeData[0] && timeData[0] < 100) {
date.setFullYear(timeData[0]);
}
return {
date : date,
granularity : granularity
};
}
/**
* converts a JSON array into an array of data objects
* @param {JSON} JSON a JSON array of data items
* @return an array of data objects
*/
GeoTemConfig.loadJson = function(JSON) {
var mapTimeObjects = [];
var runningIndex = 0;
for (var i in JSON ) {
try {
var item = JSON[i];
var index = item.index || item.id || runningIndex++;
var name = item.name || "";
var description = item.description || "";
var tableContent = item.tableContent || [];
var locations = [];
if (item.location instanceof Array) {
for (var j = 0; j < item.location.length; j++) {
var place = item.location[j].place || "unknown";
var lon = item.location[j].lon || "";
var lat = item.location[j].lat || "";
if ((lon == "" || lat == "" || isNaN(lon) || isNaN(lat) ) && !GeoTemConfig.incompleteData) {
throw "e";
}
if( lon == 180 ){
lon = 179.999;
}
if( lon == -180 ){
lon = -179.999;
}
if( lat == 90 ){
lon = 89.999;
}
if( lat == -90 ){
lat = -89.999;
}
locations.push({
longitude : lon,
latitude : lat,
place : place
});
}
} else {
var place = item.place || "unknown";
var lon = item.lon || "";
var lat = item.lat || "";
if ((lon == "" || lat == "" || isNaN(lon) || isNaN(lat) ) && !GeoTemConfig.incompleteData) {
throw "e";
}
locations.push({
longitude : lon,
latitude : lat,
place : place
});
}
var dates = [];
if (item.time instanceof Array) {
for (var j = 0; j < item.time.length; j++) {
var time = GeoTemConfig.getTimeData(item.time[j]);
if (time == null && !GeoTemConfig.incompleteData) {
throw "e";
}
dates.push(time);
}
} else {
var time = GeoTemConfig.getTimeData(item.time);
if (time == null && !GeoTemConfig.incompleteData) {
throw "e";
}
if (time != null) {
dates.push(time);
}
}
var weight = parseInt(item.weight) || 1;
var mapTimeObject = new DataObject(name, description, locations, dates, weight, tableContent);
mapTimeObject.setIndex(index);
mapTimeObjects.push(mapTimeObject);
} catch(e) {
continue;
}
}
return mapTimeObjects;
}
/**
* converts a KML dom into an array of data objects
* @param {XML dom} kml the XML dom for the KML file
* @return an array of data objects
*/
GeoTemConfig.loadKml = function(kml) {
var mapObjects = [];
var elements = kml.getElementsByTagName("Placemark");
if (elements.length == 0) {
return [];
}
var index = 0;
for (var i = 0; i < elements.length; i++) {
var placemark = elements[i];
var name, description, place, granularity, lon, lat, tableContent = [], time = [], location = [];
var weight = 1;
var timeData = false, mapData = false;
try {
name = placemark.getElementsByTagName("name")[0].childNodes[0].nodeValue;
tableContent["name"] = name;
} catch(e) {
name = "";
}
try {
description = placemark.getElementsByTagName("description")[0].childNodes[0].nodeValue;
tableContent["description"] = description;
} catch(e) {
description = "";
}
try {
place = placemark.getElementsByTagName("address")[0].childNodes[0].nodeValue;
tableContent["place"] = place;
} catch(e) {
place = "";
}
try {
var coordinates = placemark.getElementsByTagName("Point")[0].getElementsByTagName("coordinates")[0].childNodes[0].nodeValue;
var lonlat = coordinates.split(",");
lon = lonlat[0];
lat = lonlat[1];
if (lon == "" || lat == "" || isNaN(lon) || isNaN(lat)) {
throw "e";
}
if( lon == 180 ){
lon = 179.999;
}
if( lon == -180 ){
lon = -179.999;
}
if( lat == 90 ){
lon = 89.999;
}
if( lat == -90 ){
lat = -89.999;
}
location.push({
longitude : lon,
latitude : lat,
place : place
});
} catch(e) {
if (!GeoTemConfig.incompleteData) {
continue;
}
}
try {
var tuple = GeoTemConfig.getTimeData(placemark.getElementsByTagName("TimeStamp")[0].getElementsByTagName("when")[0].childNodes[0].nodeValue);
if (tuple != null) {
time.push(tuple);
timeData = true;
} else if (!GeoTemConfig.incompleteData) {
continue;
}
} catch(e) {
try {
throw "e";
var timeSpanTag = placemark.getElementsByTagName("TimeSpan")[0];
var tuple1 = GeoTemConfig.getTimeData(timeSpanTag.getElementsByTagName("begin")[0].childNodes[0].nodeValue);
timeStart = tuple1.d;
granularity = tuple1.g;
var tuple2 = GeoTemConfig.getTimeData(timeSpanTag.getElementsByTagName("end")[0].childNodes[0].nodeValue);
timeEnd = tuple2.d;
if (tuple2.g > granularity) {
granularity = tuple2.g;
}
timeData = true;
} catch(e) {
if (!GeoTemConfig.incompleteData) {
continue;
}
}
}
var object = new DataObject(name, description, location, time, 1, tableContent);
object.setIndex(index);
index++;
mapObjects.push(object);
}
return mapObjects;
};