R Leaflet Offline Map Tiles Not Loading

前端 未结 1 455
渐次进展
渐次进展 2021-01-14 14:01

I need help trying to figure out why my leaflet map using locally saved map tiles isn\'t working correctly. I\'m trying to recreate the example from here to create a leaflet

相关标签:
1条回答
  • 2021-01-14 14:56

    You were almost there. You can run the server in daemon mode, with servr::httd(port = 8000, daemon = TRUE):

    # Set the working folder
    setwd("C:/Users/OTAD USER/Documents")
    
    # Load the tiles in working_folder/mapTiles/OSM/
    library(RgoogleMaps)
    for (zoom in 10:16)
      GetMapTiles("Washington Square Park;NY", zoom = zoom,
                  nTiles = round(c(20,20)/(17-zoom)))
    
    # Start serving working folder on port 8000 in demon mode
    deamon_id <- servr::httd(port = 8000, daemon = TRUE)
    
    # Plot with leaflet
    library(leaflet)
    m = leaflet() %>% 
      addTiles( urlTemplate = "http:/localhost:8000/mapTiles/OSM/{z}_{x}_{y}.png")
    m = m %>% leaflet::setView(-73.99733, 40.73082 , zoom = 16)
    m = m %>% leaflet::addMarkers(-73.99733, 40.73082 )
    m
    
    # Stop serving
    servr::daemon_stop(deamon_id)
    
    0 讨论(0)
提交回复
热议问题