mapbox / mapbox/mapbox-gl-js

Enable data-driven expressions for collision properties

Open
#8,454 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

## Motivation

I have a use case for setting collision conditions to larger transit labels but defaulting to defaults for minor ones. Writing a data condition that effect these properties would help a lot:

- `text-allow-overlap`
- `icon-allow-overlap`
- `icon-ignore-placement`
- `text-ignore-placement`
- `text-optional`
- `icon-optional`
- `text-padding`
- `icon-padding`

## Design Alternatives

Creating a new layer to handle overlap properties. When a layer is this long, its a lot to duplicate and keep in sync:

See transit-label layer in Streets v11

```json
{
"id": "transit-label",
"type": "symbol",
"metadata": { "mapbox:featureComponent": "transit-labels", "mapbox:group": "Transit labels" },
"source": "composite",
"source-layer": "transit_stop_label",
"minzoom": 12,
"filter": [
"step",
["zoom"],
[
"all",
["match", ["get", "mode"], ["rail", "metro_rail"], true, false],
["!=", ["get", "stop_type"], "entrance"]
],
15,
[
"all",
["match", ["get", "mode"], ["rail", "metro_rail", "ferry", "light_rail"], true, false],
["!=", ["get", "stop_type"], "entrance"]
],
16,
["all", ["!=", ["get", "mode"], "bus"], ["!=", ["get", "stop_type"], "entrance"]],
17,
["!=", ["get", "stop_type"], "entrance"],
19,
true
],
"layout": {
"text-size": 12,
"icon-image": ["get", "network"],
"text-font": ["DIN Offc Pro Medium", "Arial Unicode MS Regular"],
"text-justify": ["match", ["get", "stop_type"], "entrance", "left", "center"],
"text-offset": [
"match",
["get", "stop_type"],
"entrance",
["literal", [1, 0]],
["literal", [0, 0.8]]
],
"text-anchor": ["match", ["get", "stop_type"], "entrance", "left", "top"],
"text-field": [
"step",
["zoom"],
"",
14,
[
"match",
["get", "mode"],
["rail", "metro_rail"],
["coalesce", ["get", "name_en"], ["get", "name"]],
""
],
16,
[
"match",
["get", "mode"],
["bus", "bicycle"],
"",
["coalesce", ["get", "name_en"], ["get", "name"]]
],
18,
["coalesce", ["get", "name_en"], ["get", "name"]]
],
"text-letter-spacing": 0.01,
"text-max-width": ["match", ["get", "stop_type"], "entrance", 15, 9]
},
"paint": {
"text-halo-color": "hsl(35, 17%, 100%)",
"text-color": [
"match",
["get", "network"],
"tokyo-metro",
"hsl(180, 50%, 30%)",
"mexico-city-metro",
"hsl(25, 100%, 100%)",
["barcelona-metro", "delhi-metro", "hong-kong-mtr", "milan-metro", "osaka-subway"],
"hsl(0, 90%, 47%)",
["boston-t", "washington-metro"],
"hsl(0, 0%, 0%)",
["chongqing-rail-transit", "kiev-metro", "singapore-mrt", "taipei-metro"],
"hsl(140, 90%, 25%)",
"hsl(230, 48%, 44%)"
],
"text-halo-blur": 0.5,
"text-halo-width": 0.5
}
}
```


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

No files, tests, or entry points are named. Start by locating how symbol collision properties are defined and evaluated, then trace existing data-driven expression support. The work is done when expressions are supported and tested for all eight listed properties without requiring a duplicated layer.

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
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.