✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Doubled and tripled position of the last object in the map legend

Hello,
I would like to create a battle animation on the map. I prepared all data, merge them in the data frame and put it in the scatter map function. It almost works perfectly but…
During the battle, some units died earlier than another and they should disappear from the map. When it happens, the last position of the last unit on the legend stays on the map and doesn’t move (black dots on the map). The object also is doubled and tripled on the legend. It looks like a map and legend need to be refreshed.
Bellow, there are two screens from animation: Timestamp 116 - when all units are on the map, and 221 when 2 kinds of the unit had disappeared already.

My question is: is there any function parameter (or other solution) that can eliminate this problem.


Full animation, code, and sample data are available here: