离线R地图与RggogleMap和Leaflet

时间:2017-08-02 18:55:09

标签: r maps leaflet offline rgooglemaps

我正试图在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)

Hovever,当我在地图上放大/缩小时,灰色瓷砖出现在他们之前的地方:

This zoomed in image shows a grey tile over toronto

但是,

This more zoomed-out image shows toronto

关于什么是错误的任何想法? 谢谢!

1 个答案:

答案 0 :(得分:1)

nTiles = round(c(20,20)/(17-zoom)) 该声明将无法始终如一地工作。如果要获取加拿大地图,可以不用指定nTiles,而是可以这样指定边界:lonR = c(-142,-52),latR = c(41,84)