Clustering with option minPoints 1
With option minPoints: 1, my assumption would be that a cluster could exist with 1 point in the cluster area, but since minPoints is 1, it would have zero neighbors.
Including another if (!clusterProperties) clusterProperties = this._map(p, true); after the for loop solves this by setting the clusterProperties when no neighbors are found.
Fork with change: https://github.com/michaelfarrelly/supercluster/commit/3dbbc52fc0c7bb8a20cc52ac338f74b3c4ddfca0
If this against the purpose of this property, then I can revoke this request. My projects goal was to have clustering only (no points) when zoomed out.
https://github.com/mapbox/supercluster/blob/main/index.js#L266-L282
for (const neighborId of neighborIds) {
const b = tree.points[neighborId];
if (b.zoom <= zoom) continue;
b.zoom = zoom; // save the zoom (so it doesn't get processed twice)
const numPoints2 = b.numPoints || 1;
wx += b.x * numPoints2; // accumulate coordinates for calculating weighted center
wy += b.y * numPoints2;
b.parentId = id;
if (reduce) {
if (!clusterProperties) clusterProperties = this._map(p, true);
reduce(clusterProperties, this._map(b));
}
}
=>
for (const neighborId of neighborIds) {
const b = tree.points[neighborId];
if (b.zoom <= zoom) continue;
b.zoom = zoom; // save the zoom (so it doesn't get processed twice)
const numPoints2 = b.numPoints || 1;
wx += b.x * numPoints2; // accumulate coordinates for calculating weighted center
wy += b.y * numPoints2;
b.parentId = id;
if (reduce) {
if (!clusterProperties) clusterProperties = this._map(p, true);
reduce(clusterProperties, this._map(b));
}
}
if (!clusterProperties) clusterProperties = this._map(p, true);
Hi!
We encounter the same situation on my project. It would be nice if we you can support this case 🙏
Hi. We encountered the same situation too. Would be great to be able to set minPoints with 1 so that everything shown on the map is a cluster. The markers will be shown when the user zooms in, based on the maxZoom option which will disable clustering.
Encountered same situation BUT :
My opinion is that the minPointspurpose is different from the clusterOnly purpose where the getClustersmethod should only return clusters.
The goal of the minPoints options is to define the minimum of points to be able to create a Cluster. Whereas a clusterOnly options would force the algorithm to return clusters.
IMO Both parameters could be used, for ex to have clusters with a minPoints = 3 and clustersOnly = truewhere it would form normal clusters of 3 points minimum, and the other points would be clusterized in clusters of 1 point.
Same for me. clusterOnly can be a good property to have a proper display with clusters only.
Any reference/example on how this be achieved?
@spaceod something like this ?
const supercluster = new Supercluster({
minPoints: 1,
minZoom: 1,
radius: 150,
}).load();
...
supercluster
.getClusters([-180, -85, 180, 85], zoomLevel)
.filter((c) => c.properties.cluster === true);
Encountered the same situation. Intuitively used minPoints: 1 but it didn't work