folium icon indicating copy to clipboard operation
folium copied to clipboard

Performance issue when trying to draw lots of markers: prefer_canvas option inefficient

Open FabeG opened this issue 7 years ago • 0 comments

Trying to plot thousands of circleMarkers, it appeared that rendering the map was very slow.

I tried to use the prefer_canvas option during Map creation:


carte = folium.Map(
        location=[48, 8.33],
        tiles='Mapbox Bright',
        prefer_canvas=True,
    )

but didn't see any performance improvement. Looking into the generated html, it seems that the prefer_canvas option is rendered as a Global Switch:

<script>
            L_PREFER_CANVAS = true;
            L_NO_TOUCH = false;
            L_DISABLE_3D = false;
</script>

Unfortunately, it seems that the L_PREFER_CANVAS switch isn't supported anymore since Leaflet 1.0, the prefered way of using Canvas is now during the map creation (https://leafletjs.com/reference-1.4.0.html#map-prefercanvas).

Adding directly the preferCanvas: true option in the html, I saw a huge speed improvement in the drawing of the markers.

FabeG avatar Apr 18 '19 08:04 FabeG