【问题标题】:Mapbox: Update custom layer paint propertyMapbox:更新自定义图层绘制属性
【发布时间】:2021-06-17 08:31:34
【问题描述】:

在一个 mapbox 项目上工作。我创建了一个自定义图层,并希望更新该图层的绘制属性。我试过的方法不起作用。以下是详细信息:

我创建的层:

map.addLayer({
        id: 'points-circle',
        source: 'points',
        type: 'circle',
        paint: {
          'circle-radius': pointSize*.6,
          'circle-color': {type: 'identity', property: 'color'},
        }
      })

稍后,我尝试更新circle-radius 属性,如下所示:

map.setPaintProperty('points-circle','circle-radius', pointSize*.6)

失败并出现错误:Error: The layer 'points-circle' does not exist in the map's style and cannot be styled. 如何更新自定义添加层的圆半径?

【问题讨论】:

  • map和this._map一样吗?
  • @AndrewHarvey 我更新了问题以消除这种混乱。
  • @astrojams1 给我们看一个最小的例子。作为一个选项 - 在 jsfiddle 上。
  • 如果您收到消息Error: The layer 'points-circle' does not exist in the map's style and cannot be styled.,那么在addLayer 步骤中出现了问题。你需要先解决这个问题。

标签: mapbox mapbox-gl-js


【解决方案1】:

您可能需要等待地图idle 事件触发才能知道图层已准备好进行样式设置。见https://docs.mapbox.com/mapbox-gl-js/api/map/#map.event:idle

如果map.addLayer 返回一个承诺,该承诺在图层能够设置样式时解决...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-26
    • 1970-01-01
    • 1970-01-01
    • 2020-09-07
    • 2018-01-02
    • 1970-01-01
    相关资源
    最近更新 更多