What is the logic for adding and deleting points on the map? I see "deleted":true but how do you keep track of the state to figure out which ones to delete. My current map when I move the boundary it clears and then selects a current extents of the map for a new batch of points and clears then add the points. It work great most of the time. However, I'm finding that if I click on the popup and the boundary moves slightly to fit the popup then the point disappears briefly and then re-appears closing my popup. So, I guess I need to implement some sort of state machine and then filter through all of the old points to delete what is not in the current view. Maybe I could add a buffer as well but then that all gets very complicated and possibly memory intensive.
The rough logic would be something like this...
init last =
select => current
current not in last => add to map
last not in current => delete from map
current in last => update on map (I could skip since my data set is fairly static)
set current = last
Any ideas out there how to do this?
Yes. Entirely up to you to keep track. The map will hold lots of points out of view so it’s up to you if you really need to delete them or can just leave them.
Ok, so it looks like I can use a node like node-red-contrib-differences to get the one side but what I really needs is a node that does something like the
diff command. Does anyone have any ideas if such a node exists or how to even approach the diff problem with large lists of objects (~500) in node-red? I can envision a node where it takes two arrays as inputs (flow.stash, msg.payload) and has three outputs "add", "delete", and "common". But, I'm lost from there.
The command line already has two commands that have this capability
$ diff -u <(echo -ne "1\n2\n3\n") <(echo -ne "1\n3\n4\n")
--- /dev/fd/63 2022-10-26 07:43:42.635457846 -0400
+++ /dev/fd/62 2022-10-26 07:43:42.635457846 -0400
@@ -1,3 +1,3 @@
- 1 - ignore
- 2 - delete
- 3 - ignore
- 4 - add
$ comm -3 <(echo -ne "1\n2\n3\n") <(echo -ne "1\n3\n4\n")
I'm sure that my solution is not the most efficient but I was able to get it to work for 99% of the cases. So, based on timing I had to "stash" the point list twice. I stash the point list from the flow to the msg before the diff so that the add and del can operate on the same stash without having to worry about one finishing before the other.
Here is what my flow looks like with the node-red-contrib-differences node.
My only issue is when I hit my select LIMIT = 500 from PostgreSQL then my logic ends up deleting some random points (so just zoom in right!). So, I think the boundary needs a little buffer (~10%) and then the delete list should be calculated based on outside the buffer and not outside the select results.
There is one bug in the worldmap node where it resends the boundary on clear command so I had to add the "hasPoints" logic to work around an infinite loop issue. But, in general this is a great tool to display a large data set of points for users who don't have QGIS or ESRI.
Can you expand on that a bit ? Is it possible to create a simple example (just using injects rather than your database) that shows this ? (Or indeed maybe raise an issue). Thanks
Thanks for that. Fixed in v2.30.1