[android] - add expression conversion, add getters (#11352)
This commit is contained in:
@@ -5,9 +5,13 @@ 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 java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -101,10 +105,6 @@ public class Expression {
|
||||
return new ExpressionLiteral(bool);
|
||||
}
|
||||
|
||||
//
|
||||
// Types
|
||||
//
|
||||
|
||||
/**
|
||||
* Create a literal object expression.
|
||||
*
|
||||
@@ -159,10 +159,6 @@ public class Expression {
|
||||
return rgb(literal(red), literal(green), literal(blue));
|
||||
}
|
||||
|
||||
//
|
||||
// Literals
|
||||
//
|
||||
|
||||
/**
|
||||
* Creates a color value from red, green, blue components, which must range between 0 and 255,
|
||||
* and an alpha component which must range between 0 and 1.
|
||||
@@ -224,10 +220,6 @@ public class Expression {
|
||||
return new Expression("==", compareOne, compareTwo);
|
||||
}
|
||||
|
||||
//
|
||||
// Color
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns true if the input values are equal, false otherwise.
|
||||
*
|
||||
@@ -301,10 +293,6 @@ public class Expression {
|
||||
return new Expression("!=", literal(compareOne), literal(compareTwo));
|
||||
}
|
||||
|
||||
//
|
||||
// Decision
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns `true` if the input values are not equal, `false` otherwise.
|
||||
*
|
||||
@@ -477,7 +465,6 @@ public class Expression {
|
||||
* @return expression
|
||||
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-all">Style specification</a>
|
||||
*/
|
||||
|
||||
public static Expression all(@NonNull Expression... input) {
|
||||
return new Expression("all", input);
|
||||
}
|
||||
@@ -494,7 +481,6 @@ public class Expression {
|
||||
* @return expression
|
||||
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-any">Style specification</a>
|
||||
*/
|
||||
|
||||
public static Expression any(@NonNull Expression... input) {
|
||||
return new Expression("any", input);
|
||||
}
|
||||
@@ -532,7 +518,6 @@ public class Expression {
|
||||
* @return expression
|
||||
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-case">Style specification</a>
|
||||
*/
|
||||
|
||||
public static Expression switchCase(@NonNull @Size(min = 1) Expression... input) {
|
||||
return new Expression("case", input);
|
||||
}
|
||||
@@ -661,10 +646,6 @@ public class Expression {
|
||||
return new Expression("get", input);
|
||||
}
|
||||
|
||||
//
|
||||
// FeatureData
|
||||
//
|
||||
|
||||
/**
|
||||
* Retrieves a property value from the current feature's properties,
|
||||
* or from another object if a second argument is provided.
|
||||
@@ -704,10 +685,6 @@ public class Expression {
|
||||
return get(literal(key), object);
|
||||
}
|
||||
|
||||
//
|
||||
// Heatmap
|
||||
//
|
||||
|
||||
/**
|
||||
* Tests for the presence of an property value in the current feature's properties.
|
||||
*
|
||||
@@ -719,10 +696,6 @@ public class Expression {
|
||||
return new Expression("has", key);
|
||||
}
|
||||
|
||||
//
|
||||
// Lookup
|
||||
//
|
||||
|
||||
/**
|
||||
* Tests for the presence of an property value in the current feature's properties.
|
||||
*
|
||||
@@ -817,7 +790,6 @@ public class Expression {
|
||||
* @return expression
|
||||
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-+">Style specification</a>
|
||||
*/
|
||||
|
||||
public static Expression sum(@Size(min = 2) Expression... numbers) {
|
||||
return new Expression("+", numbers);
|
||||
}
|
||||
@@ -829,7 +801,6 @@ public class Expression {
|
||||
* @return expression
|
||||
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-+">Style specification</a>
|
||||
*/
|
||||
|
||||
public static Expression sum(@Size(min = 2) Number... numbers) {
|
||||
Expression[] numberExpression = new Expression[numbers.length];
|
||||
for (int i = 0; i < numbers.length; i++) {
|
||||
@@ -845,7 +816,6 @@ public class Expression {
|
||||
* @return expression
|
||||
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-*">Style specification</a>
|
||||
*/
|
||||
|
||||
public static Expression product(@Size(min = 2) Expression... numbers) {
|
||||
return new Expression("*", numbers);
|
||||
}
|
||||
@@ -857,7 +827,6 @@ public class Expression {
|
||||
* @return expression
|
||||
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-*">Style specification</a>
|
||||
*/
|
||||
|
||||
public static Expression product(@Size(min = 2) Number... numbers) {
|
||||
Expression[] numberExpression = new Expression[numbers.length];
|
||||
for (int i = 0; i < numbers.length; i++) {
|
||||
@@ -866,10 +835,6 @@ public class Expression {
|
||||
return product(numberExpression);
|
||||
}
|
||||
|
||||
//
|
||||
// Math
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns the result of subtracting a number from 0.
|
||||
*
|
||||
@@ -1215,7 +1180,6 @@ public class Expression {
|
||||
* @return expression
|
||||
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-min">Style specification</a>
|
||||
*/
|
||||
|
||||
public static Expression min(@Size(min = 1) Expression... numbers) {
|
||||
return new Expression("min", numbers);
|
||||
}
|
||||
@@ -1227,7 +1191,6 @@ public class Expression {
|
||||
* @return expression
|
||||
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-min">Style specification</a>
|
||||
*/
|
||||
|
||||
public static Expression min(@Size(min = 1) Number... numbers) {
|
||||
Expression[] numberExpression = new Expression[numbers.length];
|
||||
for (int i = 0; i < numbers.length; i++) {
|
||||
@@ -1243,7 +1206,6 @@ public class Expression {
|
||||
* @return expression
|
||||
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-max">Style specification</a>
|
||||
*/
|
||||
|
||||
public static Expression max(@Size(min = 1) Expression... numbers) {
|
||||
return new Expression("max", numbers);
|
||||
}
|
||||
@@ -1255,7 +1217,6 @@ public class Expression {
|
||||
* @return expression
|
||||
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-max">Style specification</a>
|
||||
*/
|
||||
|
||||
public static Expression max(@Size(min = 1) Number... numbers) {
|
||||
Expression[] numberExpression = new Expression[numbers.length];
|
||||
for (int i = 0; i < numbers.length; i++) {
|
||||
@@ -1331,7 +1292,6 @@ public class Expression {
|
||||
* @return expression
|
||||
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-concat">Style specification</a>
|
||||
*/
|
||||
|
||||
public static Expression concat(@NonNull Expression... input) {
|
||||
return new Expression("concat", input);
|
||||
}
|
||||
@@ -1343,7 +1303,6 @@ public class Expression {
|
||||
* @return expression
|
||||
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-concat">Style specification</a>
|
||||
*/
|
||||
|
||||
public static Expression concat(@NonNull String... input) {
|
||||
Expression[] stringExpression = new Expression[input.length];
|
||||
for (int i = 0; i < input.length; i++) {
|
||||
@@ -1365,10 +1324,6 @@ public class Expression {
|
||||
return new Expression("array", input);
|
||||
}
|
||||
|
||||
//
|
||||
// String
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns a string describing the type of the given value.
|
||||
*
|
||||
@@ -1448,10 +1403,6 @@ public class Expression {
|
||||
return new Expression("to-string", input);
|
||||
}
|
||||
|
||||
//
|
||||
// Types
|
||||
//
|
||||
|
||||
/**
|
||||
* Converts the input value to a number, if possible.
|
||||
* If the input is null or false, the result is 0.
|
||||
@@ -1501,7 +1452,6 @@ public class Expression {
|
||||
* @return expression
|
||||
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-let">Style specification</a>
|
||||
*/
|
||||
|
||||
public static Expression let(@Size(min = 1) Expression... input) {
|
||||
return new Expression("let", input);
|
||||
}
|
||||
@@ -1565,7 +1515,6 @@ public class Expression {
|
||||
* @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 Expression expression, Expression... stops) {
|
||||
return step(literal(input), expression, stops);
|
||||
}
|
||||
@@ -1582,15 +1531,10 @@ public class Expression {
|
||||
* @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 Expression expression, Expression... stops) {
|
||||
return new Expression("step", join(new Expression[] {input, expression}, stops));
|
||||
}
|
||||
|
||||
//
|
||||
// Variable binding
|
||||
//
|
||||
|
||||
/**
|
||||
* 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\"]`).
|
||||
@@ -1603,14 +1547,8 @@ public class Expression {
|
||||
* @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 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);
|
||||
return step(literal(input), expression, Stop.toExpressionArray(stops));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1625,14 +1563,8 @@ public class Expression {
|
||||
* @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 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);
|
||||
return step(input, expression, Stop.toExpressionArray(stops));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1647,16 +1579,11 @@ public class Expression {
|
||||
* @return expression
|
||||
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-interpolate">Style specification</a>
|
||||
*/
|
||||
|
||||
public static Expression interpolate(@NonNull Interpolator interpolation,
|
||||
@NonNull Expression number, Expression... stops) {
|
||||
return new Expression("interpolate", join(new Expression[] {interpolation, number}, stops));
|
||||
}
|
||||
|
||||
//
|
||||
// Zoom
|
||||
//
|
||||
|
||||
/**
|
||||
* Produces continuous, smooth results by interpolating between pairs of input and output values (\"stops\").
|
||||
* The `input` may be any numeric expression (e.g., `[\"get\", \"population\"]`).
|
||||
@@ -1669,21 +1596,11 @@ public class Expression {
|
||||
* @return expression
|
||||
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-interpolate">Style specification</a>
|
||||
*/
|
||||
|
||||
public static Expression interpolate(@NonNull Interpolator interpolation,
|
||||
@NonNull Expression 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);
|
||||
return interpolate(interpolation, number, Stop.toExpressionArray(stops));
|
||||
}
|
||||
|
||||
//
|
||||
// Ramps, scales, curves
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* interpolates linearly between the pair of stops just less than and just greater than the input.
|
||||
*
|
||||
@@ -1834,6 +1751,43 @@ public class Expression {
|
||||
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>
|
||||
@@ -1841,27 +1795,72 @@ public class Expression {
|
||||
* {@link #literal(String)} and {@link #literal(Object)}.
|
||||
* </p>
|
||||
*/
|
||||
private static class ExpressionLiteral extends Expression {
|
||||
public static class ExpressionLiteral extends Expression {
|
||||
|
||||
protected Object literal;
|
||||
|
||||
/**
|
||||
* Create an ExpressionValue wrapper.
|
||||
* Create an expression literal.
|
||||
*
|
||||
* @param object the object to be wrapped
|
||||
* @param object the object to be treated as literal
|
||||
*/
|
||||
ExpressionLiteral(@NonNull Object object) {
|
||||
public ExpressionLiteral(@NonNull Object object) {
|
||||
this.literal = object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the wrapped object.
|
||||
* Get the literal object.
|
||||
*
|
||||
* @return the wrapped 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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1896,9 +1895,9 @@ public class Expression {
|
||||
/**
|
||||
* Converts the int color to rgba(d, d, d, d) string representation
|
||||
*
|
||||
* @return
|
||||
* @return the string representation of a color
|
||||
*/
|
||||
public String convertColor() {
|
||||
String convertColor() {
|
||||
return PropertyFactory.colorToRgbaString(color);
|
||||
}
|
||||
}
|
||||
@@ -1921,9 +1920,90 @@ public class Expression {
|
||||
private Object value;
|
||||
private Object output;
|
||||
|
||||
public Stop(Object value, 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -3,7 +3,6 @@ package com.mapbox.mapboxsdk.style.layers;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.functions.Function;
|
||||
|
||||
/**
|
||||
* Base class for the different Layer types
|
||||
@@ -89,12 +88,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;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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,12 +41,27 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the expression of the property.
|
||||
*
|
||||
* @return the property expression
|
||||
*/
|
||||
@Nullable
|
||||
public Expression getExpression() {
|
||||
if (isExpression()) {
|
||||
return Expression.Converter.convert((JsonArray) value);
|
||||
} else {
|
||||
Timber.w("not a expression, try value");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,18 +70,7 @@ public class PropertyValue<T> {
|
||||
* @return true if is a value, false if not
|
||||
*/
|
||||
public boolean isValue() {
|
||||
return !isNull() && !isFunction();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Function<?, T> getFunction() {
|
||||
if (isFunction()) {
|
||||
// noinspection unchecked
|
||||
return (Function<?, T>) value;
|
||||
} else {
|
||||
Timber.w("not a function, try value");
|
||||
return null;
|
||||
}
|
||||
return !isNull() && !isExpression();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)",
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.style.layers;
|
||||
|
||||
import com.mapbox.mapboxsdk.style.functions.Function;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.functions.Function.zoom;
|
||||
import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop;
|
||||
import static com.mapbox.mapboxsdk.style.functions.stops.Stops.interval;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineBlur;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* Tests Function
|
||||
*/
|
||||
public class FunctionTest {
|
||||
|
||||
@Test
|
||||
public void testZoomFunction() {
|
||||
Function<Float, Float> zoomF = zoom(interval(
|
||||
stop(1f, lineBlur(1f)),
|
||||
stop(10f, lineBlur(20f))
|
||||
)
|
||||
);
|
||||
|
||||
assertNotNull(zoomF.toValueObject());
|
||||
assertArrayEquals(
|
||||
new Object[] {new Object[] {1f, 1f}, new Object[] {10f, 20f}},
|
||||
(Object[]) zoomF.toValueObject().get("stops")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,31 +3,18 @@
|
||||
package com.mapbox.mapboxsdk.testapp.style;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.support.test.espresso.UiController;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.style.functions.CompositeFunction;
|
||||
import com.mapbox.mapboxsdk.style.functions.CameraFunction;
|
||||
import com.mapbox.mapboxsdk.style.functions.SourceFunction;
|
||||
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 com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.BackgroundLayer;
|
||||
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.functions.Function.*;
|
||||
import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop;
|
||||
import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.*;
|
||||
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
|
||||
import static org.junit.Assert.*;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Property.*;
|
||||
@@ -51,11 +38,8 @@ public class BackgroundLayerTest extends BaseActivityTest {
|
||||
|
||||
private void setupLayer() {
|
||||
Timber.i("Retrieving layer");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
layer = mapboxMap.getLayerAs("background");
|
||||
}
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
layer = mapboxMap.getLayerAs("background");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -64,18 +48,15 @@ public class BackgroundLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("Visibility");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Get initial
|
||||
assertEquals(layer.getVisibility().getValue(), VISIBLE);
|
||||
// Get initial
|
||||
assertEquals(layer.getVisibility().getValue(), VISIBLE);
|
||||
|
||||
// Set
|
||||
layer.setProperties(visibility(NONE));
|
||||
assertEquals(layer.getVisibility().getValue(), NONE);
|
||||
}
|
||||
// Set
|
||||
layer.setProperties(visibility(NONE));
|
||||
assertEquals(layer.getVisibility().getValue(), NONE);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -84,16 +65,13 @@ public class BackgroundLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("background-colorTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setBackgroundColorTransition(options);
|
||||
assertEquals(layer.getBackgroundColorTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setBackgroundColorTransition(options);
|
||||
assertEquals(layer.getBackgroundColorTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -102,47 +80,12 @@ public class BackgroundLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("background-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(backgroundColor("rgba(0, 0, 0, 1)"));
|
||||
assertEquals((String) layer.getBackgroundColor().getValue(), (String) "rgba(0, 0, 0, 1)");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBackgroundColorAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("background-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
backgroundColor(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, backgroundColor("rgba(0, 0, 0, 1)"))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getBackgroundColor());
|
||||
assertNotNull(layer.getBackgroundColor().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getBackgroundColor().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getBackgroundColor().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getBackgroundColor().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getBackgroundColor().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(backgroundColor("rgba(0, 0, 0, 1)"));
|
||||
assertEquals((String) layer.getBackgroundColor().getValue(), (String) "rgba(0, 0, 0, 1)");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -151,15 +94,12 @@ public class BackgroundLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("background-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(backgroundColor(Color.RED));
|
||||
assertEquals(layer.getBackgroundColorAsInt(), Color.RED);
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(backgroundColor(Color.RED));
|
||||
assertEquals(layer.getBackgroundColorAsInt(), Color.RED);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -168,16 +108,13 @@ public class BackgroundLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("background-patternTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setBackgroundPatternTransition(options);
|
||||
assertEquals(layer.getBackgroundPatternTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setBackgroundPatternTransition(options);
|
||||
assertEquals(layer.getBackgroundPatternTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -186,46 +123,12 @@ public class BackgroundLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("background-pattern");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(backgroundPattern("pedestrian-polygon"));
|
||||
assertEquals((String) layer.getBackgroundPattern().getValue(), (String) "pedestrian-polygon");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBackgroundPatternAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("background-pattern");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
backgroundPattern(
|
||||
zoom(
|
||||
interval(
|
||||
stop(2, backgroundPattern("pedestrian-polygon"))
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getBackgroundPattern());
|
||||
assertNotNull(layer.getBackgroundPattern().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getBackgroundPattern().getFunction().getClass());
|
||||
assertEquals(IntervalStops.class, layer.getBackgroundPattern().getFunction().getStops().getClass());
|
||||
assertEquals(1, ((IntervalStops) layer.getBackgroundPattern().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(backgroundPattern("pedestrian-polygon"));
|
||||
assertEquals((String) layer.getBackgroundPattern().getValue(), (String) "pedestrian-polygon");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -234,16 +137,13 @@ public class BackgroundLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("background-opacityTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setBackgroundOpacityTransition(options);
|
||||
assertEquals(layer.getBackgroundOpacityTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setBackgroundOpacityTransition(options);
|
||||
assertEquals(layer.getBackgroundOpacityTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -252,48 +152,12 @@ public class BackgroundLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("background-opacity");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(backgroundOpacity(0.3f));
|
||||
assertEquals((Float) layer.getBackgroundOpacity().getValue(), (Float) 0.3f);
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(backgroundOpacity(0.3f));
|
||||
assertEquals((Float) layer.getBackgroundOpacity().getValue(), (Float) 0.3f);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBackgroundOpacityAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("background-opacity");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
backgroundOpacity(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, backgroundOpacity(0.3f))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getBackgroundOpacity());
|
||||
assertNotNull(layer.getBackgroundOpacity().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getBackgroundOpacity().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getBackgroundOpacity().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getBackgroundOpacity().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getBackgroundOpacity().getFunction().getStops()).size());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,207 @@
|
||||
package com.mapbox.mapboxsdk.testapp.style;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.FillLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.style.sources.Source;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.exponential;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.literal;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.match;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.rgb;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.rgba;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.step;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.stop;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.string;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.toColor;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillAntialias;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillColor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillOutlineColor;
|
||||
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExpressionTest extends BaseActivityTest {
|
||||
|
||||
private FillLayer layer;
|
||||
|
||||
@Test
|
||||
public void testConstantExpressionConversion() {
|
||||
validateTestSetup();
|
||||
setupStyle();
|
||||
Timber.i("camera function");
|
||||
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
// create color expression
|
||||
Expression inputExpression = rgba(255.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
// set color expression
|
||||
layer.setProperties(
|
||||
fillColor(inputExpression)
|
||||
);
|
||||
|
||||
// get color value
|
||||
int color = layer.getFillColor().getColorInt();
|
||||
|
||||
// compare
|
||||
assertEquals("input expression should match", Color.RED, color);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetExpressionWrapping() {
|
||||
validateTestSetup();
|
||||
setupStyle();
|
||||
Timber.i("camera function");
|
||||
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
// create get expression
|
||||
Expression inputExpression = get("fill");
|
||||
|
||||
// set get expression
|
||||
layer.setProperties(
|
||||
fillColor(inputExpression)
|
||||
);
|
||||
|
||||
// get actual expression
|
||||
Expression actualExpression = layer.getFillColor().getExpression();
|
||||
|
||||
// create wrapped expected expression
|
||||
Expression expectedExpression = toColor(get("fill"));
|
||||
|
||||
// compare
|
||||
assertEquals("input expression should match", expectedExpression, actualExpression);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupStyle();
|
||||
Timber.i("camera function");
|
||||
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
// create camera function expression
|
||||
Expression inputExpression = interpolate(
|
||||
exponential(0.5f), zoom(),
|
||||
stop(1.0f, rgba(255.0f, 0.0f, 0.0f, 1.0f)),
|
||||
stop(5.0f, rgba(0.0f, 0.0f, 255.0f, 1.0f)),
|
||||
stop(10.0f, rgba(0.0f, 255.0f, 0.0f, 1.0f))
|
||||
);
|
||||
|
||||
// set camera function expression
|
||||
layer.setProperties(
|
||||
fillColor(inputExpression)
|
||||
);
|
||||
|
||||
// get camera function expression
|
||||
Expression outputExpression = layer.getFillColor().getExpression();
|
||||
|
||||
// compare
|
||||
assertEquals("input expression should match", inputExpression, outputExpression);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSourceFunction() {
|
||||
validateTestSetup();
|
||||
setupStyle();
|
||||
Timber.i("camera function");
|
||||
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
// create camera function expression
|
||||
Expression inputExpression = toColor(get("fill"));
|
||||
|
||||
// set camera function expression
|
||||
layer.setProperties(
|
||||
fillColor(inputExpression)
|
||||
);
|
||||
|
||||
// get camera function expression
|
||||
Expression outputExpression = layer.getFillColor().getExpression();
|
||||
|
||||
// compare
|
||||
assertEquals("input expression should match", inputExpression, outputExpression);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompositeFunction() {
|
||||
validateTestSetup();
|
||||
setupStyle();
|
||||
Timber.i("camera function");
|
||||
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
// create camera function expression
|
||||
Expression inputExpression = step(zoom(),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f),
|
||||
stop(7.0f, match(
|
||||
string(get("name")),
|
||||
literal("Westerpark"), rgba(255.0f, 0.0f, 0.0f, 1.0f),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f)
|
||||
)),
|
||||
stop(8.0f, match(
|
||||
string(get("name")),
|
||||
literal("Westerpark"), rgba(0.0f, 0.0f, 255.0f, 1.0f),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f)
|
||||
))
|
||||
);
|
||||
|
||||
// set camera function expression
|
||||
layer.setProperties(
|
||||
fillColor(inputExpression)
|
||||
);
|
||||
|
||||
// get camera function expression
|
||||
Expression outputExpression = layer.getFillColor().getExpression();
|
||||
|
||||
// compare
|
||||
assertEquals("input expression should match", inputExpression, outputExpression);
|
||||
});
|
||||
}
|
||||
|
||||
private void setupStyle() {
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
// Add a source
|
||||
Source source;
|
||||
try {
|
||||
source = new GeoJsonSource("amsterdam-parks-source",
|
||||
ResourceUtils.readRawResource(rule.getActivity(), R.raw.amsterdam));
|
||||
mapboxMap.addSource(source);
|
||||
} catch (IOException ioException) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add a fill layer
|
||||
mapboxMap.addLayer(layer = new FillLayer("amsterdam-parks-layer", source.getId())
|
||||
.withProperties(
|
||||
fillColor(rgba(0.0f, 0.0f, 0.0f, 0.5f)),
|
||||
fillOutlineColor(rgb(0, 0, 255)),
|
||||
fillAntialias(true)
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class getActivityClass() {
|
||||
return EspressoTestActivity.class;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,31 +3,18 @@
|
||||
package com.mapbox.mapboxsdk.testapp.style;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.support.test.espresso.UiController;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.style.functions.CompositeFunction;
|
||||
import com.mapbox.mapboxsdk.style.functions.CameraFunction;
|
||||
import com.mapbox.mapboxsdk.style.functions.SourceFunction;
|
||||
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 com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.FillLayer;
|
||||
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.functions.Function.*;
|
||||
import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop;
|
||||
import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.*;
|
||||
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
|
||||
import static org.junit.Assert.*;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Property.*;
|
||||
@@ -51,17 +38,14 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
|
||||
private void setupLayer() {
|
||||
Timber.i("Retrieving layer");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
|
||||
Timber.i("Adding layer");
|
||||
layer = new FillLayer("my-layer", "composite");
|
||||
layer.setSourceLayer("composite");
|
||||
mapboxMap.addLayer(layer);
|
||||
// Layer reference is now stale, get new reference
|
||||
layer = mapboxMap.getLayerAs("my-layer");
|
||||
}
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
|
||||
Timber.i("Adding layer");
|
||||
layer = new FillLayer("my-layer", "composite");
|
||||
layer.setSourceLayer("composite");
|
||||
mapboxMap.addLayer(layer);
|
||||
// Layer reference is now stale, get new reference
|
||||
layer = mapboxMap.getLayerAs("my-layer");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -71,18 +55,15 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("Visibility");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Get initial
|
||||
assertEquals(layer.getVisibility().getValue(), VISIBLE);
|
||||
// Get initial
|
||||
assertEquals(layer.getVisibility().getValue(), VISIBLE);
|
||||
|
||||
// Set
|
||||
layer.setProperties(visibility(NONE));
|
||||
assertEquals(layer.getVisibility().getValue(), NONE);
|
||||
}
|
||||
// Set
|
||||
layer.setProperties(visibility(NONE));
|
||||
assertEquals(layer.getVisibility().getValue(), NONE);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -91,19 +72,16 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("SourceLayer");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Get initial
|
||||
assertEquals(layer.getSourceLayer(), "composite");
|
||||
// Get initial
|
||||
assertEquals(layer.getSourceLayer(), "composite");
|
||||
|
||||
// Set
|
||||
final String sourceLayer = "test";
|
||||
layer.setSourceLayer(sourceLayer);
|
||||
assertEquals(layer.getSourceLayer(), sourceLayer);
|
||||
}
|
||||
// Set
|
||||
final String sourceLayer = "test";
|
||||
layer.setSourceLayer(sourceLayer);
|
||||
assertEquals(layer.getSourceLayer(), sourceLayer);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -112,46 +90,12 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-antialias");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(fillAntialias(true));
|
||||
assertEquals((Boolean) layer.getFillAntialias().getValue(), (Boolean) true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillAntialiasAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-antialias");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
fillAntialias(
|
||||
zoom(
|
||||
interval(
|
||||
stop(2, fillAntialias(true))
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getFillAntialias());
|
||||
assertNotNull(layer.getFillAntialias().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getFillAntialias().getFunction().getClass());
|
||||
assertEquals(IntervalStops.class, layer.getFillAntialias().getFunction().getStops().getClass());
|
||||
assertEquals(1, ((IntervalStops) layer.getFillAntialias().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(fillAntialias(true));
|
||||
assertEquals((Boolean) layer.getFillAntialias().getValue(), (Boolean) true);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -160,16 +104,13 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-opacityTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setFillOpacityTransition(options);
|
||||
assertEquals(layer.getFillOpacityTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setFillOpacityTransition(options);
|
||||
assertEquals(layer.getFillOpacityTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -178,198 +119,43 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-opacity");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(fillOpacity(0.3f));
|
||||
assertEquals((Float) layer.getFillOpacity().getValue(), (Float) 0.3f);
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(fillOpacity(0.3f));
|
||||
assertEquals((Float) layer.getFillOpacity().getValue(), (Float) 0.3f);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillOpacityAsCameraFunction() {
|
||||
public void testFillOpacityAsExpression() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-opacity");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
Timber.i("fill-opacity-expression");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
fillOpacity(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, fillOpacity(0.3f))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getFillOpacity());
|
||||
assertNotNull(layer.getFillOpacity().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getFillOpacity().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getFillOpacity().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getFillOpacity().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getFillOpacity().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
Expression expression = number(Expression.get("undefined"));
|
||||
layer.setProperties(fillOpacity(expression));
|
||||
assertEquals(layer.getFillOpacity().getExpression(), expression);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillOpacityAsIdentitySourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-opacity");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
fillOpacity(property("FeaturePropertyA", Stops.<Float>identity()))
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getFillOpacity());
|
||||
assertNotNull(layer.getFillOpacity().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.getFillOpacity().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillOpacity().getFunction()).getProperty());
|
||||
assertEquals(IdentityStops.class, layer.getFillOpacity().getFunction().getStops().getClass());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillOpacityAsExponentialSourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-opacity");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
fillOpacity(
|
||||
property(
|
||||
"FeaturePropertyA",
|
||||
exponential(
|
||||
stop(0.3f, fillOpacity(0.3f))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getFillOpacity());
|
||||
assertNotNull(layer.getFillOpacity().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.getFillOpacity().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillOpacity().getFunction()).getProperty());
|
||||
assertEquals(ExponentialStops.class, layer.getFillOpacity().getFunction().getStops().getClass());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillOpacityAsCategoricalSourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-opacity");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
fillOpacity(
|
||||
property(
|
||||
"FeaturePropertyA",
|
||||
categorical(
|
||||
stop(1.0f, fillOpacity(0.3f))
|
||||
)
|
||||
).withDefaultValue(fillOpacity(0.3f))
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getFillOpacity());
|
||||
assertNotNull(layer.getFillOpacity().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.getFillOpacity().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillOpacity().getFunction()).getProperty());
|
||||
assertEquals(CategoricalStops.class, layer.getFillOpacity().getFunction().getStops().getClass());
|
||||
assertNotNull(((SourceFunction) layer.getFillOpacity().getFunction()).getDefaultValue());
|
||||
assertNotNull(((SourceFunction) layer.getFillOpacity().getFunction()).getDefaultValue().getValue());
|
||||
assertEquals(0.3f, ((SourceFunction) layer.getFillOpacity().getFunction()).getDefaultValue().getValue());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillOpacityAsCompositeFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-opacity");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
fillOpacity(
|
||||
composite(
|
||||
"FeaturePropertyA",
|
||||
exponential(
|
||||
stop(0, 0.3f, fillOpacity(0.9f))
|
||||
).withBase(0.5f)
|
||||
).withDefaultValue(fillOpacity(0.3f))
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getFillOpacity());
|
||||
assertNotNull(layer.getFillOpacity().getFunction());
|
||||
assertEquals(CompositeFunction.class, layer.getFillOpacity().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getFillOpacity().getFunction()).getProperty());
|
||||
assertEquals(ExponentialStops.class, layer.getFillOpacity().getFunction().getStops().getClass());
|
||||
assertEquals(1, ((ExponentialStops) layer.getFillOpacity().getFunction().getStops()).size());
|
||||
|
||||
ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops =
|
||||
(ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getFillOpacity().getFunction().getStops();
|
||||
Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next();
|
||||
assertEquals(0f, stop.in.zoom, 0.001);
|
||||
assertEquals(0.3f, stop.in.value, 0.001f);
|
||||
assertEquals(0.9f, stop.out, 0.001f);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillColorTransition() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-colorTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setFillColorTransition(options);
|
||||
assertEquals(layer.getFillColorTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setFillColorTransition(options);
|
||||
assertEquals(layer.getFillColorTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -378,157 +164,42 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(fillColor("rgba(0, 0, 0, 1)"));
|
||||
assertEquals((String) layer.getFillColor().getValue(), (String) "rgba(0, 0, 0, 1)");
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(fillColor("rgba(0, 0, 0, 1)"));
|
||||
assertEquals((String) layer.getFillColor().getValue(), (String) "rgba(0, 0, 0, 1)");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillColorAsCameraFunction() {
|
||||
public void testFillColorAsExpression() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
Timber.i("fill-color-expression");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
fillColor(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, fillColor("rgba(0, 0, 0, 1)"))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getFillColor());
|
||||
assertNotNull(layer.getFillColor().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getFillColor().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getFillColor().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getFillColor().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getFillColor().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
Expression expression = toColor(Expression.get("undefined"));
|
||||
layer.setProperties(fillColor(expression));
|
||||
assertEquals(layer.getFillColor().getExpression(), expression);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillColorAsIdentitySourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
fillColor(property("FeaturePropertyA", Stops.<String>identity()))
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getFillColor());
|
||||
assertNotNull(layer.getFillColor().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.getFillColor().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillColor().getFunction()).getProperty());
|
||||
assertEquals(IdentityStops.class, layer.getFillColor().getFunction().getStops().getClass());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillColorAsExponentialSourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
fillColor(
|
||||
property(
|
||||
"FeaturePropertyA",
|
||||
exponential(
|
||||
stop(Color.RED, fillColor(Color.RED))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getFillColor());
|
||||
assertNotNull(layer.getFillColor().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.getFillColor().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillColor().getFunction()).getProperty());
|
||||
assertEquals(ExponentialStops.class, layer.getFillColor().getFunction().getStops().getClass());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillColorAsCategoricalSourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
fillColor(
|
||||
property(
|
||||
"FeaturePropertyA",
|
||||
categorical(
|
||||
stop("valueA", fillColor(Color.RED))
|
||||
)
|
||||
).withDefaultValue(fillColor(Color.GREEN))
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getFillColor());
|
||||
assertNotNull(layer.getFillColor().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.getFillColor().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillColor().getFunction()).getProperty());
|
||||
assertEquals(CategoricalStops.class, layer.getFillColor().getFunction().getStops().getClass());
|
||||
assertNotNull(((SourceFunction) layer.getFillColor().getFunction()).getDefaultValue());
|
||||
assertNotNull(((SourceFunction) layer.getFillColor().getFunction()).getDefaultValue().getValue());
|
||||
assertEquals(Color.GREEN, (int) ((SourceFunction) layer.getFillColor().getFunction()).getDefaultValue().getColorInt());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillColorAsIntConstant() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(fillColor(Color.RED));
|
||||
assertEquals(layer.getFillColorAsInt(), Color.RED);
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(fillColor(Color.RED));
|
||||
assertEquals(layer.getFillColorAsInt(), Color.RED);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -537,16 +208,13 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-outline-colorTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setFillOutlineColorTransition(options);
|
||||
assertEquals(layer.getFillOutlineColorTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setFillOutlineColorTransition(options);
|
||||
assertEquals(layer.getFillOutlineColorTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -555,157 +223,42 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-outline-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(fillOutlineColor("rgba(0, 0, 0, 1)"));
|
||||
assertEquals((String) layer.getFillOutlineColor().getValue(), (String) "rgba(0, 0, 0, 1)");
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(fillOutlineColor("rgba(0, 0, 0, 1)"));
|
||||
assertEquals((String) layer.getFillOutlineColor().getValue(), (String) "rgba(0, 0, 0, 1)");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillOutlineColorAsCameraFunction() {
|
||||
public void testFillOutlineColorAsExpression() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-outline-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
Timber.i("fill-outline-color-expression");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
fillOutlineColor(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, fillOutlineColor("rgba(0, 0, 0, 1)"))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getFillOutlineColor());
|
||||
assertNotNull(layer.getFillOutlineColor().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getFillOutlineColor().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getFillOutlineColor().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getFillOutlineColor().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getFillOutlineColor().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
Expression expression = toColor(Expression.get("undefined"));
|
||||
layer.setProperties(fillOutlineColor(expression));
|
||||
assertEquals(layer.getFillOutlineColor().getExpression(), expression);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillOutlineColorAsIdentitySourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-outline-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
fillOutlineColor(property("FeaturePropertyA", Stops.<String>identity()))
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getFillOutlineColor());
|
||||
assertNotNull(layer.getFillOutlineColor().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.getFillOutlineColor().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillOutlineColor().getFunction()).getProperty());
|
||||
assertEquals(IdentityStops.class, layer.getFillOutlineColor().getFunction().getStops().getClass());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillOutlineColorAsExponentialSourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-outline-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
fillOutlineColor(
|
||||
property(
|
||||
"FeaturePropertyA",
|
||||
exponential(
|
||||
stop(Color.RED, fillOutlineColor(Color.RED))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getFillOutlineColor());
|
||||
assertNotNull(layer.getFillOutlineColor().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.getFillOutlineColor().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillOutlineColor().getFunction()).getProperty());
|
||||
assertEquals(ExponentialStops.class, layer.getFillOutlineColor().getFunction().getStops().getClass());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillOutlineColorAsCategoricalSourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-outline-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
fillOutlineColor(
|
||||
property(
|
||||
"FeaturePropertyA",
|
||||
categorical(
|
||||
stop("valueA", fillOutlineColor(Color.RED))
|
||||
)
|
||||
).withDefaultValue(fillOutlineColor(Color.GREEN))
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getFillOutlineColor());
|
||||
assertNotNull(layer.getFillOutlineColor().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.getFillOutlineColor().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.getFillOutlineColor().getFunction()).getProperty());
|
||||
assertEquals(CategoricalStops.class, layer.getFillOutlineColor().getFunction().getStops().getClass());
|
||||
assertNotNull(((SourceFunction) layer.getFillOutlineColor().getFunction()).getDefaultValue());
|
||||
assertNotNull(((SourceFunction) layer.getFillOutlineColor().getFunction()).getDefaultValue().getValue());
|
||||
assertEquals(Color.GREEN, (int) ((SourceFunction) layer.getFillOutlineColor().getFunction()).getDefaultValue().getColorInt());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillOutlineColorAsIntConstant() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-outline-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(fillOutlineColor(Color.RED));
|
||||
assertEquals(layer.getFillOutlineColorAsInt(), Color.RED);
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(fillOutlineColor(Color.RED));
|
||||
assertEquals(layer.getFillOutlineColorAsInt(), Color.RED);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -714,16 +267,13 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-translateTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setFillTranslateTransition(options);
|
||||
assertEquals(layer.getFillTranslateTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setFillTranslateTransition(options);
|
||||
assertEquals(layer.getFillTranslateTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -732,47 +282,12 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-translate");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(fillTranslate(new Float[] {0f, 0f}));
|
||||
assertEquals((Float[]) layer.getFillTranslate().getValue(), (Float[]) new Float[] {0f, 0f});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillTranslateAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-translate");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
fillTranslate(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, fillTranslate(new Float[] {0f, 0f}))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getFillTranslate());
|
||||
assertNotNull(layer.getFillTranslate().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getFillTranslate().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getFillTranslate().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getFillTranslate().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getFillTranslate().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(fillTranslate(new Float[] {0f, 0f}));
|
||||
assertEquals((Float[]) layer.getFillTranslate().getValue(), (Float[]) new Float[] {0f, 0f});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -781,46 +296,12 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-translate-anchor");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(fillTranslateAnchor(FILL_TRANSLATE_ANCHOR_MAP));
|
||||
assertEquals((String) layer.getFillTranslateAnchor().getValue(), (String) FILL_TRANSLATE_ANCHOR_MAP);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillTranslateAnchorAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-translate-anchor");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
fillTranslateAnchor(
|
||||
zoom(
|
||||
interval(
|
||||
stop(2, fillTranslateAnchor(FILL_TRANSLATE_ANCHOR_MAP))
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getFillTranslateAnchor());
|
||||
assertNotNull(layer.getFillTranslateAnchor().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getFillTranslateAnchor().getFunction().getClass());
|
||||
assertEquals(IntervalStops.class, layer.getFillTranslateAnchor().getFunction().getStops().getClass());
|
||||
assertEquals(1, ((IntervalStops) layer.getFillTranslateAnchor().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(fillTranslateAnchor(FILL_TRANSLATE_ANCHOR_MAP));
|
||||
assertEquals((String) layer.getFillTranslateAnchor().getValue(), (String) FILL_TRANSLATE_ANCHOR_MAP);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -829,16 +310,13 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-patternTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setFillPatternTransition(options);
|
||||
assertEquals(layer.getFillPatternTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setFillPatternTransition(options);
|
||||
assertEquals(layer.getFillPatternTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -847,47 +325,12 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-pattern");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(fillPattern("pedestrian-polygon"));
|
||||
assertEquals((String) layer.getFillPattern().getValue(), (String) "pedestrian-polygon");
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(fillPattern("pedestrian-polygon"));
|
||||
assertEquals((String) layer.getFillPattern().getValue(), (String) "pedestrian-polygon");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillPatternAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("fill-pattern");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
fillPattern(
|
||||
zoom(
|
||||
interval(
|
||||
stop(2, fillPattern("pedestrian-polygon"))
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getFillPattern());
|
||||
assertNotNull(layer.getFillPattern().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getFillPattern().getFunction().getClass());
|
||||
assertEquals(IntervalStops.class, layer.getFillPattern().getFunction().getStops().getClass());
|
||||
assertEquals(1, ((IntervalStops) layer.getFillPattern().getFunction().getStops()).size());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,31 +3,18 @@
|
||||
package com.mapbox.mapboxsdk.testapp.style;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.support.test.espresso.UiController;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.style.functions.CompositeFunction;
|
||||
import com.mapbox.mapboxsdk.style.functions.CameraFunction;
|
||||
import com.mapbox.mapboxsdk.style.functions.SourceFunction;
|
||||
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 com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.HeatmapLayer;
|
||||
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.functions.Function.*;
|
||||
import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop;
|
||||
import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.*;
|
||||
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
|
||||
import static org.junit.Assert.*;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Property.*;
|
||||
@@ -51,17 +38,14 @@ public class HeatmapLayerTest extends BaseActivityTest {
|
||||
|
||||
private void setupLayer() {
|
||||
Timber.i("Retrieving layer");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
|
||||
Timber.i("Adding layer");
|
||||
layer = new HeatmapLayer("my-layer", "composite");
|
||||
layer.setSourceLayer("composite");
|
||||
mapboxMap.addLayer(layer);
|
||||
// Layer reference is now stale, get new reference
|
||||
layer = mapboxMap.getLayerAs("my-layer");
|
||||
}
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
|
||||
Timber.i("Adding layer");
|
||||
layer = new HeatmapLayer("my-layer", "composite");
|
||||
layer.setSourceLayer("composite");
|
||||
mapboxMap.addLayer(layer);
|
||||
// Layer reference is now stale, get new reference
|
||||
layer = mapboxMap.getLayerAs("my-layer");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -71,18 +55,15 @@ public class HeatmapLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("Visibility");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Get initial
|
||||
assertEquals(layer.getVisibility().getValue(), VISIBLE);
|
||||
// Get initial
|
||||
assertEquals(layer.getVisibility().getValue(), VISIBLE);
|
||||
|
||||
// Set
|
||||
layer.setProperties(visibility(NONE));
|
||||
assertEquals(layer.getVisibility().getValue(), NONE);
|
||||
}
|
||||
// Set
|
||||
layer.setProperties(visibility(NONE));
|
||||
assertEquals(layer.getVisibility().getValue(), NONE);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -91,19 +72,16 @@ public class HeatmapLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("SourceLayer");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Get initial
|
||||
assertEquals(layer.getSourceLayer(), "composite");
|
||||
// Get initial
|
||||
assertEquals(layer.getSourceLayer(), "composite");
|
||||
|
||||
// Set
|
||||
final String sourceLayer = "test";
|
||||
layer.setSourceLayer(sourceLayer);
|
||||
assertEquals(layer.getSourceLayer(), sourceLayer);
|
||||
}
|
||||
// Set
|
||||
final String sourceLayer = "test";
|
||||
layer.setSourceLayer(sourceLayer);
|
||||
assertEquals(layer.getSourceLayer(), sourceLayer);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -112,16 +90,13 @@ public class HeatmapLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("heatmap-radiusTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setHeatmapRadiusTransition(options);
|
||||
assertEquals(layer.getHeatmapRadiusTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setHeatmapRadiusTransition(options);
|
||||
assertEquals(layer.getHeatmapRadiusTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -130,380 +105,73 @@ public class HeatmapLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("heatmap-radius");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(heatmapRadius(0.3f));
|
||||
assertEquals((Float) layer.getHeatmapRadius().getValue(), (Float) 0.3f);
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(heatmapRadius(0.3f));
|
||||
assertEquals((Float) layer.getHeatmapRadius().getValue(), (Float) 0.3f);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeatmapRadiusAsCameraFunction() {
|
||||
public void testHeatmapRadiusAsExpression() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("heatmap-radius");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
Timber.i("heatmap-radius-expression");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
heatmapRadius(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, heatmapRadius(0.3f))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getHeatmapRadius());
|
||||
assertNotNull(layer.getHeatmapRadius().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getHeatmapRadius().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getHeatmapRadius().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getHeatmapRadius().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getHeatmapRadius().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
Expression expression = number(Expression.get("undefined"));
|
||||
layer.setProperties(heatmapRadius(expression));
|
||||
assertEquals(layer.getHeatmapRadius().getExpression(), expression);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeatmapRadiusAsIdentitySourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("heatmap-radius");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
heatmapRadius(property("FeaturePropertyA", Stops.<Float>identity()))
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getHeatmapRadius());
|
||||
assertNotNull(layer.getHeatmapRadius().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.getHeatmapRadius().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.getHeatmapRadius().getFunction()).getProperty());
|
||||
assertEquals(IdentityStops.class, layer.getHeatmapRadius().getFunction().getStops().getClass());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeatmapRadiusAsExponentialSourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("heatmap-radius");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
heatmapRadius(
|
||||
property(
|
||||
"FeaturePropertyA",
|
||||
exponential(
|
||||
stop(0.3f, heatmapRadius(0.3f))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getHeatmapRadius());
|
||||
assertNotNull(layer.getHeatmapRadius().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.getHeatmapRadius().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.getHeatmapRadius().getFunction()).getProperty());
|
||||
assertEquals(ExponentialStops.class, layer.getHeatmapRadius().getFunction().getStops().getClass());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeatmapRadiusAsCategoricalSourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("heatmap-radius");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
heatmapRadius(
|
||||
property(
|
||||
"FeaturePropertyA",
|
||||
categorical(
|
||||
stop(1.0f, heatmapRadius(0.3f))
|
||||
)
|
||||
).withDefaultValue(heatmapRadius(0.3f))
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getHeatmapRadius());
|
||||
assertNotNull(layer.getHeatmapRadius().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.getHeatmapRadius().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.getHeatmapRadius().getFunction()).getProperty());
|
||||
assertEquals(CategoricalStops.class, layer.getHeatmapRadius().getFunction().getStops().getClass());
|
||||
assertNotNull(((SourceFunction) layer.getHeatmapRadius().getFunction()).getDefaultValue());
|
||||
assertNotNull(((SourceFunction) layer.getHeatmapRadius().getFunction()).getDefaultValue().getValue());
|
||||
assertEquals(0.3f, ((SourceFunction) layer.getHeatmapRadius().getFunction()).getDefaultValue().getValue());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeatmapRadiusAsCompositeFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("heatmap-radius");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
heatmapRadius(
|
||||
composite(
|
||||
"FeaturePropertyA",
|
||||
exponential(
|
||||
stop(0, 0.3f, heatmapRadius(0.9f))
|
||||
).withBase(0.5f)
|
||||
).withDefaultValue(heatmapRadius(0.3f))
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getHeatmapRadius());
|
||||
assertNotNull(layer.getHeatmapRadius().getFunction());
|
||||
assertEquals(CompositeFunction.class, layer.getHeatmapRadius().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getHeatmapRadius().getFunction()).getProperty());
|
||||
assertEquals(ExponentialStops.class, layer.getHeatmapRadius().getFunction().getStops().getClass());
|
||||
assertEquals(1, ((ExponentialStops) layer.getHeatmapRadius().getFunction().getStops()).size());
|
||||
|
||||
ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops =
|
||||
(ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getHeatmapRadius().getFunction().getStops();
|
||||
Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next();
|
||||
assertEquals(0f, stop.in.zoom, 0.001);
|
||||
assertEquals(0.3f, stop.in.value, 0.001f);
|
||||
assertEquals(0.9f, stop.out, 0.001f);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeatmapWeightAsConstant() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("heatmap-weight");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(heatmapWeight(0.3f));
|
||||
assertEquals((Float) layer.getHeatmapWeight().getValue(), (Float) 0.3f);
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(heatmapWeight(0.3f));
|
||||
assertEquals((Float) layer.getHeatmapWeight().getValue(), (Float) 0.3f);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeatmapWeightAsCameraFunction() {
|
||||
public void testHeatmapWeightAsExpression() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("heatmap-weight");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
Timber.i("heatmap-weight-expression");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
heatmapWeight(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, heatmapWeight(0.3f))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getHeatmapWeight());
|
||||
assertNotNull(layer.getHeatmapWeight().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getHeatmapWeight().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getHeatmapWeight().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getHeatmapWeight().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getHeatmapWeight().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
Expression expression = number(Expression.get("undefined"));
|
||||
layer.setProperties(heatmapWeight(expression));
|
||||
assertEquals(layer.getHeatmapWeight().getExpression(), expression);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeatmapWeightAsIdentitySourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("heatmap-weight");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
heatmapWeight(property("FeaturePropertyA", Stops.<Float>identity()))
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getHeatmapWeight());
|
||||
assertNotNull(layer.getHeatmapWeight().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.getHeatmapWeight().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.getHeatmapWeight().getFunction()).getProperty());
|
||||
assertEquals(IdentityStops.class, layer.getHeatmapWeight().getFunction().getStops().getClass());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeatmapWeightAsExponentialSourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("heatmap-weight");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
heatmapWeight(
|
||||
property(
|
||||
"FeaturePropertyA",
|
||||
exponential(
|
||||
stop(0.3f, heatmapWeight(0.3f))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getHeatmapWeight());
|
||||
assertNotNull(layer.getHeatmapWeight().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.getHeatmapWeight().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.getHeatmapWeight().getFunction()).getProperty());
|
||||
assertEquals(ExponentialStops.class, layer.getHeatmapWeight().getFunction().getStops().getClass());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeatmapWeightAsCategoricalSourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("heatmap-weight");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
heatmapWeight(
|
||||
property(
|
||||
"FeaturePropertyA",
|
||||
categorical(
|
||||
stop(1.0f, heatmapWeight(0.3f))
|
||||
)
|
||||
).withDefaultValue(heatmapWeight(0.3f))
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getHeatmapWeight());
|
||||
assertNotNull(layer.getHeatmapWeight().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.getHeatmapWeight().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.getHeatmapWeight().getFunction()).getProperty());
|
||||
assertEquals(CategoricalStops.class, layer.getHeatmapWeight().getFunction().getStops().getClass());
|
||||
assertNotNull(((SourceFunction) layer.getHeatmapWeight().getFunction()).getDefaultValue());
|
||||
assertNotNull(((SourceFunction) layer.getHeatmapWeight().getFunction()).getDefaultValue().getValue());
|
||||
assertEquals(0.3f, ((SourceFunction) layer.getHeatmapWeight().getFunction()).getDefaultValue().getValue());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeatmapWeightAsCompositeFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("heatmap-weight");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
heatmapWeight(
|
||||
composite(
|
||||
"FeaturePropertyA",
|
||||
exponential(
|
||||
stop(0, 0.3f, heatmapWeight(0.9f))
|
||||
).withBase(0.5f)
|
||||
).withDefaultValue(heatmapWeight(0.3f))
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getHeatmapWeight());
|
||||
assertNotNull(layer.getHeatmapWeight().getFunction());
|
||||
assertEquals(CompositeFunction.class, layer.getHeatmapWeight().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getHeatmapWeight().getFunction()).getProperty());
|
||||
assertEquals(ExponentialStops.class, layer.getHeatmapWeight().getFunction().getStops().getClass());
|
||||
assertEquals(1, ((ExponentialStops) layer.getHeatmapWeight().getFunction().getStops()).size());
|
||||
|
||||
ExponentialStops<Stop.CompositeValue<Float, Float>, Float> stops =
|
||||
(ExponentialStops<Stop.CompositeValue<Float, Float>, Float>) layer.getHeatmapWeight().getFunction().getStops();
|
||||
Stop<Stop.CompositeValue<Float, Float>, Float> stop = stops.iterator().next();
|
||||
assertEquals(0f, stop.in.zoom, 0.001);
|
||||
assertEquals(0.3f, stop.in.value, 0.001f);
|
||||
assertEquals(0.9f, stop.out, 0.001f);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeatmapIntensityTransition() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("heatmap-intensityTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setHeatmapIntensityTransition(options);
|
||||
assertEquals(layer.getHeatmapIntensityTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setHeatmapIntensityTransition(options);
|
||||
assertEquals(layer.getHeatmapIntensityTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -512,47 +180,12 @@ public class HeatmapLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("heatmap-intensity");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(heatmapIntensity(0.3f));
|
||||
assertEquals((Float) layer.getHeatmapIntensity().getValue(), (Float) 0.3f);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeatmapIntensityAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("heatmap-intensity");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
heatmapIntensity(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, heatmapIntensity(0.3f))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getHeatmapIntensity());
|
||||
assertNotNull(layer.getHeatmapIntensity().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getHeatmapIntensity().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getHeatmapIntensity().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getHeatmapIntensity().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getHeatmapIntensity().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(heatmapIntensity(0.3f));
|
||||
assertEquals((Float) layer.getHeatmapIntensity().getValue(), (Float) 0.3f);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -561,16 +194,13 @@ public class HeatmapLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("heatmap-opacityTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setHeatmapOpacityTransition(options);
|
||||
assertEquals(layer.getHeatmapOpacityTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setHeatmapOpacityTransition(options);
|
||||
assertEquals(layer.getHeatmapOpacityTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -579,48 +209,12 @@ public class HeatmapLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("heatmap-opacity");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(heatmapOpacity(0.3f));
|
||||
assertEquals((Float) layer.getHeatmapOpacity().getValue(), (Float) 0.3f);
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(heatmapOpacity(0.3f));
|
||||
assertEquals((Float) layer.getHeatmapOpacity().getValue(), (Float) 0.3f);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeatmapOpacityAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("heatmap-opacity");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
heatmapOpacity(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, heatmapOpacity(0.3f))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getHeatmapOpacity());
|
||||
assertNotNull(layer.getHeatmapOpacity().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getHeatmapOpacity().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getHeatmapOpacity().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getHeatmapOpacity().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getHeatmapOpacity().getFunction().getStops()).size());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,31 +3,18 @@
|
||||
package com.mapbox.mapboxsdk.testapp.style;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.support.test.espresso.UiController;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.style.functions.CompositeFunction;
|
||||
import com.mapbox.mapboxsdk.style.functions.CameraFunction;
|
||||
import com.mapbox.mapboxsdk.style.functions.SourceFunction;
|
||||
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 com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.HillshadeLayer;
|
||||
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.functions.Function.*;
|
||||
import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop;
|
||||
import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.*;
|
||||
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
|
||||
import static org.junit.Assert.*;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Property.*;
|
||||
@@ -51,17 +38,14 @@ public class HillshadeLayerTest extends BaseActivityTest {
|
||||
|
||||
private void setupLayer() {
|
||||
Timber.i("Retrieving layer");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
|
||||
Timber.i("Adding layer");
|
||||
layer = new HillshadeLayer("my-layer", "composite");
|
||||
layer.setSourceLayer("composite");
|
||||
mapboxMap.addLayer(layer);
|
||||
// Layer reference is now stale, get new reference
|
||||
layer = mapboxMap.getLayerAs("my-layer");
|
||||
}
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
|
||||
Timber.i("Adding layer");
|
||||
layer = new HillshadeLayer("my-layer", "composite");
|
||||
layer.setSourceLayer("composite");
|
||||
mapboxMap.addLayer(layer);
|
||||
// Layer reference is now stale, get new reference
|
||||
layer = mapboxMap.getLayerAs("my-layer");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -71,18 +55,15 @@ public class HillshadeLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("Visibility");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Get initial
|
||||
assertEquals(layer.getVisibility().getValue(), VISIBLE);
|
||||
// Get initial
|
||||
assertEquals(layer.getVisibility().getValue(), VISIBLE);
|
||||
|
||||
// Set
|
||||
layer.setProperties(visibility(NONE));
|
||||
assertEquals(layer.getVisibility().getValue(), NONE);
|
||||
}
|
||||
// Set
|
||||
layer.setProperties(visibility(NONE));
|
||||
assertEquals(layer.getVisibility().getValue(), NONE);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -91,47 +72,12 @@ public class HillshadeLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("hillshade-illumination-direction");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(hillshadeIlluminationDirection(0.3f));
|
||||
assertEquals((Float) layer.getHillshadeIlluminationDirection().getValue(), (Float) 0.3f);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHillshadeIlluminationDirectionAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("hillshade-illumination-direction");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
hillshadeIlluminationDirection(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, hillshadeIlluminationDirection(0.3f))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getHillshadeIlluminationDirection());
|
||||
assertNotNull(layer.getHillshadeIlluminationDirection().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getHillshadeIlluminationDirection().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getHillshadeIlluminationDirection().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getHillshadeIlluminationDirection().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getHillshadeIlluminationDirection().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(hillshadeIlluminationDirection(0.3f));
|
||||
assertEquals((Float) layer.getHillshadeIlluminationDirection().getValue(), (Float) 0.3f);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -140,46 +86,12 @@ public class HillshadeLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("hillshade-illumination-anchor");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(hillshadeIlluminationAnchor(HILLSHADE_ILLUMINATION_ANCHOR_MAP));
|
||||
assertEquals((String) layer.getHillshadeIlluminationAnchor().getValue(), (String) HILLSHADE_ILLUMINATION_ANCHOR_MAP);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHillshadeIlluminationAnchorAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("hillshade-illumination-anchor");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
hillshadeIlluminationAnchor(
|
||||
zoom(
|
||||
interval(
|
||||
stop(2, hillshadeIlluminationAnchor(HILLSHADE_ILLUMINATION_ANCHOR_MAP))
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getHillshadeIlluminationAnchor());
|
||||
assertNotNull(layer.getHillshadeIlluminationAnchor().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getHillshadeIlluminationAnchor().getFunction().getClass());
|
||||
assertEquals(IntervalStops.class, layer.getHillshadeIlluminationAnchor().getFunction().getStops().getClass());
|
||||
assertEquals(1, ((IntervalStops) layer.getHillshadeIlluminationAnchor().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(hillshadeIlluminationAnchor(HILLSHADE_ILLUMINATION_ANCHOR_MAP));
|
||||
assertEquals((String) layer.getHillshadeIlluminationAnchor().getValue(), (String) HILLSHADE_ILLUMINATION_ANCHOR_MAP);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -188,16 +100,13 @@ public class HillshadeLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("hillshade-exaggerationTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setHillshadeExaggerationTransition(options);
|
||||
assertEquals(layer.getHillshadeExaggerationTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setHillshadeExaggerationTransition(options);
|
||||
assertEquals(layer.getHillshadeExaggerationTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -206,47 +115,12 @@ public class HillshadeLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("hillshade-exaggeration");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(hillshadeExaggeration(0.3f));
|
||||
assertEquals((Float) layer.getHillshadeExaggeration().getValue(), (Float) 0.3f);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHillshadeExaggerationAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("hillshade-exaggeration");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
hillshadeExaggeration(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, hillshadeExaggeration(0.3f))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getHillshadeExaggeration());
|
||||
assertNotNull(layer.getHillshadeExaggeration().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getHillshadeExaggeration().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getHillshadeExaggeration().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getHillshadeExaggeration().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getHillshadeExaggeration().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(hillshadeExaggeration(0.3f));
|
||||
assertEquals((Float) layer.getHillshadeExaggeration().getValue(), (Float) 0.3f);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -255,16 +129,13 @@ public class HillshadeLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("hillshade-shadow-colorTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setHillshadeShadowColorTransition(options);
|
||||
assertEquals(layer.getHillshadeShadowColorTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setHillshadeShadowColorTransition(options);
|
||||
assertEquals(layer.getHillshadeShadowColorTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -273,47 +144,12 @@ public class HillshadeLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("hillshade-shadow-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(hillshadeShadowColor("rgba(0, 0, 0, 1)"));
|
||||
assertEquals((String) layer.getHillshadeShadowColor().getValue(), (String) "rgba(0, 0, 0, 1)");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHillshadeShadowColorAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("hillshade-shadow-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
hillshadeShadowColor(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, hillshadeShadowColor("rgba(0, 0, 0, 1)"))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getHillshadeShadowColor());
|
||||
assertNotNull(layer.getHillshadeShadowColor().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getHillshadeShadowColor().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getHillshadeShadowColor().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getHillshadeShadowColor().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getHillshadeShadowColor().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(hillshadeShadowColor("rgba(0, 0, 0, 1)"));
|
||||
assertEquals((String) layer.getHillshadeShadowColor().getValue(), (String) "rgba(0, 0, 0, 1)");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -322,15 +158,12 @@ public class HillshadeLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("hillshade-shadow-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(hillshadeShadowColor(Color.RED));
|
||||
assertEquals(layer.getHillshadeShadowColorAsInt(), Color.RED);
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(hillshadeShadowColor(Color.RED));
|
||||
assertEquals(layer.getHillshadeShadowColorAsInt(), Color.RED);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -339,16 +172,13 @@ public class HillshadeLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("hillshade-highlight-colorTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setHillshadeHighlightColorTransition(options);
|
||||
assertEquals(layer.getHillshadeHighlightColorTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setHillshadeHighlightColorTransition(options);
|
||||
assertEquals(layer.getHillshadeHighlightColorTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -357,47 +187,12 @@ public class HillshadeLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("hillshade-highlight-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(hillshadeHighlightColor("rgba(0, 0, 0, 1)"));
|
||||
assertEquals((String) layer.getHillshadeHighlightColor().getValue(), (String) "rgba(0, 0, 0, 1)");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHillshadeHighlightColorAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("hillshade-highlight-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
hillshadeHighlightColor(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, hillshadeHighlightColor("rgba(0, 0, 0, 1)"))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getHillshadeHighlightColor());
|
||||
assertNotNull(layer.getHillshadeHighlightColor().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getHillshadeHighlightColor().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getHillshadeHighlightColor().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getHillshadeHighlightColor().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getHillshadeHighlightColor().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(hillshadeHighlightColor("rgba(0, 0, 0, 1)"));
|
||||
assertEquals((String) layer.getHillshadeHighlightColor().getValue(), (String) "rgba(0, 0, 0, 1)");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -406,15 +201,12 @@ public class HillshadeLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("hillshade-highlight-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(hillshadeHighlightColor(Color.RED));
|
||||
assertEquals(layer.getHillshadeHighlightColorAsInt(), Color.RED);
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(hillshadeHighlightColor(Color.RED));
|
||||
assertEquals(layer.getHillshadeHighlightColorAsInt(), Color.RED);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -423,16 +215,13 @@ public class HillshadeLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("hillshade-accent-colorTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setHillshadeAccentColorTransition(options);
|
||||
assertEquals(layer.getHillshadeAccentColorTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setHillshadeAccentColorTransition(options);
|
||||
assertEquals(layer.getHillshadeAccentColorTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -441,47 +230,12 @@ public class HillshadeLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("hillshade-accent-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(hillshadeAccentColor("rgba(0, 0, 0, 1)"));
|
||||
assertEquals((String) layer.getHillshadeAccentColor().getValue(), (String) "rgba(0, 0, 0, 1)");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHillshadeAccentColorAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("hillshade-accent-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
hillshadeAccentColor(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, hillshadeAccentColor("rgba(0, 0, 0, 1)"))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getHillshadeAccentColor());
|
||||
assertNotNull(layer.getHillshadeAccentColor().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getHillshadeAccentColor().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getHillshadeAccentColor().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getHillshadeAccentColor().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getHillshadeAccentColor().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(hillshadeAccentColor("rgba(0, 0, 0, 1)"));
|
||||
assertEquals((String) layer.getHillshadeAccentColor().getValue(), (String) "rgba(0, 0, 0, 1)");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -490,16 +244,12 @@ public class HillshadeLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("hillshade-accent-color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(hillshadeAccentColor(Color.RED));
|
||||
assertEquals(layer.getHillshadeAccentColorAsInt(), Color.RED);
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(hillshadeAccentColor(Color.RED));
|
||||
assertEquals(layer.getHillshadeAccentColorAsInt(), Color.RED);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,15 +6,12 @@ import android.support.test.espresso.ViewAction;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.style.light.Light;
|
||||
import com.mapbox.mapboxsdk.style.functions.Function;
|
||||
import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.FillExtrusionLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
|
||||
import com.mapbox.mapboxsdk.style.light.Position;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.style.FillExtrusionStyleTestActivity;
|
||||
|
||||
@@ -48,14 +45,11 @@ public class LightTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLight();
|
||||
Timber.i("anchor");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
light.setAnchor(ANCHOR_MAP);
|
||||
assertEquals("Anchor should match", ANCHOR_MAP, light.getAnchor());
|
||||
}
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
light.setAnchor(ANCHOR_MAP);
|
||||
assertEquals("Anchor should match", ANCHOR_MAP, light.getAnchor());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -64,15 +58,12 @@ public class LightTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLight();
|
||||
Timber.i("positionTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
light.setPositionTransition(options);
|
||||
assertEquals("Transition options should match", options, light.getPositionTransition());
|
||||
}
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
light.setPositionTransition(options);
|
||||
assertEquals("Transition options should match", options, light.getPositionTransition());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -81,15 +72,12 @@ public class LightTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLight();
|
||||
Timber.i("position");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
Position position = new Position(1, 2, 3);
|
||||
light.setPosition(position);
|
||||
assertEquals("Position should match", position, light.getPosition());
|
||||
}
|
||||
invoke(mapboxMap,(uiController, mapboxMap) -> {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
Position position = new Position(1, 2, 3);
|
||||
light.setPosition(position);
|
||||
assertEquals("Position should match", position, light.getPosition());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -98,15 +86,12 @@ public class LightTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLight();
|
||||
Timber.i("colorTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
light.setColorTransition(options);
|
||||
assertEquals("Transition options should match", options, light.getColorTransition());
|
||||
}
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
light.setColorTransition(options);
|
||||
assertEquals("Transition options should match", options, light.getColorTransition());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -115,14 +100,11 @@ public class LightTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLight();
|
||||
Timber.i("color");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
light.setColor("rgba(0, 0, 0, 1)");
|
||||
assertEquals("Color should match", "rgba(0, 0, 0, 1)".replaceAll("\\s+", ""), light.getColor());
|
||||
}
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
light.setColor("rgba(0, 0, 0, 1)");
|
||||
assertEquals("Color should match", "rgba(0, 0, 0, 1)".replaceAll("\\s+", ""), light.getColor());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -131,15 +113,12 @@ public class LightTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLight();
|
||||
Timber.i("intensityTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
light.setIntensityTransition(options);
|
||||
assertEquals("Transition options should match", options, light.getIntensityTransition());
|
||||
}
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
light.setIntensityTransition(options);
|
||||
assertEquals("Transition options should match", options, light.getIntensityTransition());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -148,14 +127,11 @@ public class LightTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLight();
|
||||
Timber.i("intensity");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
light.setIntensity(0.3f);
|
||||
assertEquals("Intensity should match", 0.3f, light.getIntensity());
|
||||
}
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
light.setIntensity(0.3f);
|
||||
assertEquals("Intensity should match", 0.3f, light.getIntensity());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -180,8 +156,8 @@ public class LightTest extends BaseActivityTest {
|
||||
fillExtrusionLayer.setMinZoom(15);
|
||||
fillExtrusionLayer.setProperties(
|
||||
fillExtrusionColor(Color.LTGRAY),
|
||||
fillExtrusionHeight(Function.property("height", new IdentityStops<Float>())),
|
||||
fillExtrusionBase(Function.property("min_height", new IdentityStops<Float>())),
|
||||
fillExtrusionHeight(Expression.get("height")),
|
||||
fillExtrusionBase(Expression.get("min_height")),
|
||||
fillExtrusionOpacity(0.6f)
|
||||
);
|
||||
mapboxMap.addLayer(fillExtrusionLayer);
|
||||
@@ -193,4 +169,4 @@ public class LightTest extends BaseActivityTest {
|
||||
protected Class getActivityClass() {
|
||||
return FillExtrusionStyleTestActivity.class;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,31 +3,18 @@
|
||||
package com.mapbox.mapboxsdk.testapp.style;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.support.test.espresso.UiController;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.style.functions.CompositeFunction;
|
||||
import com.mapbox.mapboxsdk.style.functions.CameraFunction;
|
||||
import com.mapbox.mapboxsdk.style.functions.SourceFunction;
|
||||
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 com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.RasterLayer;
|
||||
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.functions.Function.*;
|
||||
import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop;
|
||||
import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.*;
|
||||
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
|
||||
import static org.junit.Assert.*;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Property.*;
|
||||
@@ -51,17 +38,14 @@ public class RasterLayerTest extends BaseActivityTest {
|
||||
|
||||
private void setupLayer() {
|
||||
Timber.i("Retrieving layer");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
|
||||
Timber.i("Adding layer");
|
||||
layer = new RasterLayer("my-layer", "composite");
|
||||
layer.setSourceLayer("composite");
|
||||
mapboxMap.addLayer(layer);
|
||||
// Layer reference is now stale, get new reference
|
||||
layer = mapboxMap.getLayerAs("my-layer");
|
||||
}
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
|
||||
Timber.i("Adding layer");
|
||||
layer = new RasterLayer("my-layer", "composite");
|
||||
layer.setSourceLayer("composite");
|
||||
mapboxMap.addLayer(layer);
|
||||
// Layer reference is now stale, get new reference
|
||||
layer = mapboxMap.getLayerAs("my-layer");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -71,18 +55,15 @@ public class RasterLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("Visibility");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Get initial
|
||||
assertEquals(layer.getVisibility().getValue(), VISIBLE);
|
||||
// Get initial
|
||||
assertEquals(layer.getVisibility().getValue(), VISIBLE);
|
||||
|
||||
// Set
|
||||
layer.setProperties(visibility(NONE));
|
||||
assertEquals(layer.getVisibility().getValue(), NONE);
|
||||
}
|
||||
// Set
|
||||
layer.setProperties(visibility(NONE));
|
||||
assertEquals(layer.getVisibility().getValue(), NONE);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -91,16 +72,13 @@ public class RasterLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-opacityTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setRasterOpacityTransition(options);
|
||||
assertEquals(layer.getRasterOpacityTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setRasterOpacityTransition(options);
|
||||
assertEquals(layer.getRasterOpacityTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -109,47 +87,12 @@ public class RasterLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-opacity");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(rasterOpacity(0.3f));
|
||||
assertEquals((Float) layer.getRasterOpacity().getValue(), (Float) 0.3f);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRasterOpacityAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-opacity");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
rasterOpacity(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, rasterOpacity(0.3f))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getRasterOpacity());
|
||||
assertNotNull(layer.getRasterOpacity().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getRasterOpacity().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getRasterOpacity().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getRasterOpacity().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getRasterOpacity().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(rasterOpacity(0.3f));
|
||||
assertEquals((Float) layer.getRasterOpacity().getValue(), (Float) 0.3f);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -158,16 +101,13 @@ public class RasterLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-hue-rotateTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setRasterHueRotateTransition(options);
|
||||
assertEquals(layer.getRasterHueRotateTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setRasterHueRotateTransition(options);
|
||||
assertEquals(layer.getRasterHueRotateTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -176,47 +116,12 @@ public class RasterLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-hue-rotate");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(rasterHueRotate(0.3f));
|
||||
assertEquals((Float) layer.getRasterHueRotate().getValue(), (Float) 0.3f);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRasterHueRotateAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-hue-rotate");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
rasterHueRotate(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, rasterHueRotate(0.3f))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getRasterHueRotate());
|
||||
assertNotNull(layer.getRasterHueRotate().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getRasterHueRotate().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getRasterHueRotate().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getRasterHueRotate().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getRasterHueRotate().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(rasterHueRotate(0.3f));
|
||||
assertEquals((Float) layer.getRasterHueRotate().getValue(), (Float) 0.3f);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -225,16 +130,13 @@ public class RasterLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-brightness-minTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setRasterBrightnessMinTransition(options);
|
||||
assertEquals(layer.getRasterBrightnessMinTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setRasterBrightnessMinTransition(options);
|
||||
assertEquals(layer.getRasterBrightnessMinTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -243,47 +145,12 @@ public class RasterLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-brightness-min");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(rasterBrightnessMin(0.3f));
|
||||
assertEquals((Float) layer.getRasterBrightnessMin().getValue(), (Float) 0.3f);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRasterBrightnessMinAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-brightness-min");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
rasterBrightnessMin(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, rasterBrightnessMin(0.3f))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getRasterBrightnessMin());
|
||||
assertNotNull(layer.getRasterBrightnessMin().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getRasterBrightnessMin().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getRasterBrightnessMin().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getRasterBrightnessMin().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getRasterBrightnessMin().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(rasterBrightnessMin(0.3f));
|
||||
assertEquals((Float) layer.getRasterBrightnessMin().getValue(), (Float) 0.3f);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -292,16 +159,13 @@ public class RasterLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-brightness-maxTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setRasterBrightnessMaxTransition(options);
|
||||
assertEquals(layer.getRasterBrightnessMaxTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setRasterBrightnessMaxTransition(options);
|
||||
assertEquals(layer.getRasterBrightnessMaxTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -310,47 +174,12 @@ public class RasterLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-brightness-max");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(rasterBrightnessMax(0.3f));
|
||||
assertEquals((Float) layer.getRasterBrightnessMax().getValue(), (Float) 0.3f);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRasterBrightnessMaxAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-brightness-max");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
rasterBrightnessMax(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, rasterBrightnessMax(0.3f))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getRasterBrightnessMax());
|
||||
assertNotNull(layer.getRasterBrightnessMax().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getRasterBrightnessMax().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getRasterBrightnessMax().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getRasterBrightnessMax().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getRasterBrightnessMax().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(rasterBrightnessMax(0.3f));
|
||||
assertEquals((Float) layer.getRasterBrightnessMax().getValue(), (Float) 0.3f);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -359,16 +188,13 @@ public class RasterLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-saturationTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setRasterSaturationTransition(options);
|
||||
assertEquals(layer.getRasterSaturationTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setRasterSaturationTransition(options);
|
||||
assertEquals(layer.getRasterSaturationTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -377,47 +203,12 @@ public class RasterLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-saturation");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(rasterSaturation(0.3f));
|
||||
assertEquals((Float) layer.getRasterSaturation().getValue(), (Float) 0.3f);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRasterSaturationAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-saturation");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
rasterSaturation(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, rasterSaturation(0.3f))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getRasterSaturation());
|
||||
assertNotNull(layer.getRasterSaturation().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getRasterSaturation().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getRasterSaturation().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getRasterSaturation().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getRasterSaturation().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(rasterSaturation(0.3f));
|
||||
assertEquals((Float) layer.getRasterSaturation().getValue(), (Float) 0.3f);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -426,16 +217,13 @@ public class RasterLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-contrastTransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setRasterContrastTransition(options);
|
||||
assertEquals(layer.getRasterContrastTransition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.setRasterContrastTransition(options);
|
||||
assertEquals(layer.getRasterContrastTransition(), options);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -444,47 +232,12 @@ public class RasterLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-contrast");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(rasterContrast(0.3f));
|
||||
assertEquals((Float) layer.getRasterContrast().getValue(), (Float) 0.3f);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRasterContrastAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-contrast");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
rasterContrast(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, rasterContrast(0.3f))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getRasterContrast());
|
||||
assertNotNull(layer.getRasterContrast().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getRasterContrast().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getRasterContrast().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getRasterContrast().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getRasterContrast().getFunction().getStops()).size());
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(rasterContrast(0.3f));
|
||||
assertEquals((Float) layer.getRasterContrast().getValue(), (Float) 0.3f);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -493,48 +246,12 @@ public class RasterLayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-fade-duration");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(rasterFadeDuration(0.3f));
|
||||
assertEquals((Float) layer.getRasterFadeDuration().getValue(), (Float) 0.3f);
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(rasterFadeDuration(0.3f));
|
||||
assertEquals((Float) layer.getRasterFadeDuration().getValue(), (Float) 0.3f);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRasterFadeDurationAsCameraFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("raster-fade-duration");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
rasterFadeDuration(
|
||||
zoom(
|
||||
exponential(
|
||||
stop(2, rasterFadeDuration(0.3f))
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.getRasterFadeDuration());
|
||||
assertNotNull(layer.getRasterFadeDuration().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.getRasterFadeDuration().getFunction().getClass());
|
||||
assertEquals(ExponentialStops.class, layer.getRasterFadeDuration().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.getRasterFadeDuration().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.getRasterFadeDuration().getFunction().getStops()).size());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,31 +7,18 @@
|
||||
package com.mapbox.mapboxsdk.testapp.style;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.support.test.espresso.UiController;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.style.functions.CompositeFunction;
|
||||
import com.mapbox.mapboxsdk.style.functions.CameraFunction;
|
||||
import com.mapbox.mapboxsdk.style.functions.SourceFunction;
|
||||
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 com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.<%- camelize(type) %>Layer;
|
||||
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.functions.Function.*;
|
||||
import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop;
|
||||
import static com.mapbox.mapboxsdk.style.functions.stops.Stops.*;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.*;
|
||||
import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
|
||||
import static org.junit.Assert.*;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Property.*;
|
||||
@@ -56,25 +43,19 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest {
|
||||
private void setupLayer() {
|
||||
<% if (type === 'background') { -%>
|
||||
Timber.i("Retrieving layer");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
layer = mapboxMap.getLayerAs("background");
|
||||
}
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
layer = mapboxMap.getLayerAs("background");
|
||||
});
|
||||
<% } else { -%>
|
||||
Timber.i("Retrieving layer");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
|
||||
Timber.i("Adding layer");
|
||||
layer = new <%- camelize(type) %>Layer("my-layer", "composite");
|
||||
layer.setSourceLayer("composite");
|
||||
mapboxMap.addLayer(layer);
|
||||
// Layer reference is now stale, get new reference
|
||||
layer = mapboxMap.getLayerAs("my-layer");
|
||||
}
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
|
||||
Timber.i("Adding layer");
|
||||
layer = new <%- camelize(type) %>Layer("my-layer", "composite");
|
||||
layer.setSourceLayer("composite");
|
||||
mapboxMap.addLayer(layer);
|
||||
// Layer reference is now stale, get new reference
|
||||
layer = mapboxMap.getLayerAs("my-layer");
|
||||
}
|
||||
});
|
||||
<% } -%>
|
||||
@@ -85,18 +66,15 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("Visibility");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Get initial
|
||||
assertEquals(layer.getVisibility().getValue(), VISIBLE);
|
||||
// Get initial
|
||||
assertEquals(layer.getVisibility().getValue(), VISIBLE);
|
||||
|
||||
// Set
|
||||
layer.setProperties(visibility(NONE));
|
||||
assertEquals(layer.getVisibility().getValue(), NONE);
|
||||
}
|
||||
// Set
|
||||
layer.setProperties(visibility(NONE));
|
||||
assertEquals(layer.getVisibility().getValue(), NONE);
|
||||
});
|
||||
}
|
||||
<% if (!(type === 'background' || type === 'raster' || type === 'hillshade')) { -%>
|
||||
@@ -106,19 +84,16 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("SourceLayer");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Get initial
|
||||
assertEquals(layer.getSourceLayer(), "composite");
|
||||
// Get initial
|
||||
assertEquals(layer.getSourceLayer(), "composite");
|
||||
|
||||
// Set
|
||||
final String sourceLayer = "test";
|
||||
layer.setSourceLayer(sourceLayer);
|
||||
assertEquals(layer.getSourceLayer(), sourceLayer);
|
||||
}
|
||||
// Set
|
||||
final String sourceLayer = "test";
|
||||
layer.setSourceLayer(sourceLayer);
|
||||
assertEquals(layer.getSourceLayer(), sourceLayer);
|
||||
});
|
||||
}
|
||||
<% } -%>
|
||||
@@ -131,16 +106,13 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("<%- property.name %>TransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.set<%- camelize(property.name) %>Transition(options);
|
||||
assertEquals(layer.get<%- camelize(property.name) %>Transition(), options);
|
||||
}
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
layer.set<%- camelize(property.name) %>Transition(options);
|
||||
assertEquals(layer.get<%- camelize(property.name) %>Transition(), options);
|
||||
});
|
||||
}
|
||||
<% } -%>
|
||||
@@ -150,291 +122,32 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("<%- property.name %>");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>));
|
||||
assertEquals((<%- propertyType(property) %>) layer.get<%- camelize(property.name) %>().getValue(), (<%- propertyType(property) %>) <%- defaultValueJava(property) %>);
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>));
|
||||
assertEquals((<%- propertyType(property) %>) layer.get<%- camelize(property.name) %>().getValue(), (<%- propertyType(property) %>) <%- defaultValueJava(property) %>);
|
||||
});
|
||||
}
|
||||
<% if (supportsZoomFunction(property)) { -%>
|
||||
<% if (isDataDriven(property)) { -%>
|
||||
<% if (!(property.name.endsWith("-font")||property.name.endsWith("-offset"))) { -%>
|
||||
|
||||
@Test
|
||||
public void test<%- camelize(property.name) %>AsCameraFunction() {
|
||||
public void test<%- camelize(property.name) %>AsExpression() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("<%- property.name %>");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
Timber.i("<%- property.name %>-expression");
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
<%- camelizeWithLeadingLowercase(property.name) %>(
|
||||
zoom(
|
||||
<% if (property.function == 'piecewise-constant') { -%>
|
||||
interval(
|
||||
stop(2, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>))
|
||||
)
|
||||
<% } else { -%>
|
||||
exponential(
|
||||
stop(2, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>))
|
||||
).withBase(0.5f)
|
||||
<% } -%>
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.get<%- camelize(property.name) %>());
|
||||
assertNotNull(layer.get<%- camelize(property.name) %>().getFunction());
|
||||
assertEquals(CameraFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass());
|
||||
<% if (property.function == 'piecewise-constant') { -%>
|
||||
assertEquals(IntervalStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass());
|
||||
assertEquals(1, ((IntervalStops) layer.get<%- camelize(property.name) %>().getFunction().getStops()).size());
|
||||
<% } else { -%>
|
||||
assertEquals(ExponentialStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass());
|
||||
assertEquals(0.5f, ((ExponentialStops) layer.get<%- camelize(property.name) %>().getFunction().getStops()).getBase(), 0.001);
|
||||
assertEquals(1, ((ExponentialStops) layer.get<%- camelize(property.name) %>().getFunction().getStops()).size());
|
||||
<% } -%>
|
||||
}
|
||||
});
|
||||
}
|
||||
<% } -%>
|
||||
<% if (supportsPropertyFunction(property)) { -%>
|
||||
|
||||
@Test
|
||||
public void test<%- camelize(property.name) %>AsIdentitySourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("<%- property.name %>");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
<%- camelizeWithLeadingLowercase(property.name) %>(property("FeaturePropertyA", Stops.<<%- propertyType(property) %>>identity()))
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.get<%- camelize(property.name) %>());
|
||||
assertNotNull(layer.get<%- camelize(property.name) %>().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getProperty());
|
||||
assertEquals(IdentityStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass());
|
||||
}
|
||||
});
|
||||
}
|
||||
<% if (property.function == 'piecewise-constant') { -%>
|
||||
|
||||
@Test
|
||||
public void test<%- camelize(property.name) %>AsIntervalSourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("<%- property.name %>");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
<%- camelizeWithLeadingLowercase(property.name) %>(
|
||||
property(
|
||||
"FeaturePropertyA",
|
||||
interval(
|
||||
<% if (property.type == 'color') { -%>
|
||||
stop(Color.RED, <%- camelizeWithLeadingLowercase(property.name) %>(Color.RED))
|
||||
<% } else {-%>
|
||||
stop(1, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>))
|
||||
)
|
||||
<% } -%>
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.get<%- camelize(property.name) %>());
|
||||
assertNotNull(layer.get<%- camelize(property.name) %>().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getProperty());
|
||||
assertEquals(IntervalStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass());
|
||||
}
|
||||
});
|
||||
}
|
||||
<% } else if (property.type === 'array') { -%>
|
||||
|
||||
@Test
|
||||
public void test<%- camelize(property.name) %>AsIntervalSourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("<%- property.name %>");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
<%- camelizeWithLeadingLowercase(property.name) %>(
|
||||
property(
|
||||
"FeaturePropertyA",
|
||||
interval(
|
||||
<% if (property.type == 'color') { -%>
|
||||
stop(Color.RED, <%- camelizeWithLeadingLowercase(property.name) %>(Color.RED))
|
||||
<% } else {-%>
|
||||
stop(1, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>))
|
||||
<% } -%>
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.get<%- camelize(property.name) %>());
|
||||
assertNotNull(layer.get<%- camelize(property.name) %>().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getProperty());
|
||||
assertEquals(IntervalStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass());
|
||||
}
|
||||
});
|
||||
}
|
||||
<% } else { -%>
|
||||
|
||||
@Test
|
||||
public void test<%- camelize(property.name) %>AsExponentialSourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("<%- property.name %>");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
<%- camelizeWithLeadingLowercase(property.name) %>(
|
||||
property(
|
||||
"FeaturePropertyA",
|
||||
exponential(
|
||||
<% if (property.type == 'color') { -%>
|
||||
stop(Color.RED, <%- camelizeWithLeadingLowercase(property.name) %>(Color.RED))
|
||||
<% } else {-%>
|
||||
stop(<%- defaultValueJava(property) %>, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>))
|
||||
<% } -%>
|
||||
).withBase(0.5f)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.get<%- camelize(property.name) %>());
|
||||
assertNotNull(layer.get<%- camelize(property.name) %>().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getProperty());
|
||||
assertEquals(ExponentialStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass());
|
||||
}
|
||||
// Set and Get
|
||||
Expression expression = <%- defaultExpressionJava(property) %>(Expression.get("undefined"));
|
||||
layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(expression));
|
||||
assertEquals(layer.get<%- camelize(property.name) %>().getExpression(), expression);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test<%- camelize(property.name) %>AsCategoricalSourceFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("<%- property.name %>");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
<%- camelizeWithLeadingLowercase(property.name) %>(
|
||||
property(
|
||||
"FeaturePropertyA",
|
||||
categorical(
|
||||
<% if (property.type == 'color') { -%>
|
||||
stop("valueA", <%- camelizeWithLeadingLowercase(property.name) %>(Color.RED))
|
||||
)
|
||||
).withDefaultValue(<%- camelizeWithLeadingLowercase(property.name) %>(Color.GREEN))
|
||||
<% } else {-%>
|
||||
stop(1.0f, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>))
|
||||
)
|
||||
).withDefaultValue(<%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>))
|
||||
<% } -%>
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.get<%- camelize(property.name) %>());
|
||||
assertNotNull(layer.get<%- camelize(property.name) %>().getFunction());
|
||||
assertEquals(SourceFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getProperty());
|
||||
assertEquals(CategoricalStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass());
|
||||
assertNotNull(((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getDefaultValue());
|
||||
assertNotNull(((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getDefaultValue().getValue());
|
||||
<% if (property.type === 'color') { -%>
|
||||
assertEquals(Color.GREEN, (int) ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getDefaultValue().getColorInt());
|
||||
<% } else { -%>
|
||||
assertEquals(<%- defaultValueJava(property) %>, ((SourceFunction) layer.get<%- camelize(property.name) %>().getFunction()).getDefaultValue().getValue());
|
||||
<% } -%>
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
<% if (property.type !== 'color') { -%>
|
||||
|
||||
@Test
|
||||
public void test<%- camelize(property.name) %>AsCompositeFunction() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("<%- property.name %>");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set
|
||||
layer.setProperties(
|
||||
<%- camelizeWithLeadingLowercase(property.name) %>(
|
||||
composite(
|
||||
"FeaturePropertyA",
|
||||
exponential(
|
||||
stop(0, 0.3f, <%- camelizeWithLeadingLowercase(property.name) %>(0.9f))
|
||||
).withBase(0.5f)
|
||||
<% if (property.type == 'number') { -%>
|
||||
).withDefaultValue(<%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>))
|
||||
<% } else { -%>
|
||||
)
|
||||
<% } -%>
|
||||
)
|
||||
);
|
||||
|
||||
// Verify
|
||||
assertNotNull(layer.get<%- camelize(property.name) %>());
|
||||
assertNotNull(layer.get<%- camelize(property.name) %>().getFunction());
|
||||
assertEquals(CompositeFunction.class, layer.get<%- camelize(property.name) %>().getFunction().getClass());
|
||||
assertEquals("FeaturePropertyA", ((CompositeFunction) layer.get<%- camelize(property.name) %>().getFunction()).getProperty());
|
||||
assertEquals(ExponentialStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass());
|
||||
assertEquals(1, ((ExponentialStops) layer.get<%- camelize(property.name) %>().getFunction().getStops()).size());
|
||||
|
||||
ExponentialStops<Stop.CompositeValue<Float, <%- propertyType(property) %>>, <%- propertyType(property) %>> stops =
|
||||
(ExponentialStops<Stop.CompositeValue<Float, <%- propertyType(property) %>>, <%- propertyType(property) %>>) layer.get<%- camelize(property.name) %>().getFunction().getStops();
|
||||
Stop<Stop.CompositeValue<Float, <%- propertyType(property) %>>, <%- propertyType(property) %>> stop = stops.iterator().next();
|
||||
assertEquals(0f, stop.in.zoom, 0.001);
|
||||
assertEquals(0.3f, stop.in.value, 0.001f);
|
||||
assertEquals(0.9f, stop.out, 0.001f);
|
||||
}
|
||||
});
|
||||
}
|
||||
<% } -%>
|
||||
<% } -%>
|
||||
<% } -%>
|
||||
<% if (property.type == 'color') { -%>
|
||||
@@ -444,19 +157,15 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("<%- property.name %>");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(layer);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Set and Get
|
||||
layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(Color.RED));
|
||||
assertEquals(layer.get<%- camelize(property.name) %>AsInt(), Color.RED);
|
||||
}
|
||||
// Set and Get
|
||||
layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(Color.RED));
|
||||
assertEquals(layer.get<%- camelize(property.name) %>AsInt(), Color.RED);
|
||||
});
|
||||
}
|
||||
<% } -%>
|
||||
<% } -%>
|
||||
<% } -%>
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,15 +9,12 @@ import android.support.test.espresso.ViewAction;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.style.light.Light;
|
||||
import com.mapbox.mapboxsdk.style.functions.Function;
|
||||
import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.FillExtrusionLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
|
||||
import com.mapbox.mapboxsdk.style.light.Position;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.style.FillExtrusionStyleTestActivity;
|
||||
|
||||
@@ -53,15 +50,12 @@ public class LightTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLight();
|
||||
Timber.i("<%- property.name %>TransitionOptions");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
light.set<%- camelize(property.name) %>Transition(options);
|
||||
assertEquals("Transition options should match", options, light.get<%- camelize(property.name) %>Transition());
|
||||
}
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
TransitionOptions options = new TransitionOptions(300, 100);
|
||||
light.set<%- camelize(property.name) %>Transition(options);
|
||||
assertEquals("Transition options should match", options, light.get<%- camelize(property.name) %>Transition());
|
||||
});
|
||||
}
|
||||
<% } -%>
|
||||
@@ -72,15 +66,12 @@ public class LightTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLight();
|
||||
Timber.i("<%- property.name %>");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
Position position = new Position(1, 2, 3);
|
||||
light.set<%- camelize(property.name) %>(position);
|
||||
assertEquals("Position should match", position, light.get<%- camelize(property.name) %>());
|
||||
}
|
||||
invoke(mapboxMap,(uiController, mapboxMap) -> {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
Position position = new Position(1, 2, 3);
|
||||
light.set<%- camelize(property.name) %>(position);
|
||||
assertEquals("Position should match", position, light.get<%- camelize(property.name) %>());
|
||||
});
|
||||
}
|
||||
<% } else { -%>
|
||||
@@ -90,18 +81,15 @@ public class LightTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
setupLight();
|
||||
Timber.i("<%- property.name %>");
|
||||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() {
|
||||
@Override
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
light.set<%- camelize(property.name) %>(<%- defaultValueJava(property) %>);
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
assertNotNull(light);
|
||||
// Set and Get
|
||||
light.set<%- camelize(property.name) %>(<%- defaultValueJava(property) %>);
|
||||
<% if (property.name == 'color') { -%>
|
||||
assertEquals("<%- camelize(property.name) %> should match", <%- defaultValueJava(property) %>.replaceAll("\\s+", ""), light.get<%- camelize(property.name) %>());
|
||||
assertEquals("<%- camelize(property.name) %> should match", <%- defaultValueJava(property) %>.replaceAll("\\s+", ""), light.get<%- camelize(property.name) %>());
|
||||
<% } else { -%>
|
||||
assertEquals("<%- camelize(property.name) %> should match", <%- defaultValueJava(property) %>, light.get<%- camelize(property.name) %>());
|
||||
assertEquals("<%- camelize(property.name) %> should match", <%- defaultValueJava(property) %>, light.get<%- camelize(property.name) %>());
|
||||
<% } -%>
|
||||
}
|
||||
});
|
||||
}
|
||||
<% } -%>
|
||||
@@ -128,8 +116,8 @@ public class LightTest extends BaseActivityTest {
|
||||
fillExtrusionLayer.setMinZoom(15);
|
||||
fillExtrusionLayer.setProperties(
|
||||
fillExtrusionColor(Color.LTGRAY),
|
||||
fillExtrusionHeight(Function.property("height", new IdentityStops<Float>())),
|
||||
fillExtrusionBase(Function.property("min_height", new IdentityStops<Float>())),
|
||||
fillExtrusionHeight(Expression.get("height")),
|
||||
fillExtrusionBase(Expression.get("min_height")),
|
||||
fillExtrusionOpacity(0.6f)
|
||||
);
|
||||
mapboxMap.addLayer(fillExtrusionLayer);
|
||||
@@ -141,4 +129,4 @@ public class LightTest extends BaseActivityTest {
|
||||
protected Class getActivityClass() {
|
||||
return FillExtrusionStyleTestActivity.class;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,7 @@ import android.view.MenuItem;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.style.functions.Function;
|
||||
import com.mapbox.mapboxsdk.style.functions.stops.IdentityStops;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.FillExtrusionLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.Property;
|
||||
import com.mapbox.mapboxsdk.style.layers.PropertyFactory;
|
||||
@@ -57,8 +56,8 @@ public class BuildingFillExtrusionActivity extends AppCompatActivity {
|
||||
fillExtrusionLayer.setMinZoom(15);
|
||||
fillExtrusionLayer.setProperties(
|
||||
fillExtrusionColor(Color.LTGRAY),
|
||||
fillExtrusionHeight(Function.property("height", new IdentityStops<Float>())),
|
||||
fillExtrusionBase(Function.property("min_height", new IdentityStops<Float>())),
|
||||
fillExtrusionHeight(Expression.get("height")),
|
||||
fillExtrusionBase(Expression.get("min_height")),
|
||||
fillExtrusionOpacity(0.9f)
|
||||
);
|
||||
mapboxMap.addLayer(fillExtrusionLayer);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.style;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.Menu;
|
||||
@@ -23,13 +22,14 @@ import java.io.IOException;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.color;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.exponential;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.linear;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.literal;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.match;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.rgb;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.rgba;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.step;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.stop;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom;
|
||||
@@ -165,7 +165,6 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void addExponentialZoomFunction() {
|
||||
Timber.i("Add exponential zoom function");
|
||||
FillLayer layer = mapboxMap.getLayerAs("water");
|
||||
@@ -174,9 +173,9 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
fillColor(
|
||||
interpolate(
|
||||
exponential(0.5f), zoom(),
|
||||
stop(1, color(Color.RED)),
|
||||
stop(5, color(Color.BLUE)),
|
||||
stop(10, color(Color.GREEN))
|
||||
stop(1, rgb(255, 0, 0)),
|
||||
stop(5, rgb(0, 0, 255)),
|
||||
stop(10, rgb(0, 255, 0))
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -191,10 +190,10 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
layer.setProperties(
|
||||
fillColor(
|
||||
step(zoom(),
|
||||
color(Color.CYAN),
|
||||
stop(1, color(Color.RED)),
|
||||
stop(5, color(Color.BLUE)),
|
||||
stop(10, color(Color.GREEN))
|
||||
rgba(0.0f, 255.0f, 255.0f, 1.0f),
|
||||
stop(1, rgba(255.0f, 0.0f, 0.0f, 1.0f)),
|
||||
stop(5, rgba(0.0f, 0.0f, 255.0f, 1.0f)),
|
||||
stop(10, rgba(0.0f, 255.0f, 0.0f, 1.0f))
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -211,9 +210,9 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
interpolate(
|
||||
exponential(0.5f),
|
||||
get("stroke-width"),
|
||||
stop(1f, color(Color.RED)),
|
||||
stop(5f, color(Color.BLUE)),
|
||||
stop(10f, color(Color.GREEN))
|
||||
stop(1f, rgba(255.0f, 0.0f, 0.0f, 1.0f)),
|
||||
stop(5f, rgba(0.0f, 0.0f, 255.0f, 1.0f)),
|
||||
stop(10f, rgba(0.0f, 255.0f, 0.0f, 1.0f))
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -229,10 +228,10 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
fillColor(
|
||||
match(
|
||||
get("name"),
|
||||
literal("Westerpark"), color(Color.RED),
|
||||
literal("Jordaan"), color(Color.BLUE),
|
||||
literal("Prinseneiland"), color(Color.GREEN),
|
||||
color(Color.CYAN)
|
||||
literal("Westerpark"), rgba(255.0f, 0.0f, 0.0f, 1.0f),
|
||||
literal("Jordaan"), rgba(0.0f, 0.0f, 255.0f, 1.0f),
|
||||
literal("Prinseneiland"), rgba(0.0f, 255.0f, 0.0f, 1.0f),
|
||||
rgba(0.0f, 255.0f, 255.0f, 1.0f)
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -261,10 +260,10 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
fillColor(
|
||||
step(
|
||||
get("stroke-width"),
|
||||
color(Color.CYAN),
|
||||
stop(1f, color(Color.RED)),
|
||||
stop(2f, color(Color.BLUE)),
|
||||
stop(3f, color(Color.GREEN))
|
||||
rgba(0.0f, 255.0f, 255.0f, 1.0f),
|
||||
stop(1f, rgba(255.0f, 0.0f, 0.0f, 1.0f)),
|
||||
stop(2f, rgba(0.0f, 0.0f, 255.0f, 1.0f)),
|
||||
stop(3f, rgba(0.0f, 255.0f, 0.0f, 1.0f))
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -283,24 +282,24 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
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))
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f),
|
||||
stop(1f, rgba(255.0f, 0.0f, 0.0f, 1.0f)),
|
||||
stop(2f, rgba(0.0f, 0.0f, 0.0f, 1.0f)),
|
||||
stop(3f, rgba(0.0f, 0.0f, 255.0f, 1.0f))
|
||||
)),
|
||||
stop(15, step(
|
||||
get("stroke-width"),
|
||||
color(Color.BLACK),
|
||||
stop(1f, color(Color.YELLOW)),
|
||||
stop(2f, color(Color.LTGRAY)),
|
||||
stop(3f, color(Color.CYAN))
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f),
|
||||
stop(1f, rgba(255.0f, 255.0f, 0.0f, 1.0f)),
|
||||
stop(2f, rgba(211.0f, 211.0f, 211.0f, 1.0f)),
|
||||
stop(3f, rgba(0.0f, 255.0f, 255.0f, 1.0f))
|
||||
)),
|
||||
stop(18, step(
|
||||
get("stroke-width"),
|
||||
color(Color.BLACK),
|
||||
stop(1f, color(Color.WHITE)),
|
||||
stop(2f, color(Color.GRAY)),
|
||||
stop(3f, color(Color.GREEN)))
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f),
|
||||
stop(1f, rgba(0.0f, 0.0f, 0.0f, 1.0f)),
|
||||
stop(2f, rgba(128.0f, 128.0f, 128.0f, 1.0f)),
|
||||
stop(3f, rgba(0.0f, 255.0f, 0.0f, 1.0f)))
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -320,24 +319,24 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
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))
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f),
|
||||
stop(1f, rgba(255.0f, 0.0f, 0.0f, 1.0f)),
|
||||
stop(2f, rgba(0.0f, 0.0f, 0.0f, 1.0f)),
|
||||
stop(3f, rgba(0.0f, 0.0f, 255.0f, 1.0f))
|
||||
)),
|
||||
stop(15, step(
|
||||
get("stroke-width"),
|
||||
color(Color.BLACK),
|
||||
stop(1f, color(Color.YELLOW)),
|
||||
stop(2f, color(Color.LTGRAY)),
|
||||
stop(3f, color(Color.CYAN))
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f),
|
||||
stop(1f, rgba(255.0f, 255.0f, 0.0f, 1.0f)),
|
||||
stop(2f, rgba(211.0f, 211.0f, 211.0f, 1.0f)),
|
||||
stop(3f, rgba(0.0f, 255.0f, 255.0f, 1.0f))
|
||||
)),
|
||||
stop(18, step(
|
||||
get("stroke-width"),
|
||||
color(Color.BLACK),
|
||||
stop(1f, color(Color.WHITE)),
|
||||
stop(2f, color(Color.GRAY)),
|
||||
stop(3f, color(Color.GREEN))
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f),
|
||||
stop(1f, rgba(0.0f, 0.0f, 0.0f, 1.0f)),
|
||||
stop(2f, rgba(128.0f, 128.0f, 128.0f, 1.0f)),
|
||||
stop(3f, rgba(0.0f, 255.0f, 0.0f, 1.0f))
|
||||
))
|
||||
)
|
||||
)
|
||||
@@ -353,89 +352,89 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
layer.setProperties(
|
||||
fillColor(
|
||||
step(zoom(),
|
||||
color(Color.BLACK),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f),
|
||||
stop(7f, match(
|
||||
get("name"),
|
||||
literal("Westerpark"), color(Color.RED),
|
||||
color(Color.BLACK)
|
||||
literal("Westerpark"), rgba(255.0f, 0.0f, 0.0f, 1.0f),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f)
|
||||
)),
|
||||
stop(8f, match(
|
||||
get("name"),
|
||||
literal("Westerpark"), color(Color.BLUE),
|
||||
color(Color.BLACK)
|
||||
literal("Westerpark"), rgba(0.0f, 0.0f, 255.0f, 1.0f),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f)
|
||||
)),
|
||||
stop(9f, match(
|
||||
get("name"),
|
||||
literal("Westerpark"), color(Color.RED),
|
||||
color(Color.BLACK)
|
||||
literal("Westerpark"), rgba(255.0f, 0.0f, 0.0f, 1.0f),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f)
|
||||
)),
|
||||
stop(10f, match(
|
||||
get("name"),
|
||||
literal("Westerpark"), color(Color.BLUE),
|
||||
color(Color.BLACK)
|
||||
literal("Westerpark"), rgba(0.0f, 0.0f, 255.0f, 1.0f),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f)
|
||||
)),
|
||||
stop(11f, match(
|
||||
get("name"),
|
||||
literal("Westerpark"), color(Color.RED),
|
||||
color(Color.BLACK)
|
||||
literal("Westerpark"), rgba(255.0f, 0.0f, 0.0f, 1.0f),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f)
|
||||
)),
|
||||
stop(12f, match(
|
||||
get("name"),
|
||||
literal("Westerpark"), color(Color.BLUE),
|
||||
color(Color.BLACK)
|
||||
literal("Westerpark"), rgba(0.0f, 0.0f, 255.0f, 1.0f),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f)
|
||||
)),
|
||||
stop(13f, match(
|
||||
get("name"),
|
||||
literal("Westerpark"), color(Color.RED),
|
||||
color(Color.BLACK)
|
||||
literal("Westerpark"), rgba(255.0f, 0.0f, 0.0f, 1.0f),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f)
|
||||
)),
|
||||
stop(14f, match(
|
||||
get("name"),
|
||||
literal("Westerpark"), color(Color.BLUE),
|
||||
literal("Jordaan"), color(Color.GREEN),
|
||||
literal("PrinsenEiland"), color(Color.WHITE),
|
||||
color(Color.BLACK)
|
||||
literal("Westerpark"), rgba(0.0f, 0.0f, 255.0f, 1.0f),
|
||||
literal("Jordaan"), rgba(0.0f, 255.0f, 0.0f, 1.0f),
|
||||
literal("PrinsenEiland"), rgba(0.0f, 0.0f, 0.0f, 1.0f),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f)
|
||||
)),
|
||||
stop(15f, match(
|
||||
get("name"),
|
||||
literal("Westerpark"), color(Color.RED),
|
||||
color(Color.BLACK)
|
||||
literal("Westerpark"), rgba(255.0f, 0.0f, 0.0f, 1.0f),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f)
|
||||
)),
|
||||
stop(16f, match(
|
||||
get("name"),
|
||||
literal("Westerpark"), color(Color.BLUE),
|
||||
color(Color.BLACK)
|
||||
literal("Westerpark"), rgba(0.0f, 0.0f, 255.0f, 1.0f),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f)
|
||||
)),
|
||||
stop(17f, match(
|
||||
get("name"),
|
||||
literal("Westerpark"), color(Color.RED),
|
||||
color(Color.BLACK)
|
||||
literal("Westerpark"), rgba(255.0f, 0.0f, 0.0f, 1.0f),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f)
|
||||
)),
|
||||
stop(18f, match(
|
||||
get("name"),
|
||||
literal("Westerpark"), color(Color.BLUE),
|
||||
literal("Jordaan"), color(Color.CYAN),
|
||||
color(Color.BLACK)
|
||||
literal("Westerpark"), rgba(0.0f, 0.0f, 255.0f, 1.0f),
|
||||
literal("Jordaan"), rgba(0.0f, 255.0f, 255.0f, 1.0f),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f)
|
||||
)),
|
||||
stop(19f, match(
|
||||
get("name"),
|
||||
literal("Westerpark"), color(Color.RED),
|
||||
color(Color.BLACK)
|
||||
literal("Westerpark"), rgba(255.0f, 0.0f, 0.0f, 1.0f),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f)
|
||||
)),
|
||||
stop(20f, match(
|
||||
get("name"),
|
||||
literal("Westerpark"), color(Color.BLUE),
|
||||
color(Color.BLACK)
|
||||
literal("Westerpark"), rgba(0.0f, 0.0f, 255.0f, 1.0f),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f)
|
||||
)),
|
||||
stop(21f, match(
|
||||
get("name"),
|
||||
literal("Westerpark"), color(Color.RED),
|
||||
color(Color.BLACK)
|
||||
literal("Westerpark"), rgba(255.0f, 0.0f, 0.0f, 1.0f),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f)
|
||||
)),
|
||||
stop(22f, match(
|
||||
get("name"),
|
||||
literal("Westerpark"), color(Color.BLUE),
|
||||
color(Color.BLACK)
|
||||
literal("Westerpark"), rgba(0.0f, 0.0f, 255.0f, 1.0f),
|
||||
rgba(255.0f, 255.0f, 255.0f, 1.0f)
|
||||
))
|
||||
)
|
||||
)
|
||||
@@ -461,8 +460,8 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
// Add a fill layer
|
||||
mapboxMap.addLayer(new FillLayer(AMSTERDAM_PARKS_LAYER, source.getId())
|
||||
.withProperties(
|
||||
fillColor(Color.BLACK),
|
||||
fillOutlineColor(Color.BLUE),
|
||||
fillColor(rgba(0.0f, 0.0f, 0.0f, 0.5f)),
|
||||
fillOutlineColor(rgb(0, 0, 255)),
|
||||
fillAntialias(true)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.mapbox.geojson.FeatureCollection;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.Filter;
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
@@ -27,8 +28,8 @@ import com.mapbox.mapboxsdk.style.sources.Source;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@@ -39,8 +40,12 @@ import static com.mapbox.mapboxsdk.style.expressions.Expression.division;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.downcase;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.literal;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.match;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.number;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.pi;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.product;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.rgba;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.string;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.upcase;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Property.ICON_ANCHOR_BOTTOM;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_ANCHOR_TOP;
|
||||
@@ -50,6 +55,7 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconOffset;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconSize;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textAnchor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textColor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textField;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textSize;
|
||||
|
||||
@@ -196,27 +202,32 @@ public class SymbolGeneratorActivity extends AppCompatActivity implements OnMapR
|
||||
|
||||
private static class LoadDataTask extends AsyncTask<Void, Void, FeatureCollection> {
|
||||
|
||||
private SymbolGeneratorActivity activity;
|
||||
private WeakReference<SymbolGeneratorActivity> activity;
|
||||
|
||||
LoadDataTask(SymbolGeneratorActivity activity) {
|
||||
this.activity = activity;
|
||||
this.activity = new WeakReference<>(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FeatureCollection doInBackground(Void... params) {
|
||||
try {
|
||||
// read local geojson from raw folder
|
||||
String tinyCountriesJson = ResourceUtils.readRawResource(activity, R.raw.tiny_countries);
|
||||
return FeatureCollection.fromJson(tinyCountriesJson);
|
||||
Context context = activity.get();
|
||||
if (context != null) {
|
||||
try {
|
||||
// read local geojson from raw folder
|
||||
String tinyCountriesJson = ResourceUtils.readRawResource(context, R.raw.tiny_countries);
|
||||
return FeatureCollection.fromJson(tinyCountriesJson);
|
||||
|
||||
} catch (IOException exception) {
|
||||
return null;
|
||||
} catch (IOException exception) {
|
||||
Timber.e(exception);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(FeatureCollection featureCollection) {
|
||||
super.onPostExecute(featureCollection);
|
||||
SymbolGeneratorActivity activity = this.activity.get();
|
||||
if (featureCollection == null || activity == null) {
|
||||
return;
|
||||
}
|
||||
@@ -226,37 +237,64 @@ public class SymbolGeneratorActivity extends AppCompatActivity implements OnMapR
|
||||
}
|
||||
|
||||
public void onDataLoaded(@NonNull FeatureCollection featureCollection) {
|
||||
// add a geojson to the map
|
||||
Source source = new GeoJsonSource(SOURCE_ID, featureCollection);
|
||||
mapboxMap.addSource(source);
|
||||
// create expressions
|
||||
Expression iconImageExpression = string(get(literal(FEATURE_ID)));
|
||||
Expression iconSizeExpression = division(number(get(literal(FEATURE_RANK))), literal(2.0f));
|
||||
Expression textSizeExpression = product(get(literal(FEATURE_RANK)), pi());
|
||||
Expression textFieldExpression = concat(upcase(literal("a ")), upcase(string(get(literal(FEATURE_TYPE)))),
|
||||
downcase(literal(" IN ")), string(get(literal(FEATURE_REGION)))
|
||||
);
|
||||
Expression textColorExpression = match(get(literal(FEATURE_RANK)),
|
||||
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)
|
||||
);
|
||||
|
||||
// create layer use
|
||||
mapboxMap.addLayer(new SymbolLayer(LAYER_ID, SOURCE_ID)
|
||||
rgba(
|
||||
division(literal(255), get(FEATURE_RANK)),
|
||||
literal(0.0f),
|
||||
literal(0.0f),
|
||||
literal(1.0f)
|
||||
);
|
||||
|
||||
// create symbol layer
|
||||
SymbolLayer symbolLayer = new SymbolLayer(LAYER_ID, SOURCE_ID)
|
||||
.withProperties(
|
||||
|
||||
// icon configuration
|
||||
iconImage(get(literal(FEATURE_ID))),
|
||||
iconImage(iconImageExpression),
|
||||
iconAllowOverlap(false),
|
||||
iconSize(
|
||||
division(get(literal(FEATURE_RANK)), literal(2))
|
||||
),
|
||||
iconSize(iconSizeExpression),
|
||||
iconAnchor(ICON_ANCHOR_BOTTOM),
|
||||
iconOffset(new Float[] {0.0f, -5.0f}),
|
||||
|
||||
// text field configuration
|
||||
textField(
|
||||
concat(
|
||||
upcase(literal("a ")),
|
||||
get(literal(FEATURE_TYPE)),
|
||||
downcase(literal(" IN ")),
|
||||
get(literal(FEATURE_REGION))
|
||||
)
|
||||
),
|
||||
textSize(
|
||||
product(get(literal(FEATURE_RANK)), pi())
|
||||
),
|
||||
textAnchor(TEXT_ANCHOR_TOP)
|
||||
)
|
||||
textField(textFieldExpression),
|
||||
textSize(textSizeExpression),
|
||||
textAnchor(TEXT_ANCHOR_TOP),
|
||||
textColor(textColorExpression)
|
||||
);
|
||||
|
||||
// add a geojson source to the map
|
||||
Source source = new GeoJsonSource(SOURCE_ID, featureCollection);
|
||||
mapboxMap.addSource(source);
|
||||
|
||||
// add symbol layer
|
||||
mapboxMap.addLayer(symbolLayer);
|
||||
|
||||
// get expressions
|
||||
Expression iconImageExpressionResult = symbolLayer.getIconImage().getExpression();
|
||||
Expression iconSizeExpressionResult = symbolLayer.getIconSize().getExpression();
|
||||
Expression textSizeExpressionResult = symbolLayer.getTextSize().getExpression();
|
||||
Expression textFieldExpressionResult = symbolLayer.getTextField().getExpression();
|
||||
Expression textColorExpressionResult = symbolLayer.getTextColor().getExpression();
|
||||
|
||||
// reset expressions
|
||||
symbolLayer.setProperties(
|
||||
iconImage(iconImageExpressionResult),
|
||||
iconSize(iconSizeExpressionResult),
|
||||
textSize(textSizeExpressionResult),
|
||||
textField(textFieldExpressionResult),
|
||||
textColor(textColorExpressionResult)
|
||||
);
|
||||
|
||||
new GenerateSymbolTask(mapboxMap, this).execute(featureCollection);
|
||||
@@ -265,27 +303,29 @@ public class SymbolGeneratorActivity extends AppCompatActivity implements OnMapR
|
||||
private static class GenerateSymbolTask extends AsyncTask<FeatureCollection, Void, HashMap<String, Bitmap>> {
|
||||
|
||||
private MapboxMap mapboxMap;
|
||||
private Context context;
|
||||
private WeakReference<Context> context;
|
||||
|
||||
GenerateSymbolTask(MapboxMap mapboxMap, Context context) {
|
||||
this.mapboxMap = mapboxMap;
|
||||
this.context = context;
|
||||
this.context = new WeakReference<>(context);
|
||||
}
|
||||
|
||||
@SuppressWarnings("WrongThread")
|
||||
@Override
|
||||
protected HashMap<String, Bitmap> doInBackground(FeatureCollection... params) {
|
||||
FeatureCollection featureCollection = params[0];
|
||||
|
||||
HashMap<String, Bitmap> imagesMap = new HashMap<>();
|
||||
for (Feature feature : featureCollection.features()) {
|
||||
String countryName = feature.getStringProperty(FEATURE_ID);
|
||||
TextView textView = new TextView(context);
|
||||
textView.setBackgroundColor(context.getResources().getColor(R.color.blueAccent));
|
||||
textView.setPadding(10, 5, 10, 5);
|
||||
textView.setTextColor(Color.WHITE);
|
||||
textView.setText(countryName);
|
||||
imagesMap.put(countryName, SymbolGenerator.generate(textView));
|
||||
Context context = this.context.get();
|
||||
List<Feature> features = params[0].features();
|
||||
if (context != null && features != null) {
|
||||
for (Feature feature : features) {
|
||||
String countryName = feature.getStringProperty(FEATURE_ID);
|
||||
TextView textView = new TextView(context);
|
||||
textView.setBackgroundColor(context.getResources().getColor(R.color.blueAccent));
|
||||
textView.setPadding(10, 5, 10, 5);
|
||||
textView.setTextColor(Color.WHITE);
|
||||
textView.setText(countryName);
|
||||
imagesMap.put(countryName, SymbolGenerator.generate(textView));
|
||||
}
|
||||
}
|
||||
return imagesMap;
|
||||
}
|
||||
|
||||
@@ -22,11 +22,13 @@ import java.util.List;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.functions.Function.property;
|
||||
import static com.mapbox.mapboxsdk.style.functions.Function.zoom;
|
||||
import static com.mapbox.mapboxsdk.style.functions.stops.Stop.stop;
|
||||
import static com.mapbox.mapboxsdk.style.functions.stops.Stops.categorical;
|
||||
import static com.mapbox.mapboxsdk.style.functions.stops.Stops.interval;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.linear;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.literal;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.stop;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.switchCase;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconAllowOverlap;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconSize;
|
||||
@@ -101,20 +103,16 @@ public class ZoomFunctionSymbolLayerActivity extends AppCompatActivity {
|
||||
layer = new SymbolLayer(LAYER_ID, SOURCE_ID);
|
||||
layer.setProperties(
|
||||
iconImage(
|
||||
zoom(
|
||||
interval(
|
||||
stop(ZOOM_STOP_MIN_VALUE, iconImage(BUS_MAKI_ICON_ID)),
|
||||
stop(ZOOM_STOP_MAX_VALUE, iconImage(CAFE_MAKI_ICON_ID))
|
||||
)
|
||||
)
|
||||
interpolate(
|
||||
linear(), zoom(),
|
||||
stop(ZOOM_STOP_MIN_VALUE, BUS_MAKI_ICON_ID),
|
||||
stop(ZOOM_STOP_MAX_VALUE, CAFE_MAKI_ICON_ID)
|
||||
)
|
||||
),
|
||||
iconSize(
|
||||
property(
|
||||
KEY_PROPERTY_SELECTED,
|
||||
categorical(
|
||||
stop(true, iconSize(3.0f)),
|
||||
stop(false, iconSize(1.0f))
|
||||
)
|
||||
switchCase(
|
||||
get(KEY_PROPERTY_SELECTED), literal(3.0f),
|
||||
literal(1.0f)
|
||||
)
|
||||
),
|
||||
iconAllowOverlap(true)
|
||||
|
||||
@@ -16,17 +16,14 @@ public class ResourceUtils {
|
||||
public static String readRawResource(Context context, @RawRes int rawResource) throws IOException {
|
||||
String json = "";
|
||||
if (context != null) {
|
||||
InputStream is = context.getResources().openRawResource(rawResource);
|
||||
Writer writer = new StringWriter();
|
||||
char[] buffer = new char[1024];
|
||||
try {
|
||||
try (InputStream is = context.getResources().openRawResource(rawResource)) {
|
||||
Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||
int numRead;
|
||||
while ((numRead = reader.read(buffer)) != -1) {
|
||||
writer.write(buffer, 0, numRead);
|
||||
}
|
||||
} finally {
|
||||
is.close();
|
||||
}
|
||||
json = writer.toString();
|
||||
}
|
||||
|
||||
@@ -131,6 +131,7 @@ add_library(mbgl-android STATIC
|
||||
platform/android/src/conversion/constant.hpp
|
||||
platform/android/src/conversion/conversion.hpp
|
||||
platform/android/src/style/conversion/function.hpp
|
||||
platform/android/src/style/conversion/gson.hpp
|
||||
platform/android/src/style/conversion/property_value.hpp
|
||||
platform/android/src/style/conversion/types.hpp
|
||||
platform/android/src/style/conversion/types_string_values.hpp
|
||||
@@ -190,16 +191,6 @@ add_library(mbgl-android STATIC
|
||||
platform/android/src/style/sources/image_source.cpp
|
||||
platform/android/src/style/sources/raster_dem_source.cpp
|
||||
platform/android/src/style/sources/raster_dem_source.hpp
|
||||
platform/android/src/style/functions/stop.cpp
|
||||
platform/android/src/style/functions/stop.hpp
|
||||
platform/android/src/style/functions/categorical_stops.cpp
|
||||
platform/android/src/style/functions/categorical_stops.hpp
|
||||
platform/android/src/style/functions/exponential_stops.cpp
|
||||
platform/android/src/style/functions/exponential_stops.hpp
|
||||
platform/android/src/style/functions/identity_stops.cpp
|
||||
platform/android/src/style/functions/identity_stops.hpp
|
||||
platform/android/src/style/functions/interval_stops.cpp
|
||||
platform/android/src/style/functions/interval_stops.hpp
|
||||
platform/android/src/style/position.cpp
|
||||
platform/android/src/style/position.hpp
|
||||
platform/android/src/style/light.cpp
|
||||
|
||||
@@ -149,6 +149,24 @@ global.propertyTypeAnnotation = function propertyTypeAnnotation(property) {
|
||||
}
|
||||
};
|
||||
|
||||
global.defaultExpressionJava = function(property) {
|
||||
switch (property.type) {
|
||||
case 'boolean':
|
||||
return 'boolean';
|
||||
case 'number':
|
||||
return 'number';
|
||||
case 'string':
|
||||
return "string";
|
||||
case 'enum':
|
||||
return "string";
|
||||
case 'color':
|
||||
return 'toColor';
|
||||
case 'array':
|
||||
return "array";
|
||||
default: return "string";
|
||||
}
|
||||
}
|
||||
|
||||
global.defaultValueJava = function(property) {
|
||||
if(property.name.endsWith("-pattern")) {
|
||||
return '"pedestrian-polygon"';
|
||||
|
||||
@@ -40,11 +40,6 @@
|
||||
#include "offline/offline_region_error.hpp"
|
||||
#include "offline/offline_region_status.hpp"
|
||||
#include "style/transition_options.hpp"
|
||||
#include "style/functions/categorical_stops.hpp"
|
||||
#include "style/functions/exponential_stops.hpp"
|
||||
#include "style/functions/identity_stops.hpp"
|
||||
#include "style/functions/interval_stops.hpp"
|
||||
#include "style/functions/stop.hpp"
|
||||
#include "style/layers/layers.hpp"
|
||||
#include "style/sources/source.hpp"
|
||||
#include "style/light.hpp"
|
||||
@@ -163,11 +158,6 @@ void registerNatives(JavaVM *vm) {
|
||||
Source::registerNative(env);
|
||||
Light::registerNative(env);
|
||||
Position::registerNative(env);
|
||||
Stop::registerNative(env);
|
||||
CategoricalStops::registerNative(env);
|
||||
ExponentialStops::registerNative(env);
|
||||
IdentityStops::registerNative(env);
|
||||
IntervalStops::registerNative(env);
|
||||
|
||||
// Map
|
||||
CameraPosition::registerNative(env);
|
||||
|
||||
@@ -5,14 +5,9 @@
|
||||
#include "../../conversion/constant.hpp"
|
||||
#include "types.hpp"
|
||||
#include "../../java/lang.hpp"
|
||||
#include "../functions/stop.hpp"
|
||||
#include "../functions/categorical_stops.hpp"
|
||||
#include "../functions/exponential_stops.hpp"
|
||||
#include "../functions/identity_stops.hpp"
|
||||
#include "../functions/interval_stops.hpp"
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
#include "gson.hpp"
|
||||
#include <tuple>
|
||||
#include <map>
|
||||
|
||||
@@ -20,160 +15,16 @@ namespace mbgl {
|
||||
namespace android {
|
||||
namespace conversion {
|
||||
|
||||
/**
|
||||
* Conversion from core composite value to java type
|
||||
*/
|
||||
class CategoricalValueEvaluator {
|
||||
public:
|
||||
|
||||
CategoricalValueEvaluator(jni::JNIEnv& _env) : env(_env) {}
|
||||
|
||||
template <class T>
|
||||
jni::jobject* operator()(const T &value) const {
|
||||
return *convert<jni::jobject*, T>(env, value);
|
||||
}
|
||||
|
||||
private:
|
||||
jni::JNIEnv& env;
|
||||
};
|
||||
|
||||
/**
|
||||
* Conversion from core composite value to java type
|
||||
*/
|
||||
template <>
|
||||
struct Converter<jni::jobject*, mbgl::style::CategoricalValue> {
|
||||
|
||||
Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::CategoricalValue& value) const {
|
||||
CategoricalValueEvaluator evaluator(env);
|
||||
return apply_visitor(evaluator, value);
|
||||
}
|
||||
};
|
||||
|
||||
template <class I, class O>
|
||||
jni::Array<jni::Object<Stop>> toFunctionStopJavaArray(jni::JNIEnv& env, std::map<I, O> value) {
|
||||
|
||||
auto jarray = jni::Array<jni::Object<Stop>>::New(env, value.size(), Stop::javaClass);
|
||||
|
||||
size_t i = 0;
|
||||
for (auto const& stop : value) {
|
||||
jni::jobject* in = *convert<jni::jobject*, I>(env, stop.first);
|
||||
jni::jobject* out = *convert<jni::jobject*, O>(env, stop.second);
|
||||
|
||||
auto jstop = Stop::New(env, jni::Object<>(in), jni::Object<>(out));
|
||||
jarray.Set(env, i, jstop);
|
||||
|
||||
jni::DeleteLocalRef(env, in);
|
||||
jni::DeleteLocalRef(env, out);
|
||||
jni::DeleteLocalRef(env, jstop);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return jarray;
|
||||
}
|
||||
|
||||
template <class I, class O>
|
||||
jni::Array<jni::Object<Stop>> toFunctionStopJavaArray(jni::JNIEnv& env, std::map<float, std::map<I, O>> value) {
|
||||
|
||||
auto jarray = jni::Array<jni::Object<Stop>>::New(env, value.size(), Stop::javaClass);
|
||||
|
||||
for (auto const& zoomLevelMap : value) {
|
||||
size_t i = 0;
|
||||
for (auto const& stop: zoomLevelMap.second) {
|
||||
auto zoom = jni::Object<java::lang::Number>(*convert<jni::jobject*>(env, zoomLevelMap.first));
|
||||
auto in = jni::Object<>(*convert<jni::jobject*, I>(env, stop.first));
|
||||
auto out = jni::Object<>(*convert<jni::jobject*, O>(env, stop.second));
|
||||
auto compositeValue = Stop::CompositeValue::New(env, zoom, in);
|
||||
|
||||
auto jstop = Stop::New(env, compositeValue, out);
|
||||
jarray.Set(env, i, jstop);
|
||||
|
||||
jni::DeleteLocalRef(env, zoom);
|
||||
jni::DeleteLocalRef(env, in);
|
||||
jni::DeleteLocalRef(env, out);
|
||||
jni::DeleteLocalRef(env, compositeValue);
|
||||
jni::DeleteLocalRef(env, jstop);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return jarray;
|
||||
}
|
||||
|
||||
template <class I, typename O>
|
||||
inline jni::jobject* convertCompositeStopsArray(jni::JNIEnv& env, std::map<float, std::map<I, O>> value) {
|
||||
static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/stops/Stop")).release();
|
||||
static jni::jmethodID* constructor = &jni::GetMethodID(env, *javaClass, "<init>", "(Ljava/lang/Object;Ljava/lang/Object;)V");
|
||||
|
||||
jni::jarray<jni::jobject>& jarray = jni::NewObjectArray(env, value.size(), *javaClass);
|
||||
|
||||
size_t i = 0;
|
||||
for (auto const& stop : value) {
|
||||
jni::jobject* in = *convert<jni::jobject*, I>(env, stop.first);
|
||||
jni::jobject* out = *convert<jni::jobject*, O>(env, stop.second);
|
||||
jni::SetObjectArrayElement(env, jarray, i, &jni::NewObject(env, *javaClass, *constructor, in, out));
|
||||
i++;
|
||||
jni::DeleteLocalRef(env, in);
|
||||
jni::DeleteLocalRef(env, out);
|
||||
}
|
||||
|
||||
return &jarray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Conversion from core function stops to Stops java subclasses
|
||||
*/
|
||||
template <class T>
|
||||
class StopsEvaluator {
|
||||
public:
|
||||
|
||||
StopsEvaluator(jni::JNIEnv& _env) : env(_env) {}
|
||||
|
||||
jni::jobject* operator()(const mbgl::style::CategoricalStops<T> &value) const {
|
||||
return CategoricalStops::New(env, toFunctionStopJavaArray(env, value.stops)).Get();
|
||||
}
|
||||
|
||||
jni::jobject* operator()(const mbgl::style::CompositeCategoricalStops<T> &value) const {
|
||||
return CategoricalStops::New(env, toFunctionStopJavaArray(env, value.stops)).Get();
|
||||
}
|
||||
|
||||
jni::jobject* operator()(const mbgl::style::ExponentialStops<T> &value) const {
|
||||
return ExponentialStops::New(env, jni::Object<java::lang::Float>(*convert<jni::jobject*>(env, value.base)), toFunctionStopJavaArray(env, value.stops)).Get();
|
||||
}
|
||||
|
||||
jni::jobject* operator()(const mbgl::style::CompositeExponentialStops<T> &value) const {
|
||||
return ExponentialStops::New(env, jni::Object<java::lang::Float>(*convert<jni::jobject*>(env, value.base)), toFunctionStopJavaArray(env, value.stops)).Get();
|
||||
}
|
||||
|
||||
jni::jobject* operator()(const mbgl::style::IdentityStops<T> &) const {
|
||||
return IdentityStops::New(env).Get();
|
||||
}
|
||||
|
||||
jni::jobject* operator()(const mbgl::style::IntervalStops<T> &value) const {
|
||||
return IntervalStops::New(env, toFunctionStopJavaArray(env, value.stops)).Get();
|
||||
}
|
||||
|
||||
jni::jobject* operator()(const mbgl::style::CompositeIntervalStops<T> &value) const {
|
||||
return IntervalStops::New(env, toFunctionStopJavaArray(env, value.stops)).Get();
|
||||
}
|
||||
|
||||
private:
|
||||
jni::JNIEnv& env;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct Converter<jni::jobject*, mbgl::style::CameraFunction<T>> {
|
||||
|
||||
Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::CameraFunction<T>& value) const {
|
||||
static jni::jclass* clazz = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/CameraFunction")).release();
|
||||
static jni::jmethodID* constructor = &jni::GetMethodID(env, *clazz, "<init>", "(Lcom/mapbox/mapboxsdk/style/functions/stops/Stops;)V");
|
||||
// Convert expressions
|
||||
mbgl::Value expressionValue = value.getExpression().serialize();
|
||||
JsonEvaluator jsonEvaluator{env};
|
||||
jni::jobject* converted = apply_visitor(jsonEvaluator, expressionValue);
|
||||
|
||||
StopsEvaluator<T> evaluator(env);
|
||||
jni::jobject* stops = apply_visitor(evaluator, value.stops);
|
||||
jni::jobject* converted = &jni::NewObject(env, *clazz, *constructor, stops);
|
||||
|
||||
return { converted };
|
||||
return converted;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -181,21 +32,12 @@ template <class T>
|
||||
struct Converter<jni::jobject*, mbgl::style::SourceFunction<T>> {
|
||||
|
||||
Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::SourceFunction<T>& value) const {
|
||||
static jni::jclass* clazz = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/SourceFunction")).release();
|
||||
static jni::jmethodID* constructor = &jni::GetMethodID(env, *clazz, "<init>",
|
||||
"(Ljava/lang/Object;Ljava/lang/String;Lcom/mapbox/mapboxsdk/style/functions/stops/Stops;)V");
|
||||
// Convert expressions
|
||||
mbgl::Value expressionValue = value.getExpression().serialize();
|
||||
JsonEvaluator jsonEvaluator{env};
|
||||
jni::jobject* converted = apply_visitor(jsonEvaluator, expressionValue);
|
||||
|
||||
// Convert stops
|
||||
StopsEvaluator<T> evaluator(env);
|
||||
jni::jobject* stops = apply_visitor(evaluator, value.stops);
|
||||
|
||||
// Convert default value
|
||||
jni::jobject* defaultValue = nullptr;
|
||||
if (value.defaultValue) {
|
||||
defaultValue = *convert<jni::jobject*>(env, *value.defaultValue);
|
||||
}
|
||||
|
||||
return { &jni::NewObject(env, *clazz, *constructor, defaultValue, jni::Make<jni::String>(env, value.property).Get(), stops) };
|
||||
return converted;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -203,22 +45,12 @@ template <class T>
|
||||
struct Converter<jni::jobject*, mbgl::style::CompositeFunction<T>> {
|
||||
|
||||
Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::CompositeFunction<T>& value) const {
|
||||
static jni::jclass* clazz = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/CompositeFunction")).release();
|
||||
static jni::jmethodID* constructor = &jni::GetMethodID(env, *clazz, "<init>",
|
||||
"(Ljava/lang/Object;Ljava/lang/String;Lcom/mapbox/mapboxsdk/style/functions/stops/Stops;)V");
|
||||
// Convert expressions
|
||||
mbgl::Value expressionValue = value.getExpression().serialize();
|
||||
JsonEvaluator jsonEvaluator{env};
|
||||
jni::jobject* converted = apply_visitor(jsonEvaluator, expressionValue);
|
||||
|
||||
// Convert stops
|
||||
StopsEvaluator<T> evaluator(env);
|
||||
jni::jobject* stops = apply_visitor(evaluator, value.stops);
|
||||
|
||||
|
||||
// Convert default value
|
||||
jni::jobject* defaultValue = nullptr;
|
||||
if (value.defaultValue) {
|
||||
defaultValue = *convert<jni::jobject*>(env, *value.defaultValue);
|
||||
}
|
||||
|
||||
return { &jni::NewObject(env, *clazz, *constructor, defaultValue, jni::Make<jni::String>(env, value.property).Get(), stops) };
|
||||
return converted;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
114
platform/android/src/style/conversion/gson.hpp
Normal file
114
platform/android/src/style/conversion/gson.hpp
Normal file
@@ -0,0 +1,114 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../conversion/constant.hpp"
|
||||
#include "../../conversion/collection.hpp"
|
||||
|
||||
#include <mapbox/geometry.hpp>
|
||||
#include <jni/jni.hpp>
|
||||
#include "../../jni/local_object.hpp"
|
||||
#include "mapbox/geometry/feature.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
namespace conversion {
|
||||
|
||||
/**
|
||||
* Turn mapbox::geometry::value type into Java Json
|
||||
*/
|
||||
class JsonEvaluator {
|
||||
public:
|
||||
|
||||
jni::JNIEnv& env;
|
||||
|
||||
jni::jobject* operator()(const mapbox::geometry::null_value_t) const {
|
||||
return (jni::jobject*) nullptr;;
|
||||
}
|
||||
|
||||
jni::jobject* operator()(const bool& value) const {
|
||||
static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/google/gson/JsonPrimitive")).release();
|
||||
static jni::jmethodID* constructor = &jni::GetMethodID(env, *javaClass, "<init>", "(Ljava/lang/Boolean;)V");
|
||||
|
||||
// Create JsonPrimitive
|
||||
jni::LocalObject<jni::jobject> converted = jni::NewLocalObject(env, *convert<jni::jobject*, bool>(env, value));
|
||||
jni::jobject* object = &jni::NewObject(env, *javaClass, *constructor, *converted);
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
template <class Number>
|
||||
jni::jobject* operator()(const Number& value) const {
|
||||
static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/google/gson/JsonPrimitive")).release();
|
||||
static jni::jmethodID* constructor = &jni::GetMethodID(env, *javaClass, "<init>", "(Ljava/lang/Number;)V");
|
||||
|
||||
// Create JsonPrimitive
|
||||
jni::LocalObject<jni::jobject> converted = jni::NewLocalObject(env, *convert<jni::jobject*, Number>(env, value));
|
||||
jni::jobject* object = &jni::NewObject(env, *javaClass, *constructor, converted.get());
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
jni::jobject* operator()(const std::string value) const {
|
||||
static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/google/gson/JsonPrimitive")).release();
|
||||
static jni::jmethodID* constructor = &jni::GetMethodID(env, *javaClass, "<init>", "(Ljava/lang/String;)V");
|
||||
|
||||
// Create JsonPrimitive
|
||||
jni::LocalObject<jni::jobject> converted = jni::NewLocalObject(env, *convert<jni::jobject*, std::string>(env, value));
|
||||
jni::jobject* object = &jni::NewObject(env, *javaClass, *constructor, converted.get());
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
jni::jobject* operator()(const std::vector<mapbox::geometry::value> values) const {
|
||||
static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/google/gson/JsonArray")).release();
|
||||
static jni::jmethodID* constructor = &jni::GetMethodID(env, *javaClass, "<init>", "()V");;
|
||||
static jni::jmethodID* add = &jni::GetMethodID(env, *javaClass, "add", "(Lcom/google/gson/JsonElement;)V");
|
||||
|
||||
// Create json array
|
||||
jni::jobject* jarray = &jni::NewObject(env, *javaClass, *constructor);
|
||||
|
||||
// Add values
|
||||
for (const auto &v : values) {
|
||||
jni::LocalObject<jni::jobject> converted = jni::NewLocalObject(env, mapbox::geometry::value::visit(v, *this));
|
||||
jni::CallMethod<void>(env, jarray, *add, converted.get());
|
||||
}
|
||||
|
||||
return jarray;
|
||||
}
|
||||
|
||||
jni::jobject* operator()(const std::unordered_map<std::string, mapbox::geometry::value> value) const {
|
||||
static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/google/gson/JsonObject")).release();
|
||||
static jni::jmethodID* constructor = &jni::GetMethodID(env, *javaClass, "<init>", "()V");;
|
||||
static jni::jmethodID* add = &jni::GetMethodID(env, *javaClass, "add", "(Ljava/lang/String;Lcom/google/gson/JsonElement;)V");
|
||||
|
||||
// Create json object
|
||||
jni::jobject* jsonObject = &jni::NewObject(env, *javaClass, *constructor);
|
||||
|
||||
// Add items
|
||||
for (auto &item : value) {
|
||||
jni::LocalObject<jni::jobject> converted = jni::NewLocalObject(env, mbgl::Value::visit(item.second, *this));
|
||||
jni::LocalObject<jni::jobject> key = jni::NewLocalObject(env, *convert<jni::jobject*, std::string>(env, item.first));
|
||||
jni::CallMethod<void>(env, jsonObject, *add, key.get(), converted.get());
|
||||
}
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* mapbox::geometry::value -> Java Json
|
||||
*/
|
||||
template <>
|
||||
struct Converter<jni::jobject*, mapbox::geometry::value> {
|
||||
Result<jni::jobject*> operator()(jni::JNIEnv& env, const mapbox::geometry::value& value) const {
|
||||
JsonEvaluator evaluator { env } ;
|
||||
jni::jobject* converted = mapbox::geometry::value::visit(value, evaluator);
|
||||
return { converted };
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "../../conversion/constant.hpp"
|
||||
#include "types.hpp"
|
||||
#include "function.hpp"
|
||||
#include "gson.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
@@ -39,7 +40,7 @@ public:
|
||||
}
|
||||
|
||||
jni::jobject* operator()(const mbgl::style::CompositeFunction<T> &value) const {
|
||||
return *convert<jni::jobject*, mbgl::style::CompositeFunction<T>>(env, value);
|
||||
return *convert<jni::jobject*, mbgl::style::CompositeFunction<T>>(env, value);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#include "categorical_stops.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
jni::Object<CategoricalStops> CategoricalStops::New(jni::JNIEnv& env, jni::Array<jni::Object<Stop>> stops) {
|
||||
static auto constructor = CategoricalStops::javaClass.GetConstructor<jni::Array<jni::Object<Stop>>>(env);
|
||||
return CategoricalStops::javaClass.New(env, constructor, stops);
|
||||
}
|
||||
|
||||
jni::Class<CategoricalStops> CategoricalStops::javaClass;
|
||||
|
||||
void CategoricalStops::registerNative(jni::JNIEnv& env) {
|
||||
CategoricalStops::javaClass = *jni::Class<CategoricalStops>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -1,23 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
#include "stop.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
class CategoricalStops : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/functions/stops/CategoricalStops"; };
|
||||
|
||||
static jni::Object<CategoricalStops> New(jni::JNIEnv&, jni::Array<jni::Object<Stop>>);
|
||||
|
||||
static jni::Class<CategoricalStops> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -1,18 +0,0 @@
|
||||
#include "exponential_stops.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
jni::Object<ExponentialStops> ExponentialStops::New(jni::JNIEnv& env, jni::Object<java::lang::Float> base, jni::Array<jni::Object<Stop>> stops) {
|
||||
static auto constructor = ExponentialStops::javaClass.GetConstructor<jni::Object<java::lang::Float>, jni::Array<jni::Object<Stop>>>(env);
|
||||
return ExponentialStops::javaClass.New(env, constructor, base, stops);
|
||||
}
|
||||
|
||||
jni::Class<ExponentialStops> ExponentialStops::javaClass;
|
||||
|
||||
void ExponentialStops::registerNative(jni::JNIEnv& env) {
|
||||
ExponentialStops::javaClass = *jni::Class<ExponentialStops>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -1,24 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
#include "../../java/lang.hpp"
|
||||
#include "stop.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
class ExponentialStops : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/functions/stops/ExponentialStops"; };
|
||||
|
||||
static jni::Object<ExponentialStops> New(jni::JNIEnv&, jni::Object<java::lang::Float>, jni::Array<jni::Object<Stop>>);
|
||||
|
||||
static jni::Class<ExponentialStops> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -1,18 +0,0 @@
|
||||
#include "identity_stops.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
jni::Object<IdentityStops> IdentityStops::New(jni::JNIEnv& env) {
|
||||
static auto constructor = IdentityStops::javaClass.GetConstructor<>(env);
|
||||
return IdentityStops::javaClass.New(env, constructor);
|
||||
}
|
||||
|
||||
jni::Class<IdentityStops> IdentityStops::javaClass;
|
||||
|
||||
void IdentityStops::registerNative(jni::JNIEnv& env) {
|
||||
IdentityStops::javaClass = *jni::Class<IdentityStops>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -1,21 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
class IdentityStops : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/functions/stops/IdentityStops"; };
|
||||
|
||||
static jni::Object<IdentityStops> New(jni::JNIEnv&);
|
||||
|
||||
static jni::Class<IdentityStops> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -1,18 +0,0 @@
|
||||
#include "interval_stops.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
jni::Object<IntervalStops> IntervalStops::New(jni::JNIEnv& env, jni::Array<jni::Object<Stop>> stops) {
|
||||
static auto constructor = IntervalStops::javaClass.GetConstructor<jni::Array<jni::Object<Stop>>>(env);
|
||||
return IntervalStops::javaClass.New(env, constructor, stops);
|
||||
}
|
||||
|
||||
jni::Class<IntervalStops> IntervalStops::javaClass;
|
||||
|
||||
void IntervalStops::registerNative(jni::JNIEnv& env) {
|
||||
IntervalStops::javaClass = *jni::Class<IntervalStops>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -1,23 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
#include "stop.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
class IntervalStops : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/functions/stops/IntervalStops"; };
|
||||
|
||||
static jni::Object<IntervalStops> New(jni::JNIEnv&, jni::Array<jni::Object<Stop>>);
|
||||
|
||||
static jni::Class<IntervalStops> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -1,21 +0,0 @@
|
||||
#include "interval_stops.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
jni::Object<Stop::CompositeValue> Stop::CompositeValue::New(jni::JNIEnv& env, jni::Object<java::lang::Number> zoom, jni::Object<> value) {
|
||||
static auto constructor = Stop::CompositeValue::javaClass.GetConstructor<jni::Object<java::lang::Number>, jni::Object<>>(env);
|
||||
return Stop::CompositeValue::javaClass.New(env, constructor, zoom, value);
|
||||
}
|
||||
|
||||
jni::Class<Stop> Stop::javaClass;
|
||||
|
||||
jni::Class<Stop::CompositeValue> Stop::CompositeValue::javaClass;
|
||||
|
||||
void Stop::registerNative(jni::JNIEnv& env) {
|
||||
Stop::javaClass = *jni::Class<Stop>::Find(env).NewGlobalRef(env).release();
|
||||
Stop::CompositeValue::javaClass = *jni::Class<Stop::CompositeValue>::Find(env).NewGlobalRef(env).release();
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
@@ -1,36 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
#include "../../java/lang.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
class Stop : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/functions/stops/Stop"; };
|
||||
|
||||
template<class I, class O>
|
||||
static jni::Object<Stop> New(jni::JNIEnv& env, jni::Object<I> in, jni::Object<O> out) {
|
||||
static auto constructor = Stop::javaClass.GetConstructor<jni::Object<>, jni::Object<>>(env);
|
||||
return Stop::javaClass.New(env, constructor, (jni::Object<>) in, (jni::Object<>) out);
|
||||
}
|
||||
|
||||
static jni::Class<Stop> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
class CompositeValue : private mbgl::util::noncopyable {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/functions/stops/Stop$CompositeValue"; };
|
||||
|
||||
static jni::Object<Stop::CompositeValue> New(jni::JNIEnv&, jni::Object<java::lang::Number>, jni::Object<>);
|
||||
|
||||
static jni::Class<Stop::CompositeValue> javaClass;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
Reference in New Issue
Block a user