Add icon-text-fit-stretch to alter existing sprites #9169
Labels
cross-platform 📺
Requires coordination with Mapbox GL Native (style specification, rendering tests, etc.)
feature 🍏
Motivation
I would like to be able to use the sprite icons provided with the loaded style as stretchable assets; to be able to define stretch points as documented under the sprites section. I can certainly add an image and define all the relevant properties but since our designers are adding all their icons to the Studio it make better sense to also add the stretchable-label-icons to the same sprite sheet.
At this time the sprite icons can be used for the
icon-text-fit
but because the sprite.json file, containing position/dimension props, does not contain stretch props they stretch beyond their intended dimensions when rendered to cover the text. I would like to alter these props if it is not already possible.Design Alternatives
There are several design alternatives that can be done. All have their costs and benefits, it just depends on which one can be done sooner and provide the most long term value.
icon-text-fit
.icon-text-fit-stretch
) to alter/add icon stretch points.Design
The first possibility is probably the least effort that brings quite a lot of relative value. If one uses the
icon-text-fit
prop on an icon that has no stretch points defined but then gets assigned default center horizontal/vertical pixels stretch values, something like a circle will do perfectly for rounded corner labels. I don't really know enough about the inner workings of the mapbox-gl to have any idea of any drawbacks but I'm only guessing that this could be as simple as assigning defaults to the sprite-icon object.The second option I'm less interested in but is also a valid direction to allow the icon being imported to have it's properties editable so that in the receiving end the client can stretch according to the designer set values. This obviously helps empower our designers to define such things with in Mapbox Studio. Us developers usually work closely with designers and if there's anything we can help free them up to make decisions on this would help us a lot.
The direction that will provide the most benefit though is Number 3. This is because it empowers the developer to choose an icon from the sprite sheet sourced from the style and define which pixels to stretch on. Given that the sprite sheet is alterable from Mapbox Studio (by our designers) one could conceivably add a stretchable-label-icon and in the code define which pixels to stretch on.
Mock-Up
The property could look like this:
The multi-dimensional array is simple a combination of the stretchX and stretchY values
Concepts
This should be pretty much the same language defined by the stretchX/Y topic and perhaps a new example can be made to illustrate the proposed property.
Implementation
For the first point above, the part of mapbox-gl that would have to change is (possibly)
src/style/load_sprite.js:maybeComplete
. As the code traverses through the images it could assign defaults where there are none. This would then provide a way to stretch an image, I assume. I have yet to try this myself b/c I'm encountering some blockers on running the repo code in my tests. I think I just need more time to poke around and get acquainted.The text was updated successfully, but these errors were encountered: