mapbox / mapbox/mapbox-gl-js

Display dynamic symbol label with viewport

Open
#12,797 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

## Motivation

When adding a symbol label the label is by default in the center of the layer polygon but not each time in the viewport of the user. Is a function or an option could dynamically change the "point" coordinates" to match the part of the polygon which is display on the map?

I try to find something but I only found a old post from 2018 https://medium.com/@yixu0215/dynamic-label-placement-with-mapbox-gl-js-turf-polylabel-1f84f1d4bf6b talking about this dynamic feature.

### Mock-Up

with a label
![Screenshot 2023-07-16 at 16 07 43](https://github.com/mapbox/mapbox-gl-js/assets/642545/76e2e1ab-571a-48d8-98d5-937eaeb47ca2)

And when the user zoom in the map the label is not visible:
![Screenshot 2023-07-16 at 16 07 53](https://github.com/mapbox/mapbox-gl-js/assets/642545/fa12faa6-224e-46f8-82c0-51115397c010)

### Implementation

Can it be an option in the addLayer?

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

The issue names addLayer, symbol labels, and viewport-based placement but no source files or tests. Start by tracing symbol-layer label placement and how viewport changes are handled; done would require a defined option or behavior that keeps the label visible in the displayed part of the polygon.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.