Phi: Map changes and initial Config functions
- keep selected map overlays during session - add first Simulator/Config option (enable/disable ai traffic)
This commit is contained in:
parent
32cbf424f1
commit
1d1c8e28d1
6 changed files with 127 additions and 3 deletions
|
@ -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([
|
||||
|
|
|
@ -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 }
|
||||
}}"></div>
|
||||
|
|
|
@ -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 : '© <a target="_blank" href="http://openweathermap.org/">open weather map</a>',
|
||||
}),
|
||||
}
|
||||
|
||||
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
|
||||
|
|
10
webgui/topics/Simulator/Config.html
Normal file
10
webgui/topics/Simulator/Config.html
Normal file
|
@ -0,0 +1,10 @@
|
|||
<div>
|
||||
<fieldset>
|
||||
<legend>AI</legend>
|
||||
<div>
|
||||
<input type="checkbox" id="sim-config-aitraffic-on"
|
||||
data-bind="button: { refreshOn: aiEnabled }, checked: aiEnabled">
|
||||
<label for="sim-config-aitraffic-on" data-bind="css: { 'ui-state-active': aiEnabled }">AI Traffic</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
15
webgui/topics/Simulator/Config.js
Normal file
15
webgui/topics/Simulator/Config.js
Normal file
|
@ -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
|
||||
};
|
||||
});
|
|
@ -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 : {
|
||||
|
|
Loading…
Add table
Reference in a new issue