Phi: tweak the RouteManager layer
- less dominant lines - only update if the number of waypoints change (no polling)
This commit is contained in:
parent
4801887b5e
commit
49396ed83f
1 changed files with 37 additions and 57 deletions
|
@ -2,86 +2,65 @@
|
|||
if (typeof define === "function" && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define([
|
||||
'leaflet', 'props', './MapIcons'
|
||||
'leaflet', 'props', './MapIcons', 'knockout'
|
||||
], factory);
|
||||
} else {
|
||||
// Browser globals
|
||||
factory();
|
||||
}
|
||||
}(function(leaflet, SGPropertyNode, MAP_ICON) {
|
||||
}(function(leaflet, SGPropertyNode, MAP_ICON, ko) {
|
||||
|
||||
leaflet.RouteLayer = leaflet.GeoJSON.extend({
|
||||
options : {
|
||||
/*
|
||||
pointToLayer : function(feature, latlng) {
|
||||
var options = {
|
||||
title : feature.properties.callsign,
|
||||
alt : feature.properties.callsign,
|
||||
riseOnHover : true,
|
||||
};
|
||||
|
||||
if (feature.properties.type == "aircraft" || feature.properties.type == "multiplayer") {
|
||||
options.angle = feature.properties.heading;
|
||||
options.icon = MAP_ICON["aircraft"];
|
||||
}
|
||||
return new leaflet.RotatedMarker(latlng, options);
|
||||
},
|
||||
|
||||
onEachFeature : function(feature, layer) {
|
||||
if (feature.properties) {
|
||||
var popupString = '<div class="popup">';
|
||||
for ( var k in feature.properties) {
|
||||
var v = feature.properties[k];
|
||||
popupString += k + ': ' + v + '<br />';
|
||||
}
|
||||
popupString += '</div>';
|
||||
layer.bindPopup(popupString, {
|
||||
maxHeight : 200
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
*/
|
||||
style : function(feature) {
|
||||
console.log(this,feature);
|
||||
if (feature.geometry.type == "LineString")
|
||||
return {
|
||||
'color' : '#4d56db',
|
||||
'lineCap' : 'round',
|
||||
'dashArray' : '20,10,5,5,5,10',
|
||||
'weight' : '2',
|
||||
}
|
||||
},
|
||||
},
|
||||
onAdd : function(map) {
|
||||
leaflet.GeoJSON.prototype.onAdd.call(this, map);
|
||||
this.update(++this.updateId);
|
||||
var self = this;
|
||||
leaflet.GeoJSON.prototype.onAdd.call(self, map);
|
||||
self.waypointCount = ko.observable(0).extend({
|
||||
observedProperty : '/autopilot/route-manager/route/num'
|
||||
});
|
||||
self.waypointCountSubscription = self.waypointCount.subscribe(function() {
|
||||
self.update();
|
||||
|
||||
})
|
||||
},
|
||||
|
||||
onRemove : function(map) {
|
||||
this.updateId++;
|
||||
this.waypointCountSubscription.dispose();
|
||||
this.waypointCount.dispose();
|
||||
leaflet.GeoJSON.prototype.onRemove.call(this, map);
|
||||
},
|
||||
|
||||
stop : function() {
|
||||
this.updateId++;
|
||||
this.waypointCountSubscription.dispose();
|
||||
this.waypointCount.dispose();
|
||||
},
|
||||
|
||||
updateId : 0,
|
||||
update : function(id) {
|
||||
var self = this;
|
||||
|
||||
if (self.updateId != id)
|
||||
return;
|
||||
|
||||
var url = "/json/autopilot/route-manager/route?d=3";
|
||||
var jqxhr = $.get(url).done(function(data) {
|
||||
self.clearLayers();
|
||||
var geoJSON = self.routePropsToGeoJson(data);
|
||||
if( geoJSON )
|
||||
if (geoJSON)
|
||||
self.addData(geoJSON);
|
||||
}).fail(function(a, b) {
|
||||
self.updateId++;
|
||||
console.log(a, b);
|
||||
// self.stop(); // TODO: Should we?
|
||||
alert('failed to load RouteManager data');
|
||||
}).always(function() {
|
||||
});
|
||||
|
||||
if (self.updateId == id) {
|
||||
setTimeout(function() {
|
||||
self.update(id)
|
||||
}, 10000);
|
||||
}
|
||||
},
|
||||
|
||||
routePropsToGeoJson : function(props) {
|
||||
|
@ -90,15 +69,17 @@
|
|||
features : [],
|
||||
};
|
||||
var lineString = [];
|
||||
|
||||
|
||||
var root = new SGPropertyNode(props);
|
||||
root.getChildren("wp").forEach(function(wp) {
|
||||
var id = wp.getNode("id");
|
||||
var lon = wp.getNode("longitude-deg").getValue();
|
||||
var lat = wp.getNode("latitude-deg").getValue();
|
||||
|
||||
var position = [ lon, lat ];
|
||||
lineString.push( position );
|
||||
|
||||
var position = [
|
||||
lon, lat
|
||||
];
|
||||
lineString.push(position);
|
||||
|
||||
geoJSON.features.push({
|
||||
"type" : "Feature",
|
||||
|
@ -107,17 +88,16 @@
|
|||
"coordinates" : position,
|
||||
},
|
||||
"id" : id,
|
||||
"properties" : {
|
||||
},
|
||||
"properties" : {},
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
geoJSON.features.push({
|
||||
"type" : "LineString",
|
||||
"coordinates" : lineString,
|
||||
});
|
||||
|
||||
if( lineString.length >= 2 )
|
||||
|
||||
if (lineString.length >= 2)
|
||||
return geoJSON;
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue