Save object states and ignore non moving track updates

This commit is contained in:
Dave Conway-Jones 2019-04-02 13:04:06 +01:00
parent e2e3e439cb
commit 91d5398339
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
2 changed files with 24 additions and 9 deletions

View File

@ -177,6 +177,7 @@ module.exports = function(RED) {
node.send(newmsg); // send the track to be deleted node.send(newmsg); // send the track to be deleted
return; return;
} }
if (!msg.payload.hasOwnProperty("lat") || !msg.payload.hasOwnProperty("lon")) { return; }
if (!node.pointsarray.hasOwnProperty(msg.payload.name)) { if (!node.pointsarray.hasOwnProperty(msg.payload.name)) {
node.pointsarray[msg.payload.name] = []; node.pointsarray[msg.payload.name] = [];
} }
@ -190,10 +191,17 @@ module.exports = function(RED) {
} }
if (node.depth < 2) { return; } // if set less than 2 then don't bother. if (node.depth < 2) { return; } // if set less than 2 then don't bother.
node.pointsarray[msg.payload.name].push(msg.payload); var still = false;
if (node.pointsarray[msg.payload.name].length > 0) {
var oldlat = node.pointsarray[msg.payload.name][node.pointsarray[msg.payload.name].length-1].lat;
var oldlon = node.pointsarray[msg.payload.name][node.pointsarray[msg.payload.name].length-1].lon;
if (msg.payload.lat === oldlat && msg.payload.lon === oldlon) { still = true; }
}
if (!still) { node.pointsarray[msg.payload.name].push(msg.payload);
if (node.pointsarray[msg.payload.name].length > node.depth) { if (node.pointsarray[msg.payload.name].length > node.depth) {
node.pointsarray[msg.payload.name].shift(); node.pointsarray[msg.payload.name].shift();
} }
}
var line = []; var line = [];
for (var i=0; i<node.pointsarray[msg.payload.name].length; i++) { for (var i=0; i<node.pointsarray[msg.payload.name].length; i++) {
var m = node.pointsarray[msg.payload.name][i]; var m = node.pointsarray[msg.payload.name][i];

View File

@ -930,6 +930,7 @@ function setMarker(data) {
delMarker(data.name); delMarker(data.name);
return; return;
} }
var ll; var ll;
var lli = null; var lli = null;
var opt = {}; var opt = {};
@ -978,6 +979,13 @@ function setMarker(data) {
map.addLayer(overlays[lay]); map.addLayer(overlays[lay]);
//console.log("ADDED LAYER",lay,layers); //console.log("ADDED LAYER",lay,layers);
} }
if (!allData.hasOwnProperty(data.name)) { allData[data.name] = {}; }
delete data.action;
Object.keys(data).forEach(key => {
if (data[key] == null) { delete allData[data.name][key]; }
else { allData[data.name][key] = data[key]; }
});
data = Object.assign({},allData[data.name]);
} }
delete data.action; delete data.action;
@ -1055,12 +1063,6 @@ function setMarker(data) {
else if (data.hasOwnProperty("latitude") && data.hasOwnProperty("longitude") && data.hasOwnProperty("intensity")) { lli = new L.LatLng((data.latitude*1), (data.longitude*1), (data.intensity*1)); } else if (data.hasOwnProperty("latitude") && data.hasOwnProperty("longitude") && data.hasOwnProperty("intensity")) { lli = new L.LatLng((data.latitude*1), (data.longitude*1), (data.intensity*1)); }
else { lli = ll } else { lli = ll }
// if (!allData.hasOwnProperty(data.name)) { allData[data.name] = {}; }
// var foo = Object.assign(allData[data.name], data);
// allData[data.name] = foo;
// data = foo;
// console.log("A1",foo,allData);
// Create the icons... handle plane, car, ship, wind, earthquake as specials // Create the icons... handle plane, car, ship, wind, earthquake as specials
var marker, myMarker; var marker, myMarker;
var icon, q; var icon, q;
@ -1373,6 +1375,11 @@ function setMarker(data) {
delete data.lon; delete data.lon;
if (data.layer) { delete data.layer; } if (data.layer) { delete data.layer; }
if (data.lineColor) { delete data.lineColor; } if (data.lineColor) { delete data.lineColor; }
if (data.color) { delete data.color; }
if (data.weight) { delete data.weight; }
if (data.tracklength) { delete data.tracklength; }
if (data.dashArray) { delete data.dashArray; }
if (data.fill) { delete data.fill; }
if (data.draggable) { delete data.draggable; } if (data.draggable) { delete data.draggable; }
for (var i in data) { for (var i in data) {
if ((i != "name") && (i != "length")) { if ((i != "name") && (i != "length")) {