Skip to content

Commit

Permalink
Add clusterMinPoints option for GeoJSONSource (#9748)
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner authored Jun 2, 2020
1 parent d6dddef commit 3ce4e9c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
1 change: 1 addition & 0 deletions src/source/geojson_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/style-spec/reference/v8.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"]]}`"
Expand Down
2 changes: 2 additions & 0 deletions test/unit/source/geojson_source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -190,6 +191,7 @@ test('GeoJSONSource#update', (t) => {
cluster: true,
clusterMaxZoom: 12,
clusterRadius: 100,
clusterMinPoints: 3,
generateId: true
}, mockDispatcher).load();
});
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 3ce4e9c

Please sign in to comment.