如何在mapbox-gl中使用clusterProperties

问题描述 投票:0回答:1

我构建了一个mapbox-gl js(v0.52)映射,其中点聚合成簇;很像在mapbox页面的clusters example

簇颜色需要是各个点属性聚合的函数:为简单起见,假设每个点都有一个status属性,它决定了它的颜色,簇的颜色应该只是对应于每个点的max的颜色。它的点'status值。

示例geojson数据如下所示:

const geoData = {
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      properties: {
        id: 'fakeid11',
        status: 20,
      },
      geometry: {
        type: 'Point',
        coordinates: [-151.5129, 63.1016, 0]
      }
    },
    {
      type: 'Feature',
      properties: {
        id: 'fakeid22',
        status: 10,
      },
      geometry: {
        type: 'Point',
        coordinates: [-150.4048, 63.1224, 105.5]
      }
    }
  ]
};

我正在尝试使用clusterProperties计算聚合为described in the api docs,类似于this example from the source code,以创建此层:

map.addSource('earthquakes', {
  type: 'geojson',
  data: geoData,
  cluster: true,
  clusterMaxZoom: 14, // Max zoom to cluster points on
  clusterRadius: 50, // Radius of each cluster when clustering points (defaults to 50)
  clusterProperties: {
    status: ['max', ['get', 'status']]
  }
});

这个片段与mapbox页面中的cluster示例完全相同,只是用静态双元素副本替换数据,然后添加clusterProperties

但是这会抛出一个验证错误(从缩小的mapbox-gl版本中有点破坏):

Error: sources.earthquakes: unknown property "clusterProperties"
    at Object.Jr [as emitValidationErrors] (modules.js?hash=34588b9e7240c1a9b3fd2f8685e299d9dbbb40d9:504146)
    at De (modules.js?hash=34588b9e7240c1a9b3fd2f8685e299d9dbbb40d9:504150)
    at i._validate (modules.js?hash=34588b9e7240c1a9b3fd2f8685e299d9dbbb40d9:504150)

这个clusterProperties用法有什么问题?它似乎只是拒绝验证此属性。请注意,如果我评论设置它的最后3行,那么地图工作正常(当然没有status聚合属性)。

mapbox-gl-js mapbox-gl
1个回答
0
投票

几天后我找到了答案:我们使用的react-map-gl的版本依赖于mapbox-gl ~0.52.0,它还没有支持clusterProperties。 mapbox-gl 0.53支持这些聚合属性。 (并且由于反应包装器使用mapbox-gl的未记录的功能,它们依赖于补丁级别的确切版本)。这是confirmed by the react library developers

现在react-map-gl 4.0.14已经发布,并且可以使用clusterProperties,使用内部mapbox-gl 0.53.0。

© www.soinside.com 2019 - 2024. All rights reserved.