R Leaflet Offline Cards Not Loading

I need help trying to figure out why my map flyer using locally saved map fragments is not working correctly. I am trying to recreate the example from here to create an elevator map based on persisting local map fragments. However, when I create it, the background map tiles are not loaded.

The code I have is mostly straight from the example, but updated for my directory and updated to start a local server. I'm not sure if I'm trying to start the server incorrectly. I also look here for instructions on how to start a local server using servr

.

library(RgoogleMaps)
for (zoom in 10:16)
GetMapTiles("Washington Square Park;NY", zoom = zoom,
          nTiles = round(c(20,20)/(17-zoom)))

library(leaflet)
setwd("C:/Users/OTAD USER/Documents")
system("Rscript -e 'servr::httd()' -p8000")
m = leaflet() %>% 
    addTiles( urlTemplate = "http:/localhost:8000/mapTiles/OSM/{z}_{x}_{y}.png")
m = m %>% setView(-73.99733, 40.73082 , zoom = 13)
m = m %>% addMarkers(-73.99733, 40.73082 )
m

      

+2


source to share


1 answer


You were almost there. You can start the server in mode daemon

withservr::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)

      

+4


source







All Articles