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

VectorImage: Label decluttering should take label rotation into account #11725

Open
Rskut opened this issue Nov 8, 2020 · 6 comments
Open

VectorImage: Label decluttering should take label rotation into account #11725

Rskut opened this issue Nov 8, 2020 · 6 comments

Comments

@Rskut
Copy link

Rskut commented Nov 8, 2020

Current behaviour:
If I rotate a label in a polygon the decluttering function still works like the bounds are the same,
even if the label would fit withing the bounds of the polygon.

Wanted behaviour:
recalculate the bounds if the label rotation changed

@mike-000
Copy link
Contributor

mike-000 commented Nov 9, 2020

I presume you mean the overflow property of the style ( labelled as exceed length in https://openlayers.org/en/latest/examples/vector-labels.html ) always uses the unrotated width of the geometry at the label point, which is not the same as decluttering. If view rotation was passed to the builders it might be sufficient to clone and rotate the geometry when calculating widths, but there would be a performance overhead.

@Rskut
Copy link
Author

Rskut commented Nov 9, 2020

Yes exactly I mixed them up, sorry.
Why it have something to do with the view rotation? I do not rotate the view, just the labels.
Is there a way to customize this?

@mike-000
Copy link
Contributor

mike-000 commented Nov 9, 2020

Rotated labels with unrotated view has the same problem as unrotated labels with rotated view.

@ahocevar
Copy link
Member

ahocevar commented Nov 10, 2020

A more performant fix would be to rotate the extent rectangle in ol/geom/flat/interiorpoint, and create a rotated line instead of a straight line that crosses the geometry at half of the height of the (rotated) extent. @mike-000, would you be interested in attempting a pull request with such a fix? I think instead of flatCenter, the ol/geom/flat/flatInteriorPoint functions should then be called with that line. And the getFlatInteriorPoint() method of ol/geom/Polygon would need a rotation argument. Same for MultiPolygon and RenderFeature.

@mike-000
Copy link
Contributor

I don't think a method based on extent would fix cases such as this
image

@ahocevar
Copy link
Member

The algorithm works like this:
IMG_9562
The dashed line (center line of the label) crosses the geometry at half of the height of the extent, and the longest segment that's inside the geometry is used for the label. So when you rotate the extent, the dashed line won't have a constant y any more, but be expressed by a simple line equation (y = k * x + d). So the calculation of the candidate segments will be a little bit more involved (i.e. solve the equation instead of using a constant y), but overall it is much less computation effort than using a straight extent on a rotated geometry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants