问题
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
What is the maximum number of points you plot on a leaflet map without compromising the ability to navigate the map?
Would publishing the map as a shiny application help solve the loading speed, the maps lagginess and other performance issues?
If not, what other mapping programs integrate with R that yall would recommend?
Thank you for your suggestions!
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/53038090/r-leaflet-limitations-how-many-markers-does-a-leaflet-map-support