我需要帮助才能弄清楚为什么使用本地保存的地图图块的传单地图不能正常工作。我试图从here重新创建示例,以根据本地保存的地图图块创建传单地图。但是,当我创建它时,背景地图图块不会加载。
我的代码基本上是直接来自示例,但更新了我的目录,并更新以启动我的本地服务器。我不确定我是否试图将服务器启动错误。我还要查看here有关如何使用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
答案 0 :(得分:5)
你快到了。您可以daemon
模式运行服务器,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)