1

我正在尝试重现此示例:https ://github.com/SymbolixAU/mapdeck ,使用 mapdeck r 包。

我在 mapbox 网站上注册了自己并创建了我的令牌。每当我运行我的脚本时,都没有错误,但也没有地图。

library(mapdeck)
library(leaflet)

key <- set_token("pk.eyJ1IjoicmFxdWVsc2FyYWl2YTE5ODgiLCJhIjoiY2p4MzM2eHh5MG95aTN5cDQxdjVocDlxMCJ9.Wskus8QqYwjAufGpW71OVg")

df <- readRDS("df.rds")

df$Station_Long = as.numeric(as.character(df$lon_Pay))
df$Station_Lat = as.numeric(as.character(df$lat_Pay))
df$id = as.factor(as.numeric(as.factor(df$ID)))

mapdeck(
  token = key,
  style = mapdeck_style('dark')
  , location = c(104, 1)
  , zoom = 8
  , pitch = 45
) %>%
  add_arc(
    data = df
    , origin = c("centroid_lon", "centroid_lat")
    , destination = c("lon_Pay", "lat_Pay")
    , layer_id = 'arclayer'
    , stroke_width = 3
    , stroke_from = "#ccffff"
    , stroke_to = "#ccffff"
  )

我的密钥是 NULL(空)。

有谁知道为什么会这样?

4

1 回答 1

1

如果你使用set_token()你不将它分配给一个变量,你只需调用它。

library(mapdeck)

set_token( "YOUR_MAPOBX_TOKEN" )

然后将其全局存储在您的会话中

## view your token
mapdeck_tokens()

# Mapdeck tokens
# -  mapbox : YOUR_MAPBOX_TOKEN

使用set_token()意味着您不必在调用中提供token参数mapdeck()

url <- 'https://raw.githubusercontent.com/plotly/datasets/master/2011_february_aa_flight_paths.csv'
flights <- read.csv(url)
flights$id <- seq_len(nrow(flights))
flights$stroke <- sample(1:3, size = nrow(flights), replace = T)
flights$info <- paste0("<b>",flights$airport1, " - ", flights$airport2, "</b>")

mapdeck( style = mapdeck_style("dark"), pitch = 45 ) %>%
  add_arc(
    data = flights
    , layer_id = "arc_layer"
    , origin = c("start_lon", "start_lat")
    , destination = c("end_lon", "end_lat")
    , stroke_from = "airport1"
    , stroke_to = "airport2"
    , stroke_width = "stroke"
    , tooltip = "info"
    , auto_highlight = TRUE
    , legend = T
    , legend_options = list(
      stroke_from = list( title = "Origin airport" ),
      css = "max-height: 100px;")
   )

在此处输入图像描述

于 2019-06-19T22:06:11.367 回答