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

故事扮演 提交于 2019-12-20 06:18:02

问题


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!


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!