Worldmap tracks shows old value

Your tracks function node has a problem. Your code is this:

var payload = msg.payload;
var Tracks = [];

// Check if payload is 'reset' and reset Tracks array
if (payload === 'reset') {
    Tracks = [];
    msg.payload =         
        msg.payload = [
            { "name": "tracks", "deleted": true },
            { "name": "tracks_", "deleted": true }
        ];


} else {
    // Iterate over each object in the payload
    for (var i = 0; i < payload.length; i++) {
        var currentData = payload[i];

        // Extract latitude and longitude values
        if (currentData._field === "Latitude") {
            // Find the corresponding longitude data
            var longitudeData = payload.find(data => (
                data._time === currentData._time &&
                data._field === "Longitude"
            ));

            // If longitude data is found, create a track
            if (longitudeData) {
                var track = {
                    'name': 'tracks',
                    'lat': parseFloat(currentData._value),
                    'lon': parseFloat(longitudeData._value),
                    //'icon': 'uav',
                   // 'iconColor': 'blue',
                    'layer': 'tracks',
                    //'popped': false
                };

                Tracks.push(track);
                 }
            }
        }
    }

// Create a new message containing the generated tracks
var newMsg = {
    payload: Tracks
};

return newMsg;

First off, in the // Check if payload is 'reset' and reset Tracks array section you are setting msg.payload to msg.payload. Then at the end of the code, you create a newMsg and set the payload to Tracks. But the reset code needs to send the msg.payload you already set.

Try this code, ift the incoming payload is reset, it sets up msg.payload and then returns the msg ignoring the rest of the code in the function.

var payload = msg.payload;
var Tracks = [];

// Check if payload is 'reset' and reset Tracks array
if (payload === 'reset') {
    msg.payload =  { "name": "tracks_", "deleted": true }
    return msg
} else {
    // Iterate over each object in the payload
    for (var i = 0; i < payload.length; i++) {
        var currentData = payload[i];

        // Extract latitude and longitude values
        if (currentData._field === "Latitude") {
            // Find the corresponding longitude data
            var longitudeData = payload.find(data => (
                data._time === currentData._time &&
                data._field === "Longitude"
            ));

            // If longitude data is found, create a track
            if (longitudeData) {
                var track = {
                    'name': 'tracks',
                    'lat': parseFloat(currentData._value),
                    'lon': parseFloat(longitudeData._value),
                    //'icon': 'uav',
                   // 'iconColor': 'blue',
                    'layer': 'tracks',
                    //'popped': false
                };

                Tracks.push(track);
                 }
            }
        }
    }

// Create a new message containing the generated tracks
var newMsg = {
    payload: Tracks
};

return newMsg;

1 Like

There is indeed a bug in the layer deletion logic in that while it deletes the visible layer - it fails to remove the points from the local cache so a refresh just redraws the data.

Version v4.6.4 inbound

Any idea how can this bug be fixed?

Fix uploaded just now...

This is a bit complex code, but trust me the issue is not with the code. i am facing this issue for a quiet a long period of time with all my flows, In this flow i am fetching data from influxdb. In the other flows i am just doing real time tracking of drone using the below code. I face the same issue with the below code. If i do two different tracking one after an other, it shows tracks of previos flight although i reomved them from map.

var payload = msg.payload;
var topic = msg.topic;

if (topic = "+/+/telemetry"){
    var x = msg.payload.Latitude;
    var y = msg.payload.Longitude;
    var spd = msg.payload.GroundSpeed;
    var crs = msg.payload.Course;
    var alt = msg.payload.AltitudeMSL;
    var wind = msg.payload.Wind;
    var yaw = msg.payload.Yaw;
    var pitch = msg.payload.Pitch;
    var roll = msg.payload.Roll;
    var rssi = msg.payload.RSSI;

    
    
    msg.payload = {
        'name': 'Kimino',
        'lat' : x,
        'lon': y,
        'alt': alt,
        'speed': spd,
        'heading': crs,
        'Wind': wind,
        'yaw': yaw,
        'pitch': pitch,
        'roll': roll,
        'Rssi': rssi,
        'icon': 'uav',
        'iconColor': 'blue',
        'layer': 'pos',
        'popped': false
    }
    node.send(msg);
    
}

return msg;

Yes - have you tried the latest worldmap version 4.6.4 ? As I said there is/was a bug that meant although you deleted the layer - it was only partially deleted internally - so would reappear... now fixed to fully delete from the internal cache.

I have updated my worldmap node to latest version 4.6.4 and still facing the same issue.

In the debug window you can see that 4 layes are added and then the 4 layers are removed including the tracks layers but when i fetch data of new flight the tracks of old flight still reapears in the map.

Did you fix the code in the tracks function node?
You might also stop and restart NR.

Yes i checked after restarting the node-red but didn't fixed the code. Now i have used your code, now its a bit improved but still i am getting i strange line in the tracks. I will do more testing with my realtime tracking of the drone and update you guys later if that issue is resolved or not.

Sorry - only just read your code ... not sure that is that way to delete tracks... You should just need to delete the layer or layers using
msg.payload = {"command":{"map":{"delete":["waypoints","Homeposition","tracks","destinations"]}}};

fed into both the tracks node and worldmap node.

1 Like

Thanks for the hlep. Now everything is working fine for the current flow, based on your suggestions i will do some more testing with my other flows in which i am doing real time tracking of the drones and updaute you guys if i am still facing the issue or not.

Again thanks for the help.

@dceejay The Help for the tracks node needs to be updated to reflect that. As of v4.6.4 it still says

To delete a track send a msg.payload containing both the name of the object and set deleted to true - for example msg.payload = { "name":"Fred", "deleted":true }.

This will also delete the point. If you just want to clear the track set the msg.payload to the name+"", for example msg.payload = { "name":"Fred", "deleted":true }

That should still be true of a track (or point)... the command above is for deleting layers - which is what the first question was I think.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.