jupyter-widgets / ipyleaflet

A Jupyter - Leaflet.js bridge
https://ipyleaflet.readthedocs.io
MIT License
1.48k stars 363 forks source link

Can't create more than 1999 Markers consecutively #1091

Open Matti88 opened 1 year ago

Matti88 commented 1 year ago

Hello Team,

I wanted to create a cluster with more than 4000 elements and the process was running slow (or infinite), anyway more than 30 secs. I ended up testing why it was fast earlier and I found an upper limit. Apparently you can make 1999 Markers in ~1.4 seconds but with 2000th the process runs to infinite.

count = 0 
df_locations = pd.read_csv('/5000_locations.csv', sep=";")
for row_ in df_locations.iterrows():
    location=(row_[1]['lat'],row_[1]['lon'])
    Marker(location=location)
    count +=1
    if count == 1999:
        break

Tested using Python 3.11 on VS Code Jupyter

sackh commented 1 year ago

For your use case, you should consider using MarkerCluster.

Matti88 commented 1 year ago

Hello @sackh , Thank you for the quick reply. But I still need to generate a list/tuple of markers, isn’t it?

From the suggested link:

marker1 = Marker(location=(48, -2))
marker2 = Marker(location=(50, 0))
marker3 = Marker(location=(52, 2))

marker_cluster = MarkerCluster(
    markers=(marker1, marker2, marker3)
)

m.add_layer(marker_cluster);
sackh commented 1 year ago

@Matti88 yes you will need to create a list/tuple of Markers but you should not get performance issues with MarkerCluster.