Mercurial > hg > STI-GWT
comparison war/scripts/sti/STICore.js @ 68:8b58d9bc0bb6 trimmed_data
add functionality for additional tabular data from the description field (work in progress)
author | Sebastian Kruse <skruse@mpiwg-berlin.mpg.de> |
---|---|
date | Thu, 03 Jan 2013 18:43:28 +0100 |
parents | c7df41c5de53 |
children | e6b72868e395 |
comparison
equal
deleted
inserted
replaced
67:5b049141a26e | 68:8b58d9bc0bb6 |
---|---|
338 } | 338 } |
339 | 339 |
340 for (var i = 0; i < elements.length; i++) { | 340 for (var i = 0; i < elements.length; i++) { |
341 | 341 |
342 var placemark = elements[i]; | 342 var placemark = elements[i]; |
343 var name, description, place, timeData, coordinates, timeStamp, timeSpan, g; | 343 var name, description, descriptionData, place, timeData, coordinates, timeStamp, timeSpan, g; |
344 | 344 |
345 try{ | 345 try{ |
346 var nameElement = placemark.getElementsByTagName("name"); | 346 var nameElement = placemark.getElementsByTagName("name"); |
347 if ( (nameElement != null) && (nameElement.length > 0) && (nameElement[0].childNodes.length > 0) ){ | 347 if ( (nameElement != null) && (nameElement.length > 0) && (nameElement[0].childNodes.length > 0) ){ |
348 name = nameElement[0].childNodes[0].nodeValue; | 348 name = nameElement[0].childNodes[0].nodeValue; |
355 } | 355 } |
356 | 356 |
357 try{ | 357 try{ |
358 var descriptionElement = placemark.getElementsByTagName("description"); | 358 var descriptionElement = placemark.getElementsByTagName("description"); |
359 if ( (descriptionElement != null) && (descriptionElement.length > 0) && (descriptionElement[0].childNodes.length > 0) ){ | 359 if ( (descriptionElement != null) && (descriptionElement.length > 0) && (descriptionElement[0].childNodes.length > 0) ){ |
360 description = descriptionElement[0].childNodes[0].nodeValue; | 360 |
361 description = $(descriptionElement).text(); | |
362 | |
363 //check whether the description element contains a table | |
364 //if yes, this data will be loaded as separate columns | |
365 try{ | |
366 //cleanWhitespace removes non-sense text-nodes (space, tab) | |
367 //and is an addition to jquery defined in Sti.html | |
368 var descriptionDocument = $($.parseXML(description)).cleanWhitespace(); | |
369 | |
370 descriptionData = new Object(); | |
371 | |
372 $(descriptionDocument).find("tr").each( | |
373 function() { | |
374 var isHeader = true; | |
375 var lastHeader = ""; | |
376 | |
377 $(this).find("td").each( | |
378 function() { | |
379 if (isHeader) { | |
380 lastHeader = $(this).text(); | |
381 isHeader = false; | |
382 } else { | |
383 var value = $(this).text(); | |
384 descriptionData[lastHeader] = value; | |
385 isHeader = true; | |
386 } | |
387 } | |
388 ) | |
389 } | |
390 ); | |
391 } catch(e) { | |
392 //Description is either no HTML or no table | |
393 alert(e); | |
394 } | |
361 } | 395 } |
362 else { | 396 else { |
363 description = ""; | 397 description = ""; |
364 } | 398 } |
365 } catch(e) { | 399 } catch(e) { |
441 var lonlat = coordinates.split(","); | 475 var lonlat = coordinates.split(","); |
442 if( lonlat[0] == "" || lonlat[1] == "" || isNaN(lonlat[0]) || isNaN(lonlat[1]) ){ | 476 if( lonlat[0] == "" || lonlat[1] == "" || isNaN(lonlat[0]) || isNaN(lonlat[1]) ){ |
443 alert("No valid coordinate information for element " + i + "."); | 477 alert("No valid coordinate information for element " + i + "."); |
444 continue; | 478 continue; |
445 } | 479 } |
446 newObjects.push(new DataObject(name, description, place, timeStamp, timeSpan, g, lonlat[0], lonlat[1])); | 480 newObjects.push(new DataObject(name, description, place, timeStamp, timeSpan, g, lonlat[0], lonlat[1], descriptionData)); |
447 } | 481 } |
448 catch(e){ | 482 catch(e){ |
449 alert("No valid coordinate information for element " + i + "."); | 483 alert("No valid coordinate information for element " + i + "."); |
450 continue; | 484 continue; |
451 } | 485 } |