Render custom tiles in R leaflet from local directory (i.e. not from a git repository)

不羁岁月 提交于 2019-12-31 03:18:05

问题


I have created some tiles out of a very large raster using the Qtiles plugin in Qgis. I have saved them to a local directory on my computer, and now want to render them in a leaflet map using R.

The addTiles function passes a URL, but doesn't seem to work with a local filepath. In a different post (How to render custom map tiles created with gdal2tiles in Leaflet for R?), Lauren recommends using a www folder inside the shiny directory. Firstly, I'm not 100% sure what is meant by that, and secondly I don't know if that solution is applicable to what I'm trying to do; all I want to do is render these tiles in a leaflet map object and save it locally as html. Is it possible to do what I am attempting?

The code looks something like this:

library(leaflet)

map <- leaflet()

map <- addProviderTiles(map, "CartoDB.Positron")

map <- addTiles(map, "C:/mapTiles/level100Tiles/{z}/{x}/{y}.png")

Is there a different leaflet function for this specific purpose that I am not aware of? Or is it just not something that's done?

Thanks :)


回答1:


Add a ResourcePath inside server and it'll work, no need for the www folder anywhere. Source.

server <- function(input, output, session) {
    addResourcePath("mytiles", "C:/Users/.../mapTiles")
    output$map <- renderLeaflet({
      leaflet() %>% 
        addTiles(urlTemplate = "/mytiles/{z}/{x}/{y}.png")
    })


来源:https://stackoverflow.com/questions/45722157/render-custom-tiles-in-r-leaflet-from-local-directory-i-e-not-from-a-git-repos

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