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

How to use data-driven styling on text-font property #9868

Closed
dpdiliberto opened this issue Jul 10, 2020 · 2 comments
Closed

How to use data-driven styling on text-font property #9868

dpdiliberto opened this issue Jul 10, 2020 · 2 comments

Comments

@dpdiliberto
Copy link
Contributor

mapbox-gl-js version: v1.11.1

Question

The text-font property seems to look for an array of 2 values, where the second is a fallback that is used when the primary font is missing characters needed for multilingual text. If the GeoJSON for a newly added layer contains a data property that looks like the following:

"labelFont": [
"Open Sans Regular",
"Arial Unicode MS Regular"
],

what would be the corresponding expression that would grab this and set it to the text-font property? The expression ["array", ["get", "labelFont"]] results in the error message Expected array<string> but found array instead.

Links to related documentation

Examples in this page https://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/#lookup may help to clarify how this would work.

@mourner
Copy link
Member

mourner commented Jul 13, 2020

There's a limitation on text-font that disallows using expressions for it that don't have a defined constant set of possible output values (see background here mapbox/mapbox-gl-native#9939 (comment)). That means you can't do "text-font": ["get", "labelFont"] (since you can't derive from the style alone which fonts will be used by it), but you could e.g. do ["case", ["get", "isOpenSans"], "Open Sans Regular", "Arial Unicode MS Regular"] (use one or the other depending on the property).

@mourner mourner closed this as completed Jul 13, 2020
@ykessler
Copy link

ykessler commented Jun 4, 2023

This worked for me:

["case", ["get", "major"],
 ["literal", [
  "Open Sans Bold",
  "Arial Unicode MS Regular"
]],
  ["literal", [
  "Open Sans Regular",
  "Arial Unicode MS Regular"
]]]

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

No branches or pull requests

3 participants