R Leaflet 离线地图图块未加载 [英] R Leaflet Offline Map Tiles Not Loading

查看:90
本文介绍了R Leaflet 离线地图图块未加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助来弄清楚为什么使用本地保存的地图图块的传单地图无法正常工作.我正在尝试从 here 重新创建示例根据本地保存的地图图块创建传单地图.但是,当我创建它时,背景地图图块不会加载.

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 map based on map tiles saved locally. However, when I create it the background map tiles don't load.

我的代码基本上直接来自示例,但针对我的目录进行了更新,并更新为启动我的本地服务器.我不确定我是否尝试错误地启动服务器.我也在 here 寻找如何使用 servr 启动本地服务器的说明代码>.

The code I have is basically straight from the example, but updated for my directory, and updated to start my local server. I'm not sure if I'm trying to start the server wrong. I'm also looking here for instructions on how to start the 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

推荐答案

你快到了.您可以在 daemon 模式下运行服务器,使用 servr::httd(port = 8000, daemon = TRUE):

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)

这篇关于R Leaflet 离线地图图块未加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆