Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webgl / add styling options for lines: joins, caps, offset, dash #15058

Merged
merged 7 commits into from
Sep 2, 2023

Conversation

jahow
Copy link
Contributor

@jahow jahow commented Aug 29, 2023

This PR adds support for the following styling options:

  • stroke-line-cap: this can be either square, butt or round
  • stroke-line-join: this can be either bevel, miter or round
  • stroke-offset: this property works like the line-offset property from the MapLibre spec
  • stroke-miter-limit: miter ratio limit
  • stroke-line-dash: this can be an array of expressions; currently the size of the array cannot be the result of an expression
  • stroke-line-dash-offset: dash array offset in px

Most of these properties work exactly like their counterpart from the Canvas renderer. The offset property is not available in canvas yet though.

I've also added an example to try out different combinations:

https://deploy-preview-15058--ol-site.netlify.app/en/latest/examples/webgl-draw-line.html

image

Note: this PR also fixes a bug where the width of the stroke on screen used to be multiplied by 2 by mistake.

To do:

  • add rendering tests

@github-actions
Copy link

📦 Preview the website for this branch here: https://deploy-preview-15058--ol-site.netlify.app/.

@tschaub
Copy link
Member

tschaub commented Aug 30, 2023

Wow. Nice work. Will review more thoroughly later. Looks like line-cap may only apply to the end of the line. Is that intentional?

@jahow
Copy link
Contributor Author

jahow commented Aug 30, 2023

Looks like line-cap may only apply to the end of the line. Is that intentional?

Yes it does, did I miss something? Line cap is used when the segment is not connected to another one basically, otherwise it's line join.

Also support closed lines when generating the webgl buffers

Join angles for each segment are now stored with a better precision, which
makes the visual glitches/seams disappear at the joins
@jahow
Copy link
Contributor Author

jahow commented Aug 30, 2023

Just noticed a huge glitch on the webgl-vector-layer example:
image

edit: fixed, the issue was caused by applying an offset on a line where some segments were colinear and going in opposite direction; the join angle was then 2π which meant that the point was offset to infinity. In this commit I made it so that the offset would be applied similar to a line cap if the join angle was too high, see last commit.

@tschaub
Copy link
Member

tschaub commented Aug 30, 2023

Looks like line-cap may only apply to the end of the line. Is that intentional?

I should have clarified. I meant "end" as opposed to the "start" of a line. I would expect the line-cap to apply to both ends of a line.

line-cap

Instead, I'm seeing the line-cap applied somewhat inconsistently to only one end of the lines (it looks partially transparent at the end of one line and absent from the start of all lines).

@jahow
Copy link
Contributor Author

jahow commented Aug 30, 2023

Instead, I'm seeing the line-cap applied somewhat inconsistently to only one end of the lines (it looks partially transparent at the end of one line and absent from the start of all lines).

Oh right! I took a look at how the canvas renderer was handling this and it turns out the line cap is applied on every dash, not only on the line start and end.

See the comparison between webgl (first) and canvas (second):
Kooha-2023-08-30-23-44-36
Kooha-2023-08-30-23-45-39

I'll see if I can adjust the dashes to use line caps as well.

@tschaub
Copy link
Member

tschaub commented Aug 31, 2023

@jahow - I see that dashes may have been a distraction. I didn't try with a dash-free line to see that the cap style applies to both ends of the line.

image

It does seem like it would be nice if it worked with dashed lines as well.

@jahow
Copy link
Contributor Author

jahow commented Aug 31, 2023

I added a commit to render dashes with round/square line caps according to the style. The round caps are not looking exceptionally great at the joins currently:
image

Unfortunately having a better quality is going to take a while and this is as far as I'll be able to go in that PR. This will have to be revisited further.

The visual result for round caps isn't great and will have to be improved.
Copy link
Member

@tschaub tschaub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, @jahow.

@tschaub
Copy link
Member

tschaub commented Sep 2, 2023

Separately, maybe we should discuss the stroke- prefix. Going with line- instead would align more closely with the Mapbox style spec - and it would shorten things like stroke-line-cap to line-cap.

@jahow
Copy link
Contributor Author

jahow commented Sep 2, 2023

Separately, maybe we should discuss the stroke- prefix. Going with line- instead would align more closely with the Mapbox style spec - and it would shorten things like stroke-line-cap to line-cap.

Indeed, that feels a little too verbose currently!

@jahow jahow merged commit e7a771d into openlayers:main Sep 2, 2023
8 checks passed
@jahow jahow deleted the webgl-line-options branch September 2, 2023 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants