Changeset 008bce9 for src/webapp/webclient/js/GnuBoat.js
- Timestamp:
- Aug 29, 2017, 6:19:00 PM (9 years ago)
- Branches:
- 0.5, debian/bullseye, debian/jessie, master
- Children:
- 89c510f
- Parents:
- fc63b30
- File:
-
- 1 edited
-
src/webapp/webclient/js/GnuBoat.js (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/webapp/webclient/js/GnuBoat.js
rfc63b30 r008bce9 54 54 { 55 55 if(GnuBoat.private.serverBaseUrl == null){ 56 GnuBoat.displayMessage( "No server set/found");56 GnuBoat.displayMessage('<span class="error">No server set/found</span>'); 57 57 return; 58 58 } … … 67 67 { 68 68 if(GnuBoat.private.serverBaseUrl == null){ 69 GnuBoat.displayMessage( "No server set/found");69 GnuBoat.displayMessage('<span class="error">No server set/found</span>'); 70 70 return; 71 71 } … … 79 79 { 80 80 if(GnuBoat.private.serverBaseUrl == null){ 81 GnuBoat.displayMessage( "No server set/found");81 GnuBoat.displayMessage('<span class="error">No server set/found</span>'); 82 82 return; 83 83 } 84 84 $("#logfilesForm").empty(); 85 85 $.getJSON(GnuBoat.private.serverBaseUrl +"?request=logfiles", function(data){ 86 GnuBoat.private.updateMapModus(data); 86 87 if(!Array.isArray(data) || data.length < 1){ 87 88 $("<p>No Logfiles found!</p>").appendTo("#logfilesForm"); … … 90 91 } 91 92 if(("error" in data) && data["error"] == 1){ 92 alert("Failed to upload map: "+ data["errormessage"]);93 $(" #mapTileUploadProgress").hide();94 $("#mapFileInput").show();93 GnuBoat.displayMessage('<span class="error">Failed to get log files: '+ data["errormessage"] +'</span>'); 94 $("<p>No Logfiles found!</p>").appendTo("#logfilesForm"); 95 console.log(data); 95 96 return; 96 97 } … … 108 109 { 109 110 if(GnuBoat.private.serverBaseUrl == null){ 110 GnuBoat.displayMessage( "No server set/found");111 GnuBoat.displayMessage('<span class="error">No server set/found</span>'); 111 112 return; 112 113 } … … 129 130 { 130 131 if(GnuBoat.private.serverBaseUrl == null){ 131 displayMessage( "No server set/found");132 displayMessage('<span class="error">No server set/found</span>'); 132 133 return; 133 134 } … … 142 143 success: function(data){ 143 144 if(("error" in data) && data["error"] == 1){ 144 alert("Failed to upload map: "+ data["errormessage"]);145 GnuBoat.displayMessage('<span class="error">Failed to upload map: '+ data["errormessage"] +'</span>'); 145 146 $("#mapTileUploadProgress").hide(); 146 147 $("#mapFileInput").show(); 147 148 return; 148 149 } 149 alert("Map upload successfully");150 GnuBoat.displayMessage('<span class="error">Map upload successfully</span>'); 150 151 $("#mapTileUploadProgress").hide(); 151 152 $("#mapFileInput").show(); … … 153 154 }, 154 155 error: function(jqXHR, exception, errorThrown){ 155 alert("Failed to upload map (XHR): "+ exception);156 GnuBoat.displayMessage('<span class="error">Failed to upload map (XHR): '+ exception +'</span>'); 156 157 $("#mapTileUploadProgress").hide(); 157 158 $("#mapFileInput").show(); … … 167 168 GnuBoat.initialize = function() 168 169 { 170 $("#mapModusSelect").change(function(){ GnuBoat.private.mapModusChanged(); }); 169 171 $("#mapTileUploadProgress").hide(); 170 172 $("#logfilesReload").click(GnuBoat.logfilesLoad); … … 242 244 { 243 245 if(GnuBoat.private.serverBaseUrl == null){ 244 GnuBoat.displayMessage( "No server set/found");246 GnuBoat.displayMessage('<span class="error">No server set/found</span>'); 245 247 return; 246 248 } … … 250 252 if(GnuBoat.private.timerDisplay == null) 251 253 GnuBoat.private.timerDisplay = setInterval(GnuBoat.displayDataGet, 10000); 252 GnuBoat.logfilesLoad(); 254 GnuBoat.logfilesLoad(); 253 255 254 256 GnuBoat.private.animate(); … … 276 278 mapsMetadata: null, 277 279 mapBounds: null, 280 mapModusLive: true, 278 281 dataMappings: { 279 282 speedthroughwater: {display: true, map: true, mapActive: false, titleLong: "Speed Through Water", titleShort: "STW", unit: "kts"}, … … 302 305 displayDataSet: function(data) 303 306 { 307 // if(!Array.isArray(data) || data.length < 1){ 308 // console.log("No data array returned!"); 309 // console.log(data); 310 // return; 311 // } 312 if(("error" in data) && data["error"] == 1){ 313 GnuBoat.displayMessage('<span class="error">Failed to get display data and tracks: '+ data["errormessage"] +'</span>'); 314 return; 315 } 316 304 317 var keysDisplay = []; 305 318 for(var key in GnuBoat.private.dataMappings){ … … 307 320 keysDisplay.push(key); 308 321 } 309 if(!Array.isArray(data) && !(data instanceof Object)){ 310 console.log("No data array returned!"); 311 console.log(data); 312 return; 313 } 322 314 323 if(!("lastvalid" in data)){ 315 324 console.log("No last valid values given!"); … … 333 342 } 334 343 335 if(!("track" in data)){ 336 console.log("No track given!"); 337 } 338 else{ 339 if(GnuBoat.private.map == null){ 340 console.log("No map in use"); 341 } 342 else{ 343 var track = data["track"]; 344 var maximas = []; 345 var minimas = []; 346 var points = []; 347 var densityPoints = []; 348 349 var keysMap = []; 350 for(var key in GnuBoat.private.dataMappings){ 351 if(GnuBoat.private.dataMappings[key]["map"] === true) 352 keysMap.push(key); 353 } 354 for(var i = 0; i < keysMap.length; i++){ 355 if(keysMap[i] == "gpsfix") 356 continue; 357 points[keysMap[i]] = []; 358 } 359 360 // getting maximas, minimums for normalization and the tracks themselves 361 for(var time in track){ 362 for(var i = 0; i < keysMap.length; i++){ 363 var key = keysMap[i]; 364 if(key == "gpsfix") 365 continue; 366 if(!(key in maximas)) 367 maximas[key] = track[time][key] 368 else if(maximas[key] < track[time][key]) 369 maximas[key] = track[time][key]; 370 if(!(key in minimas)) 371 minimas[key] = track[time][key] 372 else if(minimas[key] > track[time][key]) 373 minimas[key] = track[time][key]; 374 points[key].push(new L.latLng(track[time]["latitude"], track[time]["longitude"], track[time][key])); 375 densityPoints.push({latitude: track[time]["latitude"], longitude: track[time]["longitude"], depth: track[time]["waterdepth"]}); 376 } 377 } 378 for(var i = 0; i < keysMap.length; i++){ 379 var key = keysMap[i]; 380 if(key == "gpsfix") 381 continue; 382 if(points[key].length > 0){ 383 if(key in GnuBoat.private.mapPolylines) 384 GnuBoat.private.mapPolylines[key].setLatLngs(points[key]); 385 else{ 386 GnuBoat.private.mapPolylines[key] = L.hotline(points[key], {weight: 3, outlineWidth: 0, min: minimas[key], max: maximas[key]}); 387 if(GnuBoat.private.mapControl){ 388 var name = GnuBoat.private.dataMappings[key]["titleLong"] +" in "+ GnuBoat.private.dataMappings[key]["unit"] +" ("+ GnuBoat.private.dataMappings[key]["titleShort"] +")"; 389 GnuBoat.private.mapControl.addOverlay(GnuBoat.private.mapPolylines[key], name); 390 } 391 if(GnuBoat.private.dataMappings[key]["mapActive"] === true) 392 GnuBoat.private.mapPolylines[key].addTo(GnuBoat.private.map); 393 } 394 } 395 } 396 GnuBoat.private.drawDensityEstimation(densityPoints, maximas["waterdepth"], minimas["waterdepth"]); 397 } 398 } 344 // map displays logged data 345 if(!GnuBoat.private.mapModusLive) 346 return; 347 else if(!("track" in data)){ 348 console.log("No track given!"); 349 return; 350 } 351 GnuBoat.private.mapAddTracks(data["track"]); 399 352 }, 400 353 … … 578 531 return result; 579 532 }, 533 534 updateMapModus: function(data) 535 { 536 var selected = $("#mapModusSelect").val(); 537 $("#mapModusSelect").empty(); 538 var selectedFound = false; 539 if(selected != null && Array.isArray(data)){ 540 data.forEach(function(value, index){ 541 if(value == selected) 542 selectedFound = true; 543 }); 544 } 545 var selectedString = ""; 546 if(!selectedFound) 547 selectedString = " selected"; 548 $('<option value="live"'+ selectedString +'>Live View</option>').appendTo("#mapModusSelect"); 549 if(!Array.isArray(data) || data.length < 1){ 550 console.log(data); 551 return; 552 } 553 if(("error" in data) && data["error"] == 1){ 554 GnuBoat.displayMessage('<span class="error">Failed to upload map: '+ data["errormessage"] +'</span>'); 555 return; 556 } 557 data.forEach(function(value, index){ 558 var selectedString = ""; 559 if(value == selected) 560 selectedString = " selected"; 561 $("<option value=\""+ value +"\""+ selected +">"+ value +"</option>").appendTo("#mapModusSelect"); 562 }); 563 }, 564 565 mapModusChanged: function() 566 { 567 var modus = $("#mapModusSelect").val(); 568 // live modus is automatically activated on displayDataSet 569 if(modus == "live"){ 570 GnuBoat.private.mapModusLive = true; 571 return; 572 } 573 // remove overlays 574 if(GnuBoat.private.mapControl != null){ 575 for(var key in GnuBoat.private.dataMappings){ 576 if(GnuBoat.private.dataMappings[key]["map"] === true) 577 if(key in GnuBoat.private.mapPolylines){ 578 GnuBoat.private.mapControl.removeLayer(GnuBoat.private.mapPolylines[key]); 579 GnuBoat.private.mapPolylines[key].remove(); 580 delete GnuBoat.private.mapPolylines[key]; 581 } 582 } 583 } 584 GnuBoat.private.mapModusLive = false; 585 $.post({ 586 url: GnuBoat.private.serverBaseUrl +'?request=replay', 587 data: { logfile: modus }, 588 success: function(data){ 589 // if(!Array.isArray(data) || data.length < 1){ 590 // console.log("No data array returned!"); 591 // console.log(data); 592 // return; 593 // } 594 if(("error" in data) && data["error"] == 1){ 595 GnuBoat.displayMessage('<span class="error">Failed to get logged tracks: '+ data["errormessage"] +'</span>'); 596 return; 597 } 598 if(!("track" in data)){ 599 console.log("No track given!"); 600 return; 601 } 602 GnuBoat.private.mapAddTracks(data["track"]); 603 } 604 }); 605 }, 606 607 mapAddTracks: function(track) 608 { 609 if(GnuBoat.private.map == null){ 610 console.log("No map in use"); 611 return; 612 } 613 614 var maximas = []; 615 var minimas = []; 616 var points = []; 617 var densityPoints = []; 618 619 var keysMap = []; 620 for(var key in GnuBoat.private.dataMappings){ 621 if(GnuBoat.private.dataMappings[key]["map"] === true) 622 keysMap.push(key); 623 } 624 for(var i = 0; i < keysMap.length; i++){ 625 points[keysMap[i]] = []; 626 } 627 628 // getting maximas, minimums for normalization and the tracks themselves 629 for(var time in track){ 630 for(var i = 0; i < keysMap.length; i++){ 631 var key = keysMap[i]; 632 if(key == "gpsfix") 633 continue; 634 if(!(key in maximas)) 635 maximas[key] = track[time][key] 636 else if(maximas[key] < track[time][key]) 637 maximas[key] = track[time][key]; 638 if(!(key in minimas)) 639 minimas[key] = track[time][key] 640 else if(minimas[key] > track[time][key]) 641 minimas[key] = track[time][key]; 642 points[key].push(new L.latLng(track[time]["latitude"], track[time]["longitude"], track[time][key])); 643 densityPoints.push({latitude: track[time]["latitude"], longitude: track[time]["longitude"], depth: track[time]["waterdepth"]}); 644 } 645 } 646 for(var i = 0; i < keysMap.length; i++){ 647 var key = keysMap[i]; 648 if(points[key].length > 0){ 649 if(key in GnuBoat.private.mapPolylines) 650 GnuBoat.private.mapPolylines[key].setLatLngs(points[key]); 651 else{ 652 GnuBoat.private.mapPolylines[key] = L.hotline(points[key], {weight: 3, outlineWidth: 0, min: minimas[key], max: maximas[key]}); 653 if(GnuBoat.private.mapControl){ 654 var name = GnuBoat.private.dataMappings[key]["titleLong"] +" in "+ GnuBoat.private.dataMappings[key]["unit"] +" ("+ GnuBoat.private.dataMappings[key]["titleShort"] +")"; 655 GnuBoat.private.mapControl.addOverlay(GnuBoat.private.mapPolylines[key], name); 656 } 657 if(GnuBoat.private.dataMappings[key]["mapActive"] === true) 658 GnuBoat.private.mapPolylines[key].addTo(GnuBoat.private.map); 659 } 660 } 661 } 662 GnuBoat.private.drawDensityEstimation(densityPoints, maximas["waterdepth"], minimas["waterdepth"]); 663 }, 580 664 };
Note:
See TracChangeset
for help on using the changeset viewer.
