Changeset b8b5e77 for src/webapp


Ignore:
Timestamp:
Aug 31, 2017, 5:18:08 PM (9 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
0.5, debian/bullseye, debian/jessie, master
Children:
99959fb
Parents:
a50c18f
git-author:
Joachim Langenbach <joachim.langenbach@…> (08/31/17 17:15:25)
git-committer:
Joachim Langenbach <joachim.langenbach@…> (08/31/17 17:18:08)
Message:

Improved coloring of the leaflet hotlines and the 3D rendering

Location:
src/webapp/webclient
Files:
3 edited

Legend:

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

    ra50c18f rb8b5e77  
    9797
    9898.viewportGeometry {
    99         width: 100%;
     99/*      width: 100%; */
    100100        height: 24em;
    101101}
    … …  
    129129        background:url('../resources/view-refresh.svg') no-repeat left center;
    130130}
     131
     132.hidden {
     133        display: none;
     134}
     135
     136#mapLgend table {
     137        margin-top: 0.25em;
     138        margin-left: 1em;
     139}
     140
     141#mapLegend table tr td.level {
     142        text-align: right;
     143}
  • src/webapp/webclient/index.html

    ra50c18f rb8b5e77  
    149149                                                        </div>
    150150                                                </form>
    151                                                 <div id="mapViewport" class="viewportGeometry"></div>
     151                                                <div class="pure-g">
     152                                                        <div class="pure-u-1 pure-u-md-4-5 pure-u-lg-4-5">
     153                                                                <div id="mapViewport" class="viewportGeometry"></div>
     154                                                        </div>
     155                                                        <div class="pure-u-1 pure-u-md-1-5 pure-u-lg-1-5">
     156                                                                <div id="mapLegend"></div>
     157                                                        </div>
     158                                                </div>
    152159                                        </div>
    153160                                        <form id="mapTileUpload" class="pure-form pure-form-aligned" enctype="multipart/form-data">
    … …  
    166173                                        </form>
    167174
    168                                         <h2 class="content-subhead">3D Rendering</h2>
     175                                        <h2 class="content-subhead">3D Rendering of Water Depth</h2>
    169176                                        <div>
    170177                                                <a name="rendering"></a>
  • src/webapp/webclient/js/GnuBoat.js

    ra50c18f rb8b5e77  
    216216        GnuBoat.private.renderControls = new THREE.OrbitControls( GnuBoat.private.renderCamera, GnuBoat.private.renderRenderer.domElement );
    217217        GnuBoat.private.renderControls.zoomSpeed = 2;
    218        
    219        
    220        
    221         var deep = new THREE.Color(0x347C7C);
    222         var shallow = new THREE.Color(0xBCD9D9);
    223         var size = 5;
    224         GnuBoat.private.renderDepthSteps = 50;
    225 
    226         var deltaR = (Math.max(deep.r, shallow.r) - Math.min(deep.r, shallow.r))/GnuBoat.private.renderDepthSteps;
    227         var deltaG = (Math.max(deep.g, shallow.g) - Math.min(deep.g, shallow.g))/GnuBoat.private.renderDepthSteps;
    228         var deltaB = (Math.max(deep.b, shallow.b) - Math.min(deep.b, shallow.b))/GnuBoat.private.renderDepthSteps;
    229         for(var i = 0; i < GnuBoat.private.renderDepthSteps; i++){
    230                 var stepColor = new THREE.Color(Math.max(deep.r, shallow.r) - i * deltaR,
    231                                                                                 Math.max(deep.g, shallow.g) - i * deltaG,
    232                                                                                 Math.max(deep.b, shallow.b) - i * deltaB);
    233                 GnuBoat.private.renderDepthMaterials.push(stepColor);
    234         }
    235         GnuBoat.private.renderDepthMaterials.push(shallow);
    236218}
    237219
    … …  
    279261        mapBounds: null,
    280262        mapModusLive: true,
     263        mapHotlineGradientDefault: { absolute: false, palette: { 0.0: 'green', 0.5: 'yellow', 1.0: 'red' } },
    281264        dataMappings: {
    282265                speedthroughwater: {display: true, map: true, mapActive: false, titleLong: "Speed Through Water", titleShort: "STW", unit: "kts"},
    283266                speedoverground:  {display: true, map: true, mapActive: false, titleLong: "Speed Over Ground", titleShort: "SOG", unit: "kts"},
    284                 waterdepth: {display: true, map: true, mapActive: true, titleLong: "Waterdepth", titleShort: "Depth", unit: "m"},
     267                waterdepth: {
     268                        display: true, map: true, mapActive: true, titleLong: "Waterdepth", titleShort: "Depth", unit: "m",
     269                        gradient: {
     270                                absolute: true,
     271                                palette: { 0: 'DarkBlue', 2: 'DodgerBlue', 6: 'LightBlue', 10: 'AliceBlue'},
     272                        }
     273                },
    285274                watertemperature: {display: true, map: true, mapActive: false, titleLong: "Watertemperature", titleShort: "Water", unit: "°C"},
    286275                gpsfix: {display: true, map: false, mapActive: false, titleLong: "GPS Fix", titleShort: "Fix", unit: ""},
    … …  
    295284        renderControls: null,
    296285        renderCloud: null,
    297         renderDepthMaterials: [],
    298         renderDepthSteps: null,
    299286       
    300287        openLink: function(target)
    … …  
    385372                        // only initialize the map (viewport) once
    386373                        GnuBoat.private.map = L.map('mapViewport');
     374                        GnuBoat.private.map.on('overlayadd', function(layerObject){ GnuBoat.private.mapOverlayLegendSwitch(layerObject.layer); });
     375                        GnuBoat.private.map.on('overlayremove', function(layerObject){ GnuBoat.private.mapOverlayLegendSwitch(layerObject.layer); });
    387376                }
    388377                GnuBoat.private.map.setView([latitudeCenter, longitudeCenter], mapZoomStart);
    … …  
    480469        },
    481470       
    482         drawDensityEstimation: function(densityPoints, maximum, minimum)
    483         {
     471        drawDensityEstimation: function(densityPoints, gradient, maximum, minimum)
     472        {
     473                var colors = GnuBoat.private.gradientToRenderColors(gradient, maximum, minimum);
     474                // converting all indizes into numbers to sort them correctly
     475                // in descending order e.g. 10, 2, 1, 0 and not 2, 10, 1, 0
     476                var colorsIndizes = Object.getOwnPropertyNames(colors);
     477                colorsIndizes.sort(function(a, b){
     478                        a = +a;
     479                        b = +b;
     480                        return a-b;
     481                });
     482                var colorsCount = colorsIndizes.length;
     483               
    484484                var material = new THREE.PointsMaterial({vertexColors: THREE.VertexColors, size: 5});
    485485                var geometry = new THREE.Geometry();
    … …  
    491491                        var mercator = GnuBoat.private.mercator(densityPoints[i].latitude, densityPoints[i].longitude);
    492492                        var vertex = new THREE.Vector3(mercator.x - mercatorSouthWest.x, mercator.y - mercatorSouthWest.y, (densityPoints[i].depth * -1) + maximum);
     493                        var step = (densityPoints[i].depth - minimum)/(maximum-minimum);
    493494                        var color = new THREE.Color(0x000000);
    494                         if(GnuBoat.private.renderDepthSteps != null){
    495                                 var step = Math.floor((densityPoints[i].depth - minimum)/((maximum-minimum)/GnuBoat.private.renderDepthSteps));
    496                                 if(step >= 0 && step < GnuBoat.private.renderDepthMaterials.length)
    497                                         color = GnuBoat.private.renderDepthMaterials[step];
     495                        for(var j = 0; j < colorsCount; j++){
     496                                if(j < colorsCount - 1)
     497                                        color = colors[colorsIndizes[j]];
     498                                if(step <= colorsIndizes[j+1]){
     499                                        color = colors[colorsIndizes[j]];
     500                                        break;
     501                                }
    498502                        }
    499503                        geometry.vertices.push(vertex);
    … …  
    612616                }
    613617               
     618                $("#mapLegend").empty();
    614619                var maximas = [];
    615620                var minimas = [];
    … …  
    630635                        for(var i = 0; i < keysMap.length; i++){
    631636                                var key = keysMap[i];
    632                                 if(key == "gpsfix")
     637                                var value = track[time][key];
     638                                if(!$.isNumeric(value))
    633639                                        continue;
    634640                                if(!(key in maximas))
    635                                         maximas[key] = track[time][key]
    636                                 else if(maximas[key] < track[time][key])
    637                                         maximas[key] = track[time][key];
     641                                        maximas[key] = value
     642                                else if(maximas[key] < value)
     643                                        maximas[key] = value;
    638644                                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"]});
     645                                        minimas[key] = value
     646                                else if(minimas[key] > value)
     647                                        minimas[key] = value;
     648                                points[key].push(new L.latLng(track[time]["latitude"], track[time]["longitude"], value));
     649                                if(key == "waterdepth")
     650                                        densityPoints.push({latitude: track[time]["latitude"], longitude: track[time]["longitude"], depth: value});
    644651                        }
    645652                }
    … …  
    647654                        var key = keysMap[i];
    648655                        if(points[key].length > 0){
    649                                 if(key in GnuBoat.private.mapPolylines)
     656                                var palette = GnuBoat.private.mapHotlineGradientDefault.palette;
     657                                var paletteLegend = GnuBoat.private.mapHotlineGradientDefault.palette;
     658                                if("gradient" in GnuBoat.private.dataMappings[key]){
     659                                        palette = GnuBoat.private.gradientToPalette(GnuBoat.private.dataMappings[key]["gradient"], maximas[key], minimas[key]);
     660                                        // use original palette, to use absolute values, if possible
     661                                        paletteLegend = GnuBoat.private.dataMappings[key]["gradient"]["palette"];
     662                                }
     663                               
     664                                var legendTable = $('<table id="'+ key +'" class="hidden"></table>');
     665                                $("<tr><th colspan=2>"+ GnuBoat.private.dataMappings[key]["titleShort"] +" in "+ GnuBoat.private.dataMappings[key]["unit"] +"</th></tr>").appendTo(legendTable);
     666                                $("<tr><th>Level</th><th>Color</th></tr>").appendTo(legendTable);
     667                                // converting all indizes into numbers to sort them correctly
     668                                // e.g. 0, 1, 2, 10 and not 0, 1, 10, 2
     669                                var indizes = Object.getOwnPropertyNames(paletteLegend);
     670                                indizes.sort(function(a, b){
     671                                        a = +a;
     672                                        b = +b;
     673                                        return a-b;
     674                                });
     675                                for(var j=0; j < indizes.length; j++){
     676                                        var index = indizes[j];
     677                                        $('<tr><td class="level">'+ index.toString() +'</td><td style="background-color: '+ paletteLegend[index] +'"></td></tr>').appendTo(legendTable);
     678                                }
     679                                $('<tr><td colspan="2">Extrema: '+ maximas[key].toString() +' / '+ minimas[key].toString() +'</td></tr>').appendTo(legendTable);
     680                               
     681                                var hotlineOptions = {
     682                                        weight: 3,
     683                                        outlineWidth: 0,
     684                                        min: minimas[key],
     685                                        max: maximas[key],
     686                                        palette: palette,
     687                                };
     688                               
     689                                legendTable.appendTo("#mapLegend");
     690                       
     691                                if(key in GnuBoat.private.mapPolylines){
     692                                        GnuBoat.private.mapPolylines[key].setStyle(hotlineOptions);
    650693                                        GnuBoat.private.mapPolylines[key].setLatLngs(points[key]);
     694                                        if(GnuBoat.private.map.hasLayer(GnuBoat.private.mapPolylines[key]))
     695                                                GnuBoat.private.mapOverlayLegendSwitch(GnuBoat.private.mapPolylines[key]);
     696                                        GnuBoat.private.mapPolylines[key].unbindPopup();
     697                                }
    651698                                else{
    652                                         GnuBoat.private.mapPolylines[key] = L.hotline(points[key], {weight: 3, outlineWidth: 0, min: minimas[key], max: maximas[key]});
     699                                        GnuBoat.private.mapPolylines[key] = L.hotline(points[key], hotlineOptions);
    653700                                        if(GnuBoat.private.mapControl){
    654701                                                var name = GnuBoat.private.dataMappings[key]["titleLong"] +" in "+ GnuBoat.private.dataMappings[key]["unit"] +" ("+ GnuBoat.private.dataMappings[key]["titleShort"] +")";
    … …  
    658705                                                GnuBoat.private.mapPolylines[key].addTo(GnuBoat.private.map);
    659706                                }
    660                         }
    661                 }
    662                 GnuBoat.private.drawDensityEstimation(densityPoints, maximas["waterdepth"], minimas["waterdepth"]);
     707                                GnuBoat.private.mapPolylines[key].bindPopup(legendTable[0].outerHTML);
     708                        }
     709                }
     710                var gradient = GnuBoat.private.mapHotlineGradientDefault.palette;
     711                if("gradient" in GnuBoat.private.dataMappings["waterdepth"])
     712                        gradient = GnuBoat.private.dataMappings["waterdepth"]["gradient"];
     713                GnuBoat.private.drawDensityEstimation(densityPoints, gradient, maximas["waterdepth"], minimas["waterdepth"]);
     714        },
     715       
     716        gradientToPalette: function(gradient, maximum, minimum)
     717        {
     718                if(!("palette" in gradient)){
     719                        return GnuBoat.private.mapHotlineGradientDefault.palette;
     720                }
     721                if(!("absolute" in gradient) || !gradient.absolute){
     722                        // palette is already relative
     723                        return gradient.palette;
     724                }
     725                var range = maximum - minimum;
     726                if(range == 0){
     727                        console.log("Range is zero --> Could not make gradient relative");
     728                        return  GnuBoat.private.mapHotlineGradientDefault.palette;
     729                }
     730                var palette = {};
     731                var addedStop = false;
     732                for(var indexAbs in gradient.palette){
     733                        var indexRel = (indexAbs - minimum)/range;
     734                        if(indexRel < 0){
     735                                // add the nearest minimum value (which might be configured smaller than minimum)
     736                                indexRel = 0;
     737                                palette[indexRel] = gradient.palette[indexAbs];
     738                                addedStop = true;
     739                        }
     740                        else if(indexRel < 1){
     741                                palette[indexRel] = gradient.palette[indexAbs];
     742                                addedStop = true;
     743                        }
     744                        else{
     745                                // add first index > 1 as the maximum value at 1
     746                                indexRel = 1;
     747                                palette[indexRel] = gradient.palette[indexAbs];
     748                                addedStop = true;
     749                                break;
     750                        }
     751                }
     752                if(!addedStop)
     753                        return GnuBoat.private.mapHotlineGradientDefault.palette;
     754                return palette;
     755        },
     756       
     757        gradientToRenderColors: function(gradient, maximum, minimum)
     758        {
     759                var paletteRelative = GnuBoat.private.gradientToPalette(gradient, maximum, minimum);
     760
     761                var colors = {};
     762                for(var index in paletteRelative)
     763                        colors[index] = new THREE.Color(paletteRelative[index].toLowerCase());
     764
     765                return colors;
     766        },
     767
     768        mapOverlayLegendSwitch: function(layer)
     769        {
     770                var overlayKey = null;
     771                for(var key in GnuBoat.private.mapPolylines){
     772                        if(GnuBoat.private.mapPolylines.hasOwnProperty(key)){
     773                                if(GnuBoat.private.mapPolylines[key] === layer){
     774                                        overlayKey = key;
     775                                        break;
     776                                }
     777                        }
     778                }
     779                // ECMAScript 6
     780//              var overlayKey = Object.keys(GnuBoat.private.mapPolylines).find(key => GnuBoat.private.mapPolylines[key] === overlay);
     781                if(overlayKey == null)
     782                        return;
     783                if(overlayKey){
     784                        $("#mapLegend #"+ overlayKey).toggleClass("hidden");
     785                }
    663786        },
    664787};
Note: See TracChangeset for help on using the changeset viewer.