Search code examples
javascriptnode.jsnode-red

Issues removing markers from worldmap on node-red


I have multiple markers with different name on my worldmap running on node-red. I can delete them one by one with the following code:

markers:

1. msg.payload = {"name":"Delivery-2","lat":55.87782,"lon":-4.32508};
return msg;

2. msg.payload = {"icon":"car", "name":"Delivery-3","lat":55.87782,"lon":-4.32308};
return msg;

delete Marker code:

msg.payload = {"name":"Delivery-3", "deleted": true};
return msg;

I am searching for the best way to delete all the markers with a single code


Solution

  • If you add your markers to a named layer, you can use the clear command to remove all markers in one go.

    e.g.

    msg.payload = {"layer": "foo", "name":"Delivery-2","lat":55.87782,"lon":-4.32508};
    

    Then clear with:

    msg.payload = {"command":{"clear":"foo"}}