diff --git a/package.json b/package.json index 13853ae7b1c..5e2c705bddd 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "quickselect": "^3.0.0", "rw": "^1.3.3", "serialize-to-js": "^3.1.2", - "supercluster": "^8.0.1", + "supercluster": "andrewharvey/supercluster#244", "tinyqueue": "^3.0.0", "tweakpane": "^4.0.4", "vt-pbf": "^3.1.3" diff --git a/src/source/geojson_source.ts b/src/source/geojson_source.ts index 4a70d00be6c..ab31324f5b4 100644 --- a/src/source/geojson_source.ts +++ b/src/source/geojson_source.ts @@ -156,7 +156,8 @@ class GeoJSONSource extends Evented implements ISource { extent: EXTENT, radius: (options.clusterRadius !== undefined ? options.clusterRadius : 50) * scale, log: false, - generateId: options.generateId || false + generateId: options.generateId || false, + arrayType: options.clusterArrayType || 'Float32Array' }, clusterProperties: options.clusterProperties, filter: options.filter, diff --git a/src/source/geojson_worker_source.ts b/src/source/geojson_worker_source.ts index f4fc1df9c25..b0ffc3584ec 100644 --- a/src/source/geojson_worker_source.ts +++ b/src/source/geojson_worker_source.ts @@ -321,6 +321,12 @@ function getSuperclusterOptions({ } }; + // convert String option value into a TypedArray constructor + const arrayTypes = { + Float32Array, Float64Array + }; + superclusterOptions.arrayType = arrayTypes[superclusterOptions.arrayType]; + return superclusterOptions; } diff --git a/src/style-spec/reference/v8.json b/src/style-spec/reference/v8.json index 66d109fda47..e5c815a09dd 100644 --- a/src/style-spec/reference/v8.json +++ b/src/style-spec/reference/v8.json @@ -1005,6 +1005,19 @@ "type": "*", "doc": "An object defining custom properties on the generated clusters if clustering is enabled, aggregating values from clustered points. Has the form `{\"property_name\": [operator, map_expression]}`. `operator` is any expression function that accepts at least 2 operands (e.g. `\"+\"` or `\"max\"`) — it accumulates the property value from clusters/points the cluster contains; `map_expression` produces the value of a single point.\n\nExample: `{\"sum\": [\"+\", [\"get\", \"scalerank\"]]}`.\n\nFor more advanced use cases, in place of `operator`, you can use a custom reduce expression that references a special `[\"accumulated\"]` value, e.g.:\n`{\"sum\": [[\"+\", [\"accumulated\"], [\"get\", \"sum\"]], [\"get\", \"scalerank\"]]}`" }, + "clusterArrayType": { + "type": "enum", + "default": "Float32Array", + "values": { + "Float32Array": { + "doc": "A Float32Array" + }, + "Float64Array": { + "doc": "A Float64Array" + } + }, + "doc": "TypedArray to use for clustering, for clusterMaxZoom values and lower clusterRadius values you may need to increase this to Float64Array for more accurate clusters." + }, "lineMetrics": { "type": "boolean", "default": false, diff --git a/src/style-spec/types.ts b/src/style-spec/types.ts index e8aaaa82981..1eb6c55cc5c 100644 --- a/src/style-spec/types.ts +++ b/src/style-spec/types.ts @@ -255,6 +255,7 @@ export type GeoJSONSourceSpecification = { "clusterMaxZoom"?: number, "clusterMinPoints"?: number, "clusterProperties"?: unknown, + "clusterArrayType"?: "Float32Array" | "Float64Array", "lineMetrics"?: boolean, "generateId"?: boolean, "promoteId"?: PromoteIdSpecification,