-
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
Allow expressions as elements in array output values #6155
Comments
This is very doable implementation-wise, once we settle on the right API design. What should we call it? As a variation on the proposal above, we could have an analogue to |
I think the second style, |
The lisp tradition (which has quite a bit of smart thinking behind it) is to have two special forms: |
Couple of comments. First, this form doesn't seem unwieldy to me:
It has the advantage that the If, perchance, the requirement for "literal" were dropped and arrays starting with numbers were automatically treated as either numbers or numeric arrays, this gets even better:
By the same logic, your "it would be amazing if this worked" should work:
I guess I don't really understand the constraints that make this impossible. Is there any public writing about the new expression syntax that explains why there has to be these extra layers of assertions ("number", "array"), conversions ("to-number", "to-array"), getter functions ("get") etc? (I really, really want to be on board with expressions but haven't really got there yet :/ ) |
@stevage This isn't impossible -- nor is, say, accepting object literals without wrapping them with @jfirebaugh yeah, I thought about quasiquote too, but I'm not sure it's warranted here -- I think it's probably sufficient to just have an equivalent for the more basic |
I bumped into this today while trying to compute |
This would be the absolute best solution from my perspective. It would allow us to use all our specialized array widgets in Studio directly inside nested expressions. Fair if there are reasons why this is not feasible, but it'd make the Studio team's job a lot easier. |
Note that even with the proposal for accepting arrays starting with a non-string without the |
Small update here: We wrote a workaround in Studio so we can support nice UI widgets to edit the output value of a simple literal expression, so no urgency from our end on addressing this issue. |
The ability to use arrays directly from geojson sources has been great via @anandthakker any plans to move forward with this approach? A style I have in mind currently has 190+ stops for each offset combination and it gets challenging to maintain, though I'm unsure if it's negatively impacting performance at this point. Being able to just do this, or other embedded expressions, seems intuitive enough to me:
|
@jstratman we should, indeed, move forward on this, but we need to decide on the API design. Main two proposals on the table:
@samanpwbb @jfirebaugh thoughts? |
A third way would be to just always use |
It would also be great if objects could contain expressions. For example, the Historically, the iOS and macOS SDKs represented function stops as dictionaries (akin to JSON objects), so it’s natural for developers migrating from style functions to attempt to index into an object. Even without migrating from style functions, dictionaries are the natural way to build a variable-length match expression. This works in general but not for types like colors that can’t be represented literally in JSON without an expression. mapbox/mapbox-gl-native#11830 has a representative example of this use case, as well as a workaround. |
That could work, although I'm wary of introducing another form of syntax. Another option would be to go back to the basic
It could be accompanied by a corresponding
|
@1ec5 the |
Sort of. No matter how we design expressions, the fact is that dictionary lookups are how Objective-C and Swift developers approach the problem, as opposed to an array of alternating keys and values. So what I’ve shared in mapbox/mapbox-gl-native#11830 (comment) is a way to build a match expression from a dictionary. |
Any news on this issue? |
Hi, any updates? |
Any update on this? |
Hi, is this still in the workings? |
I feel like this should have been included by now. Anyone working on this? |
Hello, following up again here. It would be fantastic to use data-driven properties to set things like |
Ping! |
Same here. I have offset, offsetX, offsetY values in properties that I need to use for icon-offset values. Since tilesets seem to not allow storing arrays in properties they are converted to strings. "[0,100]". How can I set icon-offset using expressions based on my offsetX and offsetY numbers? This doesn't seem to work.
|
Ping! |
side question: Is it possible to parse a JSON string to an array somehow? |
Just ran into this again - really wanted to be able to dynamically calculate a value for It seems there were half a dozen reasonable options on the table, and nothing got implemented because none stood out as the best? |
mapbox-gl-js version: v0.44.0
It would be great if I could use expressions in each element of an array value for properties like
text-font
and*-translate
.Lets take
text-offset
for example. The output value is a 2-element array. As a literal, can be written like this:Lets imagine a hypothetical situation where I wanted to offset along the y axis based on the existence of a property in my data. This would be a useful feature if I had icons for some labels but not for others. I can write this expression like so, and it's valid:
If I have more than one case where I want to adjust my y axis value (say, to check for the existence of 'big-icon' and 'small-icon'), the syntax gets even more unwieldy:
It would be amazing if the following was valid:
Now, that probably won't work because of the way the expression syntax is designed. Could a
to-array
expression get me what I want?This would be a really valuable feature for many properties, and particularly text-font, where usually users will have a universal fallback font, but would want to use an expression to dictate what the primary font is. It would also lead to a more user-friendly experience in Studio!
The text was updated successfully, but these errors were encountered: