-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[RFC] New feature: Images in labels #8604
Comments
Just wanted to note that this is what we're proposing for default images in #8052 (comment) |
@alexshalamov this is a really neat way to expand on the formatted text property to provide richer text composing and layout! The timing of this couldn't be better, because there is alignment on adding an "image" expression operator in #8052 as well.
This has been discussed in the past and is a big change that affects not just the expression and style-spec, but also studio and offline functionality in gl-native.
Is the options argument needed for the images to be usable inside text fields? In the absence of options, would the images in text-fields always be scaled to fit within the line height? When the text field is laid out vertically (either using |
@asheemmamoowala thanks for feedback! Few comments.
All properties for an options object could be added later if we find any of them useful for map designers. Initially, we could provide 'placeholder' in parser code. Parser would expect optional 'image options' object that in the future could contain new properties, therefore, we could guarantee style parsing backward / forward compatibility.
I would say yes, I would expect image with same options to produce similar rendering result.
Most rich-text editors would change line metrics if image with height that is larger than the line height is embedded. Another option is to proportionally scale image to the line height and if designers want image to be larger, scale option may be used in that case.
I would say that image should be in it's natural orientation, upright, in any writing mode. I will add note to myself to research if there are use-cases for rotated images in vertical writing modes. |
The Would it work to put the image formatter options into the formatter object, similar to how
|
@asheemmamoowala Good point. Let's move options out of expression, so that it can be reused in 'icon-image'. I will update proposal accordingly. Still, I would keep one optional 'object' (3rd argument) for an 'image' expression. Would be easy to add common options in the future, for example 'sources'. |
@mapbox/studio @mapbox/map-design-team - any thoughts on this proposal? |
cc: mobile engineers in case you have any feedback -- we're planning to start implementation soon! @mapbox/maps-ios @mapbox/maps-android @1ec5 |
This is going to be great @alexshalamov, really like the api design. |
This looks great! I agree that sources/width/height/color could be left out in the first version and considered separately so that they also work with icon-image. In order to avoid reshaping the text on every frame the icon would need to scale together with the text. This means that text-size would affect the icon. How does this work? Let's say we have
Sounds good to me |
I reviewed this on behalf of the Studio team. First of all, can you verify that the example has some errors? Here's what I would expect a valid example to look like (always require an options object, no arbitrary option keys):
Feedback:
Additional questions:
["format",
"London ",
{},
["match", ["get", "building_type"], ["image", "taipei-metro"], "some more text"]
{ "font-scale": 1.2}
] |
This is a powerful feature and I’m excited to see it coming together. 🎉 So far all the examples I’ve seen demonstrate manually hard-coding images inside Whereas a standalone icon may be decorative when paired with a text label, an icon embedded within a label would tend to carry semantic meaning. Currently, the iOS map SDK and gl-accessibility plugin integrate with screen readers to read the
I wonder if this feature could be a solution for proper display of concurrent highway route shields. The existing icon symbol options are inadequate for concurrent shields, because conventionally they’re line-placed, offset from each other along the line, and always oriented upright with respect to the map: Unfortunately, it isn’t currently possible to achieve the desired effect using The formatted-images-line rendering test in #8904 accomplishes the desired line placement and offset. The two missing pieces would be a way to:
Even if it isn’t the right time to support concurrent shields via this feature, I’m glad this feature will give us an easier way to put emoji-oids inside labels that doesn’t require overhauling the text rendering system. 😅 |
@alexshalamov asked on the PR:
One suggestion:
I'm of the opinion that the image size has to scale with
Pretty sure that, if you wanted to use a zoom-dependent expression for The other use cases that come to mind are when a user needs the size of text on the map to change based on 1) accessibility settings or 2) differing aspect ratios and screen sizes. A user might deploy a single map simultaneously on small and large screens of varying sizes, e.g., in cars. I'm not sure to what extent we support these use cases today or what users do in these situations, but I think that we shouldn't break those implementations, i.e., we shouldn't make a decision that would force those users to start managing multiple styles if they used this feature and wanted the inlined images to scale with the text. So, I'm not so sure about lack of vector icon support forcing fixed image sizes in labels, even though I do think crisply-rendered images are important. |
I think images should not scale in relation to text size. Resolution should be maintained and a designer would upload a scaled version to match larger text if needed.
@1ec5 Thanks for bringing up the accessibility plugin. Should an image field support some sort of 'text-field': ['format',
'London',
{},
['image', 'gb-national-rail.london-tfl-rail.london-underground'],
{
'aria-label': 'GB National rail, London TfL rail, London underground'
}
] |
@samanpwbb @tristen Thanks for feedback. At the moment I'm porting For data-driven and constant sizes it should be rather simple to implement. For zoom-dependent, I'm not sure what to do at the moment. |
This merged 🎉 |
Images inside text-field
This RFC explores possibility of embedding images within a text defined by symbol layer's
text-field
property.Style interface
Images within a text could be added via new
image
expression that takes one mandatory argument that must evaluate to string, for example["image", "car-15"]
.Within 'format' expression, optional image options object may be provided after 'image' expression. Image options properties could be:
height
- sets height of an imagewidth
- sets width of an imagescale
- proportional scalingcolor
- applicable for SDF iconssources
- array of sources from where image would be tried to be fetched, like<img src=[url1, url2...]>
(spritesheet, base url, etc). Example:["spritesheet://icons", "https://www.mapbox.com/images/"]
Support for aforementioned image option properties may be added in the future if found useful.
Example syntax
The new
image
expression can be used as a section withintext-field
’sformat
expression, for instance:The new image expression could be represented by Image object ('coercable' to string if needed). The Image object would contain image id and image options. If needed,
"icon-image"
property could be converted to accept"image"
expression, so that the text-field and icon-image properties would benefit from new functionality.Rendering result
The text was updated successfully, but these errors were encountered: