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

symbol-placement: line-center produces incorrect results at some zoom levels #9628

Open
mike-unearth opened this issue Apr 24, 2020 · 6 comments
Labels

Comments

@mike-unearth
Copy link

mike-unearth commented Apr 24, 2020

mapbox-gl-js version: 1.9.1

browser: Chrome 81

Steps to Trigger Behavior

  1. Create a geojson source with a LineString feature
  2. Create a text layer for the source with symbol-placement: line-center
  3. Zoom in

Link to Demonstration

https://jsfiddle.net/37sgzkme/

Expected Behavior

My understanding is that the label should appear at the center of the geometry at all zoom levels.

Actual Behavior

The label appears at the center of the geometry at all zoom levels below 18. Above 18, multiple labels are rendered along the line, or in some cases the single label simply moves to a new location on the line.

Increasing the source buffer size definitely helps, and in fact solves the issue for some simple lines, but my dataset is dynamic.

The following two lines in symbol_layout.js are certainly eye-catching, but I haven't yet figured out exactly what's going wrong and why.

//   4. `text-size` at zoom level 18. Used for something line-symbol-placement-related.
...
sizes.textMaxSize = unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(18));
@mike-unearth mike-unearth changed the title symbol-placement: line-center produces incorrect results above zoom 18 symbol-placement: line-center produces incorrect results at some zoom levels Apr 24, 2020
@mike-unearth
Copy link
Author

The zoom level 18 thing appears to be a red herring: I'm now thinking that what's happening is that the geometry used to calculate the line center is the portion of the line within the current tile, not the entire feature. So each tile calculates a different center, and as you zoom in it becomes increasingly likely that multiple anchors will be placed. If I'm on the right track, then the only case when the center is correctly calculated is when the entire feature fits within one tile + buffer.

mike-unearth added a commit to procore/sdt-mapbox-gl-js that referenced this issue Apr 24, 2020
@mike-unearth
Copy link
Author

Hmm. I have a fix that works up through the current release (1.9.1) but does work with current master due to major changes via #9219. I'll wait for the next stable release before opening a PR.

@arindam1993
Copy link
Contributor

Your hypothesis is correct @mike-unearth , and you fix looks like its the correct approach 🎉 .

Could you please update the style-spec docs for line-center stating that it only works with geojson sources since geojson-vt is what introduces those parameters.

@simonmumenthaler
Copy link

Problem still exists - is there any fix?

@FunnyElevator
Copy link

Also run into into this issue. Any timeline when this is being fixed?

@momsse
Copy link

momsse commented Oct 12, 2023

Same here, using line midpoint instead, sadge

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

No branches or pull requests

5 participants