Render custom tiles in R leaflet from local direct

2019-07-22 03:12发布

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条回答
Viruses.
2楼-- · 2019-07-22 03:22

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")
    })
查看更多
登录 后发表回答