Repository navigation
Variable label placement - #7596
Conversation
ce8eb79 to
10dbeb1
Compare
10dbeb1 to
6430567
Compare
825d4ee to
96b2d15
Compare
|
The issue here is that pitch and rotation aren't being correctly handled by the dynamic anchor offset code, because the offset is applied before projection happens in the shader. I think we could:
I'm leaning towards the first solution because I'm hoping it will allow us to avoid adding yet more confusing logic to the already-too-complex shader. It's extra CPU work, but hopefully it should be relatively small compared to the amount of projection we're already doing for line labels. cc @ansis |
|
@ChrisLoer I noticed a couple of minor irregularities/unexpected behavior with text offsetting:
|
|
Thanks for documenting these cases! The current offset logic just doesn't work in a lot of cases, and I think we need to apply the offset at render time instead of at collision detection time the way the current code runs. As I work on it, I'll check against these situations. Rotation and pitch handling for the offset are also broken.
🤔Instead of doing a radial offset, should we just apply the "dynamic-text-offset" in both the x and y directions for the diagonal cases? Or we could for the corner cases we could use the full x offset and some smaller y offset, to avoid making the radial distance increase so much (although this could be hard to explain clearly). |
|
@ChrisLoer Just wanted to note here, per chat, that the first three offset issues I noted in my comment above seem to have been resolved via your recent commit that changed the base anchor of offsets 🎉 For the last issue regarding diagonal placements, looking at this again I think an additional problem here is that the text itself within a text box is further away from the corner of the text box than it is from the sides, so I think that the shortest distance from the anchor to closest point of the text is actually larger.
Wouldn't these two options make the diagonal offsets larger, rather than smaller? 🤔 |
Ah, I was thinking about this the wrong way -- I was thinking that keeping the alignment of the left/right edges of the boxes consistent would make it more legible. Yeah, you're right.
Yeah, although I think for a single-line label this should be a pretty small effect. For a multi-line label it could be more dramatic if for instance the bottom line is significantly shorter than the top line. I'm somewhat uncomfortable with just arbitrarily shortening the radial offset in the diagonal case, 'cause I'm not sure it would always get the effect you want and it just seems harder to explain? |
|
OK, I think I have viewport-pitch/rotation-aligned labels working in pitched views now. There are a bunch of loose ends I need to track down:
cc @ansis |
|
I did some initial profiling of a large-screen NYC dynamically placed POI case. It should be a pretty good stress test of a very dynamic-anchor heavy map: The actual cost of the extra collision detection doesn't end up looking too large ( On the other hand, at render time, in this example, the dynamic placement of anchors looks like it's costing twice as much as the dynamic updating of road labels (this example does have many more POIs than roads). That render-time cost is dominated by re-building and re-uploading the dynamic layout arrays.
Overall, this seems tolerable? An alternative approach would be to upload a full set of glyphs for every possible anchor placement. The tradeoffs are roughly:
I'm not sure it's likely to make a big enough difference to be worth prototyping. |
|
I implemented the "only do multiple shapings for multi-line labels" optimization, and in the NYC dense POI label test case from above, it looks like a pretty significant improvement. I wouldn't put too much weight on the absolute numbers, but what looks promising is the dynamic-anchor:line-label cost ratio went from 2:1 down to 1:1. From discussion with @chloekraw @nickidlugash and @elifitch, we're currently planning these changes to the style-spec side:
|
|
I just pushed a small change to the rendering of debug collision boxes that makes them a little more legible in my mind:
|
bcd1443 to
091951a
Compare
091951a to
2afb5c3
Compare
|
@ansis I think this is ready for review. I edited Molly's original post to include a little introduction. cc @mapbox/studio @mapbox/map-design (see style-spec changes in v8.json or quick description at top of PR). |
nickidlugash
left a comment
There was a problem hiding this comment.
@ChrisLoer This looks great to me 👍
The radial offsets look good for all anchor directions. I think the current offset logic makes sense. I've been testing this PR with both labels that have a circular icon and labels that have square icons. Depending on the shape of the icon and the shape of the text, there are minor visual discrepancies in apparent offset distance (e.g. with circular icons, diagonal offsets still appear slightly larger than offsets in other directions), but I don't think we should try to address this. Just wanted to make that disclaimer on this PR in case it comes up in the future.
The bonus functionality of being able to use text-radial-offset and text-justify: auto in conjunction with the non-variable text-anchor property is awesome. I tested these with a complex data-driven text-anchor value, and the style definition is so much simpler and concise 🎉
|
Hopefully this makes it into the next release! |
|
@bradjonesca - this won't make it into v0.53, but it will be in v0.54 (~early/mid March). Thanks for using Mapbox! |
|
Overall, this looks great! I think we should remove
I think the animation is neat, but I don't think it would be useful enough to justify the spec and code additions. A question about The implementation looks good and I have no requested changes there. |
|
I talked this over with @ansis and I’m OK with removing the animated label transitions -- does this sound OK to you @nickidlugash and @chloekraw? My thinking is roughly:
I'll try to do this tomorrow. As for collapsing |
2afb5c3 to
4a6a35a
Compare
4a6a35a to
35df8c9
Compare













Implements #5038.
This PR introduces support for variable label placement through a few style-spec additions:
text-variable-anchor: As an alternative totext-anchor, provide an array of anchor positions. At collision detection time, we attempt placing at the positions in this list in the provided order. If the symbol was successfully placed in a previous round, we attempt that anchor position first before moving on to the rest of the list.(removed: see discussion below)text-variable-anchor-animation: boolean, controls whether variable anchors uses a cubic ease to move between positions, or whether they just immediately change position after a collision. Defaults totrue.text-radial-offset: Liketext-offsetbut just a scalar value, applied in the direction of the anchor. Can be used with static or variable anchors, but required for applying offsets to variable anchors.text-justify: auto: Choose text justification based on the anchor position. Useful for making justification respond to automatically chosen anchor positions.Ex ante, we worried about the added collision detection cost. This did not end up being a very big deal. The biggest cost ends up being the updating of dynamic layout vertex buffers on each frame, similar to the cost of dynamic layout for line labels. We considered an alternate approach in which we generate a separate set of glyphs for every possible anchor, and just used the existing opacity update process to switch between different labels. That approach would be friendly to cross-fading, while the current approach is friendly to doing a translation animation. The only reason we didn't try the other approach is that we didn't start with it and the current approach seems to work pretty well, so we didn't want to spend more time prototyping.
My impression after playing with various test scenarios is that performance is not really the primary concern with using this feature. By the time you get a noticeable performance impact, your map will feel pretty "unstable", with labels moving all over the place. Visually, it works best when used sparingly, to make sure a relatively small number of high priority labels show on the screen.
The PR introduces a novelty: the results of one collision detection depend on what happened in the collision detection before. This was easy to do, hasn't seemed to cause many problems, and significantly reduces the perception of "jumpiness". But it does make reasoning about the map a little more difficult. You won't necessarily be able to reproduce what a user sees just by going to the same location/pitch/rotation/viewport. In tests, it's possible you could introduce pretty subtle instability related to timing (if your test depends on a couple resources to load and multiple placements happen before the test finishes rendering, the order of loading could affect the eventual result)
Implemented by @mollymerp, final touches by @ChrisLoer.
Launch Checklist
@mapbox/studioand/or@mapbox/maps-designif this PR includes style spec changes