You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用R的mapdeck包加载自定义Mapbox样式时底图不显示

自定义Mapbox样式在mapdeck中无法显示底图

使用mapdeck包加载自定义Mapbox样式作为底图时,数据层可正常显示,但底图在R Studio viewer及各类浏览器中均无法加载。已持有有效的Mapbox token,使用官方标准Mapbox样式模板时代码可正常运行,求排查方向。

运行环境与代码

Mac系统,R Studio中运行,私有信息已替换:

library(mapdeck)

# 加载CSV数据 ----------
# {my_data}

# 加载Mapbox token ----------
key <- "{my_token}"

# 绘制地图 ----------
mapdeck(token = key, style = "mapbox://styles/{my_user_name}/{my_styleID}", pitch = 70) %>% 
  add_arc(
    data = sites
    , layer_id = "arc_layer"
    , origin = c("site_lon", "site_lat")
    , destination = c("lab_lon", "lab_lat")
    , stroke_from = "site"
    , stroke_to = "lab"
  ) %>%
  add_scatterplot(
    data = labs_active
    , layer_id = "scatter"
    , lon = "lon"
    , lat = "lat"
    , radius = 120
    , fill_colour = "status"
  )

Safari浏览器控制台报错信息

  • Error: layers[39].filter[3][1][0]: Unknown expression "pitch". If you wanted a literal array, use ["literal", [...]].
  • message: "undefined is not an object (evaluating 'r.familiesBySource[this.source]')"
  • constructor: function()
  • _classRegistryKey: "Error"
  • arguments: TypeError: 'arguments', 'callee', and 'caller' cannot be accessed in this context.
  • caller: TypeError: 'arguments', 'callee', and 'caller' cannot be accessed in this context
  • [Warning] WebGL: non-portable extension enabled: WEBGL_polygon_mode

排查方案

  1. 修复样式表达式兼容性
    控制台报错明确指向pitch表达式不被识别,说明自定义样式中使用了mapdeck底层不支持的Mapbox样式语法。检查样式中所有涉及pitch的过滤规则,要么改用["literal", [...]]包裹数组字面量,要么将样式规范版本降级到v11(mapdeck对该版本兼容性更稳定)。
  2. 验证样式权限与路径
    确认mapbox://styles/{my_user_name}/{my_styleID}路径完全正确,自定义样式若为私有,需确保你的Mapbox token拥有该样式的访问权限(可在Mapbox控制台检查token的权限范围)。
  3. 更新mapdeck包
    旧版本mapdeck对自定义Mapbox样式的支持存在bug,执行install.packages("mapdeck")更新到最新版本后重试。
  4. 排除WebGL干扰
    虽然WebGL警告不是直接原因,但可尝试在浏览器设置中禁用非标准WebGL扩展,或更换Chrome/Edge浏览器测试。

内容的提问来源于stack exchange,提问作者user47014

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 10:11:20