【问题标题】:Offline R map with RggogleMap and Leaflet带有 RggogleMap 和 Leaflet 的离线 R 地图
【发布时间】:2018-01-10 03:42:42
【问题描述】:

我正在尝试在 R 中创建加拿大的交互式离线地图 经过一番搜索,RgoogleMaps 和 Leaflet 似乎是最好的选择。我按照这里的代码:R Leaflet Offline Map Tiles Not Loading

这是我的代码:

setwd("C:/Users/user/Documents")
library(servr)
library(RgoogleMaps)

# Load the tiles in working_folder/mapTiles/OSM/
for (zoom in 2:13)
  GetMapTiles("Canada", 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/OMS/{z}_{x}_{y}.png")
m = m %>% leaflet::setView(-76, 45 , zoom = 5)
m = m %>% leaflet::addMarkers(-76, 45 )
m

# Stop serving
servr::daemon_stop(deamon_id)

但是,当我在地图上放大/缩小时,灰色图块出现在以前没有的地方:

This zoomed in image shows a grey tile over toronto

但是,

This more zoomed-out image shows toronto

对出了什么问题有任何想法吗? 谢谢!

【问题讨论】:

    标签: r maps leaflet offline rgooglemaps


    【解决方案1】:

    nTiles = round(c(20,20)/(17-zoom)) 该声明不会始终如一地工作。如果你想得到加拿大的地图,而不是指定nTiles,你可以像这样指定边界:lonR = c(-142,-52),latR = c(41,84)

    【讨论】:

    • 您能否将我的答案标记为正确?这是我的第一个答案:)
    猜你喜欢
    • 1970-01-01
    • 2017-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-06
    相关资源
    最近更新 更多