Skip to content
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

Merged
merged 7 commits into from
Nov 5, 2019

Conversation

clif-os
Copy link
Contributor

@clif-os clif-os commented May 7, 2019

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 and generateId = true for my source specification. In this case, only the cluster points have ids, which breaks the use of setFeatureState per usual.

Closes #97.

@clif-os clif-os changed the title offset cluster ids by features.length, provide features index ids offset cluster ids, add index ids to non cluster points May 7, 2019
@@ -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;
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok will change now

Copy link
Contributor Author

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?

Copy link
Member

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);
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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...

Copy link
Member

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);
Copy link
Contributor Author

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);
Copy link
Contributor Author

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;
Copy link
Contributor Author

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;
Copy link
Contributor Author

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 };
}

Copy link
Contributor Author

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

Copy link
Member

@mourner mourner left a 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.

Copy link
Member

@mourner mourner left a 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.

@mourner
Copy link
Member

mourner commented Jun 24, 2019

@ChiefKleef hey, would you mind doing a final pass before I merge?

@robyoder
Copy link

This is a blocker for me. I'm going to fork and apply these changes, but it'd be nice to get this merged.

@asheemmamoowala
Copy link
Contributor

@mourner Are the changes suggested in #121 (review) required before this can merge?

@mourner
Copy link
Member

mourner commented Aug 29, 2019

@asheemmamoowala yes, pending removal of yarn.lock.

@asheemmamoowala
Copy link
Contributor

@ChiefKleef , this is ready to merge except the removal of the yarn.lock file as mentioned above #121 (comment)

@mourner mourner merged commit 1f984c3 into mapbox:master Nov 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to Generate IDs for input features
4 participants