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

Overzoomed line label has characters of reversed string #5179

Open
wipfli opened this issue Dec 9, 2024 · 13 comments
Open

Overzoomed line label has characters of reversed string #5179

wipfli opened this issue Dec 9, 2024 · 13 comments
Labels
bug Something isn't working need more info Further information is requested PR is more than welcomed Extra attention is needed

Comments

@wipfli
Copy link
Contributor

wipfli commented Dec 9, 2024

maplibre-gl-js version: 4.7.1

browser: chrome ubuntu

Steps to Trigger Behavior

  1. open https://jsbin.com/cacihux/edit?html,output
  2. see how the 50 line label sometimes appears as 05

Link to Demonstration

https://jsbin.com/cacihux/edit?html,output

Image

Expected Behavior

characters of string appear in the normal order

Actual Behavior

characters of string appear in reversed order

@wipfli
Copy link
Contributor Author

wipfli commented Dec 9, 2024

The rotation seems also off by 180 degrees when the string is reversed.

@HarelM
Copy link
Collaborator

HarelM commented Dec 9, 2024

Can you check what is the first version experiencing this issue? Maybe we'll be able to find the offending PR.

@wipfli
Copy link
Contributor Author

wipfli commented Dec 9, 2024

3.0.0

@wipfli
Copy link
Contributor Author

wipfli commented Dec 9, 2024

And more precisely, 3.0.0-pre.5

@wipfli
Copy link
Contributor Author

wipfli commented Dec 9, 2024

Possibly related pull request is #2260

@HarelM
Copy link
Collaborator

HarelM commented Dec 9, 2024

@ChrisLoer any chance you can take a look at this issue?

@HarelM HarelM added bug Something isn't working PR is more than welcomed Extra attention is needed labels Dec 9, 2024
@ChrisLoer
Copy link
Contributor

I think this is a line that doubles directly back on itself? At least I see there are overlapping features making up this line:

Image

Removing the text-offset: [0, 1] shows the doubling back in this video:

double_back_fort.mov

I'm not sure the exact mechanics, but it's kind of not surprising to me that the orientation would get flipped if it just can't calculate a meaningful normal to the line.

@ChrisLoer
Copy link
Contributor

Well maybe I'm wrong about doubling back, but I'm definitely confused by the intended geometry here -- it looks like all of these features have just two vertices but they overlap each other sometimes going in the same direction (but with different lengths) and sometimes going in opposite directions?

{ "type": "Feature", "properties": { "mvt_id": null, "edge_id": 45185, "length": 12.907566720770523, "visits": 49, "after_list": [ 45185, 49 ] }, "geometry": { "type": "LineString", "coordinates": [ [ 2839.0, 3066.0 ], [ 2945.0, 3138.0 ] ] } },
{ "type": "Feature", "properties": { "mvt_id": null, "edge_id": 45186, "length": 6.9214614238149998, "visits": 49, "after_list": [ 45186, 49 ] }, "geometry": { "type": "LineString", "coordinates": [ [ 2839.0, 3066.0 ], [ 2783.0, 3028.0 ] ] } },
{ "type": "Feature", "properties": { "mvt_id": null, "edge_id": 45159, "length": 11.855569527575458, "visits": 50, "after_list": [ 45159, 50 ] }, "geometry": { "type": "LineString", "coordinates": [ [ 2716.0, 2483.0 ], [ 2648.0, 2579.0 ] ] } },
{ "type": "Feature", "properties": { "mvt_id": null, "edge_id": 45160, "length": 22.855715638137209, "visits": 50, "after_list": [ 45160, 50 ] }, "geometry": { "type": "LineString", "coordinates": [ [ 2716.0, 2483.0 ], [ 2866.0, 2313.0 ] ] } },
{ "type": "Feature", "properties": { "mvt_id": null, "edge_id": 45157, "length": 22.855715638137209, "visits": 50, "after_list": [ 45157, 50 ] }, "geometry": { "type": "LineString", "coordinates": [ [ 2866.0, 2313.0 ], [ 2716.0, 2483.0 ] ] } },
{ "type": "Feature", "properties": { "mvt_id": null, "edge_id": 45158, "length": 3.4125469570288272, "visits": 50, "after_list": [ 45158, 50 ] }, "geometry": { "type": "LineString", "coordinates": [ [ 2866.0, 2313.0 ], [ 2889.0, 2288.0 ] ] } },
{ "type": "Feature", "properties": { "mvt_id": null, "edge_id": 45155, "length": 3.4125469570288272, "visits": 50, "after_list": [ 45155, 50 ] }, "geometry": { "type": "LineString", "coordinates": [ [ 2889.0, 2288.0 ], [ 2866.0, 2313.0 ] ] } },
{ "type": "Feature", "properties": { "mvt_id": null, "edge_id": 45156, "length": 5.3431562053574986, "visits": 50, "after_list": [ 45156, 50 ] }, "geometry": { "type": "LineString", "coordinates": [ [ 2889.0, 2288.0 ], [ 2916.0, 2243.0 ] ] } },

@HarelM
Copy link
Collaborator

HarelM commented Dec 11, 2024

Thanks for looking into this @ChrisLoer, @wipfli can you check if the data is valid?

@HarelM HarelM added the need more info Further information is requested label Dec 11, 2024
@wipfli
Copy link
Contributor Author

wipfli commented Dec 11, 2024

What is the best way to validate a vector tile?

@HarelM
Copy link
Collaborator

HarelM commented Dec 11, 2024

Look at the points and at the features in it and make sure the data makes sense in terms of geometry.
Probably using this library:
https://github.com/mapbox/pbf

@wipfli
Copy link
Contributor Author

wipfli commented Dec 11, 2024

@ChrisLoer what tool did you use to generate the above geojson from the pbf?
Your description of the data by the way is accurate. The tile contains linestrings each having only 2 vertices (one linear segment) and all linestrings should have a reversed counterpart. Since there are no polygons there is not much potential for invalid geometries.

@ChrisLoer
Copy link
Contributor

I downloaded the PBF, opened it in QGIS, and then exported it as GeoJSON. I think you could also use ogr2ogr to do it more directly, but I sniffed around in QGIS first to get a sense for what was in it. Another tool I think is super useful for looking at tiles is (although not so much in this case) @stevage 's Vector Inspector (https://stevage.github.io/vector-inspector/#?url=%20https://wipfli.github.io/debug-assets/reversed-label/16/34323/22952.pbf&loc=16.7/47.366937/8.545262)

I didn't see anything that looked invalid about the geometry, it's more that it's kind of edge-casey and "weird" in a way that seems like it might be triggering the behavior. If you look at addToLineVertexArray, getAnchors, updateLineLabels or placeGlyphAlongLine, you'll see a lot of logic that's trying to iterate over segments of a line -- in this case all of those loops should reduce to a single operation that either fits something on the segment or doesn't, but it kind of seems like maybe there's a logic error in there that's letting it... traverse the same segment backwards? or accidentally traverse on to an adjacent entry in the line vertex array?

I do think turning off the offset kind of highlights the root issue because you can see the doubling back happen incrementally, and I think it rules out the findOffsetIntersectionPoint as the source b/c it skips that whole pathway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working need more info Further information is requested PR is more than welcomed Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants