Ignore:
Timestamp:
Aug 22, 2017, 6:03:09 PM (9 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
0.5, debian/bullseye, debian/jessie, master
Children:
17bc29b
Parents:
e44e1f1
Message:

Added colored track lines to leaflet map view

Location:
src/webapp/webclient
Files:
2 added
1 edited

Legend:

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

    re44e1f1 rfb91143  
    230230        map: null,
    231231        mapLayerCurrent: null,
    232         // var mapControl = null;
     232        mapPolylines: [],
     233        mapControl: null,
    233234        mapsMetadata: null,
    234         polyline: null,
     235        dataMappings: {
     236                speedthroughwater: {display: true, map: true, mapActive: false, titleLong: "Speed Through Water", titleShort: "STW", unit: "kts"},
     237                speedoverground:  {display: true, map: true, mapActive: false, titleLong: "Speed Over Ground", titleShort: "SOG", unit: "kts"},
     238                waterdepth: {display: true, map: true, mapActive: true, titleLong: "Waterdepth", titleShort: "Depth", unit: "m"},
     239                watertemperature: {display: true, map: true, mapActive: false, titleLong: "Watertemperature", titleShort: "Water", unit: "°C"},
     240                gpsfix: {display: true, map: false, mapActive: false, titleLong: "GPS Fix", titleShort: "Fix", unit: ""},
     241        },
    235242        serverBaseUrl: null,
    236243        timerDisplay: null,
    … …  
    243250        displayDataSet: function(data)
    244251        {
     252                var keysDisplay = [];
     253                for(var key in GnuBoat.private.dataMappings){
     254                        if(GnuBoat.private.dataMappings[key]["display"] === true)
     255                                keysDisplay.push(key);
     256                }
    245257                if(!Array.isArray(data) && !(data instanceof Object)){
    246258                        console.log("No data array returned!");
    247259                        console.log(data);
    248260                        return;
    249                         }
     261                }
    250262                if(!("lastvalid" in data)){
    251263                                console.log("No last valid values given!");
    … …  
    253265                else{
    254266                        var lastValid = data["lastvalid"];
    255                         var keys = ["speedthroughwater", "speedoverground", "waterdepth", "watertemperature", "gpsfix"];
    256                         for(var i = 0; i < keys.length; i++){
    257                                 var key = keys[i];
     267                        for(var i = 0; i < keysDisplay.length; i++){
     268                                var key = keysDisplay[i];
    258269                                var value = lastValid[key];
    259270                                if($.isNumeric(value)){
    … …  
    262273                                                text = value.toFixed(0);
    263274                                        }
    264                                         $("#display #"+ keys[i] +" #value").text(text);
     275                                        $("#display #"+ key +" #value").text(text);
    265276                                }
    266277                                else if(key == "gpsfix"){
    267                                         $("#display #"+ keys[i] +" #value").text(value);
     278                                        $("#display #"+ key +" #value").text(value);
    268279                                }
    269280                        }
    … …  
    279290                        else{
    280291                                var track = data["track"];
     292                                var maximas = [];
     293                                var minimas = [];
    281294                                var points = [];
     295                               
     296                                var keysMap = [];
     297                                for(var key in GnuBoat.private.dataMappings){
     298                                        if(GnuBoat.private.dataMappings[key]["map"] === true)
     299                                                keysMap.push(key);
     300                                }
     301                                for(var i = 0; i < keysMap.length; i++){
     302                                        if(keysMap[i] == "gpsfix")
     303                                                continue;
     304                                        points[keysMap[i]] = [];
     305                                }
     306                               
     307                                // getting maximas, minimums for normalization and the tracks themselves
    282308                                for(var time in track){
    283                                         points.push(new L.latLng(track[time]["latitude"], track[time]["longitude"]));
    284                                 }
    285                                 if(points.length > 0){
    286                                         if(!GnuBoat.private.polyline){
    287                                                 GnuBoat.private.polyline = L.polyline(points, {color: 'red'}).addTo(GnuBoat.private.map);
     309                                        for(var i = 0; i < keysMap.length; i++){
     310                                                var key = keysMap[i];
     311                                                if(key == "gpsfix")
     312                                                        continue;
     313                                                if(!(key in maximas))
     314                                                        maximas[key] = track[time][key]
     315                                                else if(maximas[key] < track[time][key])
     316                                                        maximas[key] = track[time][key];
     317                                                if(!(key in minimas))
     318                                                        minimas[key] = track[time][key]
     319                                                else if(minimas[key] > track[time][key])
     320                                                        minimas[key] = track[time][key];
     321                                                points[key].push(new L.latLng(track[time]["latitude"], track[time]["longitude"], track[time][key]));
    288322                                        }
    289                                         else{
    290                                                 GnuBoat.private.polyline.setLatLngs(points);
     323                                }
     324                                for(var i = 0; i < keysMap.length; i++){
     325                                        var key = keysMap[i];
     326                                        if(key == "gpsfix")
     327                                                continue;
     328                                        if(points[key].length > 0){
     329                                                if(key in GnuBoat.private.mapPolylines){
     330                                                        GnuBoat.private.mapPolylines[key].setLatLngs(points[key]);
     331                                                }
     332                                                else{
     333                                                        GnuBoat.private.mapPolylines[key] = L.hotline(points[key], {weight: 3, outlineWidth: 0, min: minimas[key], max: maximas[key]});
     334                                                        if(GnuBoat.private.mapControl){
     335                                                                var name = GnuBoat.private.dataMappings[key]["titleLong"] +" in "+ GnuBoat.private.dataMappings[key]["unit"] +" ("+ GnuBoat.private.dataMappings[key]["titleShort"] +")";
     336                                                                GnuBoat.private.mapControl.addOverlay(GnuBoat.private.mapPolylines[key], name);
     337                                                        }
     338                                                        if(GnuBoat.private.dataMappings[key]["mapActive"] === true)
     339                                                                GnuBoat.private.mapPolylines[key].addTo(GnuBoat.private.map);
     340                                                }
    291341                                        }
    292                                         GnuBoat.private.map.fitBounds(GnuBoat.private.polyline.getBounds());
    293342                                }
    294343                        }
    … …  
    334383                if(GnuBoat.private.mapLayerCurrent != null){
    335384                        GnuBoat.private.map.removeLayer(GnuBoat.private.mapLayerCurrent);
     385                        if(GnuBoat.private.mapControl)
     386                                GnuBoat.private.mapControl.removeLayer(GnuBoat.private.mapLayerCurrent);
    336387                        GnuBoat.private.mapLayerCurrent = null;
    337388                }
    … …  
    342393                        opacity: 0.85
    343394                        }).addTo(GnuBoat.private.map);
     395                if(GnuBoat.private.mapControl)
     396                        GnuBoat.private.mapControl.addBaseLayer(GnuBoat.private.mapLayerCurrent, "Map");
     397                else{
     398                        GnuBoat.private.mapControl = L.control.layers({"Map": GnuBoat.private.mapLayerCurrent}, GnuBoat.private.mapOverlaysToList(), {hideSingleBase: true, sortLayers: true, }).addTo(GnuBoat.private.map);
     399                }
    344400        },
    345401       
    … …  
    358414                $("#mapSelect").change(function(){ mapSetup(); });
    359415        },
    360 };
     416       
     417        mapOverlaysToList: function()
     418        {
     419                var overlays = {};
     420                for(var key in GnuBoat.private.mapPolylines){
     421                        overlays[key] = GnuBoat.private.mapPolylines[key];
     422                }
     423                return overlays;
     424        },
     425};
Note: See TracChangeset for help on using the changeset viewer.