From 1d1c8e28d1fbe69e35b8710784e6bd85087b3864 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Tue, 10 Mar 2015 21:48:11 +0100 Subject: [PATCH] Phi: Map changes and initial Config functions - keep selected map overlays during session - add first Simulator/Config option (enable/disable ai traffic) --- webgui/main.js | 20 ++++++++ webgui/topics/Map.html | 4 +- webgui/topics/Map.js | 71 ++++++++++++++++++++++++++++- webgui/topics/Simulator/Config.html | 10 ++++ webgui/topics/Simulator/Config.js | 15 ++++++ webgui/widgets/map.js | 10 ++++ 6 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 webgui/topics/Simulator/Config.html create mode 100644 webgui/topics/Simulator/Config.js diff --git a/webgui/main.js b/webgui/main.js index 35b308aed..8f0675b8d 100644 --- a/webgui/main.js +++ b/webgui/main.js @@ -212,6 +212,26 @@ require([ return ko.utils.knockprops.get(target, prop); }; + ko.extenders.fgPropertyGetSet = function(target,option) { + + fgCommand.getPropertyValue(option, function(value) { + target(value); + }, self); + + var p = ko.pureComputed({ + read : target, + write : function(newValue) { + if (newValue == target()) + return; + target(newValue); + target.notifySubscribers(newValue); + fgCommand.setPropertyValue(option, newValue ); + } + }); + return p; + } + + ko.utils.knockprops = new KnockProps(); ko.utils.knockprops.setAliases([ diff --git a/webgui/topics/Map.html b/webgui/topics/Map.html index f747b4536..cbfb25abc 100644 --- a/webgui/topics/Map.html +++ b/webgui/topics/Map.html @@ -6,15 +6,17 @@ zoom: 11 }, on: { - 'resize': mapResize, + 'resize' : mapResize, 'zoomend': mapZoomend, 'moveend': mapMoveend, + 'unload' : mapUnload, }, css: { width: '100%', height: '100%' }, overlays: overlays, + selectedOverlays: selectedOverlays, hasFollowAircraft: true, scale: { metric: false } }}"> diff --git a/webgui/topics/Map.js b/webgui/topics/Map.js index 1d4f90a50..9d7f580b1 100644 --- a/webgui/topics/Map.js +++ b/webgui/topics/Map.js @@ -2,9 +2,61 @@ define([ 'knockout', 'text!./Map.html', './Map/NavdbLayer', './Map/AILayer' ], function(ko, htmlString, NavdbLayer ) { + function StoredSettings(key, settings, session ) { + this.key = key; + this.settings = settings; + if( session ) this.session = true; + else this.session = false; + } + + StoredSettings.prototype.save = function() { + if(typeof(Storage) === "undefined") { + console.log("Storage not supported :-("); + return; + } + + var storage = this.session ? sessionStorage : localStorage; + + for( var setting in this.settings ) { + var settingKey = this.key + "_" + setting; + if( null == this.settings[setting] ) { + storage.removeItem(settingKey); + } else { + var t = JSON.stringify(this.settings[setting]); + storage.setItem(settingKey,JSON.stringify(this.settings[setting])); + } + } + } + + StoredSettings.prototype.load = function() { + if(typeof(Storage) === "undefined") { + console.log("Storage not supported :-("); + return; + } + + var storage = this.session ? sessionStorage : localStorage; + + for( var setting in this.settings ) { + var settingKey = this.key + "_" + setting; + var storedSetting = storage.getItem(settingKey); + if( storedSetting != null ) { + this.settings[setting] = JSON.parse(storedSetting); + } + } + } + + function ViewModel(params) { var self = this; + this.storedSettings = new StoredSettings("flightgear_map", { + selectedBase: null, + selectedOverlays: [], + }, true); + + this.storedSettings.load(); + self.selectedOverlays = this.storedSettings.settings.selectedOverlays; + var trackLayer = new L.GeoJSON(null, {}); trackLayer.maxTrackPoints = 1000; @@ -175,6 +227,7 @@ define([ attribution : '© open weather map', }), } + self.mapResize = function(a,b) { self.overlays.NavDB.invalidate(); } @@ -187,9 +240,23 @@ define([ self.overlays.NavDB.invalidate(); } - } + self.mapLoad = function(a,b) { +console.log("load",a,b); + } + + self.mapUnload = function(evt) { + var map = evt.target + var settings = self.storedSettings.settings; + settings.selectedOverlays.length = 0; + for( var layerName in self.overlays ) { + var layer = self.overlays[layerName]; + if( map.hasLayer(layer) ) { + settings.selectedOverlays.push(layerName); + } + } + self.storedSettings.save(); + } - ViewModel.prototype.dispose = function() { } // Return component definition diff --git a/webgui/topics/Simulator/Config.html b/webgui/topics/Simulator/Config.html new file mode 100644 index 000000000..5fd2af241 --- /dev/null +++ b/webgui/topics/Simulator/Config.html @@ -0,0 +1,10 @@ +
+
+ AI +
+ + +
+
+
diff --git a/webgui/topics/Simulator/Config.js b/webgui/topics/Simulator/Config.js new file mode 100644 index 000000000..c3df2de68 --- /dev/null +++ b/webgui/topics/Simulator/Config.js @@ -0,0 +1,15 @@ +define([ + 'jquery', 'knockout', 'text!./Config.html', 'fgcommand', 'kojqui/button', 'kojqui/buttonset' +], function(jquery, ko, htmlString,fgCommand ) { + function ViewModel(params) { + var self = this; + + self.aiEnabled = ko.observable().extend({ fgPropertyGetSet: "/sim/traffic-manager/enabled" }); + } + + // Return component definition + return { + viewModel : ViewModel, + template : htmlString + }; +}); diff --git a/webgui/widgets/map.js b/webgui/widgets/map.js index c534d01de..da32477ac 100644 --- a/webgui/widgets/map.js +++ b/webgui/widgets/map.js @@ -86,6 +86,12 @@ define( L.control.layers(baseLayers, params.overlays).addTo(self.map); } + if( params && params.selectedOverlays && params.overlays ) { + params.selectedOverlays.forEach(function(ovl) { + params.overlays[ovl].addTo(self.map); + }); + } + if (params && params.scale) { L.control.scale(params.scale).addTo(self.map); } @@ -222,6 +228,10 @@ define( aircraftMarker.setLatLng(center); } + ViewModel.prototype.dispose = function() { + this.map.remove(); + } + // Return component definition return { viewModel : {