-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
offset cluster ids, add index ids to non cluster points #121
Changes from 4 commits
bf046e1
40d8344
af9610a
c5cdcf0
eda8974
c818706
91137c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,8 +85,7 @@ export default class Supercluster { | |
} | ||
|
||
getChildren(clusterId) { | ||
const originId = clusterId >> 5; | ||
const originZoom = clusterId % 32; | ||
const { originId, originZoom } = this._decodeClusterId(clusterId); | ||
const errorMsg = 'No cluster with the specified id.'; | ||
|
||
const index = this.trees[originZoom]; | ||
|
@@ -151,14 +150,14 @@ export default class Supercluster { | |
} | ||
|
||
getClusterExpansionZoom(clusterId) { | ||
let clusterZoom = (clusterId % 32) - 1; | ||
while (clusterZoom <= this.options.maxZoom) { | ||
let expansionZoom = this._decodeClusterId(clusterId).originZoom - 1; | ||
while (expansionZoom <= this.options.maxZoom) { | ||
const children = this.getChildren(clusterId); | ||
clusterZoom++; | ||
expansionZoom++; | ||
if (children.length !== 1) break; | ||
clusterId = children[0].properties.cluster_id; | ||
} | ||
return clusterZoom; | ||
return expansionZoom; | ||
} | ||
|
||
_appendLeaves(result, clusterId, limit, offset, skipped) { | ||
|
@@ -192,18 +191,30 @@ export default class Supercluster { | |
_addTileFeatures(ids, points, x, y, z2, tile) { | ||
for (const i of ids) { | ||
const c = points[i]; | ||
const isCluster = c.numPoints; | ||
const f = { | ||
type: 1, | ||
geometry: [[ | ||
Math.round(this.options.extent * (c.x * z2 - x)), | ||
Math.round(this.options.extent * (c.y * z2 - y)) | ||
]], | ||
tags: c.numPoints ? getClusterProperties(c) : this.points[c.index].properties | ||
tags: isCluster ? getClusterProperties(c) : this.points[c.index].properties | ||
}; | ||
const id = c.numPoints ? c.id : this.points[c.index].id; | ||
if (id !== undefined) { | ||
f.id = id; | ||
|
||
// assign id | ||
let id; | ||
if (isCluster) { | ||
id = c.id; | ||
} else if (this.options.generateId) { | ||
// optionally generate id | ||
id = c.index; | ||
} else if (this.points[c.index].id) { | ||
// keep id if already assigned | ||
id = this.points[c.index].id; | ||
} | ||
|
||
if (id !== undefined) f.id = id; | ||
|
||
tile.features.push(f); | ||
} | ||
} | ||
|
@@ -234,8 +245,8 @@ export default class Supercluster { | |
|
||
const clusterProperties = reduce ? this._map(p, true) : null; | ||
|
||
// encode both zoom and point index on which the cluster originated | ||
const id = (i << 5) + (zoom + 1); | ||
// encode both zoom and point index on which the cluster originated -- offset by total length of features | ||
const id = (i << 5) + (zoom + 1) + this.points.length; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're changing the meaning of cluster There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok will change now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, updated decoding for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
for (const neighborId of neighborIds) { | ||
const b = tree.points[neighborId]; | ||
|
@@ -266,6 +277,13 @@ export default class Supercluster { | |
return clusters; | ||
} | ||
|
||
_decodeClusterId(clusterId) { | ||
const decremented = clusterId - this.points.length | ||
const originId = decremented >> 5; | ||
const originZoom = decremented % 32; | ||
return { originZoom, originId }; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this the correct decoding @mourner |
||
_map(point, clone) { | ||
if (point.numPoints) { | ||
return clone ? extend({}, point.properties) : point.properties; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mourner ok i
generateId
option (not sure if that is directly avail from the mapbox gl options)generateId
option is false, otherwise we overwrite it -- could see that being reversed