我正在使用Mabpox-gl-js v0.45对集群进行测试。
我想要自定义我的集群属性(实际默认值为point_count和point_count_abbreviated)。 每个点(每个城市一个)都有一个面积属性(整数),我希望在聚类时对这些点进行求和。
我在mapbox的源代码中看到了引用reduce函数来计算自定义属性的内容:
SuperCluster.prototype = {
options: {
minZoom: 0, // min zoom to generate clusters on
// .....
log: false, // whether to log timing info
// a reduce function for calculating custom cluster properties
reduce: null, // function (accumulated, props) { accumulated.sum += props.sum; }
// initial properties of a cluster (before running the reducer)
initial: function () { return {}; }, // function () { return {sum: 0}; },
// properties to use for individual points when running the reducer
map: function (props) { return props; } // function (props) { return {sum: props.my_value}; },
},
但我在文档中没有看到任何关于此的提及。如何设置这些选项?
Mapbox似乎没有发布这些接口(请参阅群集文档),并且在提供的示例中也没有提到:
map.addSource("earthquakes", {
type: "geojson",
// Point to GeoJSON data. This example visualizes all M1.0+ earthquakes
// from 12/22/15 to 1/21/16 as logged by USGS' Earthquake hazards program.
data: "/mapbox-gl-js/assets/earthquakes.geojson",
cluster: true,
clusterMaxZoom: 14, // Max zoom to cluster points on
clusterRadius: 50 // Radius of each cluster when clustering points (defaults to 50)
});