mapbox / mapbox/mapbox-gl-js

Best option for preventing labels from touching edge of map

Open
#6,432 14 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hello!

I am trying to prevent map labels from getting placed such that they get cut off from the edge of the map for my project (IRLMap.com). In the screenshot below, I show examples of labels that are getting cut off marked with 🚫.

My first idea was to create a rectangular polygon at the perimeter of my map, but doing so did not appear to shift the underlying labels. My second idea comes from the insight that I notice my points DO shift underlying labels out of the way: add a series of invisible points at the perimeter of the map, but this feels hacky and strange.

What is the best approach for preventing labels from touching the edge of my map?

screen shot 2018-03-30 at 6 15 06 pm

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 by reproducing the label-placement examples shown in the linked screenshot and compare the behavior of perimeter polygons with invisible perimeter points. Done should be a documented, supported approach for preventing labels from being clipped at the map edge, with the result reflected in the issue or an accompanying test.

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.