R - Leaflet Limitations - How many markers does a

2019-08-27 19:31发布

Data

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

The Situation

I would like to publish the map online via a markdown document.

The Problem

When I export the map as an html page or in markdown the map is:

  • Laggy
  • Hard to navigate
  • Webpage Loads slowly

Questions

  1. What is the maximum number of points you plot on a leaflet map without compromising the ability to navigate the map?

  2. Would publishing the map as a shiny application help solve the loading speed, the maps lagginess and other performance issues?

  3. If not, what other mapping programs integrate with R that yall would recommend?

Thank you for your suggestions!

2条回答
Root(大扎)
2楼-- · 2019-08-27 20:11

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"))

See leaflet.glify

查看更多
三岁会撩人
3楼-- · 2019-08-27 20:30

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 more fast in terms of navigation. I didn't try leaflet.glify yet, but is a good solution for thousand points using leaflet package.

查看更多
登录 后发表回答