R - Leaflet Limitations - How many markers does a leaflet map support?

前端 未结 2 1841
無奈伤痛
無奈伤痛 2021-01-28 05:24

Data

I have a dataframe which contains 35,000 lat/lon locations. The locations have been plotted onto an interactive leaflet map.

The S

相关标签:
2条回答
  • 2021-01-28 05:43

    There are a couple options I can think that might help. The best would probably be to make clusters (see Marker Clusters):

    addMarkers(..., clusterOptions = markerClusterOptions())
    

    This prevents all 35 000 points from rendering at once which speeds up the loading time.

    addCircles() and addCircleMarkers() seem to load quicker than addMarkers() as well if they're okay for your purposes although they're still slow with 35 000 points.

    You could then do:

    addCircleMarkers(..., clusterOptions = markerClusterOptions())
    

    which should load even faster.

    Update

    Use leaflet.glify (devtools::install_github("tim-salabim/leaflet.glify"))

    [Now leafgl (devtools::install_github("r-spatial/leafgl")) - see comment below.]

    See leaflet.glify [Now leafgl - see comment below.]

    0 讨论(0)
  • 2021-01-28 05:52

    An approach I did use recently to plot more than 100k points and worked very well:

    leaflet(options = leafletOptions(preferCanvas = TRUE))
    

    This forces leaflet to render the map as canvas. More info here.

    The map appearance keep the same, but is much faster in terms of navigation. I didn't try leaflet.glify yet, but it seems to be a good solution to plot thousand points using leaflet package.

    0 讨论(0)
提交回复
热议问题