diff --git a/package.json b/package.json index 092d5c79ed1..88cc8960808 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "potpack": "^1.0.1", "quickselect": "^2.0.0", "rw": "^1.3.3", - "supercluster": "^7.0.0", + "supercluster": "^7.1.0", "tinyqueue": "^2.0.3", "vt-pbf": "^3.1.1" }, diff --git a/src/source/geojson_source.js b/src/source/geojson_source.js index 67cfab6f8a8..6bfc40b0cef 100644 --- a/src/source/geojson_source.js +++ b/src/source/geojson_source.js @@ -138,6 +138,7 @@ class GeoJSONSource extends Evented implements Source { maxZoom: options.clusterMaxZoom !== undefined ? Math.min(options.clusterMaxZoom, this.maxzoom - 1) : (this.maxzoom - 1), + minPoints: Math.max(2, options.clusterMinPoints || 2), extent: EXTENT, radius: (options.clusterRadius || 50) * scale, log: false, diff --git a/src/style-spec/reference/v8.json b/src/style-spec/reference/v8.json index dc09427c641..e713ee924e5 100644 --- a/src/style-spec/reference/v8.json +++ b/src/style-spec/reference/v8.json @@ -377,6 +377,10 @@ "type": "number", "doc": "Max zoom on which to cluster points if clustering is enabled. Defaults to one zoom less than maxzoom (so that last zoom features are not clustered)." }, + "clusterMinPoints": { + "type": "number", + "doc": "Minimum number of points necessary to form a cluster if clustering is enabled. Defaults to `2`." + }, "clusterProperties": { "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\"]]}`" diff --git a/test/unit/source/geojson_source.test.js b/test/unit/source/geojson_source.test.js index ee672172ae5..ba8328460a3 100644 --- a/test/unit/source/geojson_source.test.js +++ b/test/unit/source/geojson_source.test.js @@ -176,6 +176,7 @@ test('GeoJSONSource#update', (t) => { t.equal(message, 'geojson.loadData'); t.deepEqual(params.superclusterOptions, { maxZoom: 12, + minPoints: 3, extent: 8192, radius: 1600, log: false, @@ -190,6 +191,7 @@ test('GeoJSONSource#update', (t) => { cluster: true, clusterMaxZoom: 12, clusterRadius: 100, + clusterMinPoints: 3, generateId: true }, mockDispatcher).load(); }); diff --git a/yarn.lock b/yarn.lock index 9d306d9edeb..e15ae38e4c4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10299,10 +10299,10 @@ sugarss@^2.0.0: dependencies: postcss "^7.0.2" -supercluster@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/supercluster/-/supercluster-7.0.0.tgz#75d474fafb0a055db552ed7bd7bbda583f6ab321" - integrity sha512-8VuHI8ynylYQj7Qf6PBMWy1PdgsnBiIxujOgc9Z83QvJ8ualIYWNx2iMKyKeC4DZI5ntD9tz/CIwwZvIelixsA== +supercluster@^7.1.0: + version "7.1.0" + resolved "https://registry.yarnpkg.com/supercluster/-/supercluster-7.1.0.tgz#f0a457426ec0ab95d69c5f03b51e049774b94479" + integrity sha512-LDasImUAFMhTqhK+cUXfy9C2KTUqJ3gucLjmNLNFmKWOnDUBxLFLH9oKuXOTCLveecmxh8fbk8kgh6Q0gsfe2w== dependencies: kdbush "^3.0.0"