Leaflet: local offline tiles using urlTemplate and addResourcePath

Hello,

I would like to include local tiles for offline leaflet. I have tried to imitate various examples I found on SO, but so far no tiles :slight_smile: . The minimal example looks like this:

library(shiny)
library(dplyr)
library(RgoogleMaps)

#download tiles for a given regions, save it to C:\Users\...\mapTiles\OSM
for (zoom in 10:16)
  GetMapTiles(center = c(lat = 52.431635, lon = 13.194773),
              zoom = zoom,
              nTiles = round(c(20,20)/(17-zoom)))

#just ui
ui = fluidPage(leafletOutput("map"))

#create basic map, load tiles from directory and set view to centre of donloaded tiles
server = function(input, output, server){
  addResourcePath(prefix = "OSM", "C:/Users/.../mapTiles")
  output$map = renderLeaflet({
    leaflet() %>% 
      addTiles( urlTemplate = "OSM/{z}_{x}_{y}.png") %>% 
      setView(52.431635, 13.194773 , zoom = 10) %>% 
      addMarkers(52.431635, 13.194773 )
  }
  )
}

#run shiny app
shinyApp(ui, server)

I admit, I don't have a clear undertanding of addResourcePath, and haven't found a resource or documentation that would help me with that. So that might be the culprit here.
Thanks!

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.