mapbox / mapbox/mapbox-gl-js

Look up clusterId based on id of leaf node

Open
#11,322 0 comments 0 reactions 1 assignee View on GitHub

@mourner is already working on this.

Since Dec 2, 2021.

feature :green_apple:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

Motivation

We have a hovered id that updates whenever a user hovers over an item in the DOM, and want to update the feature state when this happens.

The source also happens to be clustered, so we'd like to be able to change the feature state of the clusterId if any of its leaves are the hovered id.

I'd like to propose an API method on a GeoJSON source that given the ID of a leaf, returns any clusterIds the leaf may be a part of at different zooms.

The user could also specify a target zoom here, either option works really.

Design Alternatives

This is a nice to have for our application, so "do nothing" is an option, but I could see this being useful in ways that were less trivial than hover states.

Design

It seems possible to do this by traversing the parentId for the leaf in supercluster, so the function could just return a list of parentIds.

If we decided to do a zoom option, the function could just return the parentId of the cluster at that zoom.

Mock-Up

Option A:

const parents = source.getClusterLeafParentIds("abc");
// parents = [43,56,44,...]

Option B:

const parent = source.getClusterLeafParent("abc", 12);
// parent = 43
Concepts
Implementation

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.