-
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
Conversation
@@ -235,7 +232,7 @@ 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); | |||
const id = (i << 5) + (zoom + 1) + this.points.length; |
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.
If we're changing the meaning of cluster id
, we should also change how it's decoded in methods like getLeaves
, getChildren
and getClusterExpansionZoom
, otherwise those will break.
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.
ok will change now
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.
Ok, updated decoding for getChildren
and getClusterExpansionZoom
-- I didn't see where it was decoded in the function series starting at getLeaves
, am I missing something?
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.
getLeaves
decodes it through getChildren
so should be good 👍
index.js
Outdated
if (id !== undefined) { | ||
f.id = id; | ||
} | ||
f.id = c.numPoints ? c.id : (this.points[c.index].id || c.index); |
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.
This will break with points that have an id of 0
. Better check for undefined
.
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.
Also, instead of always assigning an id
, I would put this behind an option (e.g. generateIds
), like discussed in #97.
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 how are options linked between mapbox gl and supercluster? does supercluster have access to the same set?
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.
currently the option is actually called generateId
, so I'll put it behind that unless we are going to rename it to generateIds
simultaneously...
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.
We relay the options manually in GL JS. Let's go with generateId
though to be consistent with geojson-vt
which already has that option.
index.js
Outdated
if (id !== undefined) { | ||
f.id = id; | ||
} | ||
f.id = c.numPoints ? c.id : (this.points[c.index].id || c.index); |
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 how are options linked between mapbox gl and supercluster? does supercluster have access to the same set?
index.js
Outdated
if (id !== undefined) { | ||
f.id = id; | ||
} | ||
f.id = c.numPoints ? c.id : (this.points[c.index].id || c.index); |
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.
currently the option is actually called generateId
, so I'll put it behind that unless we are going to rename it to generateIds
simultaneously...
} | ||
|
||
if (id !== undefined) f.id = id; |
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
- put id assignment behind an undef check
- put id generation behind the
generateId
option (not sure if that is directly avail from the mapbox gl options) - persisted already existing ids if the
generateId
option is false, otherwise we overwrite it -- could see that being reversed
@@ -235,7 +232,7 @@ 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); | |||
const id = (i << 5) + (zoom + 1) + this.points.length; |
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.
Ok, updated decoding for getChildren
and getClusterExpansionZoom
-- I didn't see where it was decoded in the function series starting at getLeaves
, am I missing something?
const originZoom = decremented % 32; | ||
return { originZoom, originId }; | ||
} | ||
|
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.
is this the correct decoding @mourner
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.
Thanks for the updates — I'll review this next week! Please remove yarn.lock
in the PR — if we decide to add it, it should be a separate change anyway, not a part of this PR.
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.
Reviewed — this looks good, pending removal of yarn.lock
.
One more stylistic change I'd personally make is break decodeClusterId
into two methods so that we don't have to allocate a temporary object on calls to it (e.g. replace with _getOriginId(clusterId)
and _getOriginZoom(clusterId)
), but it probably doesn't make much difference.
@ChiefKleef hey, would you mind doing a final pass before I merge? |
This is a blocker for me. I'm going to fork and apply these changes, but it'd be nice to get this merged. |
@mourner Are the changes suggested in #121 (review) required before this can merge? |
@asheemmamoowala yes, pending removal of |
@ChiefKleef , this is ready to merge except the removal of the |
Here is my interpretation of the discussion here
I am unsure how to regenerate test data to fix the tests, can someone point me in the right direction? Is it a manual process?
I originally opened this bug, as I was using
cluster = true
andgenerateId = true
for my source specification. In this case, only the cluster points have ids, which breaks the use of setFeatureState per usual.Closes #97.