按点值绘制的Mapbox热图

SER*_*ERG 5 mapbox mapbox-gl mapbox-gl-js

有一个热图示例https://www.mapbox.com/mapbox-gl-js/example/heatmap/,显示的是区域上标记/点的数量。但是,有没有一种方法可以通过平均引脚/标记值显示热图?例如,如果我有5个引脚,并且其平均道具价值速度= 3,那么它将显示为绿色簇/热图,并且如果它们是av。prop val是6,那么它将是红色的群集/热图。

我发现“ clusterAggregates”属性可以提供帮助,但是找不到使用它的任何示例。

谢谢

Rom*_*ere 1

我会留下我的方式这样做。老问题,有时会出现,但没有很好的解决方案,所以......Turf的hexgrid(http://turfjs.org/docs/#hexGrid)可以提供帮助:

const hexagons = hexGrid(bbox, size);
const collection = // collection of your points;

const hexagonsWithin = collect(hexagons, collection, "propertyToAgretateFrom", "propertyToAggregateIn");
const notEmptyHexagonValues = hexagonsWithin.features.filter(({ properties }) => properties.propertyToAggregateIn.length !== 0);
const notEmptyHexagons = {
    "type": "FeatureCollection",
    "features": notEmptyHexagonValues,
};
// at this point you're having not empty hexagons as a geojson, which you can add to the map
Run Code Online (Sandbox Code Playgroud)

collect是来自 turf 的另一种方法,collection您可以在文档中查找应该是什么,因为它变化很大。

背后的总体思想是bbox通过方法将地图()的可见部分“划分”为六边形hexGrid,并将每个六边形内的每个标记所需的一些属性聚合到数组中,这样您就可以获得平均值,例如。并根据它分配颜色。

假设feature.properties.propertyToAgretateFrom两个标记中有 4 和 5。聚合后,如果这些标记位于一个多边形内,您就会拥有它feature.properties.propertyToAggregateIn: [4, 5]- 此功能是多边形。从现在开始你几乎可以做任何你想做的事情。