diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style')
37 files changed, 2746 insertions, 3309 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java index 7b841a2580..bd5b40c6ce 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java @@ -5,16 +5,20 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.Size; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; import com.mapbox.mapboxsdk.style.layers.PropertyFactory; +import com.mapbox.mapboxsdk.style.layers.PropertyValue; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** * The value for any layout property, paint property, or filter may be specified as an expression. * An expression defines a formula for computing the value of the property using the operators described below. * The set of expression operators provided by Mapbox GL includes: - * <p> * <ul> * <li>Element</li> * <li>Mathematical operators for performing arithmetic and other operations on numeric values</li> @@ -23,7 +27,6 @@ import java.util.List; * <li>Data operators, providing access to the properties of source features</li> * <li>Camera operators, providing access to the parameters defining the current map view</li> * </ul> - * </p> * <p> * Expressions are represented as JSON arrays. * The first element of an expression array is a string naming the expression operator, @@ -46,10 +49,40 @@ import java.util.List; * Such composite expressions allows a layer's appearance to be determined by * a combination of the zoom level and individual feature properties. * </p> - * - * @param <T> the type of the expression + * <p> + * Example expression: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setProperties( + * fillColor( + * interpolate( linear(), zoom(), + * stop(12, step(get("stroke-width"), + * color(Color.BLACK), + * stop(1f, color(Color.RED)), + * stop(2f, color(Color.WHITE)), + * stop(3f, color(Color.BLUE)) + * )), + * stop(15, step(get("stroke-width"), + * color(Color.BLACK), + * stop(1f, color(Color.YELLOW)), + * stop(2f, color(Color.LTGRAY)), + * stop(3f, color(Color.CYAN)) + * )), + * stop(18, step(get("stroke-width"), + * color(Color.BLACK), + * stop(1f, color(Color.WHITE)), + * stop(2f, color(Color.GRAY)), + * stop(3f, color(Color.GREEN)) + * )) + * ) + * ) + * ) + * } + * </pre> */ -public class Expression<T> { +public class Expression { private final String operator; private final Expression[] arguments; @@ -68,205 +101,116 @@ public class Expression<T> { * @param operator the expression operator * @param arguments expressions input */ - @SafeVarargs public Expression(@NonNull String operator, @Nullable Expression... arguments) { this.operator = operator; this.arguments = arguments; } /** - * Converts the expression to Object array representation. + * Create a literal number expression. * <p> - * The output will later be converted to a JSON Object array. + * Example usage: * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(literal(10.0f)) + * ); + * } + * </pre> * - * @return the converted object array expression - */ - @NonNull - public Object[] toArray() { - List<Object> array = new ArrayList<>(); - array.add(operator); - if (arguments != null) { - for (Expression argument : arguments) { - if (argument instanceof Expression.ExpressionLiteral) { - array.add(toValue((ExpressionLiteral) argument)); - } else { - array.add(argument.toArray()); - } - } - } - return array.toArray(); - } - - /** - * Converts the expression value to an Object. - * - * @param expressionValue the expression value to convert - * @return the converted object expression + * @param number the number + * @return the expression */ - private Object toValue(ExpressionLiteral expressionValue) { - Object value = expressionValue.toValue(); - if (value instanceof Expression.Color) { - return ((Expression.Color) value).convertColor(); - } else if (value instanceof Expression.ExpressionLiteral) { - return toValue((ExpressionLiteral) value); - } else if (value instanceof Expression) { - return ((Expression) value).toArray(); - } - return value; + public static Expression literal(@NonNull Number number) { + return new ExpressionLiteral(number); } /** - * ExpressionLiteral wraps an object to be used as a literal in an expression. + * Create a literal string expression. * <p> - * ExpressionLiteral is created with {@link #literal(Number)}, {@link #literal(boolean)}, - * {@link #literal(String)} and {@link #literal(Object)}. + * Example usage: * </p> + * <pre> + * {@code + * SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); + * symbolLayer.setProperties( + * textField(literal("Text")) + * ); + * } + * </pre> * - * @param <T> - */ - private static class ExpressionLiteral<T> extends Expression<T> { - - protected T object; - - /** - * Create an ExpressionValue wrapper. - * - * @param object the object to be wrapped - */ - ExpressionLiteral(@NonNull T object) { - this.object = object; - } - - /** - * Get the wrapped object. - * - * @return the wrapped object - */ - Object toValue() { - return object; - } - } - - // - // Types - // - - /** - * Expression interpolator type. - * <p> - * Is used for first parameter of {@link #interpolate(Expression, Expression, Stop...)}. - * </p> - */ - public static class Interpolator { - } - - /** - * Expression color type. + * @param string the string + * @return the expression */ - public static class Color { - - private int color; - - /** - * Creates a color color type from a color int. - * - * @param color the int color - */ - public Color(@ColorInt int color) { - this.color = color; - } - - /** - * Converts the int color to rgba(d, d, d, d) string representation - * - * @return - */ - public String convertColor() { - return PropertyFactory.colorToRgbaString(color); - } + public static Expression literal(@NonNull String string) { + return new ExpressionLiteral(string); } /** - * Expression array type. - */ - public static class Array { - } - - /** - * Expression stop type. + * Create a literal boolean expression. * <p> - * Can be used for {@link #stop(Object, Object)} as part of varargs parameter in - * {@link #step(Number, Expression, Stop...)} or {@link #interpolate(Expression, Expression, Stop...)}. + * Example usage: * </p> - */ - public static class Stop { - - private Object value; - private Object output; - - public Stop(Object value, Object output) { - this.value = value; - this.output = output; - } - } - - // - // Literals - // - - /** - * Create a literal number expression. + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setProperties( + * fillAntialias(literal(true)) + * ); + * } + * </pre> * - * @param number the number - * @return the expression - */ - public static Expression<Number> literal(@NonNull Number number) { - return new ExpressionLiteral<>(number); - } - - /** - * Create a literal string expression. - * - * @param string the string + * @param bool the boolean * @return the expression */ - public static Expression<String> literal(@NonNull String string) { - return new ExpressionLiteral<>(string); + public static Expression literal(boolean bool) { + return new ExpressionLiteral(bool); } /** - * Create a literal boolean expression. + * Create a literal object expression. * - * @param bool the boolean + * @param object the object * @return the expression */ - public static Expression<Boolean> literal(boolean bool) { - return new ExpressionLiteral<>(bool); + public static Expression literal(@NonNull Object object) { + if (object.getClass().isArray()) { + return literal(ExpressionArray.toObjectArray(object)); + } + return new ExpressionLiteral(object); } /** - * Create a literal object expression + * Create a literal array expression * - * @param object the object + * @param array the array * @return the expression */ - public static Expression<Object> literal(@NonNull Object object) { - return new ExpressionLiteral<>(object); + public static Expression literal(@NonNull Object[] array) { + return new ExpressionArray(array); } - // - // Color - // - /** * Expression literal utility method to convert a color int to an color expression + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setProperties( + * fillColor(color(Color.GREEN)) + * ); + * } + * </pre> * * @param color the int color * @return the color expression */ - public static Expression<Color> color(@ColorInt int color) { - return new ExpressionLiteral<>(new Color(color)); + public static Expression color(@ColorInt int color) { + return toColor(literal(PropertyFactory.colorToRgbaString(color))); } /** @@ -275,15 +219,32 @@ public class Expression<T> { * <p> * If any component is out of range, the expression is an error. * </p> + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setProperties( + * fillColor( + * rgb( + * literal(255.0f), + * literal(255.0f), + * literal(255.0f) + * ) + * ) + * ); + * } + * </pre> * * @param red red color expression * @param green green color expression * @param blue blue color expression * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-rgb">Style specification</a> */ - public static Expression<Color> rgb(@NonNull Expression<Number> red, @NonNull Expression<Number> green, - @NonNull Expression<Number> blue) { - return new Expression<>("rgb", red, green, blue); + public static Expression rgb(@NonNull Expression red, @NonNull Expression green, @NonNull Expression blue) { + return new Expression("rgb", red, green, blue); } /** @@ -292,13 +253,27 @@ public class Expression<T> { * <p> * If any component is out of range, the expression is an error. * </p> + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setProperties( + * fillColor( + * rgb(255.0f, 255.0f, 255.0f) + * ) + * ); + * } + * </pre> * * @param red red color value * @param green green color value * @param blue blue color value * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-rgb">Style specification</a> */ - public static Expression<Color> rgb(@NonNull Number red, @NonNull Number green, @NonNull Number blue) { + public static Expression rgb(@NonNull Number red, @NonNull Number green, @NonNull Number blue) { return rgb(literal(red), literal(green), literal(blue)); } @@ -308,16 +283,35 @@ public class Expression<T> { * <p> * If any component is out of range, the expression is an error. * </p> + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setProperties( + * fillColor( + * rgba( + * literal(255.0f), + * literal(255.0f), + * literal(255.0f), + * literal(1.0f) + * ) + * ) + * ); + * } + * </pre> * * @param red red color value * @param green green color value * @param blue blue color value * @param alpha alpha color value * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-rgba">Style specification</a> */ - public static Expression<Color> rgba(@NonNull Expression<Number> red, @NonNull Expression<Number> green, - @NonNull Expression<Number> blue, @NonNull Expression<Number> alpha) { - return new Expression<>("rgba", red, green, blue, alpha); + public static Expression rgba(@NonNull Expression red, @NonNull Expression green, + @NonNull Expression blue, @NonNull Expression alpha) { + return new Expression("rgba", red, green, blue, alpha); } /** @@ -326,14 +320,28 @@ public class Expression<T> { * <p> * If any component is out of range, the expression is an error. * </p> + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setProperties( + * fillColor( + * rgb(255.0f, 255.0f, 255.0f, 1.0f) + * ) + * ); + * } + * </pre> * * @param red red color value * @param green green color value * @param blue blue color value * @param alpha alpha color value * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-rgba">Style specification</a> */ - public static Expression<Color> rgba(@NonNull Number red, @NonNull Number green, @NonNull Number blue, @NonNull Number alpha) { + public static Expression rgba(@NonNull Number red, @NonNull Number green, @NonNull Number blue, @NonNull Number alpha) { return rgba(literal(red), literal(green), literal(blue), literal(alpha)); } @@ -342,239 +350,476 @@ public class Expression<T> { * * @param expression an expression to convert to a color * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-to-rgba">Style specification</a> */ - public static Expression<Array> toRgba(@NonNull Expression<Color> expression) { - return new Expression<>("to-rgba", expression); + public static Expression toRgba(@NonNull Expression expression) { + return new Expression("to-rgba", expression); } - // - // Decision - // - /** * Returns true if the input values are equal, false otherwise. * The inputs must be numbers, strings, or booleans, and both of the same type. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * eq(get("keyToValue"), get("keyToOtherValue")) + * ); + * } + * </pre> * * @param compareOne the first expression * @param compareTwo the second expression * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-==">Style specification</a> */ - public static Expression<Boolean> eq(@NonNull Expression compareOne, @NonNull Expression compareTwo) { - return new Expression<>("==", compareOne, compareTwo); + public static Expression eq(@NonNull Expression compareOne, @NonNull Expression compareTwo) { + return new Expression("==", compareOne, compareTwo); } /** * Returns true if the input values are equal, false otherwise. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * eq(get("keyToValue"), true) + * ); + * } + * </pre> * - * @param compareOne the first boolean + * @param compareOne the first expression * @param compareTwo the second boolean * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-==">Style specification</a> */ - public static Expression<Boolean> eq(boolean compareOne, boolean compareTwo) { - return eq(literal(compareOne), literal(compareTwo)); + public static Expression eq(Expression compareOne, boolean compareTwo) { + return eq(compareOne, literal(compareTwo)); } /** * Returns true if the input values are equal, false otherwise. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * eq(get("keyToValue"), "value") + * ); + * } + * </pre> * - * @param compareOne the first number + * @param compareOne the first expression * @param compareTwo the second number * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-==">Style specification</a> */ - public static Expression<Boolean> eq(@NonNull String compareOne, @NonNull String compareTwo) { + public static Expression eq(@NonNull Expression compareOne, @NonNull String compareTwo) { return eq(literal(compareOne), literal(compareTwo)); } /** * Returns true if the input values are equal, false otherwise. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * eq(get("keyToValue"), 2.0f) + * ); + * } + * </pre> * - * @param compareOne the first number + * @param compareOne the first expression * @param compareTwo the second number * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-==">Style specification</a> */ - public static Expression<Boolean> eq(@NonNull Number compareOne, @NonNull Number compareTwo) { + public static Expression eq(@NonNull Expression compareOne, @NonNull Number compareTwo) { return eq(literal(compareOne), literal(compareTwo)); } /** * Returns true if the input values are not equal, false otherwise. * The inputs must be numbers, strings, or booleans, and both of the same type. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * neq(get("keyToValue"), get("keyToOtherValue")) + * ); + * } + * </pre> * * @param compareOne the first expression * @param compareTwo the second expression * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-!=">Style specification</a> */ - public static Expression<Boolean> neq(@NonNull Expression compareOne, @NonNull Expression compareTwo) { - return new Expression<>("!=", compareOne, compareTwo); + public static Expression neq(@NonNull Expression compareOne, @NonNull Expression compareTwo) { + return new Expression("!=", compareOne, compareTwo); } /** * Returns true if the input values are equal, false otherwise. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * neq(get("keyToValue"), true) + * ); + * } + * </pre> * - * @param compareOne the first boolean + * @param compareOne the first expression * @param compareTwo the second boolean * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-!=">Style specification</a> */ - public static Expression<Boolean> neq(boolean compareOne, boolean compareTwo) { - return new Expression<>("!=", literal(compareOne), literal(compareTwo)); + public static Expression neq(Expression compareOne, boolean compareTwo) { + return new Expression("!=", literal(compareOne), literal(compareTwo)); } /** * Returns `true` if the input values are not equal, `false` otherwise. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * neq(get("keyToValue"), "value")) + * ); + * } + * </pre> * - * @param compareOne the first string + * @param compareOne the first expression * @param compareTwo the second string * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-!=">Style specification</a> */ - public static Expression<Boolean> neq(@NonNull String compareOne, @NonNull String compareTwo) { - return new Expression<>("!=", literal(compareOne), literal(compareTwo)); + public static Expression neq(@NonNull Expression compareOne, @NonNull String compareTwo) { + return new Expression("!=", literal(compareOne), literal(compareTwo)); } /** * Returns `true` if the input values are not equal, `false` otherwise. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * neq(get("keyToValue"), 2.0f)) + * ); + * } + * </pre> * - * @param compareOne the first number + * @param compareOne the first expression * @param compareTwo the second number * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-!=">Style specification</a> */ - public static Expression<Boolean> neq(@NonNull Number compareOne, @NonNull Number compareTwo) { - return new Expression<>("!=", literal(compareOne), literal(compareTwo)); + public static Expression neq(@NonNull Expression compareOne, @NonNull Number compareTwo) { + return new Expression("!=", literal(compareOne), literal(compareTwo)); } /** * Returns true if the first input is strictly greater than the second, false otherwise. * The inputs must be numbers or strings, and both of the same type. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * gt(get("keyToValue"), get("keyToOtherValue")) + * ); + * } + * </pre> * * @param compareOne the first expression * @param compareTwo the second expression * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3E">Style specification</a> */ - public static Expression<Boolean> gt(@NonNull Expression compareOne, @NonNull Expression compareTwo) { - return new Expression<>(">", compareOne, compareTwo); + public static Expression gt(@NonNull Expression compareOne, @NonNull Expression compareTwo) { + return new Expression(">", compareOne, compareTwo); } /** * Returns true if the first input is strictly greater than the second, false otherwise. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * gt(get("keyToValue"), 2.0f) + * ); + * } + * </pre> * - * @param compareOne the first number + * @param compareOne the first expression * @param compareTwo the second number * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3E">Style specification</a> */ - public static Expression<Boolean> gt(@NonNull Number compareOne, @NonNull Number compareTwo) { - return new Expression<>(">", literal(compareOne), literal(compareTwo)); + public static Expression gt(@NonNull Expression compareOne, @NonNull Number compareTwo) { + return new Expression(">", literal(compareOne), literal(compareTwo)); } /** * Returns true if the first input is strictly greater than the second, false otherwise. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * gt(get("keyToValue"), "value") + * ); + * } + * </pre> * - * @param compareOne the first string + * @param compareOne the first expression * @param compareTwo the second string * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3E">Style specification</a> */ - public static Expression<Boolean> gt(@NonNull String compareOne, @NonNull String compareTwo) { - return new Expression<>(">", literal(compareOne), literal(compareTwo)); + public static Expression gt(@NonNull Expression compareOne, @NonNull String compareTwo) { + return new Expression(">", literal(compareOne), literal(compareTwo)); } /** * Returns true if the first input is strictly less than the second, false otherwise. * The inputs must be numbers or strings, and both of the same type. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * lt(get("keyToValue"), get("keyToOtherValue")) + * ); + * } + * </pre> * - * @param compareOne the first number + * @param compareOne the first expression * @param compareTwo the second number * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3C">Style specification</a> */ - public static Expression<Boolean> lt(@NonNull Expression compareOne, @NonNull Expression compareTwo) { - return new Expression<>("<", compareOne, compareTwo); + public static Expression lt(@NonNull Expression compareOne, @NonNull Expression compareTwo) { + return new Expression("<", compareOne, compareTwo); } /** * Returns true if the first input is strictly less than the second, false otherwise. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * lt(get("keyToValue"), 2.0f) + * ); + * } + * </pre> * - * @param compareOne the first number + * @param compareOne the first expression * @param compareTwo the second number * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3C">Style specification</a> */ - public static Expression<Boolean> lt(@NonNull Number compareOne, @NonNull Number compareTwo) { - return new Expression<>("<", literal(compareOne), literal(compareTwo)); + public static Expression lt(@NonNull Expression compareOne, @NonNull Number compareTwo) { + return new Expression("<", literal(compareOne), literal(compareTwo)); } /** * Returns true if the first input is strictly less than the second, false otherwise. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * lt(get("keyToValue"), "value")) + * ); + * } + * </pre> * - * @param compareOne the first string + * @param compareOne the first expression * @param compareTwo the second string * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3C">Style specification</a> */ - public static Expression<Boolean> lt(@NonNull String compareOne, @NonNull String compareTwo) { - return new Expression<>("<", literal(compareOne), literal(compareTwo)); + public static Expression lt(@NonNull Expression compareOne, @NonNull String compareTwo) { + return new Expression("<", literal(compareOne), literal(compareTwo)); } /** * Returns true if the first input is greater than or equal to the second, false otherwise. * The inputs must be numbers or strings, and both of the same type. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * gte(get("keyToValue"), get("keyToOtherValue")) + * ); + * } + * </pre> * * @param compareOne the first expression * @param compareTwo the second expression * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3E%3D">Style specification</a> */ - public static Expression<Boolean> gte(@NonNull Expression compareOne, @NonNull Expression compareTwo) { - return new Expression<>(">=", compareOne, compareTwo); + public static Expression gte(@NonNull Expression compareOne, @NonNull Expression compareTwo) { + return new Expression(">=", compareOne, compareTwo); } /** * Returns true if the first input is greater than or equal to the second, false otherwise. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * gte(get("keyToValue"), 2.0f) + * ); + * } + * </pre> * - * @param compareOne the first number + * @param compareOne the first expression * @param compareTwo the second number * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3E%3D">Style specification</a> */ - public static Expression<Boolean> gte(@NonNull Number compareOne, @NonNull Number compareTwo) { - return new Expression<>(">=", literal(compareOne), literal(compareTwo)); + public static Expression gte(@NonNull Expression compareOne, @NonNull Number compareTwo) { + return new Expression(">=", literal(compareOne), literal(compareTwo)); } /** * Returns true if the first input is greater than or equal to the second, false otherwise. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * neq(get("keyToValue"), "value") + * ); + * } + * </pre> * - * @param compareOne the first string + * @param compareOne the first expression * @param compareTwo the second string * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3E%3D">Style specification</a> */ - public static Expression<Boolean> gte(@NonNull String compareOne, @NonNull String compareTwo) { - return new Expression<>(">=", literal(compareOne), literal(compareTwo)); + public static Expression gte(@NonNull Expression compareOne, @NonNull String compareTwo) { + return new Expression(">=", literal(compareOne), literal(compareTwo)); } /** * Returns true if the first input is less than or equal to the second, false otherwise. * The inputs must be numbers or strings, and both of the same type. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * lte(get("keyToValue"), get("keyToOtherValue")) + * ); + * } + * </pre> * * @param compareOne the first expression * @param compareTwo the second expression * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3C%3D">Style specification</a> */ - public static Expression<Boolean> lte(@NonNull Expression compareOne, @NonNull Expression compareTwo) { - return new Expression<>("<=", compareOne, compareTwo); + public static Expression lte(@NonNull Expression compareOne, @NonNull Expression compareTwo) { + return new Expression("<=", compareOne, compareTwo); } /** * Returns true if the first input is less than or equal to the second, false otherwise. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * lte(get("keyToValue"), 2.0f) + * ); + * } + * </pre> * - * @param compareOne the first number + * @param compareOne the first expression * @param compareTwo the second number * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3C%3D">Style specification</a> */ - public static Expression<Boolean> lte(@NonNull Number compareOne, @NonNull Number compareTwo) { - return new Expression<>("<=", literal(compareOne), literal(compareTwo)); + public static Expression lte(@NonNull Expression compareOne, @NonNull Number compareTwo) { + return new Expression("<=", literal(compareOne), literal(compareTwo)); } /** * Returns true if the first input is less than or equal to the second, false otherwise. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * lte(get("keyToValue"), "value") + * ); + * } + * </pre> * - * @param compareOne the first string + * @param compareOne the first expression * @param compareTwo the second string * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%3C%3D">Style specification</a> */ - public static Expression<Boolean> lte(@NonNull String compareOne, @NonNull String compareTwo) { - return new Expression<>("<=", literal(compareOne), literal(compareTwo)); + public static Expression lte(@NonNull Expression compareOne, @NonNull String compareTwo) { + return new Expression("<=", literal(compareOne), literal(compareTwo)); } /** @@ -584,13 +829,24 @@ public class Expression<T> { * once an input expression evaluates to `false`, * the result is `false` and no further input expressions are evaluated. * </p> + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * all(get("keyToValue"), get("keyToOtherValue")) + * ); + * } + * </pre> * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-all">Style specification</a> */ - @SafeVarargs - public static Expression<Boolean> all(@NonNull Expression<Boolean>... input) { - return new Expression<>("all", input); + public static Expression all(@NonNull Expression... input) { + return new Expression("all", input); } /** @@ -600,42 +856,98 @@ public class Expression<T> { * once an input expression evaluates to `true`, * the result is `true` and no further input expressions are evaluated. * </p> + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * any(get("keyToValue"), get("keyToOtherValue")) + * ); + * } + * </pre> * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-any">Style specification</a> */ - @SafeVarargs - public static Expression<Boolean> any(@NonNull Expression<Boolean>... input) { - return new Expression<>("any", input); + public static Expression any(@NonNull Expression... input) { + return new Expression("any", input); } /** * Logical negation. Returns `true` if the input is `false`, and `false` if the input is `true`. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * not(get("keyToValue")) + * ); + * } + * </pre> * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-!">Style specification</a> */ - public static Expression<Boolean> not(@NonNull Expression<Boolean> input) { - return new Expression<>("!", input); + public static Expression not(@NonNull Expression input) { + return new Expression("!", input); } /** * Logical negation. Returns `true` if the input is `false`, and `false` if the input is `true`. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * not(false) + * ); + * } + * </pre> * * @param input boolean input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-!">Style specification</a> */ - public static Expression<Boolean> not(boolean input) { + public static Expression not(boolean input) { return not(literal(input)); } /** * Selects the first output whose corresponding test condition evaluates to true. + * <p> + * For each case a condition and an output should be provided. + * The last parameter should provide the default output. + * </p> + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); + * symbolLayer.setProperties( + * iconSize( + * switchCase( + * get(KEY_TO_BOOLEAN), literal(3.0f), + * get(KEY_TO_OTHER_BOOLEAN), literal(5.0f) + * literal(1.0f) // default value + * ) + * ) + * ); + * } + * </pre> * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-case">Style specification</a> */ - @SafeVarargs public static Expression switchCase(@NonNull @Size(min = 1) Expression... input) { return new Expression("case", input); } @@ -644,9 +956,29 @@ public class Expression<T> { * Selects the output whose label value matches the input value, or the fallback value if no match is found. * The `input` can be any string or number expression. * Each label can either be a single literal value or an array of values. + * If types of the input and keys don't match, or the input value doesn't exist, + * the expresion will fail without falling back to the default value. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); + * symbolLayer.setProperties( + * textColor( + * match(get("keyToValue"), + * literal(1), rgba(255, 0, 0, 1.0f), + * literal(2), rgba(0, 0, 255.0f, 1.0f), + * rgba(0.0f, 255.0f, 0.0f, 1.0f) + * ); + * ) + * ); + * } + * </pre> * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-match">Style specification</a> */ public static Expression match(@NonNull @Size(min = 2) Expression... input) { return new Expression("match", input); @@ -656,91 +988,172 @@ public class Expression<T> { * Selects the output whose label value matches the input value, or the fallback value if no match is found. * The `input` can be any string or number expression. * Each label can either be a single literal value or an array of values. + * If types of the input and keys don't match, or the input value doesn't exist, + * the expresion will fail without falling back to the default value. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); + * symbolLayer.setProperties( + * textColor( + * match(get("keyToValue"), + * literal(1), rgba(255, 0, 0, 1.0f), + * literal(2), rgba(0, 0, 255.0f, 1.0f), + * rgba(0.0f, 255.0f, 0.0f, 1.0f) + * ); + * ) + * ); + * } + * </pre> * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-match">Style specification</a> */ - public static Expression match(@NonNull Expression input, @NonNull Stop... stops) { - Expression[] expressions = new Expression[stops.length * 2]; + public static Expression match(@NonNull Expression input, @NonNull Expression defaultOutput, @NonNull Stop... stops) { + Expression[] expressionStops = new Expression[stops.length * 2]; for (int i = 0; i < stops.length; i++) { - expressions[i * 2] = literal(stops[i].value); - expressions[i * 2 + 1] = literal(stops[i].output); + expressionStops[i * 2] = literal(stops[i].value); + expressionStops[i * 2 + 1] = literal(stops[i].output); } - return match(join(new Expression[] {input}, expressions)); + return match(join(join(new Expression[] {input}, expressionStops), new Expression[] {defaultOutput})); } /** * Evaluates each expression in turn until the first non-null value is obtained, and returns that value. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); + * symbolLayer.setProperties( + * textColor( + * coalesce( + * get("keyToNullValue"), + * get("keyToNonNullValue") + * ); + * ) + * ); + * } + * </pre> * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-coalesce">Style specification</a> */ public static Expression coalesce(@NonNull Expression... input) { return new Expression("coalesce", input); } - // - // FeatureData - // - /** * Gets the feature properties object. * <p> * Note that in some cases, it may be more efficient to use {@link #get(Expression)}} instead. * </p> + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); + * symbolLayer.setProperties( + * textField(get("key-to-value", properties()))) + * ); + * } + * </pre> * * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-properties">Style specification</a> */ - public static Expression<Object> properties() { - return new Expression<>("properties"); + public static Expression properties() { + return new Expression("properties"); } /** * Gets the feature's geometry type: Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); + * symbolLayer.setProperties( + * textField(concat(get("key-to-value"), literal(" "), geometryType()) + * ); + * } + * </pre> * * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-geometry-types">Style specification</a> */ - public static Expression<String> geometryType() { - return new Expression<>("geometry-type"); + public static Expression geometryType() { + return new Expression("geometry-type"); } /** * Gets the feature's id, if it has one. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); + * symbolLayer.setProperties( + * textField(id()) + * ); + * } + * </pre> * * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-id">Style specification</a> */ - public static Expression<Number> id() { - return new Expression<>("id"); + public static Expression id() { + return new Expression("id"); } - // - // Heatmap - // - /** * Gets the kernel density estimation of a pixel in a heatmap layer, * which is a relative measure of how many data points are crowded around a particular pixel. * Can only be used in the `heatmap-color` property. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * HeatmapLayer layer = new HeatmapLayer("layer-id", "source-id"); + * layer.setProperties( + * heatmapColor(interpolate(linear(), heatmapDensity(), + * literal(0), rgba(33, 102, 172, 0), + * literal(0.2), rgb(103, 169, 207), + * literal(0.4), rgb(209, 229, 240), + * literal(0.6), rgb(253, 219, 199), + * literal(0.8), rgb(239, 138, 98), + * literal(1), rgb(178, 24, 43) + * ) + * ) + * } + * </pre> * * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-heatmap-density">Style specification</a> */ - public static Expression<Number> heatmapDensity() { - return new Expression<>("heatmap-density"); + public static Expression heatmapDensity() { + return new Expression("heatmap-density"); } - // - // Lookup - // - /** * Retrieves an item from an array. * * @param number the index expression * @param expression the array expression * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-at">Style specification</a> */ - public static Expression<Object> at(@NonNull Expression<Number> number, @NonNull Expression expression) { - return new Expression<>("at", number, expression); + public static Expression at(@NonNull Expression number, @NonNull Expression expression) { + return new Expression("at", number, expression); } /** @@ -749,8 +1162,9 @@ public class Expression<T> { * @param number the index expression * @param expression the array expression * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-at">Style specification</a> */ - public static Expression<Object> at(@NonNull Number number, @NonNull Expression expression) { + public static Expression at(@NonNull Number number, @NonNull Expression expression) { return at(literal(number), expression); } @@ -758,21 +1172,45 @@ public class Expression<T> { * Retrieves a property value from the current feature's properties, * or from another object if a second argument is provided. * Returns null if the requested property is missing. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); + * symbolLayer.setProperties( + * textField(get("key-to-feature")) + * ); + * } + * </pre> * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-get">Style specification</a> */ - public static Expression get(@NonNull Expression<String> input) { - return new Expression<>("get", input); + public static Expression get(@NonNull Expression input) { + return new Expression("get", input); } /** * Retrieves a property value from the current feature's properties, * or from another object if a second argument is provided. * Returns null if the requested property is missing. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); + * symbolLayer.setProperties( + * textField(get("key-to-feature")) + * ); + * } + * </pre> * * @param input string input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-get">Style specification</a> */ public static Expression get(@NonNull String input) { return get(literal(input)); @@ -781,66 +1219,138 @@ public class Expression<T> { /** * Retrieves a property value from another object. * Returns null if the requested property is missing. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); + * symbolLayer.setProperties( + * textField(get("key-to-property", get("key-to-object"))) + * ); + * } + * </pre> * * @param key a property value key * @param object an expression object * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-get">Style specification</a> */ - public static Expression<Object> get(@NonNull Expression<String> key, @NonNull Expression<Object> object) { - return new Expression<>("get", key, object); + public static Expression get(@NonNull Expression key, @NonNull Expression object) { + return new Expression("get", key, object); } /** * Retrieves a property value from another object. * Returns null if the requested property is missing. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); + * symbolLayer.setProperties( + * textField(get("key-to-property", get("key-to-object"))) + * ); + * } + * </pre> * * @param key a property value key * @param object an expression object * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-get">Style specification</a> */ - public static Expression<Object> get(@NonNull String key, @NonNull Expression<Object> object) { + public static Expression get(@NonNull String key, @NonNull Expression object) { return get(literal(key), object); } /** * Tests for the presence of an property value in the current feature's properties. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * has(get("keyToValue")) + * ); + * } + * </pre> * * @param key the expression property value key * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-has">Style specification</a> */ - public static Expression<Boolean> has(@NonNull Expression<String> key) { - return new Expression<>("has", key); + public static Expression has(@NonNull Expression key) { + return new Expression("has", key); } /** * Tests for the presence of an property value in the current feature's properties. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * has("keyToValue") + * ); + * } + * </pre> * * @param key the property value key * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-has">Style specification</a> */ - public static Expression<Boolean> has(@NonNull String key) { + public static Expression has(@NonNull String key) { return has(literal(key)); } /** * Tests for the presence of an property value from another object. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * has(get("keyToValue"), get("keyToObject")) + * ); + * } + * </pre> * * @param key the expression property value key * @param object an expression object * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-has">Style specification</a> */ - public static Expression<Boolean> has(@NonNull Expression<String> key, @NonNull Expression<Object> object) { - return new Expression<>("has", key, object); + public static Expression has(@NonNull Expression key, @NonNull Expression object) { + return new Expression("has", key, object); } /** * Tests for the presence of an property value from another object. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setFilter( + * has("keyToValue", get("keyToObject)) + * ); + * } + * </pre> * * @param key the property value key * @param object an expression object * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-has">Style specification</a> */ - public static Expression<Boolean> has(@NonNull String key, @NonNull Expression<Object> object) { + public static Expression has(@NonNull String key, @NonNull Expression object) { return has(literal(key), object); } @@ -849,9 +1359,10 @@ public class Expression<T> { * * @param expression an expression object or expression string * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-lenght">Style specification</a> */ - public static Expression<Number> length(@NonNull Expression<?> expression) { - return new Expression<>("length", expression); + public static Expression length(@NonNull Expression expression) { + return new Expression("length", expression); } /** @@ -859,62 +1370,117 @@ public class Expression<T> { * * @param input a string * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-lenght">Style specification</a> */ - public static Expression<Number> length(@NonNull String input) { + public static Expression length(@NonNull String input) { return length(literal(input)); } - // - // Math - // - /** * Returns mathematical constant ln(2). + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(product(literal(10.0f), ln2()))) + * ); + * } + * </pre> * * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-ln2">Style specification</a> */ - public static Expression<Number> ln2() { - return new Expression<>("ln2"); + public static Expression ln2() { + return new Expression("ln2"); } /** * Returns the mathematical constant pi. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(product(literal(10.0f), pi()))) + * ); + * } + * </pre> * * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-pi">Style specification</a> */ - public static Expression<Number> pi() { - return new Expression<>("pi"); + public static Expression pi() { + return new Expression("pi"); } /** * Returns the mathematical constant e. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(product(literal(10.0f), e()))) + * ); + * } + * </pre> * * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-e">Style specification</a> */ - public static Expression<Number> e() { - return new Expression<>("e"); + public static Expression e() { + return new Expression("e"); } /** * Returns the sum of the inputs. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(sum(literal(10.0f), ln2(), pi()))) + * ); + * } + * </pre> * * @param numbers the numbers to calculate the sum for * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-+">Style specification</a> */ - @SafeVarargs - public static Expression<Number> sum(@Size(min = 2) Expression<Number>... numbers) { - return new Expression<>("+", numbers); + public static Expression sum(@Size(min = 2) Expression... numbers) { + return new Expression("+", numbers); } /** * Returns the sum of the inputs. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(sum(10.0f, 5.0f, 3.0f))) + * ); + * } + * </pre> * * @param numbers the numbers to calculate the sum for * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-+">Style specification</a> */ - @SuppressWarnings("unchecked") - public static Expression<Number> sum(@Size(min = 2) Number... numbers) { - Expression<Number>[] numberExpression = (Expression<Number>[]) new Expression<?>[numbers.length]; + public static Expression sum(@Size(min = 2) Number... numbers) { + Expression[] numberExpression = new Expression[numbers.length]; for (int i = 0; i < numbers.length; i++) { numberExpression[i] = literal(numbers[i]); } @@ -923,24 +1489,46 @@ public class Expression<T> { /** * Returns the product of the inputs. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(product(literal(10.0f), ln2()))) + * ); + * } + * </pre> * * @param numbers the numbers to calculate the product for * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-*">Style specification</a> */ - @SafeVarargs - public static Expression<Number> product(@Size(min = 2) Expression<Number>... numbers) { - return new Expression<>("*", numbers); + public static Expression product(@Size(min = 2) Expression... numbers) { + return new Expression("*", numbers); } /** * Returns the product of the inputs. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(product(10.0f, 2.0f))) + * ); + * } + * </pre> * * @param numbers the numbers to calculate the product for * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-*">Style specification</a> */ - @SuppressWarnings("unchecked") - public static Expression<Number> product(@Size(min = 2) Number... numbers) { - Expression<Number>[] numberExpression = (Expression<Number>[]) new Expression<?>[numbers.length]; + public static Expression product(@Size(min = 2) Number... numbers) { + Expression[] numberExpression = new Expression[numbers.length]; for (int i = 0; i < numbers.length; i++) { numberExpression[i] = literal(numbers[i]); } @@ -949,334 +1537,714 @@ public class Expression<T> { /** * Returns the result of subtracting a number from 0. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(subtract(pi())) + * ); + * } + * </pre> * * @param number the number subtract from 0 * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions--">Style specification</a> */ - public static Expression<Number> subtract(@NonNull Expression<Number> number) { - return new Expression<>("-", number); + public static Expression subtract(@NonNull Expression number) { + return new Expression("-", number); } /** * Returns the result of subtracting a number from 0. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(subtract(10.0f)) + * ); + * } + * </pre> * * @param number the number subtract from 0 * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions--">Style specification</a> */ - public static Expression<Number> subtract(@NonNull Number number) { + public static Expression subtract(@NonNull Number number) { return subtract(literal(number)); } /** * Returns the result of subtracting the second input from the first. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(subtract(literal(10.0f), pi()))) + * ); + * } + * </pre> * * @param first the first number * @param second the second number * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions--">Style specification</a> */ - public static Expression<Number> subtract(@NonNull Expression<Number> first, @NonNull Expression<Number> second) { - return new Expression<>("-", first, second); + public static Expression subtract(@NonNull Expression first, @NonNull Expression second) { + return new Expression("-", first, second); } /** * Returns the result of subtracting the second input from the first. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(subtract(10.0f, 20.0f))) + * ); + * } + * </pre> * * @param first the first number * @param second the second number * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions--">Style specification</a> */ - public static Expression<Number> subtract(@NonNull Number first, @NonNull Number second) { + public static Expression subtract(@NonNull Number first, @NonNull Number second) { return subtract(literal(first), literal(second)); } /** * Returns the result of floating point division of the first input by the second. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(division(literal(10.0f), pi()))) + * ); + * } + * </pre> * * @param first the first number * @param second the second number * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-/">Style specification</a> */ - @SuppressWarnings("unchecked") - public static Expression<Number> division(@NonNull Expression<Number> first, @NonNull Expression<Number> second) { - return new Expression<>("/", first, second); + public static Expression division(@NonNull Expression first, @NonNull Expression second) { + return new Expression("/", first, second); } /** * Returns the result of floating point division of the first input by the second. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(division(10.0f, 20.0f))) + * ); + * } + * </pre> * * @param first the first number * @param second the second number * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-/">Style specification</a> */ - @SuppressWarnings("unchecked") - public static Expression<Number> division(@NonNull Number first, @NonNull Number second) { + public static Expression division(@NonNull Number first, @NonNull Number second) { return division(literal(first), literal(second)); } /** * Returns the remainder after integer division of the first input by the second. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(mod(literal(10.0f), pi())) + * ); + * } + * </pre> * * @param first the first number * @param second the second number * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%25">Style specification</a> */ - public static Expression<Number> mod(@NonNull Expression<Number> first, @NonNull Expression<Number> second) { - return new Expression<>("%", first, second); + public static Expression mod(@NonNull Expression first, @NonNull Expression second) { + return new Expression("%", first, second); } /** * Returns the remainder after integer division of the first input by the second. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(mod(10.0f, 10.0f)) + * ); + * } + * </pre> * * @param first the first number * @param second the second number * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%25">Style specification</a> */ - public static Expression<Number> mod(@NonNull Number first, @NonNull Number second) { + public static Expression mod(@NonNull Number first, @NonNull Number second) { return mod(literal(first), literal(second)); } /** * Returns the result of raising the first input to the power specified by the second. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(pow(pi(), literal(2.0f)) + * ); + * } + * </pre> * * @param first the first number * @param second the second number * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%5E">Style specification</a> */ - public static Expression<Number> pow(@NonNull Expression<Number> first, @NonNull Expression<Number> second) { - return new Expression<>("^", first, second); + public static Expression pow(@NonNull Expression first, @NonNull Expression second) { + return new Expression("^", first, second); } /** * Returns the result of raising the first input to the power specified by the second. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(pow(5.0f, 2.0f)) + * ); + * } + * </pre> * * @param first the first number * @param second the second number * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-%5E">Style specification</a> */ - public static Expression<Number> pow(@NonNull Number first, @NonNull Number second) { + public static Expression pow(@NonNull Number first, @NonNull Number second) { return pow(literal(first), literal(second)); } /** * Returns the square root of the input + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(sqrt(pi())) + * ); + * } + * </pre> * * @param number the number to take the square root from * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-sqrt">Style specification</a> */ - public static Expression<Number> sqrt(@NonNull Expression<Number> number) { - return new Expression<>("sqrt", number); + public static Expression sqrt(@NonNull Expression number) { + return new Expression("sqrt", number); } /** * Returns the square root of the input + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(sqrt(25.0f)) + * ); + * } + * </pre> * * @param number the number to take the square root from * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-sqrt">Style specification</a> */ - public static Expression<Number> sqrt(@NonNull Number number) { + public static Expression sqrt(@NonNull Number number) { return sqrt(literal(number)); } /** * Returns the base-ten logarithm of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(log10(pi())) + * ); + * } + * </pre> * * @param number the number to take base-ten logarithm from * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-log10">Style specification</a> */ - public static Expression<Number> log10(@NonNull Expression<Number> number) { - return new Expression<>("log10", number); + public static Expression log10(@NonNull Expression number) { + return new Expression("log10", number); } /** * Returns the base-ten logarithm of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(log10(10)) + * ); + * } + * </pre> * * @param number the number to take base-ten logarithm from * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-log10">Style specification</a> */ - public static Expression<Number> log10(@NonNull Number number) { + public static Expression log10(@NonNull Number number) { return log10(literal(number)); } /** * Returns the natural logarithm of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(ln(pi())) + * ); + * } + * </pre> * * @param number the number to take natural logarithm from * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-ln">Style specification</a> */ - public static Expression<Number> ln(Expression<Number> number) { - return new Expression<>("ln", number); + public static Expression ln(Expression number) { + return new Expression("ln", number); } /** * Returns the natural logarithm of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(ln(10)) + * ); + * } + * </pre> * * @param number the number to take natural logarithm from * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-ln">Style specification</a> */ - public static Expression<Number> ln(Number number) { + public static Expression ln(Number number) { return ln(literal(number)); } /** * Returns the base-two logarithm of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(log2(pi())) + * ); + * } + * </pre> * * @param number the number to take base-two logarithm from * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-log2">Style specification</a> */ - public static Expression<Number> log2(@NonNull Expression<Number> number) { - return new Expression<>("log2", number); + public static Expression log2(@NonNull Expression number) { + return new Expression("log2", number); } /** * Returns the base-two logarithm of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(log2(2)) + * ); + * } + * </pre> * * @param number the number to take base-two logarithm from * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-log2">Style specification</a> */ - public static Expression<Number> log2(@NonNull Number number) { + public static Expression log2(@NonNull Number number) { return log2(literal(number)); } /** * Returns the sine of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(sin(pi())) + * ); + * } + * </pre> * * @param number the number to calculate the sine for * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-sin">Style specification</a> */ - public static Expression<Number> sin(@NonNull Expression<Number> number) { - return new Expression<>("sin", number); + public static Expression sin(@NonNull Expression number) { + return new Expression("sin", number); } /** * Returns the sine of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(sin(90.0f)) + * ); + * } + * </pre> * * @param number the number to calculate the sine for * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-sin">Style specification</a> */ - public static Expression<Number> sin(@NonNull Number number) { + public static Expression sin(@NonNull Number number) { return sin(literal(number)); } /** * Returns the cosine of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(cos(pi())) + * ); + * } + * </pre> * * @param number the number to calculate the cosine for * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-cos">Style specification</a> */ - public static Expression<Number> cos(@NonNull Expression<Number> number) { - return new Expression<>("cos", number); + public static Expression cos(@NonNull Expression number) { + return new Expression("cos", number); } /** * Returns the cosine of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(cos(0))) + * ); + * } + * </pre> * * @param number the number to calculate the cosine for * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-cos">Style specification</a> */ - public static Expression<Number> cos(@NonNull Number number) { - return new Expression<>("cos", literal(number)); + public static Expression cos(@NonNull Number number) { + return new Expression("cos", literal(number)); } /** * Returns the tangent of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(tan(pi())) + * ); + * } + * </pre> * * @param number the number to calculate the tangent for * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-tan">Style specification</a> */ - public static Expression<Number> tan(@NonNull Expression<Number> number) { - return new Expression<>("tan", number); + public static Expression tan(@NonNull Expression number) { + return new Expression("tan", number); } /** * Returns the tangent of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(tan(45.0f)) + * ); + * } + * </pre> * * @param number the number to calculate the tangent for * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-tan">Style specification</a> */ - public static Expression<Number> tan(@NonNull Number number) { - return new Expression<>("tan", literal(number)); + public static Expression tan(@NonNull Number number) { + return new Expression("tan", literal(number)); } /** * Returns the arcsine of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(asin(pi())) + * ); + * } + * </pre> * * @param number the number to calculate the arcsine for * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-asin">Style specification</a> */ - public static Expression<Number> asin(@NonNull Expression<Number> number) { - return new Expression<>("asin", number); + public static Expression asin(@NonNull Expression number) { + return new Expression("asin", number); } /** * Returns the arcsine of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(asin(90)) + * ); + * } + * </pre> * * @param number the number to calculate the arcsine for * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-asin">Style specification</a> */ - public static Expression<Number> asin(@NonNull Number number) { + public static Expression asin(@NonNull Number number) { return asin(literal(number)); } /** * Returns the arccosine of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(acos(pi())) + * ); + * } + * </pre> * * @param number the number to calculate the arccosine for * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-acos">Style specification</a> */ - public static Expression<Number> acos(@NonNull Expression<Number> number) { - return new Expression<>("acos", number); + public static Expression acos(@NonNull Expression number) { + return new Expression("acos", number); } /** * Returns the arccosine of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(acos(0)) + * ); + * } + * </pre> * * @param number the number to calculate the arccosine for * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-acos">Style specification</a> */ - public static Expression<Number> acos(@NonNull Number number) { + public static Expression acos(@NonNull Number number) { return acos(literal(number)); } /** * Returns the arctangent of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(asin(pi())) + * ); + * } + * </pre> * * @param number the number to calculate the arctangent for * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-atan">Style specification</a> */ - public static Expression<Number> atan(@NonNull Expression<Number> number) { + public static Expression atan(@NonNull Expression number) { return new Expression("atan", number); } /** * Returns the arctangent of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(atan(90)) + * ); + * } + * </pre> * * @param number the number to calculate the arctangent for * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-atan">Style specification</a> */ - public static Expression<Number> atan(@NonNull Number number) { + public static Expression atan(@NonNull Number number) { return atan(literal(number)); } /** * Returns the minimum value of the inputs. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(min(pi(), literal(3.14f), literal(3.15f)) + * ); + * } + * </pre> * * @param numbers varargs of numbers to get the minimum from * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-min">Style specification</a> */ - @SafeVarargs - public static Expression<Number> min(@Size(min = 1) Expression<Number>... numbers) { - return new Expression<>("min", numbers); + public static Expression min(@Size(min = 1) Expression... numbers) { + return new Expression("min", numbers); } /** * Returns the minimum value of the inputs. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(min(3.141, 3.14f, 3.15f)) + * ); + * } + * </pre> * * @param numbers varargs of numbers to get the minimum from * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-min">Style specification</a> */ - @SuppressWarnings("unchecked") - public static Expression<Number> min(@Size(min = 1) Number... numbers) { - Expression<Number>[] numberExpression = (Expression<Number>[]) new Expression<?>[numbers.length]; + public static Expression min(@Size(min = 1) Number... numbers) { + Expression[] numberExpression = new Expression[numbers.length]; for (int i = 0; i < numbers.length; i++) { numberExpression[i] = literal(numbers[i]); } @@ -1285,33 +2253,230 @@ public class Expression<T> { /** * Returns the maximum value of the inputs. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(max(pi(), 3.14f, 3.15f)) + * ); + * } + * </pre> * * @param numbers varargs of numbers to get the maximum from * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-max">Style specification</a> */ - @SafeVarargs - public static Expression<Number> max(@Size(min = 1) Expression<Number>... numbers) { - return new Expression<>("max", numbers); + public static Expression max(@Size(min = 1) Expression... numbers) { + return new Expression("max", numbers); } /** * Returns the maximum value of the inputs. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(max(3.141, 3.14f, 3.15f)) + * ); + * } + * </pre> * * @param numbers varargs of numbers to get the maximum from * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-max">Style specification</a> */ - @SuppressWarnings("unchecked") - public static Expression<Number> max(@Size(min = 1) Number... numbers) { - Expression<Number>[] numberExpression = (Expression<Number>[]) new Expression<?>[numbers.length]; + public static Expression max(@Size(min = 1) Number... numbers) { + Expression[] numberExpression = new Expression[numbers.length]; for (int i = 0; i < numbers.length; i++) { numberExpression[i] = literal(numbers[i]); } return max(numberExpression); } - // - // String - // + /** + * Rounds the input to the nearest integer. + * Halfway values are rounded away from zero. + * For example `[\"round\", -1.5]` evaluates to -2. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(round(pi())) + * ); + * } + * </pre> + * + * @param expression number expression to round + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-round">Style specification</a> + */ + public static Expression round(Expression expression) { + return new Expression("round", expression); + } + + /** + * Rounds the input to the nearest integer. + * Halfway values are rounded away from zero. + * For example `[\"round\", -1.5]` evaluates to -2. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(round(3.14159265359f)) + * ); + * } + * </pre> + * + * @param number number to round + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-round">Style specification</a> + */ + public static Expression round(Number number) { + return round(literal(number)); + } + + /** + * Returns the absolute value of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(abs(subtract(pi()))) + * ); + * } + * </pre> + * + * @param expression number expression to get absolute value from + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-abs">Style specification</a> + */ + public static Expression abs(Expression expression) { + return new Expression("abs", expression); + } + + /** + * Returns the absolute value of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(abs(-3.14159265359f)) + * ); + * } + * </pre> + * + * @param number number to get absolute value from + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-abs">Style specification</a> + */ + public static Expression abs(Number number) { + return abs(literal(number)); + } + + /** + * Returns the smallest integer that is greater than or equal to the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(ceil(pi())) + * ); + * } + * </pre> + * + * @param expression number expression to get value from + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-abs">Style specification</a> + */ + public static Expression ceil(Expression expression) { + return new Expression("ceil", expression); + } + + /** + * Returns the smallest integer that is greater than or equal to the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(ceil(3.14159265359)) + * ); + * } + * </pre> + * @param number number to get value from + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-abs">Style specification</a> + */ + public static Expression ceil(Number number) { + return ceil(literal(number)); + } + + /** + * Returns the largest integer that is less than or equal to the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(floor(pi())) + * ); + * } + * </pre> + * + * @param expression number expression to get value from + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-abs">Style specification</a> + */ + public static Expression floor(Expression expression) { + return new Expression("floor", expression); + } + + /** + * Returns the largest integer that is less than or equal to the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(floor(pi())) + * ); + * } + * </pre> + * + * @param number number to get value from + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-abs">Style specification</a> + */ + public static Expression floor(Number number) { + return floor(literal(number)); + } /** * Returns the input string converted to uppercase. @@ -1319,12 +2484,24 @@ public class Expression<T> { * Follows the Unicode Default Case Conversion algorithm * and the locale-insensitive case mappings in the Unicode Character Database. * </p> + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); + * symbolLayer.setProperties( + * textField(upcase(get("key-to-string-value")) + * ); + * } + * </pre> * * @param string the string to upcase * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-upcase">Style specification</a> */ - public static Expression<String> upcase(@NonNull Expression<String> string) { - return new Expression<>("upcase", string); + public static Expression upcase(@NonNull Expression string) { + return new Expression("upcase", string); } /** @@ -1333,11 +2510,23 @@ public class Expression<T> { * Follows the Unicode Default Case Conversion algorithm * and the locale-insensitive case mappings in the Unicode Character Database. * </p> + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); + * symbolLayer.setProperties( + * textField(upcase("text")) + * ); + * } + * </pre> * * @param string string to upcase * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-upcase">Style specification</a> */ - public static Expression<String> upcase(@NonNull String string) { + public static Expression upcase(@NonNull String string) { return upcase(literal(string)); } @@ -1347,12 +2536,24 @@ public class Expression<T> { * Follows the Unicode Default Case Conversion algorithm * and the locale-insensitive case mappings in the Unicode Character Database. * </p> + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); + * symbolLayer.setProperties( + * textField(downcase(get("key-to-string-value")) + * ); + * } + * </pre> * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-downcase">Style specification</a> */ - public static Expression<String> downcase(@NonNull Expression<String> input) { - return new Expression<>("downcase", input); + public static Expression downcase(@NonNull Expression input) { + return new Expression("downcase", input); } /** @@ -1361,44 +2562,74 @@ public class Expression<T> { * Follows the Unicode Default Case Conversion algorithm * and the locale-insensitive case mappings in the Unicode Character Database. * </p> + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); + * symbolLayer.setProperties( + * textField(upcase("key-to-string-value") + * ); + * } + * </pre> * * @param input string to downcase * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-downcase">Style specification</a> */ - public static Expression<String> downcase(@NonNull String input) { + public static Expression downcase(@NonNull String input) { return downcase(literal(input)); } /** * Returns a string consisting of the concatenation of the inputs. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); + * symbolLayer.setProperties( + * textField(concat(get("key-to-string-value"), literal("other string")) + * ); + * } + * </pre> * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-concat">Style specification</a> */ - @SafeVarargs - public static Expression<String> concat(@NonNull Expression<String>... input) { - return new Expression<>("concat", input); + public static Expression concat(@NonNull Expression... input) { + return new Expression("concat", input); } /** * Returns a string consisting of the concatenation of the inputs. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); + * symbolLayer.setProperties( + * textField(concat("foo", "bar")) + * ); + * } + * </pre> * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-concat">Style specification</a> */ - @SuppressWarnings("unchecked") - public static Expression<String> concat(@NonNull String... input) { - Expression<String>[] stringExpression = (Expression<String>[]) new Expression<?>[input.length]; + public static Expression concat(@NonNull String... input) { + Expression[] stringExpression = new Expression[input.length]; for (int i = 0; i < input.length; i++) { stringExpression[i] = literal(input[i]); } return concat(stringExpression); } - // - // Types - // - /** * Asserts that the input is an array (optionally with a specific item type and length). * If, when the input expression is evaluated, it is not of the asserted type, @@ -1406,9 +2637,10 @@ public class Expression<T> { * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-types-array">Style specification</a> */ - public static Expression<Boolean> array(@NonNull Expression input) { - return new Expression<>("array", input); + public static Expression array(@NonNull Expression input) { + return new Expression("array", input); } /** @@ -1416,55 +2648,64 @@ public class Expression<T> { * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-types-typeof">Style specification</a> */ - public static Expression<String> typeOf(@NonNull Expression input) { - return new Expression<>("typeof", input); + public static Expression typeOf(@NonNull Expression input) { + return new Expression("typeof", input); } /** * Asserts that the input value is a string. * If multiple values are provided, each one is evaluated in order until a string value is obtained. * If none of the inputs are strings, the expression is an error. + * The asserted input value is returned as result. * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-types-string">Style specification</a> */ - public static Expression<Boolean> string(@NonNull Expression input) { - return new Expression<>("string", input); + public static Expression string(@NonNull Expression... input) { + return new Expression("string", input); } /** * Asserts that the input value is a number. * If multiple values are provided, each one is evaluated in order until a number value is obtained. * If none of the inputs are numbers, the expression is an error. + * The asserted input value is returned as result. * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-types-number">Style specification</a> */ - public static Expression<Boolean> number(@NonNull Expression input) { - return new Expression<>("number", input); + public static Expression number(@NonNull Expression... input) { + return new Expression("number", input); } /** * Asserts that the input value is a boolean. * If multiple values are provided, each one is evaluated in order until a boolean value is obtained. * If none of the inputs are booleans, the expression is an error. + * The asserted input value is returned as result. * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-types-boolean">Style specification</a> */ - public static Expression<Boolean> bool(@NonNull Expression input) { - return new Expression<>("boolean", input); + public static Expression bool(@NonNull Expression... input) { + return new Expression("boolean", input); } /** * Asserts that the input value is an object. If it is not, the expression is an error + * The asserted input value is returned as result. * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-types-object">Style specification</a> */ - public static Expression<Boolean> object(@NonNull Expression input) { - return new Expression<>("object", input); + public static Expression object(@NonNull Expression input) { + return new Expression("object", input); } /** @@ -1476,12 +2717,24 @@ public class Expression<T> { * where `r`, `g`, and `b` are numerals ranging from 0 to 255, and `a` ranges from 0 to 1. * Otherwise, the input is converted to a string in the format specified by the JSON.stringify in the ECMAScript * Language Specification. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); + * symbolLayer.setProperties( + * textField(toString(get("key-to-number-value"))) + * ); + * } + * </pre> * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-types-to-string">Style specification</a> */ - public static Expression<String> toString(@NonNull Expression input) { - return new Expression<>("to-string", input); + public static Expression toString(@NonNull Expression input) { + return new Expression("to-string", input); } /** @@ -1491,51 +2744,83 @@ public class Expression<T> { * If the input is a string, it is converted to a number as specified by the ECMAScript Language Specification. * If multiple values are provided, each one is evaluated in order until the first successful conversion is obtained. * If none of the inputs can be converted, the expression is an error. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(toNumber(get("key-to-string-value"))) + * ); + * } + * </pre> * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-types-to-number">Style specification</a> */ - public static Expression<Number> toNumber(@NonNull Expression input) { - return new Expression<>("to-number", input); + public static Expression toNumber(@NonNull Expression input) { + return new Expression("to-number", input); } /** - * "Converts the input value to a boolean. The result is `false` when then input is an empty string, 0, false, + * Converts the input value to a boolean. The result is `false` when then input is an empty string, 0, false, * null, or NaN; otherwise it is true. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(toBool(get("key-to-value")); + * ); + * } + * </pre> * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-types-to-boolean">Style specification</a> */ - public static Expression<Boolean> toBool(@NonNull Expression input) { - return new Expression<>("to-boolean", input); + public static Expression toBool(@NonNull Expression input) { + return new Expression("to-boolean", input); } /** * Converts the input value to a color. If multiple values are provided, * each one is evaluated in order until the first successful conversion is obtained. * If none of the inputs can be converted, the expression is an error. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new FillLayer("layer-id", "source-id"); + * fillLayer.setProperties( + * fillColor(toColor(get("keyStringValue"))) + * ); + * } + * </pre> * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-types-to-color">Style specification</a> */ - public static Expression<Color> toColor(@NonNull Expression input) { - return new Expression<>("to-color", input); + public static Expression toColor(@NonNull Expression input) { + return new Expression("to-color", input); } - // - // Variable binding - // - /** * Binds input to named variables, * which can then be referenced in the result expression using {@link #var(String)} or {@link #var(Expression)}. * * @param input expression input * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-let">Style specification</a> */ - @SafeVarargs public static Expression let(@Size(min = 1) Expression... input) { - return new Expression<>("let", input); + return new Expression("let", input); } /** @@ -1543,9 +2828,10 @@ public class Expression<T> { * * @param expression the variable naming expression that was bound with using let * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-var">Style specification</a> */ - public static Expression<Object> var(@NonNull Expression<String> expression) { - return new Expression<>("var", expression); + public static Expression var(@NonNull Expression expression) { + return new Expression("var", expression); } /** @@ -1553,32 +2839,66 @@ public class Expression<T> { * * @param variableName the variable naming that was bound with using let * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-var">Style specification</a> */ public static Expression var(@NonNull String variableName) { return var(literal(variableName)); } - // - // Zoom - // - /** * Gets the current zoom level. * <p> * Note that in style layout and paint properties, * zoom may only appear as the input to a top-level step or interpolate expression. * </p> + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new fillLayer("layer-id", "source-id"); + * fillLayer.setProperties( + * fillColor( + * interpolate( + * exponential(0.5f), zoom(), + * literal(1.0f), color(Color.RED), + * literal(5.0f, color(Color.BLUE), + * literal(10.0f, color(Color.GREEN) + * ) + * ) + * ); + * } + * </pre> * * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-zoom">Style specification</a> */ - public static Expression<Number> zoom() { - return new Expression<>("zoom"); + public static Expression zoom() { + return new Expression("zoom"); } - // - // Ramps, scales, curves - // - + /** + * Produces a stop value to be used as part of the step expression. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius( + * step(zoom(), literal(0.0f), + * stop(1.0f, 2.5f), + * stop(10.0f, 5.0f) + * ) + * ); + * } + * </pre> + * + * @param stop the stop input + * @param value the stop output + * @return the stop + */ public static Stop stop(@NonNull Object stop, @NonNull Object value) { return new Stop(stop, value); } @@ -1589,14 +2909,30 @@ public class Expression<T> { * Stop inputs must be numeric literals in strictly ascending order. * Returns the output value of the stop just less than the input, * or the first input if the input is less than the first stop. - * - * @param input the input value - * @param stops pair of input and output values + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius( + * step(zoom(), literal(0.0f), + * literal(1.0f), literal(2.5f), + * literal(10.0f), literal(5.0f) + * ) + * ); + * } + * </pre> + * + * @param input the input value + * @param defaultOutput the default output expression + * @param stops pair of input and output values * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-step">Style specification</a> */ - @SafeVarargs - public static Expression step(@NonNull Number input, @NonNull Expression expression, Expression... stops) { - return step(literal(input), expression, stops); + public static Expression step(@NonNull Number input, @NonNull Expression defaultOutput, Expression... stops) { + return step(literal(input), defaultOutput, stops); } /** @@ -1605,14 +2941,30 @@ public class Expression<T> { * Stop inputs must be numeric literals in strictly ascending order. * Returns the output value of the stop just less than the input, * or the first input if the input is less than the first stop. - * - * @param expression the input expression - * @param stops pair of input and output values + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius( + * step(zoom(), literal(0.0f), + * literal(1.0f), literal(2.5f), + * literal(10.0f), literal(5.0f) + * ) + * ); + * } + * </pre> + * + * @param input the input expression + * @param defaultOutput the default output expression + * @param stops pair of input and output values * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-step">Style specification</a> */ - @SafeVarargs - public static Expression step(@NonNull Expression<Number> input, @NonNull Expression expression, Expression... stops) { - return new Expression("step", join(new Expression[] {input, expression}, stops)); + public static Expression step(@NonNull Expression input, @NonNull Expression defaultOutput, Expression... stops) { + return new Expression("step", join(new Expression[] {input, defaultOutput}, stops)); } /** @@ -1621,19 +2973,30 @@ public class Expression<T> { * Stop inputs must be numeric literals in strictly ascending order. * Returns the output value of the stop just less than the input, * or the first input if the input is less than the first stop. - * - * @param input the input value - * @param stops pair of input and output values + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius( + * step(zoom(), literal(0.0f), + * stop(1, 2.5f), + * stop(10, 5.0f) + * ) + * ); + * } + * </pre> + * + * @param input the input value + * @param defaultOutput the default output expression + * @param stops pair of input and output values * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-step">Style specification</a> */ - @SafeVarargs - public static Expression step(@NonNull Number input, @NonNull Expression expression, Stop... stops) { - Expression[] expressions = new Expression[stops.length * 2]; - for (int i = 0; i < stops.length; i++) { - expressions[i * 2] = literal(stops[i].value); - expressions[i * 2 + 1] = literal(stops[i].output); - } - return step(literal(input), expression, expressions); + public static Expression step(@NonNull Number input, @NonNull Expression defaultOutput, Stop... stops) { + return step(literal(input), defaultOutput, Stop.toExpressionArray(stops)); } /** @@ -1642,19 +3005,158 @@ public class Expression<T> { * Stop inputs must be numeric literals in strictly ascending order. * Returns the output value of the stop just less than the input, * or the first input if the input is less than the first stop. - * - * @param input the input value - * @param stops pair of input and output values + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius( + * step(zoom(), literal(0.0f), + * stop(1, 2.5f), + * stop(10, 5.0f) + * ) + * ); + * } + * </pre> + * + * @param input the input value + * @param defaultOutput the default output expression + * @param stops pair of input and output values * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-step">Style specification</a> */ - @SafeVarargs - public static Expression step(@NonNull Expression<Number> input, @NonNull Expression expression, Stop... stops) { - Expression[] expressions = new Expression[stops.length * 2]; - for (int i = 0; i < stops.length; i++) { - expressions[i * 2] = literal(stops[i].value); - expressions[i * 2 + 1] = literal(stops[i].output); - } - return step(input, expression, expressions); + public static Expression step(@NonNull Expression input, @NonNull Expression defaultOutput, Stop... stops) { + return step(input, defaultOutput, Stop.toExpressionArray(stops)); + } + + /** + * Produces discrete, stepped results by evaluating a piecewise-constant function defined by pairs of + * input and output values (\"stops\"). The `input` may be any numeric expression (e.g., `[\"get\", \"population\"]`). + * Stop inputs must be numeric literals in strictly ascending order. + * Returns the output value of the stop just less than the input, + * or the first input if the input is less than the first stop. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius( + * step(1.0f, 0.0f, + * literal(1.0f), literal(2.5f), + * literal(10.0f), literal(5.0f) + * ) + * ); + * } + * </pre> + * + * @param input the input value + * @param defaultOutput the default output expression + * @param stops pair of input and output values + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-step">Style specification</a> + */ + public static Expression step(@NonNull Number input, @NonNull Number defaultOutput, Expression... stops) { + return step(literal(input), defaultOutput, stops); + } + + /** + * Produces discrete, stepped results by evaluating a piecewise-constant function defined by pairs of + * input and output values (\"stops\"). The `input` may be any numeric expression (e.g., `[\"get\", \"population\"]`). + * Stop inputs must be numeric literals in strictly ascending order. + * Returns the output value of the stop just less than the input, + * or the first input if the input is less than the first stop. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius( + * step(zoom(), 0.0f, + * literal(1.0f), literal(2.5f), + * literal(10.0f), literal(5.0f) + * ) + * ); + * } + * </pre> + * + * @param input the input expression + * @param defaultOutput the default output expression + * @param stops pair of input and output values + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-step">Style specification</a> + */ + public static Expression step(@NonNull Expression input, @NonNull Number defaultOutput, Expression... stops) { + return step(input, literal(defaultOutput), stops); + } + + /** + * Produces discrete, stepped results by evaluating a piecewise-constant function defined by pairs of + * input and output values (\"stops\"). The `input` may be any numeric expression (e.g., `[\"get\", \"population\"]`). + * Stop inputs must be numeric literals in strictly ascending order. + * Returns the output value of the stop just less than the input, + * or the first input if the input is less than the first stop. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius( + * step(zoom(), 0.0f, + * stop(1, 2.5f), + * stop(10, 5.0f) + * ) + * ); + * } + * </pre> + * + * @param input the input value + * @param defaultOutput the default output expression + * @param stops pair of input and output values + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-step">Style specification</a> + */ + public static Expression step(@NonNull Number input, @NonNull Number defaultOutput, Stop... stops) { + return step(literal(input), defaultOutput, Stop.toExpressionArray(stops)); + } + + /** + * Produces discrete, stepped results by evaluating a piecewise-constant function defined by pairs of + * input and output values (\"stops\"). The `input` may be any numeric expression (e.g., `[\"get\", \"population\"]`). + * Stop inputs must be numeric literals in strictly ascending order. + * Returns the output value of the stop just less than the input, + * or the first input if the input is less than the first stop. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius( + * step(zoom(), 0.0f, + * stop(1, 2.5f), + * stop(10, 5.0f) + * ) + * ); + * } + * </pre> + * + * @param input the input value + * @param defaultOutput the default output expression + * @param stops pair of input and output values + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-step">Style specification</a> + */ + public static Expression step(@NonNull Expression input, @NonNull Number defaultOutput, Stop... stops) { + return step(input, defaultOutput, Stop.toExpressionArray(stops)); } /** @@ -1662,15 +3164,33 @@ public class Expression<T> { * The `input` may be any numeric expression (e.g., `[\"get\", \"population\"]`). * Stop inputs must be numeric literals in strictly ascending order. * The output type must be `number`, `array<number>`, or `color`. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new fillLayer("layer-id", "source-id"); + * fillLayer.setProperties( + * fillColor( + * interpolate( + * exponential(0.5f), zoom(), + * literal(1.0f), color(Color.RED), + * literal(5.0f, color(Color.BLUE), + * literal(10.0f, color(Color.GREEN) + * ) + * ) + * ); + * } + * </pre> * * @param interpolation type of interpolation * @param number the input expression * @param stops pair of input and output values * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-interpolate">Style specification</a> */ - @SafeVarargs - public static Expression interpolate(@NonNull Expression<Interpolator> interpolation, - @NonNull Expression<Number> number, Expression... stops) { + public static Expression interpolate(@NonNull Interpolator interpolation, + @NonNull Expression number, Expression... stops) { return new Expression("interpolate", join(new Expression[] {interpolation, number}, stops)); } @@ -1679,30 +3199,62 @@ public class Expression<T> { * The `input` may be any numeric expression (e.g., `[\"get\", \"population\"]`). * Stop inputs must be numeric literals in strictly ascending order. * The output type must be `number`, `array<number>`, or `color`. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new fillLayer("layer-id", "source-id"); + * fillLayer.setProperties( + * fillColor( + * interpolate( + * exponential(0.5f), zoom(), + * literal(1.0f), color(Color.RED), + * literal(5.0f, color(Color.BLUE), + * literal(10.0f, color(Color.GREEN) + * ) + * ) + * ); + * } + * </pre> * * @param interpolation type of interpolation * @param number the input expression * @param stops pair of input and output values * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-interpolate">Style specification</a> */ - @SafeVarargs - public static Expression interpolate(@NonNull Expression<Interpolator> interpolation, - @NonNull Expression<Number> number, Stop... stops) { - Expression[] expressions = new Expression[stops.length * 2]; - for (int i = 0; i < stops.length; i++) { - expressions[i * 2] = literal(stops[i].value); - expressions[i * 2 + 1] = literal(stops[i].output); - } - return interpolate(interpolation, number, expressions); + public static Expression interpolate(@NonNull Interpolator interpolation, + @NonNull Expression number, Stop... stops) { + return interpolate(interpolation, number, Stop.toExpressionArray(stops)); } /** * interpolates linearly between the pair of stops just less than and just greater than the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new fillLayer("layer-id", "source-id"); + * fillLayer.setProperties( + * fillColor( + * interpolate( + * linear(), zoom(), + * literal(1.0f), color(Color.RED), + * literal(5.0f, color(Color.BLUE), + * literal(10.0f, color(Color.GREEN) + * ) + * ) + * ); + * } + * </pre> * * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-interpolate">Style specification</a> */ - public static Expression<Interpolator> linear() { - return new Expression<>("linear"); + public static Interpolator linear() { + return new Interpolator("linear"); } /** @@ -1710,11 +3262,30 @@ public class Expression<T> { * `base` controls the rate at which the output increases: * higher values make the output increase more towards the high end of the range. * With values close to 1 the output increases linearly. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new fillLayer("layer-id", "source-id"); + * fillLayer.setProperties( + * fillColor( + * interpolate( + * exponential(0.5f), zoom(), + * literal(1.0f), color(Color.RED), + * literal(5.0f, color(Color.BLUE), + * literal(10.0f, color(Color.GREEN) + * ) + * ) + * ); + * } + * </pre> * * @param base value controlling the route at which the output increases * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-interpolate">Style specification</a> */ - public static Expression<Interpolator> exponential(@NonNull Number base) { + public static Interpolator exponential(@NonNull Number base) { return exponential(literal(base)); } @@ -1723,39 +3294,96 @@ public class Expression<T> { * The parameter controls the rate at which the output increases: * higher values make the output increase more towards the high end of the range. * With values close to 1 the output increases linearly. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new fillLayer("layer-id", "source-id"); + * fillLayer.setProperties( + * fillColor( + * interpolate( + * exponential(get("keyToValue"), zoom(), + * literal(1.0f), color(Color.RED), + * literal(5.0f, color(Color.BLUE), + * literal(10.0f, color(Color.GREEN) + * ) + * ) + * ); + * } + * </pre> * * @param expression base number expression * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-interpolate">Style specification</a> */ - public static Expression<Interpolator> exponential(@NonNull Expression<Number> expression) { - return new Expression<>("exponential", expression); + public static Interpolator exponential(@NonNull Expression expression) { + return new Interpolator("exponential", expression); } /** * Interpolates using the cubic bezier curve defined by the given control points. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new fillLayer("layer-id", "source-id"); + * fillLayer.setProperties( + * fillColor( + * interpolate( + * cubicBezier(0.42f, 0.0f, 1.0f, 1.0f), zoom(), + * literal(1.0f), color(Color.RED), + * literal(5.0f, color(Color.BLUE), + * literal(10.0f, color(Color.GREEN) + * ) + * ) + * ); + * } + * </pre> * * @param x1 x value of the first point of a cubic bezier, ranges from 0 to 1 * @param y1 y value of the first point of a cubic bezier, ranges from 0 to 1 * @param x2 x value of the second point of a cubic bezier, ranges from 0 to 1 * @param y2 y value fo the second point of a cubic bezier, ranges from 0 to 1 * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-interpolate">Style specification</a> */ - public static Expression<Interpolator> cubicBezier(@NonNull Expression<Number> x1, @NonNull Expression<Number> y1, - @NonNull Expression<Number> x2, @NonNull Expression<Number> y2) { - return new Expression<>("cubic-bezier", x1, y1, x2, y2); + public static Interpolator cubicBezier(@NonNull Expression x1, @NonNull Expression y1, + @NonNull Expression x2, @NonNull Expression y2) { + return new Interpolator("cubic-bezier", x1, y1, x2, y2); } /** * Interpolates using the cubic bezier curve defined by the given control points. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * FillLayer fillLayer = new fillLayer("layer-id", "source-id"); + * fillLayer.setProperties( + * fillColor( + * interpolate( + * cubicBezier(0.42f, 0.0f, 1.0f, 1.0f), zoom(), + * literal(1.0f), color(Color.RED), + * literal(5.0f, color(Color.BLUE), + * literal(10.0f, color(Color.GREEN) + * ) + * ) + * ); + * } + * </pre> * * @param x1 x value of the first point of a cubic bezier, ranges from 0 to 1 * @param y1 y value of the first point of a cubic bezier, ranges from 0 to 1 * @param x2 x value of the second point of a cubic bezier, ranges from 0 to 1 * @param y2 y value fo the second point of a cubic bezier, ranges from 0 to 1 * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-interpolate">Style specification</a> */ - public static Expression<Interpolator> cubicBezier(@NonNull Number x1, @NonNull Number y1, - @NonNull Number x2, @NonNull Number y2) { + public static Interpolator cubicBezier(@NonNull Number x1, @NonNull Number y1, + @NonNull Number x2, @NonNull Number y2) { return cubicBezier(literal(x1), literal(y1), literal(x2), literal(y2)); } @@ -1776,13 +3404,59 @@ public class Expression<T> { return output; } + /** + * Converts the expression to Object array representation. + * <p> + * The output will later be converted to a JSON Object array. + * </p> + * + * @return the converted object array expression + */ + @NonNull + public Object[] toArray() { + List<Object> array = new ArrayList<>(); + array.add(operator); + if (arguments != null) { + for (Expression argument : arguments) { + if (argument instanceof Expression.ExpressionLiteral) { + array.add(toValue((ExpressionLiteral) argument)); + } else { + array.add(argument.toArray()); + } + } + } + return array.toArray(); + } + + /** + * Converts the expression value to an Object. + * + * @param expressionValue the expression value to convert + * @return the converted object expression + */ + private Object toValue(ExpressionLiteral expressionValue) { + Object value = expressionValue.toValue(); + if (value instanceof PropertyValue) { + throw new IllegalArgumentException("PropertyValue are not allowed as an expression literal, use value instead."); + } else if (value instanceof Expression.ExpressionLiteral) { + return toValue((ExpressionLiteral) value); + } else if (value instanceof Expression) { + return ((Expression) value).toArray(); + } + return value; + } + /** + * Returns a string representation of the object that matches the definition set in the style specification. + * + * @return a string representation of the object. + */ @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("[\"").append(operator).append("\""); if (arguments != null) { - for (Expression argument : arguments) { + for (Object argument : arguments) { builder.append(", "); if (argument instanceof ExpressionLiteral) { builder.append(((ExpressionLiteral) argument).toValue()); @@ -1794,4 +3468,295 @@ public class Expression<T> { builder.append("]"); return builder.toString(); } + + /** + * Indicates whether some other object is "equal to" this one. + * + * @param o the other object + * @return true if equal, false if not + */ + @Override + public boolean equals(Object o) { + super.equals(o); + if (this == o) { + return true; + } + + if (o == null || !(o instanceof Expression)) { + return false; + } + + Expression that = (Expression) o; + + if (operator != null ? !operator.equals(that.operator) : that.operator != null) { + return false; + } + return Arrays.deepEquals(arguments, that.arguments); + } + + /** + * Returns a hash code value for the expression. + * + * @return a hash code value for this expression + */ + @Override + public int hashCode() { + int result = operator != null ? operator.hashCode() : 0; + result = 31 * result + Arrays.hashCode(arguments); + return result; + } + + /** + * ExpressionLiteral wraps an object to be used as a literal in an expression. + * <p> + * ExpressionLiteral is created with {@link #literal(Number)}, {@link #literal(boolean)}, + * {@link #literal(String)} and {@link #literal(Object)}. + * </p> + */ + public static class ExpressionLiteral extends Expression { + + protected Object literal; + + /** + * Create an expression literal. + * + * @param object the object to be treated as literal + */ + public ExpressionLiteral(@NonNull Object object) { + this.literal = object; + } + + /** + * Get the literal object. + * + * @return the literal object + */ + Object toValue() { + return literal; + } + + /** + * Returns a string representation of the expression literal. + * + * @return a string representation of the object. + */ + @Override + public String toString() { + return literal.toString(); + } + + /** + * Indicates whether some other object is "equal to" this one. + * + * @param o the other object + * @return true if equal, false if not + */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + if (!super.equals(o)) { + return false; + } + + ExpressionLiteral that = (ExpressionLiteral) o; + + return literal != null ? literal.equals(that.literal) : that.literal == null; + } + + /** + * Returns a hash code value for the expression literal. + * + * @return a hash code value for this expression literal + */ + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (literal != null ? literal.hashCode() : 0); + return result; + } + } + + /** + * Expression interpolator type. + * <p> + * Is used for first parameter of {@link #interpolate(Interpolator, Expression, Stop...)}. + * </p> + */ + public static class Interpolator extends Expression { + + Interpolator(@NonNull String operator, @Nullable Expression... arguments) { + super(operator, arguments); + } + } + + /** + * Expression array type. + */ + public static class Array { + } + + /** + * Expression stop type. + * <p> + * Can be used for {@link #stop(Object, Object)} as part of varargs parameter in + * {@link #step(Number, Expression, Stop...)} or {@link #interpolate(Interpolator, Expression, Stop...)}. + * </p> + */ + public static class Stop { + + private Object value; + private Object output; + + Stop(Object value, Object output) { + this.value = value; + this.output = output; + } + + /** + * Converts a varargs of Stops to a Expression array. + * + * @param stops the stops to convert + * @return the converted stops as an expression array + */ + static Expression[] toExpressionArray(Stop... stops) { + Expression[] expressions = new Expression[stops.length * 2]; + Stop stop; + Object inputValue, outputValue; + for (int i = 0; i < stops.length; i++) { + stop = stops[i]; + inputValue = stop.value; + outputValue = stop.output; + + if (!(inputValue instanceof Expression)) { + inputValue = literal(inputValue); + } + + if (!(outputValue instanceof Expression)) { + outputValue = literal(outputValue); + } + + expressions[i * 2] = (Expression) inputValue; + expressions[i * 2 + 1] = (Expression) outputValue; + } + return expressions; + } + } + + /** + * Converts a JsonArray to an expression. + */ + public final static class Converter { + + /** + * Converts a JsonArray to an expression + * + * @param jsonArray the json array to convert + * @return the expression + */ + public static Expression convert(@NonNull JsonArray jsonArray) { + if (jsonArray.size() == 0) { + throw new IllegalArgumentException("Can't convert empty jsonArray expressions"); + } + + final String operator = jsonArray.get(0).getAsString(); + final List<Expression> arguments = new ArrayList<>(); + + JsonElement jsonElement; + for (int i = 1; i < jsonArray.size(); i++) { + jsonElement = jsonArray.get(i); + if (jsonElement instanceof JsonArray) { + arguments.add(convert((JsonArray) jsonElement)); + } else if (jsonElement instanceof JsonPrimitive) { + arguments.add(convert((JsonPrimitive) jsonElement)); + } else { + throw new RuntimeException("Unsupported expression conversion for " + jsonElement.getClass()); + } + } + return new Expression(operator, arguments.toArray(new Expression[arguments.size()])); + } + + /** + * Converts a JsonPrimitive to an expression literal + * + * @param jsonPrimitive the json primitive to convert + * @return the expression literal + */ + private static Expression convert(@NonNull JsonPrimitive jsonPrimitive) { + if (jsonPrimitive.isBoolean()) { + return new Expression.ExpressionLiteral(jsonPrimitive.getAsBoolean()); + } else if (jsonPrimitive.isNumber()) { + return new Expression.ExpressionLiteral(jsonPrimitive.getAsFloat()); + } else if (jsonPrimitive.isString()) { + return new Expression.ExpressionLiteral(jsonPrimitive.getAsString()); + } else { + throw new RuntimeException("Unsupported literal expression conversion for " + jsonPrimitive.getClass()); + } + } + } + + /** + * Expression to wrap Object[] as a literal + */ + private static class ExpressionArray extends Expression { + + private Object[] array; + + ExpressionArray(Object[] array) { + this.array = array; + } + + @NonNull + @Override + public Object[] toArray() { + return new Object[] { + "literal", array + }; + } + + /** + * Convert the expression array to a string representation. + * + * @return the string representation of the expression array + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder("[\"literal\"], ["); + Object argument; + for (int i = 0; i < array.length; i++) { + argument = array[i]; + if (argument instanceof String) { + builder.append("\"").append(argument).append("\""); + } else { + builder.append(argument); + } + + if (i != array.length - 1) { + builder.append(", "); + } + } + builder.append("]]"); + return builder.toString(); + } + } + + /** + * Converts an object that is a primitive array to an Object[] + * + * @param object the object to convert to an object array + * @return the converted object array + */ + static Object[] toObjectArray(Object object) { + // object is a primitive array + int len = java.lang.reflect.Array.getLength(object); + Object[] objects = new Object[len]; + for (int i = 0; i < len; i++) { + objects[i] = java.lang.reflect.Array.get(object, i); + } + return objects; + } }
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/package-info.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/package-info.java new file mode 100644 index 0000000000..ee2b96fa61 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/package-info.java @@ -0,0 +1,4 @@ +/** + * Contains the Mapbox Maps Android Expression API classes. + */ +package com.mapbox.mapboxsdk.style.expressions; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CameraFunction.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CameraFunction.java deleted file mode 100644 index bb87fe8a39..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CameraFunction.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.mapbox.mapboxsdk.style.functions; - -import android.support.annotation.Keep; -import android.support.annotation.NonNull; - -import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; -import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; -import com.mapbox.mapboxsdk.style.functions.stops.Stop; -import com.mapbox.mapboxsdk.style.functions.stops.Stops; - -/** - * Camera function. Functions that take camera properties as input (zoom for now) - * <p> - * Zoom functions allow the appearance of a map feature to change with map’s zoom level. - * Zoom functions can be used to create the illusion of depth and control data density. - * Each stop is an array with two elements: the first is a zoom level and the second is - * a function output value. - * - * @param <I> the input type - * @param <O> the output type - * @see Function#zoom - */ -public class CameraFunction<I extends Number, O> extends Function<I, O> { - - /** - * Create an exponential camera function - * - * @param stops @see {@link com.mapbox.mapboxsdk.style.functions.stops.Stops#exponential(float, Stop[])} - */ - CameraFunction(@NonNull ExponentialStops<I, O> stops) { - super(stops); - } - - /** - * Create an interval camera function - * - * @param stops @see {@link com.mapbox.mapboxsdk.style.functions.stops.Stops#interval(Stop[])} - */ - CameraFunction(@NonNull IntervalStops<I, O> stops) { - super(stops); - } - - /** - * JNI constructor - */ - @Keep - private CameraFunction(Stops<I, O> stops) { - super(stops); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CompositeFunction.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CompositeFunction.java deleted file mode 100644 index 15e4474105..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CompositeFunction.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.mapbox.mapboxsdk.style.functions; - -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - -import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; -import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; -import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; -import com.mapbox.mapboxsdk.style.functions.stops.Stop; -import com.mapbox.mapboxsdk.style.functions.stops.Stops; -import com.mapbox.mapboxsdk.style.layers.PropertyValue; - -import java.util.Map; - -/** - * Composite functions combine Camera and SourceFunctions. - * <p> - * Composite functions allow the appearance of a map feature to change with both its - * properties and zoom. Each stop is an array with two elements, the first is an object - * with a property input value and a zoom, and the second is a function output value. Note - * that support for property functions is not yet complete. - * - * @param <Z> the zoom type (usually Float) - * @param <I> the input type (the feature property type) - * @param <O> the output type (the property type) - * @see Function#composite - */ -public class CompositeFunction<Z extends Number, I, O> extends Function<Stop.CompositeValue<Z, I>, O> { - - private final String property; - private PropertyValue<O> defaultValue; - - CompositeFunction(@NonNull String property, - @NonNull CategoricalStops<Stop.CompositeValue<Z, I>, O> stops) { - this(null, property, stops); - } - - CompositeFunction(@NonNull String property, - @NonNull ExponentialStops<Stop.CompositeValue<Z, I>, O> stops) { - this(null, property, stops); - } - - CompositeFunction(@NonNull String property, - @NonNull IntervalStops<Stop.CompositeValue<Z, I>, O> stops) { - this(null, property, stops); - } - - - /** - * JNI Constructor - */ - private CompositeFunction(@Nullable O defaultValue, @NonNull String property, - @NonNull Stops<Stop.CompositeValue<Z, I>, O> stops) { - super(stops); - this.defaultValue = new PropertyValue<>(property, defaultValue); - this.property = property; - } - - /** - * Set the default value - * - * @param defaultValue the default value to use when no other applies - * @return this (for chaining) - */ - public CompositeFunction<Z, I, O> withDefaultValue(PropertyValue<O> defaultValue) { - this.defaultValue = defaultValue; - return this; - } - - /** - * @return the defaultValue - */ - @Nullable - public PropertyValue<O> getDefaultValue() { - return defaultValue; - } - - /** - * INTERNAL USAGE ONLY - * - * @return the feature property name - */ - public String getProperty() { - return property; - } - - /** - * {@inheritDoc} - */ - @Override - public Map<String, Object> toValueObject() { - Map<String, Object> valueObject = super.toValueObject(); - valueObject.put(PROPERTY_KEY, property); - if (defaultValue != null) { - valueObject.put(DEFAULT_VALUE_KEY, defaultValue.value); - } - return valueObject; - } - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/Function.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/Function.java deleted file mode 100644 index e7bb52ebb3..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/Function.java +++ /dev/null @@ -1,300 +0,0 @@ -package com.mapbox.mapboxsdk.style.functions; - -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - -import com.mapbox.mapboxsdk.style.functions.stops.CategoricalStops; -import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; -import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops; -import com.mapbox.mapboxsdk.style.functions.stops.IntervalStops; -import com.mapbox.mapboxsdk.style.functions.stops.Stop; -import com.mapbox.mapboxsdk.style.functions.stops.Stops; - -import java.util.Map; - -import timber.log.Timber; - -/** - * Functions are used to change properties in relation to the state of the map. - * <p> - * The value for any layout or paint property may be specified as a function. Functions allow you to - * make the appearance of a map feature change with the current zoom level and/or the feature's properties. - * - * @param <I> the function's input type - * @param <O> the target property's value type. Make sure it matches. - * @see <a href="https://www.mapbox.com/mapbox-gl-style-spec/#types-function">The style specification</a> - */ -public class Function<I, O> { - - static final String PROPERTY_KEY = "property"; - static final String DEFAULT_VALUE_KEY = "default"; - - /** - * Create an exponential {@link CameraFunction} - * <p> - * Zoom functions allow the appearance of a map feature to change with map’s zoom. - * Zoom functions can be used to create the illusion of depth and control data density. - * Each stop is an array with two elements, the first is a zoom and the second is a function output value. - * - * @param <Z> the zoom level type (Float, Integer) - * @param <O> the property type - * @param stops the stops implementation that define the function. @see {@link Stops#exponential(Stop[])} - * @return the {@link CameraFunction} - * @see CameraFunction - * @see ExponentialStops - * @see Stops#exponential(Stop[]) - * @see Stops#exponential(Stop[]) - * @see Stop#stop - */ - public static <Z extends Number, O> CameraFunction<Z, O> zoom(@NonNull ExponentialStops<Z, O> stops) { - return new CameraFunction<>(stops); - } - - /** - * Create an interval {@link CameraFunction} - * <p> - * Zoom functions allow the appearance of a map feature to change with map’s zoom. - * Zoom functions can be used to create the illusion of depth and control data density. - * Each stop is an array with two elements, the first is a zoom and the second is a function output value. - * - * @param <Z> the zoom level type (Float, Integer) - * @param <O> the property type - * @param stops the stops implementation that define the function. @see {@link Stops#interval(Stop[])} - * @return the {@link CameraFunction} - * @see CameraFunction - * @see IntervalStops - * @see Stops#interval(Stop[]) - * @see Stop#stop - */ - public static <Z extends Number, O> CameraFunction<Z, O> zoom(@NonNull IntervalStops<Z, O> stops) { - return new CameraFunction<>(stops); - } - - /** - * Create an exponential {@link SourceFunction} - * <p> - * Source functions allow the appearance of a map feature to change with - * its properties. Source functions can be used to visually differentiate - * types of features within the same layer or create data visualizations. - * Each stop is an array with two elements, the first is a property input - * value and the second is a function output value. Note that support for - * property functions is not available across all properties and platforms - * at this time. - * - * @param property the feature property name - * @param stops the stops - * @param <I> the function input type - * @param <O> the function output type - * @return the {@link SourceFunction} - * @see SourceFunction - * @see ExponentialStops - * @see Stops#exponential(Stop[]) - * @see Stop#stop - */ - public static <I, O> SourceFunction<I, O> property(@NonNull String property, @NonNull ExponentialStops<I, O> stops) { - return new SourceFunction<>(property, stops); - } - - /** - * Create an identity {@link SourceFunction} - * <p> - * Source functions allow the appearance of a map feature to change with - * its properties. Source functions can be used to visually differentiate - * types of features within the same layer or create data visualizations. - * Each stop is an array with two elements, the first is a property input - * value and the second is a function output value. Note that support for - * property functions is not available across all properties and platforms - * at this time. - * - * @param property the feature property name - * @param stops the stops - * @param <T> the function input/output type - * @return the {@link SourceFunction} - * @see SourceFunction - * @see IdentityStops - * @see Stops#identity() - * @see Stop#stop - */ - public static <T> SourceFunction<T, T> property(@NonNull String property, @NonNull IdentityStops<T> stops) { - return new SourceFunction<>(property, stops); - } - - /** - * Create an interval {@link SourceFunction} - * <p> - * Source functions allow the appearance of a map feature to change with - * its properties. Source functions can be used to visually differentiate - * types of features within the same layer or create data visualizations. - * Each stop is an array with two elements, the first is a property input - * value and the second is a function output value. Note that support for - * property functions is not available across all properties and platforms - * at this time. - * - * @param property the feature property name - * @param stops the stops - * @param <I> the function input type - * @param <O> the function output type - * @return the {@link SourceFunction} - * @see SourceFunction - * @see IntervalStops - * @see Stops#interval(Stop[]) - * @see Stop#stop - */ - public static <I, O> SourceFunction<I, O> property(@NonNull String property, @NonNull IntervalStops<I, O> stops) { - return new SourceFunction<>(property, stops); - } - - /** - * Create an categorical {@link SourceFunction} - * <p> - * Source functions allow the appearance of a map feature to change with - * its properties. Source functions can be used to visually differentiate - * types of features within the same layer or create data visualizations. - * Each stop is an array with two elements, the first is a property input - * value and the second is a function output value. Note that support for - * property functions is not available across all properties and platforms - * at this time. - * - * @param property the feature property name - * @param stops the stops - * @param <I> the function input type - * @param <O> the function output type - * @return the {@link SourceFunction} - * @see SourceFunction - * @see CategoricalStops - * @see Stops#categorical(Stop[]) - * @see Stop#stop - */ - public static <I, O> SourceFunction<I, O> property(@NonNull String property, @NonNull CategoricalStops<I, O> stops) { - return new SourceFunction<>(property, stops); - } - - /** - * Create a composite, categorical function. - * <p> - * Composite functions allow the appearance of a map feature to change with both its - * properties and zoom. Each stop is an array with two elements, the first is an object - * with a property input value and a zoom, and the second is a function output value. Note - * that support for property functions is not yet complete. - * - * @param property the feature property name for the source part of the function - * @param stops the stops - * @param <Z> the zoom function input type (Float usually) - * @param <I> the function input type for the source part of the function - * @param <O> the function output type - * @return the {@link CompositeFunction} - * @see CompositeFunction - * @see CategoricalStops - * @see Stops#categorical(Stop[]) - * @see Stop#stop - */ - public static <Z extends Number, I, O> CompositeFunction<Z, I, O> composite( - @NonNull String property, - @NonNull CategoricalStops<Stop.CompositeValue<Z, I>, O> stops) { - - return new CompositeFunction<>(property, stops); - } - - /** - * Create a composite, exponential function. - * <p> - * Composite functions allow the appearance of a map feature to change with both its - * properties and zoom. Each stop is an array with two elements, the first is an object - * with a property input value and a zoom, and the second is a function output value. Note - * that support for property functions is not yet complete. - * - * @param property the feature property name for the source part of the function - * @param stops the stops - * @param <Z> the zoom function input type (Float usually) - * @param <I> the function input type for the source part of the function - * @param <O> the function output type - * @return the {@link CompositeFunction} - * @see CompositeFunction - * @see ExponentialStops - * @see Stops#exponential(Stop[]) - * @see Stop#stop - */ - public static <Z extends Number, I, O> CompositeFunction<Z, I, O> composite( - @NonNull String property, - @NonNull ExponentialStops<Stop.CompositeValue<Z, I>, O> stops) { - - return new CompositeFunction<>(property, stops); - } - - /** - * Create a composite, interval function. - * <p> - * Composite functions allow the appearance of a map feature to change with both its - * properties and zoom. Each stop is an array with two elements, the first is an object - * with a property input value and a zoom, and the second is a function output value. Note - * that support for property functions is not yet complete. - * - * @param property the feature property name for the source part of the function - * @param stops the stops - * @param <Z> the zoom function input type (Float usually) - * @param <I> the function input type for the source part of the function - * @param <O> the function output type - * @return the {@link CompositeFunction} - * @see CompositeFunction - * @see IntervalStops - * @see Stops#interval(Stop[]) - * @see Stop#stop - */ - public static <Z extends Number, I, O> CompositeFunction<Z, I, O> composite( - @NonNull String property, - @NonNull IntervalStops<Stop.CompositeValue<Z, I>, O> stops) { - - return new CompositeFunction<>(property, stops); - } - - // Class definition // - - private final Stops<I, O> stops; - - /** - * JNI Cosntructor for implementation classes - * - * @param stops the stops - */ - Function(@NonNull Stops<I, O> stops) { - this.stops = stops; - } - - /** - * @return the stops in this function - */ - public Stops getStops() { - return stops; - } - - /** - * Convenience method - * - * @param <S> the Stops implementation type - * @return the Stops implementation or null when the wrong type is specified - */ - @Nullable - public <S extends Stops> S getStopsAs() { - try { - // noinspection unchecked - return (S) stops; - } catch (ClassCastException exception) { - Timber.e(exception, "Stops: %s is a different type: ", stops.getClass()); - return null; - } - } - - /** - * INTERNAL USAGE ONLY - * - * @return a value object representation for core conversion - */ - public Map<String, Object> toValueObject() { - return stops.toValueObject(); - } - - @Override - public String toString() { - return String.format("%s: %s", getClass().getSimpleName(), stops); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/SourceFunction.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/SourceFunction.java deleted file mode 100644 index 33f436ae71..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/SourceFunction.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.mapbox.mapboxsdk.style.functions; - -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - -import com.mapbox.mapboxsdk.style.functions.stops.Stops; -import com.mapbox.mapboxsdk.style.layers.PropertyValue; - -import java.util.Map; - -/** - * Source functions take Feature property names as input. - * <p> - * Source functions allow the appearance of a map feature to change with - * its properties. Source functions can be used to visually differentiate - * types of features within the same layer or create data visualizations. - * Each stop is an array with two elements, the first is a property input - * value and the second is a function output value. Note that support for - * property functions is not available across all properties and platforms - * at this time. - * - * @param <I> the input type - * @param <O> the output type - * @see Function#property - */ -public class SourceFunction<I, O> extends Function<I, O> { - - private final String property; - private PropertyValue<O> defaultValue; - - SourceFunction(@NonNull String property, @NonNull Stops<I, O> stops) { - this(null, property, stops); - } - - /** - * JNI Constructor - */ - private SourceFunction(@Nullable O defaultValue, @NonNull String property, @NonNull Stops<I, O> stops) { - super(stops); - this.property = property; - this.defaultValue = defaultValue != null ? new PropertyValue<>(property, defaultValue) : null; - } - - - /** - * INTERNAL USAGE ONLY - * - * @return The feature property name - */ - public String getProperty() { - return property; - } - - /** - * Set the default value - * - * @param defaultValue the default value to use when no other applies - * @return this (for chaining) - */ - public SourceFunction<I, O> withDefaultValue(PropertyValue<O> defaultValue) { - this.defaultValue = defaultValue; - return this; - } - - /** - * @return the defaultValue - */ - @Nullable - public PropertyValue<O> getDefaultValue() { - return defaultValue; - } - - /** - * {@inheritDoc} - */ - @Override - public Map<String, Object> toValueObject() { - Map<String, Object> valueObject = super.toValueObject(); - valueObject.put(PROPERTY_KEY, property); - if (defaultValue != null) { - valueObject.put(DEFAULT_VALUE_KEY, defaultValue.value); - } - return valueObject; - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/package-info.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/package-info.java deleted file mode 100644 index 6979676c9e..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Contains the Mapbox Maps Android Style Function API classes. - * - * @see <a href="https://www.mapbox.com/mapbox-gl-style-spec/#types-function">The style specification</a> - */ -package com.mapbox.mapboxsdk.style.functions; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/CategoricalStops.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/CategoricalStops.java deleted file mode 100644 index f9b2929350..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/CategoricalStops.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.mapbox.mapboxsdk.style.functions.stops; - -import android.support.annotation.NonNull; -import android.support.annotation.Size; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.Map; - -/** - * {@link Stops} implementation for categorical functions - * - * @param <I> the {@link Stop} input type - * @param <O> the {@link Stop} output type - */ -public class CategoricalStops<I, O> extends IterableStops<I, O, Stop<I, O>> { - - private final Stop<I, O>[] stops; - - /** - * Create a categorical {@link Stops} implementation. Use through {@link Stops#categorical(Stop[])} - * - * @param stops the stops - */ - @SafeVarargs - public CategoricalStops(@NonNull @Size(min = 1) Stop<I, O>... stops) { - this.stops = stops; - } - - /** - * {@inheritDoc} - */ - @Override - public Map<String, Object> toValueObject() { - Map<String, Object> map = super.toValueObject(); - map.put("stops", toValueObjects(stops)); - return map; - } - - /** - * {@inheritDoc} - */ - @Override - public String getTypeName() { - return "categorical"; - } - - /** - * {@inheritDoc} - */ - @Override - public Iterator<Stop<I, O>> iterator() { - return Arrays.asList(stops).iterator(); - } - - /** - * {@inheritDoc} - */ - @Override - public int size() { - return stops.length; - } - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/ExponentialStops.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/ExponentialStops.java deleted file mode 100644 index d47aa1fc91..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/ExponentialStops.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.mapbox.mapboxsdk.style.functions.stops; - -import android.support.annotation.NonNull; -import android.support.annotation.Size; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.Map; - -/** - * The {@link Stops} implementation for exponential functions - * - * @param <I> the input type - * @param <O> the output type - */ -public class ExponentialStops<I, O> extends IterableStops<I, O, Stop<I, O>> { - - private float base; - private final Stop<I, O>[] stops; - - /** - * Create exponential stops with an explicit base. Use through {@link Stops#exponential(Stop[])} - * - * @param base The exponential base of the interpolation curve. It controls the rate at which the function output - * increases. Higher values make the output increase more towards the high end of the range. - * With values close to 1 the output increases linearly. - * @param stops the stops - */ - @SafeVarargs - public ExponentialStops(Float base, @NonNull @Size(min = 1) Stop<I, O>... stops) { - this.base = base != null ? base : 1.0f; - this.stops = stops; - } - - /** - * Create exponential stops without an explicit base. Use through {@link Stops#exponential(Stop[])} - * - * @param stops the stops - */ - @SafeVarargs - public ExponentialStops(@NonNull @Size(min = 1) Stop<I, O>... stops) { - this(null, stops); - } - - /** - * Set the exponential base - * - * @param base the base to use in the exponential function - * @return this (for chaining) - */ - public ExponentialStops<I, O> withBase(float base) { - this.base = base; - return this; - } - - /** - * @return The exponential base - */ - public float getBase() { - return base; - } - - /** - * {@inheritDoc} - */ - @Override - public Map<String, Object> toValueObject() { - Map<String, Object> map = super.toValueObject(); - map.put("base", base); - map.put("stops", toValueObjects(stops)); - return map; - } - - /** - * {@inheritDoc} - */ - @Override - public String getTypeName() { - return "exponential"; - } - - /** - * {@inheritDoc} - */ - @Override - public Iterator<Stop<I, O>> iterator() { - return Arrays.asList(stops).iterator(); - } - - /** - * {@inheritDoc} - */ - @Override - public int size() { - return stops.length; - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IdentityStops.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IdentityStops.java deleted file mode 100644 index 2c0b198dc2..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IdentityStops.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.mapbox.mapboxsdk.style.functions.stops; - -/** - * The {@link Stops} implementation for identity functions - * - * @param <T> the input/output type - */ -public class IdentityStops<T> extends Stops<T, T> { - - /** - * {@inheritDoc} - */ - @Override - protected String getTypeName() { - return "identity"; - } - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IntervalStops.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IntervalStops.java deleted file mode 100644 index 9d95b3f8c1..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IntervalStops.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.mapbox.mapboxsdk.style.functions.stops; - -import android.support.annotation.NonNull; -import android.support.annotation.Size; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.Map; - -/** - * The {@link Stops} implementation for interval functions - * - * @param <I> the input type - * @param <O> the output type - */ -public class IntervalStops<I, O> extends IterableStops<I, O, Stop<I, O>> { - - private final Stop<I, O>[] stops; - - @SafeVarargs - public IntervalStops(@NonNull @Size(min = 1) Stop<I, O>... stops) { - this.stops = stops; - } - - /** - * {@inheritDoc} - */ - @Override - public String getTypeName() { - return "interval"; - } - - /** - * {@inheritDoc} - */ - @Override - public Map<String, Object> toValueObject() { - Map<String, Object> map = super.toValueObject(); - map.put("stops", toValueObjects(stops)); - return map; - } - - /** - * @return an {@link Iterator} for the contained stops - */ - @Override - public Iterator<Stop<I, O>> iterator() { - return Arrays.asList(stops).iterator(); - } - - /** - * @return The number of contained stops - */ - @Override - public int size() { - return stops.length; - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IterableStops.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IterableStops.java deleted file mode 100644 index 8c5a6e8913..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IterableStops.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.mapbox.mapboxsdk.style.functions.stops; - -import java.util.Iterator; - -/** - * Base class for {@link Stops} implementations with a collection of stops - * - * @param <I> the {@link Stops} input type - * @param <O> the {@link Stops} output type - * @param <S> the {@link Iterable} element type (usually {@link Stop}) - */ -public abstract class IterableStops<I, O, S> extends Stops<I, O> implements Iterable<S> { - - /** - * @return The size of the contained stops collection - */ - public abstract int size(); - - /** - * Convenience function to toValueObjects an array of stops to an array of value objects - * - * @param stops the stops to toValueObjects - * @return the stops as value objects - */ - Object[] toValueObjects(Stop<I, O>[] stops) { - if (stops != null) { - Object[] stopsValue = new Object[stops.length]; - - for (int i = 0; i < stopsValue.length; i++) { - Stop stop = stops[i]; - stopsValue[i] = stop.toValueObject(); - } - return stopsValue; - } - - return null; - } - - @Override - public String toString() { - StringBuilder buffer = new StringBuilder(); - Iterator<S> iterator = iterator(); - while (iterator.hasNext()) { - S stop = iterator.next(); - buffer.append(stop); - if (iterator.hasNext()) { - buffer.append(","); - } - } - return String.format("%s: [%s]", super.toString(), buffer.toString()); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stop.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stop.java deleted file mode 100644 index 72164f4c4b..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stop.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.mapbox.mapboxsdk.style.functions.stops; - -import com.mapbox.mapboxsdk.style.functions.Function; -import com.mapbox.mapboxsdk.style.layers.PropertyValue; - -import java.util.HashMap; -import java.util.Map; - -/** - * A stop represents a certain point in the range of this function - * - * @param <I> input the stop (function) input type - * @param <O> output the stop (function) output type - * @see <a href="https://www.mapbox.com/mapbox-gl-style-spec/#types-function">The style specification</a> - */ -public class Stop<I, O> { - /** - * Creates a {@link Stop} to use in a {@link Function} - * - * @param in the input for the stop - * @param output the output for the stop - * @param <I> the input property type - * @param <O> the output property type - * @return the {@link Stop} - */ - public static <I, O> Stop<I, O> stop(I in, PropertyValue<O> output) { - return new Stop<>(in, output.value); - } - - /** - * Create a composite {@link Stop} for use in a {@link com.mapbox.mapboxsdk.style.functions.CompositeFunction} - * - * @param zoom the zoom input - * @param value the feature property input - * @param output the output for the stop - * @param <Z> the zoom type - * @param <I> the feature property input type - * @param <O> the output property type - * @return the {@link Stop} - * @see Function#composite(String, ExponentialStops) - */ - public static <Z extends Number, I, O> Stop<Stop.CompositeValue<Z, I>, O> stop(Z zoom, - I value, - PropertyValue<O> output) { - return new Stop<>(new Stop.CompositeValue<>(zoom, value), output.value); - } - - /** - * Represents a composite input value for composite functions (eg zoom and feature property value) - * - * @param <Z> the zoom input type (typically Float) - * @param <V> the feature property input type - */ - public static class CompositeValue<Z extends Number, V> { - public final Z zoom; - public final V value; - - CompositeValue(Z zoom, V value) { - this.zoom = zoom; - this.value = value; - } - - /** - * INTERNAL USAGE ONLY - * - * @return the value object representation for core conversion - */ - Map<String, Object> toValueObject() { - HashMap<String, Object> map = new HashMap<>(); - map.put("zoom", zoom); - map.put("value", value); - return map; - } - - @Override - public String toString() { - return String.format("[zoom: %s, value: %s]", zoom, value); - } - } - - /** - * The input type - */ - public final I in; - - /** - * The output type - */ - public final O out; - - Stop(I in, O out) { - this.in = in; - this.out = out; - } - - /** - * INTERNAL USAGE ONLY - * - * @return an array representation of the Stop - */ - Object[] toValueObject() { - return new Object[] {in instanceof CompositeValue ? ((CompositeValue) in).toValueObject() : in, out}; - } - - @Override - public String toString() { - return String.format("[%s, %s]", in, out); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stops.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stops.java deleted file mode 100644 index af4f53c072..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stops.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.mapbox.mapboxsdk.style.functions.stops; - -import android.support.annotation.CallSuper; -import android.support.annotation.NonNull; -import android.support.annotation.Size; - -import java.util.HashMap; -import java.util.Map; - -/** - * The base class for different stops implementations - * - * @param <I> the input type - * @param <O> the output type - * @see <a href="https://www.mapbox.com/mapbox-gl-style-spec/#types-function">The style specification</a> - */ -public abstract class Stops<I, O> { - - /** - * Convenience method for use in function declarations - * - * @param stops the collections of discrete stops - * @param <I> the Stops input type - * @param <O> the Stops output type - * @return the {@link Stops} implementation - * @see Stop#stop - * @see CategoricalStops - */ - @SafeVarargs - public static <I, O> CategoricalStops<I, O> categorical(@NonNull @Size(min = 1) Stop<I, O>... stops) { - return new CategoricalStops<>(stops); - } - - /** - * Convenience method for use in function declarations - * - * @param stops the collections of discrete stops - * @param <I> the Stops input type - * @param <O> the Stops output type - * @return the {@link Stops} implementation - * @see Stop#stop - * @see ExponentialStops - */ - @SafeVarargs - public static <I, O> ExponentialStops<I, O> exponential(@NonNull @Size(min = 1) Stop<I, O>... stops) { - return new ExponentialStops<>(stops); - } - - /** - * Convenience method for use in function declarations - * - * @param <T> the Stops input/output type - * @return the {@link IdentityStops} implementation - * @see Stop#stop - * @see IdentityStops - */ - public static <T> IdentityStops<T> identity() { - return new IdentityStops<>(); - } - - /** - * Convenience method for use in function declarations - * - * @param stops the collections of discrete stops - * @param <I> the Stops input type - * @param <O> the Stops output type - * @return the {@link Stops} implementation - * @see Stop#stop - * @see IntervalStops - */ - @SafeVarargs - public static <I, O> IntervalStops<I, O> interval(@NonNull @Size(min = 1) Stop<I, O>... stops) { - return new IntervalStops<>(stops); - } - - /** - * INTERNAL USAGE ONLY - * - * @return the value object representation for conversion to core - */ - @CallSuper - public Map<String, Object> toValueObject() { - HashMap<String, Object> map = new HashMap<>(); - map.put("type", getTypeName()); - return map; - } - - /** - * INTERNAL USAGE ONLY - * - * @return the unique type name as a string according to the style specification - */ - protected abstract String getTypeName(); - - @Override - public String toString() { - return getTypeName(); - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/package-info.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/package-info.java deleted file mode 100644 index fa388a9589..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/package-info.java +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Contains the Mapbox Maps Android Style Function Stop implementation API classes. - * - * @see <a href="https://www.mapbox.com/mapbox-gl-style-spec/#types-function">The style specification</a> - */ -package com.mapbox.mapboxsdk.style.functions.stops; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java index 978fa29ef8..60c2aa907b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java @@ -4,10 +4,13 @@ package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.annotation.UiThread; import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; +import com.google.gson.JsonArray; +import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.TransitionOptions; /** diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java index 10663142b5..94929398d5 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java @@ -4,10 +4,13 @@ package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.annotation.UiThread; import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; +import com.google.gson.JsonArray; +import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.TransitionOptions; /** @@ -69,26 +72,41 @@ public class CircleLayer extends Layer { } /** - * Set a single filter. + * Set a single expression filter. * - * @param filter the filter to set + * @param filter the expression filter to set */ - public void setFilter(Filter.Statement filter) { + public void setFilter(Expression filter) { nativeSetFilter(filter.toArray()); } /** - * Set a single filter. + * Set a single expression filter. * - * @param filter the filter to set + * @param filter the expression filter to set * @return This */ - public CircleLayer withFilter(Filter.Statement filter) { + public CircleLayer withFilter(Expression filter) { setFilter(filter); return this; } /** + * Get a single expression filter. + * + * @return the expression filter to get + */ + @Nullable + public Expression getFilter() { + Expression expression = null; + JsonArray array = (JsonArray) nativeGetFilter(); + if (array != null) { + expression = Expression.Converter.convert(array); + } + return expression; + } + + /** * Set a property or properties. * * @param properties the var-args properties diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CustomLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CustomLayer.java index f77e7280f0..a0ba1e2159 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CustomLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CustomLayer.java @@ -9,20 +9,8 @@ package com.mapbox.mapboxsdk.style.layers; public class CustomLayer extends Layer { public CustomLayer(String id, - long context, - long initializeFunction, - long renderFunction, - long deinitializeFunction) { - this(id, context, initializeFunction, renderFunction, 0L, deinitializeFunction); - } - - public CustomLayer(String id, - long context, - long initializeFunction, - long renderFunction, - long contextLostFunction, - long deinitializeFunction) { - initialize(id, initializeFunction, renderFunction, contextLostFunction, deinitializeFunction, context); + long host) { + initialize(id, host); } public CustomLayer(long nativePtr) { @@ -33,9 +21,7 @@ public class CustomLayer extends Layer { nativeUpdate(); } - protected native void initialize(String id, long initializeFunction, long renderFunction, - long contextLostFunction, long deinitializeFunction, - long context); + protected native void initialize(String id, long host); protected native void nativeUpdate(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillExtrusionLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillExtrusionLayer.java index 6772da73b1..29e2b49d76 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillExtrusionLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillExtrusionLayer.java @@ -4,10 +4,13 @@ package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.annotation.UiThread; import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; +import com.google.gson.JsonArray; +import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.TransitionOptions; /** @@ -69,26 +72,41 @@ public class FillExtrusionLayer extends Layer { } /** - * Set a single filter. + * Set a single expression filter. * - * @param filter the filter to set + * @param filter the expression filter to set */ - public void setFilter(Filter.Statement filter) { + public void setFilter(Expression filter) { nativeSetFilter(filter.toArray()); } /** - * Set a single filter. + * Set a single expression filter. * - * @param filter the filter to set + * @param filter the expression filter to set * @return This */ - public FillExtrusionLayer withFilter(Filter.Statement filter) { + public FillExtrusionLayer withFilter(Expression filter) { setFilter(filter); return this; } /** + * Get a single expression filter. + * + * @return the expression filter to get + */ + @Nullable + public Expression getFilter() { + Expression expression = null; + JsonArray array = (JsonArray) nativeGetFilter(); + if (array != null) { + expression = Expression.Converter.convert(array); + } + return expression; + } + + /** * Set a property or properties. * * @param properties the var-args properties diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java index 3719ae9e1b..ed780811c0 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java @@ -4,10 +4,13 @@ package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.annotation.UiThread; import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; +import com.google.gson.JsonArray; +import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.TransitionOptions; /** @@ -69,26 +72,41 @@ public class FillLayer extends Layer { } /** - * Set a single filter. + * Set a single expression filter. * - * @param filter the filter to set + * @param filter the expression filter to set */ - public void setFilter(Filter.Statement filter) { + public void setFilter(Expression filter) { nativeSetFilter(filter.toArray()); } /** - * Set a single filter. + * Set a single expression filter. * - * @param filter the filter to set + * @param filter the expression filter to set * @return This */ - public FillLayer withFilter(Filter.Statement filter) { + public FillLayer withFilter(Expression filter) { setFilter(filter); return this; } /** + * Get a single expression filter. + * + * @return the expression filter to get + */ + @Nullable + public Expression getFilter() { + Expression expression = null; + JsonArray array = (JsonArray) nativeGetFilter(); + if (array != null) { + expression = Expression.Converter.convert(array); + } + return expression; + } + + /** * Set a property or properties. * * @param properties the var-args properties diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Filter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Filter.java deleted file mode 100644 index 4dbb461e4c..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Filter.java +++ /dev/null @@ -1,230 +0,0 @@ -package com.mapbox.mapboxsdk.style.layers; - -import java.util.ArrayList; -import java.util.Collections; - -/** - * Utility to build filter expressions more easily. - * - * @see <a href="https://www.mapbox.com/mapbox-gl-style-spec/#types-filter">The online documentation</a> - */ -public class Filter { - - /** - * Base Filter statement. Subclassed to provide concrete statements. - */ - public abstract static class Statement { - protected final String operator; - - public Statement(String operator) { - this.operator = operator; - } - - /** - * Generate a raw array representation of the filter - * - * @return the filter represented as an array - */ - public abstract Object[] toArray(); - } - - /** - * Represents a {@link Filter} statement. Can be unary (eg `has()`, etc) or take any number of values. - */ - private static class SimpleStatement extends Statement { - private final String key; - private final Object[] values; - - /** - * @param operator the operator (eg `=`, etc) - * @param key the property key - * @param values the values to operate on, if any - */ - SimpleStatement(String operator, String key, Object... values) { - super(operator); - this.key = key; - this.values = values; - } - - - /** - * {@inheritDoc} - */ - @Override - public Object[] toArray() { - ArrayList<Object> array = new ArrayList<>(2 + values.length); - array.add(operator); - array.add(key); - Collections.addAll(array, values); - return array.toArray(); - } - } - - /** - * Represents a collection of {@link Statement}s with an operator that describes their relationship - */ - private static class CompoundStatement extends Statement { - private final Statement[] statements; - - /** - * @param operator the relationship operator - * @param statements the statements to compound - */ - CompoundStatement(String operator, Statement... statements) { - super(operator); - this.statements = statements; - } - - /** - * {@inheritDoc} - */ - @Override - public Object[] toArray() { - ArrayList<Object> array = new ArrayList<>(1 + statements.length); - array.add(operator); - for (Statement statement : statements) { - array.add(statement.toArray()); - } - return array.toArray(); - } - } - - /** - * Groups a collection of statements in an 'all' relationship - * - * @param statements the collection of statements - * @return the statements compounded - */ - public static Statement all(Statement... statements) { - return new CompoundStatement("all", statements); - } - - /** - * Groups a collection of statements in an 'any' relationship - * - * @param statements the collection of statements - * @return the statements compounded - */ - public static Statement any(Statement... statements) { - return new CompoundStatement("any", statements); - } - - /** - * Groups a collection of statements in an 'none' relationship - * - * @param statements the collection of statements - * @return the statements compounded - */ - public static Statement none(Statement... statements) { - return new CompoundStatement("none", statements); - } - - /** - * Check the property's existence - * - * @param key the property key - * @return the statement - */ - public static Statement has(String key) { - return new SimpleStatement("has", key); - } - - /** - * Check the property's existence, negated - * - * @param key the property key - * @return the statement - */ - public static Statement notHas(String key) { - return new SimpleStatement("!has", key); - } - - /** - * Check the property equals the given value - * - * @param key the property key - * @param value the value to check against - * @return the statement - */ - public static Statement eq(String key, Object value) { - return new SimpleStatement("==", key, value); - } - - /** - * Check the property does not equals the given value - * - * @param key the property key - * @param value the value to check against - * @return the statement - */ - public static Statement neq(String key, Object value) { - return new SimpleStatement("!=", key, value); - } - - /** - * Check the property exceeds the given value - * - * @param key the property key - * @param value the value to check against - * @return the statement - */ - public static Statement gt(String key, Object value) { - return new SimpleStatement(">", key, value); - } - - /** - * Check the property exceeds or equals the given value - * - * @param key the property key - * @param value the value to check against - * @return the statement - */ - public static Statement gte(String key, Object value) { - return new SimpleStatement(">=", key, value); - } - - /** - * Check the property does not exceeds the given value - * - * @param key the property key - * @param value the value to check against - * @return the statement - */ - public static Statement lt(String key, Object value) { - return new SimpleStatement("<", key, value); - } - - /** - * Check the property equals or does not exceeds the given value - * - * @param key the property key - * @param value the value to check against - * @return the statement - */ - public static Statement lte(String key, Object value) { - return new SimpleStatement("<=", key, value); - } - - /** - * Check the property is within the given set - * - * @param key the property key - * @param values the set of values to check against - * @return the statement - */ - public static Statement in(String key, Object... values) { - return new SimpleStatement("in", key, values); - } - - /** - * Check the property is not within the given set - * - * @param key the property key - * @param values the set of values to check against - * @return the statement - */ - public static Statement notIn(String key, Object... values) { - return new SimpleStatement("!in", key, values); - } - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HeatmapLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HeatmapLayer.java index 6b8fd65def..42b4210710 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HeatmapLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HeatmapLayer.java @@ -4,10 +4,13 @@ package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.annotation.UiThread; import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; +import com.google.gson.JsonArray; +import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.TransitionOptions; /** @@ -69,26 +72,41 @@ public class HeatmapLayer extends Layer { } /** - * Set a single filter. + * Set a single expression filter. * - * @param filter the filter to set + * @param filter the expression filter to set */ - public void setFilter(Filter.Statement filter) { + public void setFilter(Expression filter) { nativeSetFilter(filter.toArray()); } /** - * Set a single filter. + * Set a single expression filter. * - * @param filter the filter to set + * @param filter the expression filter to set * @return This */ - public HeatmapLayer withFilter(Filter.Statement filter) { + public HeatmapLayer withFilter(Expression filter) { setFilter(filter); return this; } /** + * Get a single expression filter. + * + * @return the expression filter to get + */ + @Nullable + public Expression getFilter() { + Expression expression = null; + JsonArray array = (JsonArray) nativeGetFilter(); + if (array != null) { + expression = Expression.Converter.convert(array); + } + return expression; + } + + /** * Set a property or properties. * * @param properties the var-args properties @@ -168,6 +186,32 @@ public class HeatmapLayer extends Layer { } /** + * Get the HeatmapColor property + * + * @return property wrapper value around String + */ + @SuppressWarnings("unchecked") + public PropertyValue<String> getHeatmapColor() { + return (PropertyValue<String>) new PropertyValue("heatmap-color", nativeGetHeatmapColor()); + } + + /** + * Defines the color of each pixel based on its density value in a heatmap. Should be an expression that uses `["heatmap-density"]` as input. + * + * @return int representation of a rgba string color + * @throws RuntimeException thrown if property isn't a value + */ + @ColorInt + public int getHeatmapColorAsInt() { + PropertyValue<String> value = getHeatmapColor(); + if (value.isValue()) { + return rgbaToColor(value.getValue()); + } else { + throw new RuntimeException("heatmap-color was set as a Function"); + } + } + + /** * Get the HeatmapOpacity property * * @return property wrapper value around Float @@ -209,6 +253,8 @@ public class HeatmapLayer extends Layer { private native void nativeSetHeatmapIntensityTransition(long duration, long delay); + private native Object nativeGetHeatmapColor(); + private native Object nativeGetHeatmapOpacity(); private native TransitionOptions nativeGetHeatmapOpacityTransition(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HillshadeLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HillshadeLayer.java index 7e3d3a7779..fb086f424b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HillshadeLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HillshadeLayer.java @@ -4,10 +4,13 @@ package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.annotation.UiThread; import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; +import com.google.gson.JsonArray; +import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.TransitionOptions; /** diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java index 5400e04589..411fbe4435 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java @@ -2,8 +2,9 @@ package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.NonNull; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; import com.mapbox.mapboxsdk.style.expressions.Expression; -import com.mapbox.mapboxsdk.style.functions.Function; /** * Base class for the different Layer types @@ -72,6 +73,8 @@ public abstract class Layer { protected native void nativeSetFilter(Object[] filter); + protected native JsonElement nativeGetFilter(); + protected native void nativeSetSourceLayer(String sourceLayer); protected native String nativeGetSourceLayer(); @@ -89,12 +92,8 @@ public abstract class Layer { } private Object convertValue(Object value) { - if (value != null) { - if (value instanceof Function) { - return ((Function) value).toValueObject(); - } else if (value instanceof Expression) { - return ((Expression) value).toArray(); - } + if (value != null && value instanceof Expression) { + return ((Expression) value).toArray(); } return value; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java index ca106cc106..5e6e6d38e7 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java @@ -4,10 +4,13 @@ package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.annotation.UiThread; import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; +import com.google.gson.JsonArray; +import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.TransitionOptions; /** @@ -69,26 +72,41 @@ public class LineLayer extends Layer { } /** - * Set a single filter. + * Set a single expression filter. * - * @param filter the filter to set + * @param filter the expression filter to set */ - public void setFilter(Filter.Statement filter) { + public void setFilter(Expression filter) { nativeSetFilter(filter.toArray()); } /** - * Set a single filter. + * Set a single expression filter. * - * @param filter the filter to set + * @param filter the expression filter to set * @return This */ - public LineLayer withFilter(Filter.Statement filter) { + public LineLayer withFilter(Expression filter) { setFilter(filter); return this; } /** + * Get a single expression filter. + * + * @return the expression filter to get + */ + @Nullable + public Expression getFilter() { + Expression expression = null; + JsonArray array = (JsonArray) nativeGetFilter(); + if (array != null) { + expression = Expression.Converter.convert(array); + } + return expression; + } + + /** * Set a property or properties. * * @param properties the var-args properties diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java index 18ee05e63b..4289deeda3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java @@ -4,9 +4,7 @@ package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.ColorInt; -import com.mapbox.mapboxsdk.style.functions.CameraFunction; import com.mapbox.mapboxsdk.style.expressions.Expression; -import com.mapbox.mapboxsdk.style.functions.Function; import java.util.Locale; @@ -28,18 +26,6 @@ public class PropertyFactory { } /** - * Set the property visibility. - * - * @param <T> the function input type - * @param function the visibility function - * @return property wrapper around a String function - */ - @Deprecated - public static <T> PropertyValue<Function<T, String>> visibility(Function<T, String> function) { - return new LayoutPropertyValue<>("visibility", function); - } - - /** * Whether or not the fill should be antialiased. * * @param value a Boolean value @@ -59,19 +45,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-antialias", expression); } - - /** - * Whether or not the fill should be antialiased. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Boolean - * @return property wrapper around a Boolean function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Boolean>> fillAntialias(CameraFunction<Z, Boolean> function) { - return new PaintPropertyValue<>("fill-antialias", function); - } - /** * The opacity of the entire fill layer. In contrast to the {@link PropertyFactory#fillColor}, this value will also affect the 1px stroke around the fill, if the stroke is used. * @@ -92,19 +65,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-opacity", expression); } - - /** - * The opacity of the entire fill layer. In contrast to the {@link PropertyFactory#fillColor}, this value will also affect the 1px stroke around the fill, if the stroke is used. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> fillOpacity(Function<T, Float> function) { - return new PaintPropertyValue<>("fill-opacity", function); - } - /** * The color of the filled part of this layer. This color can be specified as `rgba` with an alpha component and the color's opacity will not affect the opacity of the 1px stroke, if it is used. * @@ -135,19 +95,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-color", expression); } - - /** - * The color of the filled part of this layer. This color can be specified as `rgba` with an alpha component and the color's opacity will not affect the opacity of the 1px stroke, if it is used. - * - * @param <T> the function input type - * @param function a wrapper function for String - * @return property wrapper around a String function - */ - @Deprecated - public static <T> PropertyValue<Function<T, String>> fillColor(Function<T, String> function) { - return new PaintPropertyValue<>("fill-color", function); - } - /** * The outline color of the fill. Matches the value of {@link PropertyFactory#fillColor} if unspecified. * @@ -178,19 +125,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-outline-color", expression); } - - /** - * The outline color of the fill. Matches the value of {@link PropertyFactory#fillColor} if unspecified. - * - * @param <T> the function input type - * @param function a wrapper function for String - * @return property wrapper around a String function - */ - @Deprecated - public static <T> PropertyValue<Function<T, String>> fillOutlineColor(Function<T, String> function) { - return new PaintPropertyValue<>("fill-outline-color", function); - } - /** * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. * @@ -211,19 +145,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-translate", expression); } - - /** - * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float[] - * @return property wrapper around a Float[] function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float[]>> fillTranslate(CameraFunction<Z, Float[]> function) { - return new PaintPropertyValue<>("fill-translate", function); - } - /** * Controls the frame of reference for {@link PropertyFactory#fillTranslate}. * @@ -244,19 +165,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-translate-anchor", expression); } - - /** - * Controls the frame of reference for {@link PropertyFactory#fillTranslate}. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> fillTranslateAnchor(CameraFunction<Z, String> function) { - return new PaintPropertyValue<>("fill-translate-anchor", function); - } - /** * Name of image in sprite to use for drawing image fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). * @@ -277,19 +185,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-pattern", expression); } - - /** - * Name of image in sprite to use for drawing image fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> fillPattern(CameraFunction<Z, String> function) { - return new PaintPropertyValue<>("fill-pattern", function); - } - /** * The opacity at which the line will be drawn. * @@ -310,19 +205,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-opacity", expression); } - - /** - * The opacity at which the line will be drawn. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> lineOpacity(Function<T, Float> function) { - return new PaintPropertyValue<>("line-opacity", function); - } - /** * The color with which the line will be drawn. * @@ -353,19 +235,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-color", expression); } - - /** - * The color with which the line will be drawn. - * - * @param <T> the function input type - * @param function a wrapper function for String - * @return property wrapper around a String function - */ - @Deprecated - public static <T> PropertyValue<Function<T, String>> lineColor(Function<T, String> function) { - return new PaintPropertyValue<>("line-color", function); - } - /** * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. * @@ -386,19 +255,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-translate", expression); } - - /** - * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float[] - * @return property wrapper around a Float[] function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float[]>> lineTranslate(CameraFunction<Z, Float[]> function) { - return new PaintPropertyValue<>("line-translate", function); - } - /** * Controls the frame of reference for {@link PropertyFactory#lineTranslate}. * @@ -419,19 +275,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-translate-anchor", expression); } - - /** - * Controls the frame of reference for {@link PropertyFactory#lineTranslate}. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> lineTranslateAnchor(CameraFunction<Z, String> function) { - return new PaintPropertyValue<>("line-translate-anchor", function); - } - /** * Stroke thickness. * @@ -452,19 +295,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-width", expression); } - - /** - * Stroke thickness. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> lineWidth(Function<T, Float> function) { - return new PaintPropertyValue<>("line-width", function); - } - /** * Draws a line casing outside of a line's actual path. Value indicates the width of the inner gap. * @@ -485,19 +315,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-gap-width", expression); } - - /** - * Draws a line casing outside of a line's actual path. Value indicates the width of the inner gap. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> lineGapWidth(Function<T, Float> function) { - return new PaintPropertyValue<>("line-gap-width", function); - } - /** * The line's offset. For linear features, a positive value offsets the line to the right, relative to the direction of the line, and a negative value to the left. For polygon features, a positive value results in an inset, and a negative value results in an outset. * @@ -518,19 +335,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-offset", expression); } - - /** - * The line's offset. For linear features, a positive value offsets the line to the right, relative to the direction of the line, and a negative value to the left. For polygon features, a positive value results in an inset, and a negative value results in an outset. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> lineOffset(Function<T, Float> function) { - return new PaintPropertyValue<>("line-offset", function); - } - /** * Blur applied to the line, in density-independent pixels. * @@ -551,19 +355,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-blur", expression); } - - /** - * Blur applied to the line, in density-independent pixels. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> lineBlur(Function<T, Float> function) { - return new PaintPropertyValue<>("line-blur", function); - } - /** * Specifies the lengths of the alternating dashes and gaps that form the dash pattern. The lengths are later scaled by the line width. To convert a dash length to density-independent pixels, multiply the length by the current line width. * @@ -584,19 +375,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-dasharray", expression); } - - /** - * Specifies the lengths of the alternating dashes and gaps that form the dash pattern. The lengths are later scaled by the line width. To convert a dash length to density-independent pixels, multiply the length by the current line width. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float[] - * @return property wrapper around a Float[] function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float[]>> lineDasharray(CameraFunction<Z, Float[]> function) { - return new PaintPropertyValue<>("line-dasharray", function); - } - /** * Name of image in sprite to use for drawing image lines. For seamless patterns, image width must be a factor of two (2, 4, 8, ..., 512). * @@ -617,19 +395,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("line-pattern", expression); } - - /** - * Name of image in sprite to use for drawing image lines. For seamless patterns, image width must be a factor of two (2, 4, 8, ..., 512). - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> linePattern(CameraFunction<Z, String> function) { - return new PaintPropertyValue<>("line-pattern", function); - } - /** * The opacity at which the icon will be drawn. * @@ -650,19 +415,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("icon-opacity", expression); } - - /** - * The opacity at which the icon will be drawn. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> iconOpacity(Function<T, Float> function) { - return new PaintPropertyValue<>("icon-opacity", function); - } - /** * The color of the icon. This can only be used with sdf icons. * @@ -693,19 +445,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("icon-color", expression); } - - /** - * The color of the icon. This can only be used with sdf icons. - * - * @param <T> the function input type - * @param function a wrapper function for String - * @return property wrapper around a String function - */ - @Deprecated - public static <T> PropertyValue<Function<T, String>> iconColor(Function<T, String> function) { - return new PaintPropertyValue<>("icon-color", function); - } - /** * The color of the icon's halo. Icon halos can only be used with SDF icons. * @@ -736,19 +475,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("icon-halo-color", expression); } - - /** - * The color of the icon's halo. Icon halos can only be used with SDF icons. - * - * @param <T> the function input type - * @param function a wrapper function for String - * @return property wrapper around a String function - */ - @Deprecated - public static <T> PropertyValue<Function<T, String>> iconHaloColor(Function<T, String> function) { - return new PaintPropertyValue<>("icon-halo-color", function); - } - /** * Distance of halo to the icon outline. * @@ -769,19 +495,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("icon-halo-width", expression); } - - /** - * Distance of halo to the icon outline. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> iconHaloWidth(Function<T, Float> function) { - return new PaintPropertyValue<>("icon-halo-width", function); - } - /** * Fade out the halo towards the outside. * @@ -802,19 +515,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("icon-halo-blur", expression); } - - /** - * Fade out the halo towards the outside. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> iconHaloBlur(Function<T, Float> function) { - return new PaintPropertyValue<>("icon-halo-blur", function); - } - /** * Distance that the icon's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up. * @@ -835,19 +535,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("icon-translate", expression); } - - /** - * Distance that the icon's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float[] - * @return property wrapper around a Float[] function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float[]>> iconTranslate(CameraFunction<Z, Float[]> function) { - return new PaintPropertyValue<>("icon-translate", function); - } - /** * Controls the frame of reference for {@link PropertyFactory#iconTranslate}. * @@ -868,19 +555,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("icon-translate-anchor", expression); } - - /** - * Controls the frame of reference for {@link PropertyFactory#iconTranslate}. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> iconTranslateAnchor(CameraFunction<Z, String> function) { - return new PaintPropertyValue<>("icon-translate-anchor", function); - } - /** * The opacity at which the text will be drawn. * @@ -901,19 +575,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("text-opacity", expression); } - - /** - * The opacity at which the text will be drawn. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> textOpacity(Function<T, Float> function) { - return new PaintPropertyValue<>("text-opacity", function); - } - /** * The color with which the text will be drawn. * @@ -944,19 +605,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("text-color", expression); } - - /** - * The color with which the text will be drawn. - * - * @param <T> the function input type - * @param function a wrapper function for String - * @return property wrapper around a String function - */ - @Deprecated - public static <T> PropertyValue<Function<T, String>> textColor(Function<T, String> function) { - return new PaintPropertyValue<>("text-color", function); - } - /** * The color of the text's halo, which helps it stand out from backgrounds. * @@ -987,19 +635,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("text-halo-color", expression); } - - /** - * The color of the text's halo, which helps it stand out from backgrounds. - * - * @param <T> the function input type - * @param function a wrapper function for String - * @return property wrapper around a String function - */ - @Deprecated - public static <T> PropertyValue<Function<T, String>> textHaloColor(Function<T, String> function) { - return new PaintPropertyValue<>("text-halo-color", function); - } - /** * Distance of halo to the font outline. Max text halo width is 1/4 of the font-size. * @@ -1020,19 +655,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("text-halo-width", expression); } - - /** - * Distance of halo to the font outline. Max text halo width is 1/4 of the font-size. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> textHaloWidth(Function<T, Float> function) { - return new PaintPropertyValue<>("text-halo-width", function); - } - /** * The halo's fadeout distance towards the outside. * @@ -1053,19 +675,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("text-halo-blur", expression); } - - /** - * The halo's fadeout distance towards the outside. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> textHaloBlur(Function<T, Float> function) { - return new PaintPropertyValue<>("text-halo-blur", function); - } - /** * Distance that the text's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up. * @@ -1086,19 +695,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("text-translate", expression); } - - /** - * Distance that the text's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float[] - * @return property wrapper around a Float[] function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float[]>> textTranslate(CameraFunction<Z, Float[]> function) { - return new PaintPropertyValue<>("text-translate", function); - } - /** * Controls the frame of reference for {@link PropertyFactory#textTranslate}. * @@ -1119,19 +715,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("text-translate-anchor", expression); } - - /** - * Controls the frame of reference for {@link PropertyFactory#textTranslate}. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> textTranslateAnchor(CameraFunction<Z, String> function) { - return new PaintPropertyValue<>("text-translate-anchor", function); - } - /** * Circle radius. * @@ -1152,19 +735,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-radius", expression); } - - /** - * Circle radius. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> circleRadius(Function<T, Float> function) { - return new PaintPropertyValue<>("circle-radius", function); - } - /** * The fill color of the circle. * @@ -1195,19 +765,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-color", expression); } - - /** - * The fill color of the circle. - * - * @param <T> the function input type - * @param function a wrapper function for String - * @return property wrapper around a String function - */ - @Deprecated - public static <T> PropertyValue<Function<T, String>> circleColor(Function<T, String> function) { - return new PaintPropertyValue<>("circle-color", function); - } - /** * Amount to blur the circle. 1 blurs the circle such that only the centerpoint is full opacity. * @@ -1228,19 +785,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-blur", expression); } - - /** - * Amount to blur the circle. 1 blurs the circle such that only the centerpoint is full opacity. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> circleBlur(Function<T, Float> function) { - return new PaintPropertyValue<>("circle-blur", function); - } - /** * The opacity at which the circle will be drawn. * @@ -1261,19 +805,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-opacity", expression); } - - /** - * The opacity at which the circle will be drawn. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> circleOpacity(Function<T, Float> function) { - return new PaintPropertyValue<>("circle-opacity", function); - } - /** * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. * @@ -1294,19 +825,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-translate", expression); } - - /** - * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float[] - * @return property wrapper around a Float[] function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float[]>> circleTranslate(CameraFunction<Z, Float[]> function) { - return new PaintPropertyValue<>("circle-translate", function); - } - /** * Controls the frame of reference for {@link PropertyFactory#circleTranslate}. * @@ -1327,19 +845,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-translate-anchor", expression); } - - /** - * Controls the frame of reference for {@link PropertyFactory#circleTranslate}. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> circleTranslateAnchor(CameraFunction<Z, String> function) { - return new PaintPropertyValue<>("circle-translate-anchor", function); - } - /** * Controls the scaling behavior of the circle when the map is pitched. * @@ -1360,19 +865,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-pitch-scale", expression); } - - /** - * Controls the scaling behavior of the circle when the map is pitched. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> circlePitchScale(CameraFunction<Z, String> function) { - return new PaintPropertyValue<>("circle-pitch-scale", function); - } - /** * Orientation of circle when map is pitched. * @@ -1393,19 +885,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-pitch-alignment", expression); } - - /** - * Orientation of circle when map is pitched. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> circlePitchAlignment(CameraFunction<Z, String> function) { - return new PaintPropertyValue<>("circle-pitch-alignment", function); - } - /** * The width of the circle's stroke. Strokes are placed outside of the {@link PropertyFactory#circleRadius}. * @@ -1426,19 +905,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-stroke-width", expression); } - - /** - * The width of the circle's stroke. Strokes are placed outside of the {@link PropertyFactory#circleRadius}. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> circleStrokeWidth(Function<T, Float> function) { - return new PaintPropertyValue<>("circle-stroke-width", function); - } - /** * The stroke color of the circle. * @@ -1469,19 +935,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-stroke-color", expression); } - - /** - * The stroke color of the circle. - * - * @param <T> the function input type - * @param function a wrapper function for String - * @return property wrapper around a String function - */ - @Deprecated - public static <T> PropertyValue<Function<T, String>> circleStrokeColor(Function<T, String> function) { - return new PaintPropertyValue<>("circle-stroke-color", function); - } - /** * The opacity of the circle's stroke. * @@ -1502,19 +955,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("circle-stroke-opacity", expression); } - - /** - * The opacity of the circle's stroke. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> circleStrokeOpacity(Function<T, Float> function) { - return new PaintPropertyValue<>("circle-stroke-opacity", function); - } - /** * Radius of influence of one heatmap point in density-independent pixels. Increasing the value makes the heatmap smoother, but less detailed. * @@ -1535,19 +975,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("heatmap-radius", expression); } - - /** - * Radius of influence of one heatmap point in density-independent pixels. Increasing the value makes the heatmap smoother, but less detailed. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> heatmapRadius(Function<T, Float> function) { - return new PaintPropertyValue<>("heatmap-radius", function); - } - /** * A measure of how much an individual point contributes to the heatmap. A value of 10 would be equivalent to having 10 points of weight 1 in the same spot. Especially useful when combined with clustering. * @@ -1568,19 +995,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("heatmap-weight", expression); } - - /** - * A measure of how much an individual point contributes to the heatmap. A value of 10 would be equivalent to having 10 points of weight 1 in the same spot. Especially useful when combined with clustering. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> heatmapWeight(Function<T, Float> function) { - return new PaintPropertyValue<>("heatmap-weight", function); - } - /** * Similar to {@link PropertyFactory#heatmapWeight} but controls the intensity of the heatmap globally. Primarily used for adjusting the heatmap based on zoom level. * @@ -1601,17 +1015,34 @@ public class PropertyFactory { return new PaintPropertyValue<>("heatmap-intensity", expression); } + /** + * Defines the color of each pixel based on its density value in a heatmap. Should be an expression that uses `["heatmap-density"]` as input. + * + * @param value a int color value + * @return property wrapper around String color + */ + public static PropertyValue<String> heatmapColor(@ColorInt int value) { + return new PaintPropertyValue<>("heatmap-color", colorToRgbaString(value)); + } /** - * Similar to {@link PropertyFactory#heatmapWeight} but controls the intensity of the heatmap globally. Primarily used for adjusting the heatmap based on zoom level. + * Defines the color of each pixel based on its density value in a heatmap. Should be an expression that uses `["heatmap-density"]` as input. + * + * @param value a String value + * @return property wrapper around String + */ + public static PropertyValue<String> heatmapColor(String value) { + return new PaintPropertyValue<>("heatmap-color", value); + } + + /** + * Defines the color of each pixel based on its density value in a heatmap. Should be an expression that uses `["heatmap-density"]` as input. * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function + * @param expression an expression statement + * @return property wrapper around an expression statement */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> heatmapIntensity(CameraFunction<Z, Float> function) { - return new PaintPropertyValue<>("heatmap-intensity", function); + public static PropertyValue<Expression> heatmapColor(Expression expression) { + return new PaintPropertyValue<>("heatmap-color", expression); } /** @@ -1634,19 +1065,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("heatmap-opacity", expression); } - - /** - * The global opacity at which the heatmap layer will be drawn. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> heatmapOpacity(CameraFunction<Z, Float> function) { - return new PaintPropertyValue<>("heatmap-opacity", function); - } - /** * The opacity of the entire fill extrusion layer. This is rendered on a per-layer, not per-feature, basis, and data-driven styling is not available. * @@ -1667,19 +1085,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-extrusion-opacity", expression); } - - /** - * The opacity of the entire fill extrusion layer. This is rendered on a per-layer, not per-feature, basis, and data-driven styling is not available. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> fillExtrusionOpacity(CameraFunction<Z, Float> function) { - return new PaintPropertyValue<>("fill-extrusion-opacity", function); - } - /** * The base color of the extruded fill. The extrusion's surfaces will be shaded differently based on this color in combination with the root `light` settings. If this color is specified as `rgba` with an alpha component, the alpha component will be ignored; use {@link PropertyFactory#fillExtrusionOpacity} to set layer opacity. * @@ -1710,19 +1115,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-extrusion-color", expression); } - - /** - * The base color of the extruded fill. The extrusion's surfaces will be shaded differently based on this color in combination with the root `light` settings. If this color is specified as `rgba` with an alpha component, the alpha component will be ignored; use {@link PropertyFactory#fillExtrusionOpacity} to set layer opacity. - * - * @param <T> the function input type - * @param function a wrapper function for String - * @return property wrapper around a String function - */ - @Deprecated - public static <T> PropertyValue<Function<T, String>> fillExtrusionColor(Function<T, String> function) { - return new PaintPropertyValue<>("fill-extrusion-color", function); - } - /** * The geometry's offset. Values are [x, y] where negatives indicate left and up (on the flat plane), respectively. * @@ -1743,19 +1135,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-extrusion-translate", expression); } - - /** - * The geometry's offset. Values are [x, y] where negatives indicate left and up (on the flat plane), respectively. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float[] - * @return property wrapper around a Float[] function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float[]>> fillExtrusionTranslate(CameraFunction<Z, Float[]> function) { - return new PaintPropertyValue<>("fill-extrusion-translate", function); - } - /** * Controls the frame of reference for {@link PropertyFactory#fillExtrusionTranslate}. * @@ -1776,19 +1155,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-extrusion-translate-anchor", expression); } - - /** - * Controls the frame of reference for {@link PropertyFactory#fillExtrusionTranslate}. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> fillExtrusionTranslateAnchor(CameraFunction<Z, String> function) { - return new PaintPropertyValue<>("fill-extrusion-translate-anchor", function); - } - /** * Name of image in sprite to use for drawing images on extruded fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). * @@ -1809,19 +1175,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-extrusion-pattern", expression); } - - /** - * Name of image in sprite to use for drawing images on extruded fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> fillExtrusionPattern(CameraFunction<Z, String> function) { - return new PaintPropertyValue<>("fill-extrusion-pattern", function); - } - /** * The height with which to extrude this layer. * @@ -1842,19 +1195,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-extrusion-height", expression); } - - /** - * The height with which to extrude this layer. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> fillExtrusionHeight(Function<T, Float> function) { - return new PaintPropertyValue<>("fill-extrusion-height", function); - } - /** * The height with which to extrude the base of this layer. Must be less than or equal to {@link PropertyFactory#fillExtrusionHeight}. * @@ -1875,19 +1215,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("fill-extrusion-base", expression); } - - /** - * The height with which to extrude the base of this layer. Must be less than or equal to {@link PropertyFactory#fillExtrusionHeight}. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <T> PropertyValue<Function<T, Float>> fillExtrusionBase(Function<T, Float> function) { - return new PaintPropertyValue<>("fill-extrusion-base", function); - } - /** * The opacity at which the image will be drawn. * @@ -1908,19 +1235,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("raster-opacity", expression); } - - /** - * The opacity at which the image will be drawn. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> rasterOpacity(CameraFunction<Z, Float> function) { - return new PaintPropertyValue<>("raster-opacity", function); - } - /** * Rotates hues around the color wheel. * @@ -1941,19 +1255,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("raster-hue-rotate", expression); } - - /** - * Rotates hues around the color wheel. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> rasterHueRotate(CameraFunction<Z, Float> function) { - return new PaintPropertyValue<>("raster-hue-rotate", function); - } - /** * Increase or reduce the brightness of the image. The value is the minimum brightness. * @@ -1974,19 +1275,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("raster-brightness-min", expression); } - - /** - * Increase or reduce the brightness of the image. The value is the minimum brightness. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> rasterBrightnessMin(CameraFunction<Z, Float> function) { - return new PaintPropertyValue<>("raster-brightness-min", function); - } - /** * Increase or reduce the brightness of the image. The value is the maximum brightness. * @@ -2007,19 +1295,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("raster-brightness-max", expression); } - - /** - * Increase or reduce the brightness of the image. The value is the maximum brightness. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> rasterBrightnessMax(CameraFunction<Z, Float> function) { - return new PaintPropertyValue<>("raster-brightness-max", function); - } - /** * Increase or reduce the saturation of the image. * @@ -2040,19 +1315,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("raster-saturation", expression); } - - /** - * Increase or reduce the saturation of the image. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> rasterSaturation(CameraFunction<Z, Float> function) { - return new PaintPropertyValue<>("raster-saturation", function); - } - /** * Increase or reduce the contrast of the image. * @@ -2073,19 +1335,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("raster-contrast", expression); } - - /** - * Increase or reduce the contrast of the image. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> rasterContrast(CameraFunction<Z, Float> function) { - return new PaintPropertyValue<>("raster-contrast", function); - } - /** * Fade duration when a new tile is added. * @@ -2106,19 +1355,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("raster-fade-duration", expression); } - - /** - * Fade duration when a new tile is added. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> rasterFadeDuration(CameraFunction<Z, Float> function) { - return new PaintPropertyValue<>("raster-fade-duration", function); - } - /** * The direction of the light source used to generate the hillshading with 0 as the top of the viewport if {@link Property.HILLSHADE_ILLUMINATION_ANCHOR} is set to `viewport` and due north if {@link Property.HILLSHADE_ILLUMINATION_ANCHOR} is set to `map`. * @@ -2139,19 +1375,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("hillshade-illumination-direction", expression); } - - /** - * The direction of the light source used to generate the hillshading with 0 as the top of the viewport if {@link Property.HILLSHADE_ILLUMINATION_ANCHOR} is set to `viewport` and due north if {@link Property.HILLSHADE_ILLUMINATION_ANCHOR} is set to `map`. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> hillshadeIlluminationDirection(CameraFunction<Z, Float> function) { - return new PaintPropertyValue<>("hillshade-illumination-direction", function); - } - /** * Direction of light source when map is rotated. * @@ -2172,19 +1395,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("hillshade-illumination-anchor", expression); } - - /** - * Direction of light source when map is rotated. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> hillshadeIlluminationAnchor(CameraFunction<Z, String> function) { - return new PaintPropertyValue<>("hillshade-illumination-anchor", function); - } - /** * Intensity of the hillshade * @@ -2205,19 +1415,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("hillshade-exaggeration", expression); } - - /** - * Intensity of the hillshade - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> hillshadeExaggeration(CameraFunction<Z, Float> function) { - return new PaintPropertyValue<>("hillshade-exaggeration", function); - } - /** * The shading color of areas that face away from the light source. * @@ -2248,19 +1445,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("hillshade-shadow-color", expression); } - - /** - * The shading color of areas that face away from the light source. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> hillshadeShadowColor(CameraFunction<Z, String> function) { - return new PaintPropertyValue<>("hillshade-shadow-color", function); - } - /** * The shading color of areas that faces towards the light source. * @@ -2291,19 +1475,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("hillshade-highlight-color", expression); } - - /** - * The shading color of areas that faces towards the light source. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> hillshadeHighlightColor(CameraFunction<Z, String> function) { - return new PaintPropertyValue<>("hillshade-highlight-color", function); - } - /** * The shading color used to accentuate rugged terrain like sharp cliffs and gorges. * @@ -2334,19 +1505,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("hillshade-accent-color", expression); } - - /** - * The shading color used to accentuate rugged terrain like sharp cliffs and gorges. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> hillshadeAccentColor(CameraFunction<Z, String> function) { - return new PaintPropertyValue<>("hillshade-accent-color", function); - } - /** * The color with which the background will be drawn. * @@ -2377,19 +1535,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("background-color", expression); } - - /** - * The color with which the background will be drawn. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> backgroundColor(CameraFunction<Z, String> function) { - return new PaintPropertyValue<>("background-color", function); - } - /** * Name of image in sprite to use for drawing an image background. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). * @@ -2410,19 +1555,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("background-pattern", expression); } - - /** - * Name of image in sprite to use for drawing an image background. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> backgroundPattern(CameraFunction<Z, String> function) { - return new PaintPropertyValue<>("background-pattern", function); - } - /** * The opacity at which the background will be drawn. * @@ -2443,19 +1575,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("background-opacity", expression); } - - /** - * The opacity at which the background will be drawn. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> backgroundOpacity(CameraFunction<Z, Float> function) { - return new PaintPropertyValue<>("background-opacity", function); - } - /** * The display of line endings. * @@ -2476,18 +1595,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("line-cap", value); } - - /** - * The display of line endings. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> lineCap(CameraFunction<Z, String> function) { - return new LayoutPropertyValue<>("line-cap", function); - } - /** * The display of lines when joining. * @@ -2508,18 +1615,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("line-join", value); } - - /** - * The display of lines when joining. - * - * @param <T> the function input type - * @param function a wrapper function for String - * @return property wrapper around a String function - */ - public static <T> PropertyValue<Function<T, String>> lineJoin(Function<T, String> function) { - return new LayoutPropertyValue<>("line-join", function); - } - /** * Used to automatically convert miter joins to bevel joins for sharp angles. * @@ -2540,18 +1635,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("line-miter-limit", value); } - - /** - * Used to automatically convert miter joins to bevel joins for sharp angles. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> lineMiterLimit(CameraFunction<Z, Float> function) { - return new LayoutPropertyValue<>("line-miter-limit", function); - } - /** * Used to automatically convert round joins to miter joins for shallow angles. * @@ -2572,18 +1655,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("line-round-limit", value); } - - /** - * Used to automatically convert round joins to miter joins for shallow angles. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> lineRoundLimit(CameraFunction<Z, Float> function) { - return new LayoutPropertyValue<>("line-round-limit", function); - } - /** * Label placement relative to its geometry. * @@ -2604,18 +1675,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("symbol-placement", value); } - - /** - * Label placement relative to its geometry. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> symbolPlacement(CameraFunction<Z, String> function) { - return new LayoutPropertyValue<>("symbol-placement", function); - } - /** * Distance between two symbol anchors. * @@ -2636,18 +1695,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("symbol-spacing", value); } - - /** - * Distance between two symbol anchors. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> symbolSpacing(CameraFunction<Z, Float> function) { - return new LayoutPropertyValue<>("symbol-spacing", function); - } - /** * If true, the symbols will not cross tile edges to avoid mutual collisions. Recommended in layers that don't have enough padding in the vector tile to prevent collisions, or if it is a point symbol layer placed after a line symbol layer. * @@ -2668,18 +1715,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("symbol-avoid-edges", value); } - - /** - * If true, the symbols will not cross tile edges to avoid mutual collisions. Recommended in layers that don't have enough padding in the vector tile to prevent collisions, or if it is a point symbol layer placed after a line symbol layer. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Boolean - * @return property wrapper around a Boolean function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, Boolean>> symbolAvoidEdges(CameraFunction<Z, Boolean> function) { - return new LayoutPropertyValue<>("symbol-avoid-edges", function); - } - /** * If true, the icon will be visible even if it collides with other previously drawn symbols. * @@ -2700,18 +1735,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-allow-overlap", value); } - - /** - * If true, the icon will be visible even if it collides with other previously drawn symbols. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Boolean - * @return property wrapper around a Boolean function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, Boolean>> iconAllowOverlap(CameraFunction<Z, Boolean> function) { - return new LayoutPropertyValue<>("icon-allow-overlap", function); - } - /** * If true, other symbols can be visible even if they collide with the icon. * @@ -2732,18 +1755,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-ignore-placement", value); } - - /** - * If true, other symbols can be visible even if they collide with the icon. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Boolean - * @return property wrapper around a Boolean function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, Boolean>> iconIgnorePlacement(CameraFunction<Z, Boolean> function) { - return new LayoutPropertyValue<>("icon-ignore-placement", function); - } - /** * If true, text will display without their corresponding icons when the icon collides with other symbols and the text does not. * @@ -2764,18 +1775,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-optional", value); } - - /** - * If true, text will display without their corresponding icons when the icon collides with other symbols and the text does not. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Boolean - * @return property wrapper around a Boolean function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, Boolean>> iconOptional(CameraFunction<Z, Boolean> function) { - return new LayoutPropertyValue<>("icon-optional", function); - } - /** * In combination with {@link Property.SYMBOL_PLACEMENT}, determines the rotation behavior of icons. * @@ -2796,18 +1795,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-rotation-alignment", value); } - - /** - * In combination with {@link Property.SYMBOL_PLACEMENT}, determines the rotation behavior of icons. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> iconRotationAlignment(CameraFunction<Z, String> function) { - return new LayoutPropertyValue<>("icon-rotation-alignment", function); - } - /** * Scales the original size of the icon by the provided factor. The new pixel size of the image will be the original pixel size multiplied by {@link PropertyFactory#iconSize}. 1 is the original size; 3 triples the size of the image. * @@ -2828,18 +1815,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-size", value); } - - /** - * Scales the original size of the icon by the provided factor. The new pixel size of the image will be the original pixel size multiplied by {@link PropertyFactory#iconSize}. 1 is the original size; 3 triples the size of the image. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - public static <T> PropertyValue<Function<T, Float>> iconSize(Function<T, Float> function) { - return new LayoutPropertyValue<>("icon-size", function); - } - /** * Scales the icon to fit around the associated text. * @@ -2860,18 +1835,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-text-fit", value); } - - /** - * Scales the icon to fit around the associated text. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> iconTextFit(CameraFunction<Z, String> function) { - return new LayoutPropertyValue<>("icon-text-fit", function); - } - /** * Size of the additional area added to dimensions determined by {@link Property.ICON_TEXT_FIT}, in clockwise order: top, right, bottom, left. * @@ -2892,20 +1855,8 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-text-fit-padding", value); } - /** - * Size of the additional area added to dimensions determined by {@link Property.ICON_TEXT_FIT}, in clockwise order: top, right, bottom, left. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float[] - * @return property wrapper around a Float[] function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float[]>> iconTextFitPadding(CameraFunction<Z, Float[]> function) { - return new LayoutPropertyValue<>("icon-text-fit-padding", function); - } - - /** - * Name of image in sprite to use for drawing an image background. Within literal values and zoom functions, property names enclosed in curly brackets (e.g. `{token}`) are replaced with the value of the named property. Expressions and property functions do not support this syntax; for equivalent functionality in expressions, use the [`concat`](#expressions-concat) and [`get`](#expressions-get) operators. + * Name of image in sprite to use for drawing an image background. * * @param value a String value * @return property wrapper around String @@ -2915,7 +1866,7 @@ public class PropertyFactory { } /** - * Name of image in sprite to use for drawing an image background. Within literal values and zoom functions, property names enclosed in curly brackets (e.g. `{token}`) are replaced with the value of the named property. Expressions and property functions do not support this syntax; for equivalent functionality in expressions, use the [`concat`](#expressions-concat) and [`get`](#expressions-get) operators. + * Name of image in sprite to use for drawing an image background. * * @param value a String value * @return property wrapper around String @@ -2924,18 +1875,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-image", value); } - - /** - * Name of image in sprite to use for drawing an image background. Within literal values and zoom functions, property names enclosed in curly brackets (e.g. `{token}`) are replaced with the value of the named property. Expressions and property functions do not support this syntax; for equivalent functionality in expressions, use the [`concat`](#expressions-concat) and [`get`](#expressions-get) operators. - * - * @param <T> the function input type - * @param function a wrapper function for String - * @return property wrapper around a String function - */ - public static <T> PropertyValue<Function<T, String>> iconImage(Function<T, String> function) { - return new LayoutPropertyValue<>("icon-image", function); - } - /** * Rotates the icon clockwise. * @@ -2956,18 +1895,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-rotate", value); } - - /** - * Rotates the icon clockwise. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - public static <T> PropertyValue<Function<T, Float>> iconRotate(Function<T, Float> function) { - return new LayoutPropertyValue<>("icon-rotate", function); - } - /** * Size of the additional area around the icon bounding box used for detecting symbol collisions. * @@ -2988,18 +1915,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-padding", value); } - - /** - * Size of the additional area around the icon bounding box used for detecting symbol collisions. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> iconPadding(CameraFunction<Z, Float> function) { - return new LayoutPropertyValue<>("icon-padding", function); - } - /** * If true, the icon may be flipped to prevent it from being rendered upside-down. * @@ -3020,18 +1935,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-keep-upright", value); } - - /** - * If true, the icon may be flipped to prevent it from being rendered upside-down. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Boolean - * @return property wrapper around a Boolean function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, Boolean>> iconKeepUpright(CameraFunction<Z, Boolean> function) { - return new LayoutPropertyValue<>("icon-keep-upright", function); - } - /** * Offset distance of icon from its anchor. Positive values indicate right and down, while negative values indicate left and up. Each component is multiplied by the value of {@link PropertyFactory#iconSize} to obtain the final offset in density-independent pixels. When combined with {@link PropertyFactory#iconRotate} the offset will be as if the rotated direction was up. * @@ -3052,18 +1955,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-offset", value); } - - /** - * Offset distance of icon from its anchor. Positive values indicate right and down, while negative values indicate left and up. Each component is multiplied by the value of {@link PropertyFactory#iconSize} to obtain the final offset in density-independent pixels. When combined with {@link PropertyFactory#iconRotate} the offset will be as if the rotated direction was up. - * - * @param <T> the function input type - * @param function a wrapper function for Float[] - * @return property wrapper around a Float[] function - */ - public static <T> PropertyValue<Function<T, Float[]>> iconOffset(Function<T, Float[]> function) { - return new LayoutPropertyValue<>("icon-offset", function); - } - /** * Part of the icon placed closest to the anchor. * @@ -3084,18 +1975,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-anchor", value); } - - /** - * Part of the icon placed closest to the anchor. - * - * @param <T> the function input type - * @param function a wrapper function for String - * @return property wrapper around a String function - */ - public static <T> PropertyValue<Function<T, String>> iconAnchor(Function<T, String> function) { - return new LayoutPropertyValue<>("icon-anchor", function); - } - /** * Orientation of icon when map is pitched. * @@ -3116,18 +1995,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("icon-pitch-alignment", value); } - - /** - * Orientation of icon when map is pitched. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> iconPitchAlignment(CameraFunction<Z, String> function) { - return new LayoutPropertyValue<>("icon-pitch-alignment", function); - } - /** * Orientation of text when map is pitched. * @@ -3148,18 +2015,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-pitch-alignment", value); } - - /** - * Orientation of text when map is pitched. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> textPitchAlignment(CameraFunction<Z, String> function) { - return new LayoutPropertyValue<>("text-pitch-alignment", function); - } - /** * In combination with {@link Property.SYMBOL_PLACEMENT}, determines the rotation behavior of the individual glyphs forming the text. * @@ -3180,20 +2035,8 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-rotation-alignment", value); } - - /** - * In combination with {@link Property.SYMBOL_PLACEMENT}, determines the rotation behavior of the individual glyphs forming the text. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for String - * @return property wrapper around a String function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, String>> textRotationAlignment(CameraFunction<Z, String> function) { - return new LayoutPropertyValue<>("text-rotation-alignment", function); - } - /** - * Value to use for a text label. Within literal values and zoom functions, property names enclosed in curly brackets (e.g. `{token}`) are replaced with the value of the named property. Expressions and property functions do not support this syntax; for equivalent functionality in expressions, use the [`concat`](#expressions-concat) and [`get`](#expressions-get) operators. + * Value to use for a text label. * * @param value a String value * @return property wrapper around String @@ -3203,7 +2046,7 @@ public class PropertyFactory { } /** - * Value to use for a text label. Within literal values and zoom functions, property names enclosed in curly brackets (e.g. `{token}`) are replaced with the value of the named property. Expressions and property functions do not support this syntax; for equivalent functionality in expressions, use the [`concat`](#expressions-concat) and [`get`](#expressions-get) operators. + * Value to use for a text label. * * @param value a String value * @return property wrapper around String @@ -3212,18 +2055,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-field", value); } - - /** - * Value to use for a text label. Within literal values and zoom functions, property names enclosed in curly brackets (e.g. `{token}`) are replaced with the value of the named property. Expressions and property functions do not support this syntax; for equivalent functionality in expressions, use the [`concat`](#expressions-concat) and [`get`](#expressions-get) operators. - * - * @param <T> the function input type - * @param function a wrapper function for String - * @return property wrapper around a String function - */ - public static <T> PropertyValue<Function<T, String>> textField(Function<T, String> function) { - return new LayoutPropertyValue<>("text-field", function); - } - /** * Font stack to use for displaying text. * @@ -3244,18 +2075,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-font", value); } - - /** - * Font stack to use for displaying text. - * - * @param <T> the function input type - * @param function a wrapper function for String[] - * @return property wrapper around a String[] function - */ - public static <T> PropertyValue<Function<T, String[]>> textFont(Function<T, String[]> function) { - return new LayoutPropertyValue<>("text-font", function); - } - /** * Font size. * @@ -3276,18 +2095,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-size", value); } - - /** - * Font size. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - public static <T> PropertyValue<Function<T, Float>> textSize(Function<T, Float> function) { - return new LayoutPropertyValue<>("text-size", function); - } - /** * The maximum line width for text wrapping. * @@ -3308,18 +2115,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-max-width", value); } - - /** - * The maximum line width for text wrapping. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - public static <T> PropertyValue<Function<T, Float>> textMaxWidth(Function<T, Float> function) { - return new LayoutPropertyValue<>("text-max-width", function); - } - /** * Text leading value for multi-line text. * @@ -3340,18 +2135,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-line-height", value); } - - /** - * Text leading value for multi-line text. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> textLineHeight(CameraFunction<Z, Float> function) { - return new LayoutPropertyValue<>("text-line-height", function); - } - /** * Text tracking amount. * @@ -3372,18 +2155,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-letter-spacing", value); } - - /** - * Text tracking amount. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - public static <T> PropertyValue<Function<T, Float>> textLetterSpacing(Function<T, Float> function) { - return new LayoutPropertyValue<>("text-letter-spacing", function); - } - /** * Text justification options. * @@ -3404,18 +2175,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-justify", value); } - - /** - * Text justification options. - * - * @param <T> the function input type - * @param function a wrapper function for String - * @return property wrapper around a String function - */ - public static <T> PropertyValue<Function<T, String>> textJustify(Function<T, String> function) { - return new LayoutPropertyValue<>("text-justify", function); - } - /** * Part of the text placed closest to the anchor. * @@ -3436,18 +2195,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-anchor", value); } - - /** - * Part of the text placed closest to the anchor. - * - * @param <T> the function input type - * @param function a wrapper function for String - * @return property wrapper around a String function - */ - public static <T> PropertyValue<Function<T, String>> textAnchor(Function<T, String> function) { - return new LayoutPropertyValue<>("text-anchor", function); - } - /** * Maximum angle change between adjacent characters. * @@ -3468,18 +2215,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-max-angle", value); } - - /** - * Maximum angle change between adjacent characters. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> textMaxAngle(CameraFunction<Z, Float> function) { - return new LayoutPropertyValue<>("text-max-angle", function); - } - /** * Rotates the text clockwise. * @@ -3500,18 +2235,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-rotate", value); } - - /** - * Rotates the text clockwise. - * - * @param <T> the function input type - * @param function a wrapper function for Float - * @return property wrapper around a Float function - */ - public static <T> PropertyValue<Function<T, Float>> textRotate(Function<T, Float> function) { - return new LayoutPropertyValue<>("text-rotate", function); - } - /** * Size of the additional area around the text bounding box used for detecting symbol collisions. * @@ -3532,18 +2255,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-padding", value); } - - /** - * Size of the additional area around the text bounding box used for detecting symbol collisions. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float - * @return property wrapper around a Float function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float>> textPadding(CameraFunction<Z, Float> function) { - return new LayoutPropertyValue<>("text-padding", function); - } - /** * If true, the text may be flipped vertically to prevent it from being rendered upside-down. * @@ -3564,18 +2275,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-keep-upright", value); } - - /** - * If true, the text may be flipped vertically to prevent it from being rendered upside-down. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Boolean - * @return property wrapper around a Boolean function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, Boolean>> textKeepUpright(CameraFunction<Z, Boolean> function) { - return new LayoutPropertyValue<>("text-keep-upright", function); - } - /** * Specifies how to capitalize text, similar to the CSS {@link PropertyFactory#textTransform} property. * @@ -3596,18 +2295,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-transform", value); } - - /** - * Specifies how to capitalize text, similar to the CSS {@link PropertyFactory#textTransform} property. - * - * @param <T> the function input type - * @param function a wrapper function for String - * @return property wrapper around a String function - */ - public static <T> PropertyValue<Function<T, String>> textTransform(Function<T, String> function) { - return new LayoutPropertyValue<>("text-transform", function); - } - /** * Offset distance of text from its anchor. Positive values indicate right and down, while negative values indicate left and up. * @@ -3628,18 +2315,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-offset", value); } - - /** - * Offset distance of text from its anchor. Positive values indicate right and down, while negative values indicate left and up. - * - * @param <T> the function input type - * @param function a wrapper function for Float[] - * @return property wrapper around a Float[] function - */ - public static <T> PropertyValue<Function<T, Float[]>> textOffset(Function<T, Float[]> function) { - return new LayoutPropertyValue<>("text-offset", function); - } - /** * If true, the text will be visible even if it collides with other previously drawn symbols. * @@ -3660,18 +2335,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-allow-overlap", value); } - - /** - * If true, the text will be visible even if it collides with other previously drawn symbols. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Boolean - * @return property wrapper around a Boolean function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, Boolean>> textAllowOverlap(CameraFunction<Z, Boolean> function) { - return new LayoutPropertyValue<>("text-allow-overlap", function); - } - /** * If true, other symbols can be visible even if they collide with the text. * @@ -3692,18 +2355,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-ignore-placement", value); } - - /** - * If true, other symbols can be visible even if they collide with the text. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Boolean - * @return property wrapper around a Boolean function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, Boolean>> textIgnorePlacement(CameraFunction<Z, Boolean> function) { - return new LayoutPropertyValue<>("text-ignore-placement", function); - } - /** * If true, icons will display without their corresponding text when the text collides with other symbols and the icon does not. * @@ -3724,18 +2375,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("text-optional", value); } - - /** - * If true, icons will display without their corresponding text when the text collides with other symbols and the icon does not. - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Boolean - * @return property wrapper around a Boolean function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, Boolean>> textOptional(CameraFunction<Z, Boolean> function) { - return new LayoutPropertyValue<>("text-optional", function); - } - public static String colorToRgbaString(@ColorInt int value) { return String.format(Locale.US,"rgba(%d, %d, %d, %d)", (value >> 16) & 0xFF, (value >> 8) & 0xFF, value & 0xFF, (value >> 24) & 0xFF); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java index a57c440df4..fa1779a6c7 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java @@ -4,8 +4,9 @@ import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import com.google.gson.JsonArray; import com.mapbox.mapboxsdk.exceptions.ConversionException; -import com.mapbox.mapboxsdk.style.functions.Function; +import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.utils.ColorUtils; import timber.log.Timber; @@ -40,35 +41,39 @@ public class PropertyValue<T> { } /** - * Returns if this is a function. + * Returns if this is a expression. * - * @return true if is a function, false if not + * @return true if this is a expression, false if not */ - public boolean isFunction() { - return !isNull() && value instanceof Function; + public boolean isExpression() { + return !isNull() && value instanceof JsonArray; } /** - * Returns if this is a value. + * Get the expression of the property. * - * @return true if is a value, false if not + * @return the property expression */ - public boolean isValue() { - return !isNull() && !isFunction(); - } - @Nullable - public Function<?, T> getFunction() { - if (isFunction()) { - // noinspection unchecked - return (Function<?, T>) value; + public Expression getExpression() { + if (isExpression()) { + return Expression.Converter.convert((JsonArray) value); } else { - Timber.w("not a function, try value"); + Timber.w("not a expression, try value"); return null; } } /** + * Returns if this is a value. + * + * @return true if is a value, false if not + */ + public boolean isValue() { + return !isNull() && !isExpression(); + } + + /** * Get the value of the property. * * @return the property value @@ -77,7 +82,7 @@ public class PropertyValue<T> { public T getValue() { if (isValue()) { // noinspection unchecked - return (T) value; + return value; } else { Timber.w("not a value, try function"); return null; @@ -114,4 +119,4 @@ public class PropertyValue<T> { public String toString() { return String.format("%s: %s", name, value); } -} +}
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java index a0f45535f6..0c7948f62a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java @@ -4,10 +4,13 @@ package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.annotation.UiThread; import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; +import com.google.gson.JsonArray; +import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.TransitionOptions; /** diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java index d0fb82dce5..6a2e131d7d 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java @@ -4,10 +4,13 @@ package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.annotation.UiThread; import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; +import com.google.gson.JsonArray; +import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.TransitionOptions; /** @@ -69,26 +72,41 @@ public class SymbolLayer extends Layer { } /** - * Set a single filter. + * Set a single expression filter. * - * @param filter the filter to set + * @param filter the expression filter to set */ - public void setFilter(Filter.Statement filter) { + public void setFilter(Expression filter) { nativeSetFilter(filter.toArray()); } /** - * Set a single filter. + * Set a single expression filter. * - * @param filter the filter to set + * @param filter the expression filter to set * @return This */ - public SymbolLayer withFilter(Filter.Statement filter) { + public SymbolLayer withFilter(Expression filter) { setFilter(filter); return this; } /** + * Get a single expression filter. + * + * @return the expression filter to get + */ + @Nullable + public Expression getFilter() { + Expression expression = null; + JsonArray array = (JsonArray) nativeGetFilter(); + if (array != null) { + expression = Expression.Converter.convert(array); + } + return expression; + } + + /** * Set a property or properties. * * @param properties the var-args properties diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs index 77fa11808e..851a85f3d6 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs @@ -9,10 +9,13 @@ package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.annotation.UiThread; import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; +import com.google.gson.JsonArray; +import com.mapbox.mapboxsdk.style.expressions.Expression; import com.mapbox.mapboxsdk.style.layers.TransitionOptions; /** @@ -89,25 +92,40 @@ public class <%- camelize(type) %>Layer extends Layer { } /** - * Set a single filter. + * Set a single expression filter. * - * @param filter the filter to set + * @param filter the expression filter to set */ - public void setFilter(Filter.Statement filter) { + public void setFilter(Expression filter) { nativeSetFilter(filter.toArray()); } /** - * Set a single filter. + * Set a single expression filter. * - * @param filter the filter to set + * @param filter the expression filter to set * @return This */ - public <%- camelize(type) %>Layer withFilter(Filter.Statement filter) { + public <%- camelize(type) %>Layer withFilter(Expression filter) { setFilter(filter); return this; } + /** + * Get a single expression filter. + * + * @return the expression filter to get + */ + @Nullable + public Expression getFilter() { + Expression expression = null; + JsonArray array = (JsonArray) nativeGetFilter(); + if (array != null) { + expression = Expression.Converter.convert(array); + } + return expression; + } + <% } -%> /** * Set a property or properties. diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property_factory.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property_factory.java.ejs index 283d4e4189..6480dde3c8 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property_factory.java.ejs +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property_factory.java.ejs @@ -8,9 +8,7 @@ package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.ColorInt; -import com.mapbox.mapboxsdk.style.functions.CameraFunction; import com.mapbox.mapboxsdk.style.expressions.Expression; -import com.mapbox.mapboxsdk.style.functions.Function; import java.util.Locale; @@ -31,18 +29,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("visibility", value); } - /** - * Set the property visibility. - * - * @param <T> the function input type - * @param function the visibility function - * @return property wrapper around a String function - */ - @Deprecated - public static <T> PropertyValue<Function<T, String>> visibility(Function<T, String> function) { - return new LayoutPropertyValue<>("visibility", function); - } - <% for (const property of paintProperties) { -%> <% if (property.type == 'color') { -%> /** @@ -76,35 +62,6 @@ public class PropertyFactory { return new PaintPropertyValue<>("<%- property.name %>", expression); } -<% if (supportsPropertyFunction(property)) { -%> - - /** - * <%- propertyFactoryMethodDoc(property) %> - * - * @param <T> the function input type - * @param function a wrapper function for <%- propertyType(property) %> - * @return property wrapper around a <%- propertyType(property) %> function - */ - @Deprecated - public static <T> PropertyValue<Function<T, <%- propertyType(property) %>>> <%- camelizeWithLeadingLowercase(property.name) %>(Function<T, <%- propertyType(property) %>> function) { - return new PaintPropertyValue<>("<%- property.name %>", function); - } - -<% } else if (supportsZoomFunction(property)) { -%> - - /** - * <%- propertyFactoryMethodDoc(property) %> - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for <%- propertyType(property) %> - * @return property wrapper around a <%- propertyType(property) %> function - */ - @Deprecated - public static <Z extends Number> PropertyValue<CameraFunction<Z, <%- propertyType(property) %>>> <%- camelizeWithLeadingLowercase(property.name) %>(CameraFunction<Z, <%- propertyType(property) %>> function) { - return new PaintPropertyValue<>("<%- property.name %>", function); - } - -<% } -%> <% } -%> <% for (const property of layoutProperties) { -%> /** @@ -127,33 +84,6 @@ public class PropertyFactory { return new LayoutPropertyValue<>("<%- property.name %>", value); } -<% if (supportsPropertyFunction(property)) { -%> - - /** - * <%- propertyFactoryMethodDoc(property) %> - * - * @param <T> the function input type - * @param function a wrapper function for <%- propertyType(property) %> - * @return property wrapper around a <%- propertyType(property) %> function - */ - public static <T> PropertyValue<Function<T, <%- propertyType(property) %>>> <%- camelizeWithLeadingLowercase(property.name) %>(Function<T, <%- propertyType(property) %>> function) { - return new LayoutPropertyValue<>("<%- property.name %>", function); - } - -<% } else if (supportsZoomFunction(property)) { -%> - - /** - * <%- propertyFactoryMethodDoc(property) %> - * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for <%- propertyType(property) %> - * @return property wrapper around a <%- propertyType(property) %> function - */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, <%- propertyType(property) %>>> <%- camelizeWithLeadingLowercase(property.name) %>(CameraFunction<Z, <%- propertyType(property) %>> function) { - return new LayoutPropertyValue<>("<%- property.name %>", function); - } - -<% } -%> <% } -%> public static String colorToRgbaString(@ColorInt int value) { return String.format(Locale.US,"rgba(%d, %d, %d, %d)", diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Light.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Light.java index 8f23e7d01e..7df48001cc 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Light.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Light.java @@ -48,7 +48,7 @@ public class Light { } /** - * Set the Position property. Position of the light source relative to lit (extruded) geometries, in [r radial coordinate, a azimuthal angle, p polar angle] where r indicates the distance from the center of the base of an object to its light, a indicates the position of the light relative to 0° (0° when `light.anchor` is set to `viewport` corresponds to the top of the viewport, or 0° when `light.anchor` is set to `map` corresponds to due north, and degrees proceed clockwise), and p indicates the height of the light (from 0°, directly above, to 180°, directly below). + * Set the Position property. Position of the light source relative to lit (extruded) geometries, in [r radial coordinate, a azimuthal angle, p polar angle] where r indicates the distance from the center of the base of an object to its light, a indicates the position of the light relative to 0° (0° when `light.anchor` is set to `viewport` corresponds to the top of the viewport, or 0° when `light.anchor` is set to `map` corresponds to due north, and degrees proceed clockwise), and p indicates the height of the light (from 0°, directly above, to 180°, directly below). * * @param position of the light */ @@ -57,7 +57,7 @@ public class Light { } /** - * Get the Position property. Position of the light source relative to lit (extruded) geometries, in [r radial coordinate, a azimuthal angle, p polar angle] where r indicates the distance from the center of the base of an object to its light, a indicates the position of the light relative to 0° (0° when `light.anchor` is set to `viewport` corresponds to the top of the viewport, or 0° when `light.anchor` is set to `map` corresponds to due north, and degrees proceed clockwise), and p indicates the height of the light (from 0°, directly above, to 180°, directly below). + * Get the Position property. Position of the light source relative to lit (extruded) geometries, in [r radial coordinate, a azimuthal angle, p polar angle] where r indicates the distance from the center of the base of an object to its light, a indicates the position of the light relative to 0° (0° when `light.anchor` is set to `viewport` corresponds to the top of the viewport, or 0° when `light.anchor` is set to `map` corresponds to due north, and degrees proceed clockwise), and p indicates the height of the light (from 0°, directly above, to 180°, directly below). * * @return position as Position */ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Position.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Position.java index cd6218d3e2..00f8486a1c 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Position.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Position.java @@ -5,11 +5,11 @@ package com.mapbox.mapboxsdk.style.light; * <p> * The position is constructed out of a radial coordinate, an azimuthal angle and a polar angle. * where the radial coordinate indicates the distance from the center of the base of an object to its light, the - * azimuthal angle indicates the position of the light relative to 0° (0° when + * azimuthal angle indicates the position of the light relative to 0° (0° when * {@link com.mapbox.mapboxsdk.style.layers.Property.ANCHOR} is set to viewport corresponds to the top of the - * viewport, or 0° when {@link com.mapbox.mapboxsdk.style.layers.Property.ANCHOR} is set to map corresponds to due + * viewport, or 0° when {@link com.mapbox.mapboxsdk.style.layers.Property.ANCHOR} is set to map corresponds to due * north, and degrees proceed clockwise), and polar indicates the height of the light - * (from 0°, directly above, to 180°, directly below). + * (from 0°, directly above, to 180°, directly below). */ public class Position { @@ -21,7 +21,7 @@ public class Position { * Creates a Position from a radial coordinate, an azimuthal angle and a polar angle. * * @param radialCoordinate the distance from the center of the base of an object to its light - * @param azimuthalAngle the position of the light relative to 0° + * @param azimuthalAngle the position of the light relative to 0° * @param polarAngle the height of the light */ public Position(float radialCoordinate, float azimuthalAngle, float polarAngle) { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java index 1b0999ae2e..21a34f6064 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java @@ -8,7 +8,7 @@ import android.support.annotation.WorkerThread; import com.mapbox.geojson.Feature; import com.mapbox.geojson.FeatureCollection; import com.mapbox.mapboxsdk.geometry.LatLngBounds; -import com.mapbox.mapboxsdk.style.layers.Filter; +import com.mapbox.mapboxsdk.style.expressions.Expression; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -94,11 +94,11 @@ public class CustomGeometrySource extends Source { /** * Queries the source for features. * - * @param filter an optional filter statement to filter the returned Features + * @param filter an optional filter expression to filter the returned Features * @return the features */ @NonNull - public List<Feature> querySourceFeatures(@Nullable Filter.Statement filter) { + public List<Feature> querySourceFeatures(@Nullable Expression filter) { Feature[] features = querySourceFeatures(filter != null ? filter.toArray() : null); return features != null ? Arrays.asList(features) : new ArrayList<Feature>(); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java index 5c740554cd..efacc18741 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java @@ -7,7 +7,7 @@ import android.support.annotation.UiThread; import com.mapbox.geojson.Feature; import com.mapbox.geojson.FeatureCollection; import com.mapbox.geojson.Geometry; -import com.mapbox.mapboxsdk.style.layers.Filter; +import com.mapbox.mapboxsdk.style.expressions.Expression; import java.net.URL; import java.util.ArrayList; @@ -187,7 +187,7 @@ public class GeoJsonSource extends Source { * * @param geometry the GeoJSON {@link Geometry} to set */ - public void setGeoJson(Geometry<?> geometry) { + public void setGeoJson(Geometry geometry) { nativeSetGeometry(geometry); } @@ -238,11 +238,11 @@ public class GeoJsonSource extends Source { /** * Queries the source for features. * - * @param filter an optional filter statement to filter the returned Features + * @param filter an optional filter expression to filter the returned Features * @return the features */ @NonNull - public List<Feature> querySourceFeatures(@Nullable Filter.Statement filter) { + public List<Feature> querySourceFeatures(@Nullable Expression filter) { Feature[] features = querySourceFeatures(filter != null ? filter.toArray() : null); return features != null ? Arrays.asList(features) : new ArrayList<Feature>(); } @@ -259,7 +259,7 @@ public class GeoJsonSource extends Source { private native void nativeSetFeature(Feature feature); - private native void nativeSetGeometry(Geometry<?> geometry); + private native void nativeSetGeometry(Geometry geometry); private native Feature[] querySourceFeatures(Object[] filter); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/TileSet.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/TileSet.java index 54e4e5f5d3..25df2d91e7 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/TileSet.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/TileSet.java @@ -9,6 +9,7 @@ import java.util.Map; /** * Tile set, allows using TileJson specification as source. + * Note that `encoding` is only relevant to `raster-dem` sources, and is not supported in the TileJson spec. * * @see <a href="https://github.com/mapbox/tilejson-spec/tree/master/2.1.0">The tileset specification</a> */ @@ -28,6 +29,7 @@ public class TileSet { private Float maxZoom; private Float[] bounds; private Float[] center; + private String encoding; /** * @param tilejson A semver.org style version number. Describes the version of the TileJSON spec that is implemented @@ -246,6 +248,20 @@ public class TileSet { this.bounds = bounds; } + public String getEncoding() { + return encoding; + } + + /** + * Default: "mapbox". The encoding formula for a raster-dem tileset. + * Supported values are "mapbox" and "terrarium". + * + * @param encoding the String encoding formula to set + */ + public void setEncoding(String encoding) { + this.encoding = encoding; + } + public Float[] getCenter() { return center; } @@ -313,6 +329,10 @@ public class TileSet { if (center != null) { result.put("center", center); } + if (encoding != null) { + result.put("encoding", encoding); + } + return result; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java index 62b08a90ed..d82eaaa1c7 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java @@ -6,7 +6,7 @@ import android.support.annotation.Size; import android.support.annotation.UiThread; import com.mapbox.geojson.Feature; -import com.mapbox.mapboxsdk.style.layers.Filter; +import com.mapbox.mapboxsdk.style.expressions.Expression; import java.net.URL; import java.util.ArrayList; @@ -64,12 +64,12 @@ public class VectorSource extends Source { * Queries the source for features. * * @param sourceLayerIds the source layer identifiers. At least one must be specified. - * @param filter an optional filter statement to filter the returned Features + * @param filter an optional filter expression to filter the returned Features * @return the features */ @NonNull public List<Feature> querySourceFeatures(@Size(min = 1) String[] sourceLayerIds, - @Nullable Filter.Statement filter) { + @Nullable Expression filter) { Feature[] features = querySourceFeatures( sourceLayerIds, filter != null ? filter.toArray() : null); |