Hya all, I am plotting aircraft positions contained in a DataFrame df, on a leaflet map using Python. An icon is created with an airplane symbol. So I add all markers to the map, using:
for i in range(0, len(df)):
ac = Marker(name = df['callsign'][i],
location=(df['latitude'][i], df['longitude'][i]),
icon = icon,
rotation_angle = float(df['heading'][i]),
rotation_origin = 'center')
m.add_layer(ac)
For the next update cycle I need to remove these layers (could be up to a hundred) but I cannot find a way to address specifically the layers that need to be removed, although they are defined with the 'name' field:
# remove all the ac symbols before we go into the next loop
for i in range(0, len(df)):
m.remove_layer(i)
Gives this error:
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_18204/2482639859.py in <module>
71 # remove all the ac symbols before we go into the next loop
72 for i in range(0, len(df)):
---> 73 m.remove_layer(i)
74 #print(ac.name)
75
~\anaconda3\lib\site-packages\ipyleaflet\leaflet.py in remove_layer(self, rm_layer)
2152 The layer to remove.
2153 """
-> 2154 if rm_layer.model_id not in self._layer_ids:
2155 raise LayerException('layer not on map: %r' % rm_layer)
2156 self.layers = tuple([layer for layer in self.layers if layer.model_id != rm_layer.model_id])
AttributeError: 'int' object has no attribute 'model_id'
So it looks like I can reference to these layers somehow, but cannot find how. Any clues much appreciated.