Repository navigation
Expressions - #10654
Expressions#10654
Conversation
|
Could you also add a |
71c779e to
ec425ff
Compare
|
Noting here that I would prefer doing expression filter support as tailwork. Would love to get some feedback on this PR first before moving forward on that. This PR is ready for review. |
👍, especially since expression-based filters are still to be done in core |
ec425ff to
98597e1
Compare
|
Ok, that explains a couple of things :) I initially thought I had to wire those up myself but now seeing that |
There was a problem hiding this comment.
The word "value" gets so easily overloaded -- would it make sense to call this arguments, which is how we refer to them in the style spec as well?
There was a problem hiding this comment.
Intuitively, I'd have expected this to be Expression[] rather than Object[]. I'm guessing it's Object[] so that string/number/boolean literals can be used directly?
There was a problem hiding this comment.
Yes, that is correct, capturing from chat that I will look into the feasibility to use something as Expression instead.
There was a problem hiding this comment.
The variable name argument must be a string literal -- it can't be a subexpression -- so it might make sense to remove this overload.
There was a problem hiding this comment.
can the string literal come from another expression?
eg.
var(get("featureKey"))
If that is the case I will remove the varargs approach and expose the following:
- var(Expression expression)
- var(String string)
There was a problem hiding this comment.
Nope -- "literal" here means it can't be the output of an expression, but has to be a string directly.
There was a problem hiding this comment.
Maybe rename expression to input for consistency with docs?
There was a problem hiding this comment.
Similar to step: maybe rename number to input?
There was a problem hiding this comment.
I could see the case for creating a separate Interpolation type for the first argument here. (So linear(), exponential(), and cubicBezier() would return an Interpolation value.) Not sure whether it's actually better to do so, just mentioning it as an alternative.
There was a problem hiding this comment.
One benefit of doing it that way is that users couldn't do something weird like sum(linear(), 2). As it stands now, if they did this, they'd get an error message that linear is an unknown expression operator -- which might be confusing to them, since the linear() method claims to produce an expression.
There was a problem hiding this comment.
Could this be part of convertValue()? (And space between if and ()
There was a problem hiding this comment.
wow, don't know how I could have missed that
98597e1 to
49af916
Compare
| * | ||
| * @param <T> | ||
| */ | ||
| private static class ExpressionValue<T> extends Expression<T> { |
There was a problem hiding this comment.
ExpressionLiteral might be a better name for this class.
| * a combination of the zoom level and individual feature properties. | ||
| * </p> | ||
| */ | ||
| public class Expression<T> { |
| */ | ||
| public class Expression<T> { | ||
|
|
||
| private String operator; |
There was a problem hiding this comment.
Can both be final so that the object is immutable?
| private String operator; | ||
| private Expression[] arguments; | ||
|
|
||
| Expression() { |
There was a problem hiding this comment.
Not used except by the subclass? If it initializes the members to null, the object can be immutable
| */ | ||
| private static class ExpressionValue<T> extends Expression<T> { | ||
|
|
||
| private Object object; |
There was a problem hiding this comment.
Should this be <T> instead of Object?
There was a problem hiding this comment.
yes this should be enforced
| * @param expression an expression to convert to a color | ||
| * @return expression | ||
| */ | ||
| public static Expression toRgba(Expression<Color> expression) { |
There was a problem hiding this comment.
Missing generic specifier (<Color>) on return type?
There was a problem hiding this comment.
Correct about missing specifier, this case it should be <Array> shown in style spec with ["to-rgba", color]: array<number, 4>).
| * @param input boolean input | ||
| * @return expression | ||
| */ | ||
| public static Expression<Boolean> not(Boolean input) { |
There was a problem hiding this comment.
should this be boolean instead? Otherwise, we should indicate nullability restrictions
There was a problem hiding this comment.
correct, all boolean input should primitive
There was a problem hiding this comment.
also went through the api and applied @NonNull were needed
| * @param expression an expression object or expression string | ||
| * @return expression | ||
| */ | ||
| public static Expression<Number> length(Expression expression) { |
There was a problem hiding this comment.
Is it preferable to use Expression<?> over Expression here?
| * @param operator the expression operator | ||
| * @param arguments expressions input | ||
| */ | ||
| public Expression(@NonNull String operator, @Nullable Expression... arguments) { |
There was a problem hiding this comment.
Should we use @Size(min=1) on varargs here?
There was a problem hiding this comment.
There are cases where the size may be 0, eg: ["pi"]: number or ["properties"]: object. I wasn't aware of this annotation, will try using it in other varargs occurrences in the class.
f57fde0 to
f408c00
Compare
ivovandongen
left a comment
There was a problem hiding this comment.
Some commented code can be removed. Otherwise 👍
| ) | ||
| ) | ||
| )); | ||
| ); |
| } else if (item.getItemId() == R.id.menu_action_filter) { | ||
| SymbolLayer layer = mapboxMap.getLayerAs(LAYER_ID); | ||
| layer.setFilter(Filter.eq(FEATURE_RANK, 1)); | ||
| //layer.setFilter(eq(get(FEATURE_RANK), 1)); |
f408c00 to
862eaa0
Compare
This PR adds binding integration for expressions from #9439
Symbol layer example:
Todo:
Closes #9803
cc @mapbox/android @anandthakker