mapbox / mapbox-gl-js

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
https://docs.mapbox.com/mapbox-gl-js/
Other
11.2k stars 2.22k forks source link

Support `line-progress` for `line-offset` property #12729

Open chuhlomin opened 1 year ago

chuhlomin commented 1 year ago

Motivation

I'm trying to draw a subway map: lines are getting together in bunches and branch off. For example, here C-line (blue) and G-line (ligh-green) branch off:

Screenshot 2023-05-28 at 23 37 11

While they are in bunch, I use line-pattern:

mta_subway_pattern-GA

But then, I need to make a smooth transition from a pattern to 2 separate lines, which then would be centered normally.

More complicated example where one bunch branches of into 2 other bunches:

Screenshot 2023-05-28 at 23 54 22

Design Alternatives

Split line into smaller chunks, assign an offset property to each segment separately.

"line-offset": [
  "case",
  ["has", "offset"],
  ["to-number", ["get", "offset"]],
  0
]

There is a visible staircase effect when number of segments is low, especially on a small zoom:

Screenshot 2023-05-28 at 23 48 02

Design

Ideally, I will need to set something like this:

"line_offset": [
  "interpolate",
  ["linear"],
  ["line-progress"],
  0, 2.5, // where 2.5 is some magic number for when line is in a bunch
  1, 0
]

Unfortunately, line-progress can only be used in the line-gradient property.
https://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/#line-progress

I wonder how feasible it is to implement it for line-offset as well. Or, perhaps, there are better ways to solve my problem.

chuhlomin commented 1 year ago

Related issue: #10374

MateiAnton commented 11 months ago

Any plans to implement this soon? I need it for my project. The workaround doesn't do it for me as I have situations where the offset between the ends of a segment has different values.