Changeset fb91143
- Timestamp:
- Aug 22, 2017, 6:03:09 PM (9 years ago)
- Branches:
- 0.5, debian/bullseye, debian/jessie, master
- Children:
- 17bc29b
- Parents:
- e44e1f1
- Location:
- src/webapp/webclient
- Files:
-
- 2 added
- 1 edited
-
js/GnuBoat.js (modified) (8 diffs)
-
lib/css/resources/layers.png (added)
-
lib/js/leaflet.hotline.min.js (added)
Legend:
- Unmodified
- Added
- Removed
-
src/webapp/webclient/js/GnuBoat.js
re44e1f1 rfb91143 230 230 map: null, 231 231 mapLayerCurrent: null, 232 // var mapControl = null; 232 mapPolylines: [], 233 mapControl: null, 233 234 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 }, 235 242 serverBaseUrl: null, 236 243 timerDisplay: null, … … 243 250 displayDataSet: function(data) 244 251 { 252 var keysDisplay = []; 253 for(var key in GnuBoat.private.dataMappings){ 254 if(GnuBoat.private.dataMappings[key]["display"] === true) 255 keysDisplay.push(key); 256 } 245 257 if(!Array.isArray(data) && !(data instanceof Object)){ 246 258 console.log("No data array returned!"); 247 259 console.log(data); 248 260 return; 249 }261 } 250 262 if(!("lastvalid" in data)){ 251 263 console.log("No last valid values given!"); … … 253 265 else{ 254 266 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]; 258 269 var value = lastValid[key]; 259 270 if($.isNumeric(value)){ … … 262 273 text = value.toFixed(0); 263 274 } 264 $("#display #"+ key s[i]+" #value").text(text);275 $("#display #"+ key +" #value").text(text); 265 276 } 266 277 else if(key == "gpsfix"){ 267 $("#display #"+ key s[i]+" #value").text(value);278 $("#display #"+ key +" #value").text(value); 268 279 } 269 280 } … … 279 290 else{ 280 291 var track = data["track"]; 292 var maximas = []; 293 var minimas = []; 281 294 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 282 308 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])); 288 322 } 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 } 291 341 } 292 GnuBoat.private.map.fitBounds(GnuBoat.private.polyline.getBounds());293 342 } 294 343 } … … 334 383 if(GnuBoat.private.mapLayerCurrent != null){ 335 384 GnuBoat.private.map.removeLayer(GnuBoat.private.mapLayerCurrent); 385 if(GnuBoat.private.mapControl) 386 GnuBoat.private.mapControl.removeLayer(GnuBoat.private.mapLayerCurrent); 336 387 GnuBoat.private.mapLayerCurrent = null; 337 388 } … … 342 393 opacity: 0.85 343 394 }).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 } 344 400 }, 345 401 … … 358 414 $("#mapSelect").change(function(){ mapSetup(); }); 359 415 }, 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.
