Ignore:
Timestamp:
Aug 29, 2017, 6:19:00 PM (9 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
0.5, debian/bullseye, debian/jessie, master
Children:
89c510f
Parents:
fc63b30
Message:

First more or less working version of visualising logfiles on the map

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/webapp/webclient/js/GnuBoat.js

    rfc63b30 r008bce9  
    5454{
    5555        if(GnuBoat.private.serverBaseUrl == null){
    56                 GnuBoat.displayMessage("No server set/found");
     56                GnuBoat.displayMessage('<span class="error">No server set/found</span>');
    5757                return;
    5858        }
    … …  
    6767{
    6868        if(GnuBoat.private.serverBaseUrl == null){
    69                 GnuBoat.displayMessage("No server set/found");
     69                GnuBoat.displayMessage('<span class="error">No server set/found</span>');
    7070                return;
    7171        }
    … …  
    7979{
    8080        if(GnuBoat.private.serverBaseUrl == null){
    81                 GnuBoat.displayMessage("No server set/found");
     81                GnuBoat.displayMessage('<span class="error">No server set/found</span>');
    8282                return;
    8383        }
    8484        $("#logfilesForm").empty();
    8585        $.getJSON(GnuBoat.private.serverBaseUrl +"?request=logfiles", function(data){
     86                GnuBoat.private.updateMapModus(data);
    8687                if(!Array.isArray(data) || data.length < 1){
    8788                        $("<p>No Logfiles found!</p>").appendTo("#logfilesForm");
    … …  
    9091                }
    9192                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);
    9596                        return;
    9697                }
    … …  
    108109{
    109110        if(GnuBoat.private.serverBaseUrl == null){
    110                 GnuBoat.displayMessage("No server set/found");
     111                GnuBoat.displayMessage('<span class="error">No server set/found</span>');
    111112                return;
    112113        }
    … …  
    129130{
    130131        if(GnuBoat.private.serverBaseUrl == null){
    131                 displayMessage("No server set/found");
     132                displayMessage('<span class="error">No server set/found</span>');
    132133                return;
    133134        }
    … …  
    142143                success: function(data){
    143144                        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>');
    145146                                $("#mapTileUploadProgress").hide();
    146147                                $("#mapFileInput").show();
    147148                                return;
    148149                        }
    149                         alert("Map upload successfully");
     150                        GnuBoat.displayMessage('<span class="error">Map upload successfully</span>');
    150151                        $("#mapTileUploadProgress").hide();
    151152                        $("#mapFileInput").show();
    … …  
    153154                },
    154155                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>');
    156157                        $("#mapTileUploadProgress").hide();
    157158                        $("#mapFileInput").show();
    … …  
    167168GnuBoat.initialize = function()
    168169{
     170        $("#mapModusSelect").change(function(){ GnuBoat.private.mapModusChanged(); });
    169171        $("#mapTileUploadProgress").hide();
    170172        $("#logfilesReload").click(GnuBoat.logfilesLoad);
    … …  
    242244{
    243245        if(GnuBoat.private.serverBaseUrl == null){
    244                 GnuBoat.displayMessage("No server set/found");
     246                GnuBoat.displayMessage('<span class="error">No server set/found</span>');
    245247                return;
    246248        }
    … …  
    250252        if(GnuBoat.private.timerDisplay == null)
    251253                GnuBoat.private.timerDisplay = setInterval(GnuBoat.displayDataGet, 10000);
    252         GnuBoat.logfilesLoad(); 
     254        GnuBoat.logfilesLoad();
    253255       
    254256        GnuBoat.private.animate();
    … …  
    276278        mapsMetadata: null,
    277279        mapBounds: null,
     280        mapModusLive: true,
    278281        dataMappings: {
    279282                speedthroughwater: {display: true, map: true, mapActive: false, titleLong: "Speed Through Water", titleShort: "STW", unit: "kts"},
    … …  
    302305        displayDataSet: function(data)
    303306        {
     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
    304317                var keysDisplay = [];
    305318                for(var key in GnuBoat.private.dataMappings){
    … …  
    307320                                keysDisplay.push(key);
    308321                }
    309                 if(!Array.isArray(data) && !(data instanceof Object)){
    310                         console.log("No data array returned!");
    311                         console.log(data);
    312                         return;
    313                 }
     322
    314323                if(!("lastvalid" in data)){
    315324                                console.log("No last valid values given!");
    … …  
    333342                }
    334343               
    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"]);
    399352        },
    400353       
    … …  
    578531                return result;
    579532        },
     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        },
    580664};
Note: See TracChangeset for help on using the changeset viewer.