mapbox / mapbox/mapbox-gl-js

How to know the coordinates of a rendered road label

Open
#10,773 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hi, I'm trying to figure out if there's a way to know the exact coordinates of a rendered road label.

By calling `queryRenderedFeatures` and filtering only by labels, I am able to get all the features matching to the rendered road labels, but when accessing a feature's coordinates (.geometry.coordinates) I get an array of arrays, not just a single set of coordinates. This array appears to contain all the possible coordinates that a certain label might be rendered at by mapbox (I guess depending on collision, zoom, etc), but I can't figure out a way to know with certainty which set of coordinates in the `coordinates` array is the correct one for the label that mapbox has actually rendered.

For example, if a label can be placed in 3 different coordinate sets, we know which these are, but we don't know which set is actually being used.

Is there a way to find out?

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.

Research direction

Start with the queryRenderedFeatures entry point and inspect how filtered road-label features expose feature.geometry.coordinates. Determine whether the rendered placement is available through the current API or rendering state. Done means providing a supported way to identify the active label coordinates, or clearly documenting that the API cannot expose them.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
computer-graphics, frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.