From 7a37fdc2b9d18fcfd1f4b9d47ed2aefe78811832 Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Tue, 17 Jan 2017 17:43:49 +0200 Subject: [PATCH] [android] data driven style implementation --- .../gradle-checkstyle.gradle | 3 + .../style/functions/CameraFunction.java | 50 + .../style/functions/CompositeFunction.java | 52 + .../mapboxsdk/style/functions/Function.java | 298 +++ .../style/functions/SourceFunction.java | 51 + .../style/functions/package-info.java | 6 + .../functions/stops/CategoricalStops.java | 98 + .../style/functions/stops/CompositeStops.java | 151 ++ .../functions/stops/ExponentialStops.java | 97 + .../style/functions/stops/IdentityStops.java | 18 + .../style/functions/stops/IntervalStops.java | 58 + .../style/functions/stops/IterableStops.java | 52 + .../mapboxsdk/style/functions/stops/Stop.java | 109 + .../style/functions/stops/Stops.java | 97 + .../style/functions/stops/package-info.java | 6 + .../style/layers/BackgroundLayer.java | 11 +- .../mapboxsdk/style/layers/CircleLayer.java | 26 +- .../mapboxsdk/style/layers/FillLayer.java | 23 +- .../mapboxsdk/style/layers/Function.java | 137 -- .../mapbox/mapboxsdk/style/layers/Layer.java | 10 +- .../style/layers/LayoutProperty.java | 9 - .../style/layers/LayoutPropertyValue.java | 11 + .../mapboxsdk/style/layers/LineLayer.java | 34 +- .../mapboxsdk/style/layers/PaintProperty.java | 9 - .../style/layers/PaintPropertyValue.java | 11 + .../mapboxsdk/style/layers/Property.java | 267 +-- .../style/layers/PropertyFactory.java | 1239 +++++----- .../mapboxsdk/style/layers/PropertyValue.java | 16 +- .../mapboxsdk/style/layers/RasterLayer.java | 22 +- .../mapboxsdk/style/layers/SymbolLayer.java | 102 +- .../mapboxsdk/style/layers/layer.java.ejs | 262 +-- .../mapboxsdk/style/layers/property.java.ejs | 80 +- .../style/layers/property_factory.java.ejs | 180 +- .../gradle-checkstyle.gradle | 1 + .../style/BackgroundLayerStyleTest.java | 141 -- .../testapp/style/BackgroundLayerTest.java | 137 +- .../testapp/style/CircleLayerStyleTest.java | 265 --- .../testapp/style/CircleLayerTest.java | 1115 +++++++-- .../testapp/style/FillLayerStyleTest.java | 286 --- .../testapp/style/FillLayerTest.java | 573 ++++- .../testapp/style/LineLayerStyleTest.java | 427 ---- .../testapp/style/LineLayerTest.java | 1069 +++++++-- .../testapp/style/RasterLayerStyleTest.java | 240 -- .../testapp/style/RasterLayerTest.java | 296 ++- .../testapp/style/SymbolLayerStyleTest.java | 1283 ----------- .../testapp/style/SymbolLayerTest.java | 2013 ++++++++++++----- .../mapboxsdk/testapp/style/layer.junit.ejs | 368 ++- .../src/main/AndroidManifest.xml | 11 + .../style/DataDrivenStyleActivity.java | 395 ++++ .../activity/style/RuntimeStyleActivity.java | 35 +- .../res/layout/activity_data_driven_style.xml | 12 + .../main/res/menu/menu_data_driven_style.xml | 50 + .../src/main/res/raw/amsterdam.geojson | 6 +- .../src/main/res/values/strings.xml | 2 + .../mapboxsdk/style/layers/FunctionTest.java | 10 +- .../android/scripts/generate-style-code.js | 13 +- .../android/src/style/conversion/function.hpp | 194 +- .../src/style/conversion/property_value.hpp | 65 +- 58 files changed, 7414 insertions(+), 5188 deletions(-) create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CameraFunction.java create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CompositeFunction.java create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/Function.java create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/SourceFunction.java create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/package-info.java create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/CategoricalStops.java create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/CompositeStops.java create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/ExponentialStops.java create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IdentityStops.java create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IntervalStops.java create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IterableStops.java create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stop.java create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stops.java create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/package-info.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Function.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LayoutProperty.java create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LayoutPropertyValue.java delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PaintProperty.java create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PaintPropertyValue.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerStyleTest.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerStyleTest.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerStyleTest.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerStyleTest.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerStyleTest.java delete mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerStyleTest.java create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/DataDrivenStyleActivity.java create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_data_driven_style.xml create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_data_driven_style.xml diff --git a/platform/android/MapboxGLAndroidSDK/gradle-checkstyle.gradle b/platform/android/MapboxGLAndroidSDK/gradle-checkstyle.gradle index bfb8341dbc9..05037c6be7b 100644 --- a/platform/android/MapboxGLAndroidSDK/gradle-checkstyle.gradle +++ b/platform/android/MapboxGLAndroidSDK/gradle-checkstyle.gradle @@ -12,6 +12,9 @@ task checkstyle(type: Checkstyle) { source 'src' include '**/*.java' exclude '**/gen/**' + exclude '**/style/layers/Property.java' + exclude '**/style/layers/PropertyFactory.java' + exclude '**/style/layers/*Layer.java' classpath = files() ignoreFailures = false } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CameraFunction.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CameraFunction.java new file mode 100644 index 00000000000..bb87fe8a397 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CameraFunction.java @@ -0,0 +1,50 @@ +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) + *

+ * 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 the input type + * @param the output type + * @see Function#zoom + */ +public class CameraFunction extends Function { + + /** + * Create an exponential camera function + * + * @param stops @see {@link com.mapbox.mapboxsdk.style.functions.stops.Stops#exponential(float, Stop[])} + */ + CameraFunction(@NonNull ExponentialStops stops) { + super(stops); + } + + /** + * Create an interval camera function + * + * @param stops @see {@link com.mapbox.mapboxsdk.style.functions.stops.Stops#interval(Stop[])} + */ + CameraFunction(@NonNull IntervalStops stops) { + super(stops); + } + + /** + * JNI constructor + */ + @Keep + private CameraFunction(Stops stops) { + super(stops); + } +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CompositeFunction.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CompositeFunction.java new file mode 100644 index 00000000000..49b4bab4010 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CompositeFunction.java @@ -0,0 +1,52 @@ +package com.mapbox.mapboxsdk.style.functions; + +import android.support.annotation.NonNull; + +import com.mapbox.mapboxsdk.style.functions.stops.CompositeStops; +import com.mapbox.mapboxsdk.style.functions.stops.Stops; + +import java.util.Map; + +/** + * Composite functions combine {@link android.graphics.Camera} and {@link SourceFunction}s. + *

+ * 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 the zoom type (usually Float) + * @param the input type (the feature property type) + * @param the output type (the property type) + * @see Function#composite + */ +public class CompositeFunction extends Function { + + private final String property; + + CompositeFunction(@NonNull String property, + @NonNull CompositeStops> stops) { + super(stops); + this.property = property; + } + + /** + * INTERNAL USAGE ONLY + * + * @return the feature property name + */ + public String getProperty() { + return property; + } + + /** + * {@inheritDoc} + */ + @Override + public Map toValueObject() { + Map valueObject = super.toValueObject(); + valueObject.put("property", property); + return valueObject; + } + +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/Function.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/Function.java new file mode 100644 index 00000000000..275f8b9ef7b --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/Function.java @@ -0,0 +1,298 @@ +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.CompositeStops; +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. + *

+ * 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 the function's input type + * @param the target property's value type. Make sure it matches. + * @see The style specification + */ +public class Function { + + /** + * Create an exponential {@link CameraFunction} + *

+ * 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 the zoom level type (Float, Integer) + * @param 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 CameraFunction zoom(@NonNull ExponentialStops stops) { + return new CameraFunction<>(stops); + } + + /** + * Create an interval {@link CameraFunction} + *

+ * 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 the zoom level type (Float, Integer) + * @param 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 CameraFunction zoom(@NonNull IntervalStops stops) { + return new CameraFunction<>(stops); + } + + /** + * Create an exponential {@link SourceFunction} + *

+ * 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 the function input type + * @param the function output type + * @return the {@link SourceFunction} + * @see SourceFunction + * @see ExponentialStops + * @see Stops#exponential(Stop[]) + * @see Stop#stop + */ + public static SourceFunction property(@NonNull String property, @NonNull ExponentialStops stops) { + return new SourceFunction<>(property, stops); + } + + /** + * Create an identity {@link SourceFunction} + *

+ * 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 the function input/output type + * @return the {@link SourceFunction} + * @see SourceFunction + * @see IdentityStops + * @see Stops#identity() + * @see Stop#stop + */ + public static SourceFunction property(@NonNull String property, @NonNull IdentityStops stops) { + return new SourceFunction<>(property, stops); + } + + /** + * Create an interval {@link SourceFunction} + *

+ * 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 the function input type + * @param the function output type + * @return the {@link SourceFunction} + * @see SourceFunction + * @see IntervalStops + * @see Stops#interval(Stop[]) + * @see Stop#stop + */ + public static SourceFunction property(@NonNull String property, @NonNull IntervalStops stops) { + return new SourceFunction<>(property, stops); + } + + /** + * Create an categorical {@link SourceFunction} + *

+ * 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 the function input type + * @param the function output type + * @return the {@link SourceFunction} + * @see SourceFunction + * @see CategoricalStops + * @see Stops#categorical(Stop[]) + * @see Stop#stop + */ + public static SourceFunction property(@NonNull String property, @NonNull CategoricalStops stops) { + return new SourceFunction<>(property, stops); + } + + /** + * Create a composite, categorical function. + *

+ * 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 the zoom function input type (Float usually) + * @param the function input type for the source part of the function + * @param the function output type + * @return the {@link CompositeFunction} + * @see CompositeFunction + * @see CategoricalStops + * @see Stops#categorical(Stop[]) + * @see Stop#stop + */ + public static CompositeFunction composite( + @NonNull String property, + @NonNull CategoricalStops, O> stops) { + + return new CompositeFunction<>(property, new CompositeStops<>(stops)); + } + + /** + * Create a composite, exponential function. + *

+ * 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 the zoom function input type (Float usually) + * @param the function input type for the source part of the function + * @param the function output type + * @return the {@link CompositeFunction} + * @see CompositeFunction + * @see ExponentialStops + * @see Stops#exponential(Stop[]) + * @see Stop#stop + */ + public static CompositeFunction composite( + @NonNull String property, + @NonNull ExponentialStops, O> stops) { + + return new CompositeFunction<>(property, new CompositeStops<>(stops)); + } + + /** + * Create a composite, interval function. + *

+ * 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 the zoom function input type (Float usually) + * @param the function input type for the source part of the function + * @param the function output type + * @return the {@link CompositeFunction} + * @see CompositeFunction + * @see IntervalStops + * @see Stops#interval(Stop[]) + * @see Stop#stop + */ + public static CompositeFunction composite( + @NonNull String property, + @NonNull IntervalStops, O> stops) { + + return new CompositeFunction<>(property, new CompositeStops<>(stops)); + } + + // Class definition // + + private final Stops stops; + + /** + * JNI Cosntructor for implementation classes + * + * @param stops the stops + */ + Function(@NonNull Stops stops) { + this.stops = stops; + } + + /** + * @return the stops in this function + */ + public Stops getStops() { + return stops; + } + + /** + * Convenience method + * + * @param the Stops implementation type + * @return the Stops implementation or null when the wrong type is specified + */ + @Nullable + public S getStopsAs() { + try { + // noinspection unchecked + return (S) stops; + } catch (ClassCastException exception) { + Timber.e(String.format("Stops: %s is a different type: %s", stops.getClass(), exception)); + return null; + } + } + + /** + * INTERNAL USAGE ONLY + * + * @return a value object representation for core conversion + */ + public Map toValueObject() { + return stops.toValueObject(); + } + + @Override + public String toString() { + return String.format("%s: %s", getClass().getSimpleName(), stops); + } +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/SourceFunction.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/SourceFunction.java new file mode 100644 index 00000000000..ea77fa77a75 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/SourceFunction.java @@ -0,0 +1,51 @@ +package com.mapbox.mapboxsdk.style.functions; + +import android.support.annotation.NonNull; + +import com.mapbox.mapboxsdk.style.functions.stops.Stops; + +import java.util.Map; + +/** + * Source functions take Feature property names as input. + *

+ * 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 the input type + * @param the output type + * @see Function#property + */ +public class SourceFunction extends Function { + + private final String property; + + SourceFunction(@NonNull String property, @NonNull Stops stops) { + super(stops); + this.property = property; + } + + /** + * INTERNAL USAGE ONLY + * + * @return The feature property name + */ + public String getProperty() { + return property; + } + + /** + * {@inheritDoc} + */ + @Override + public Map toValueObject() { + Map valueObject = super.toValueObject(); + valueObject.put("property", property); + return valueObject; + } +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/package-info.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/package-info.java new file mode 100644 index 00000000000..6979676c9ea --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/package-info.java @@ -0,0 +1,6 @@ +/** + * Contains the Mapbox Maps Android Style Function API classes. + * + * @see The style specification + */ +package com.mapbox.mapboxsdk.style.functions; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/CategoricalStops.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/CategoricalStops.java new file mode 100644 index 00000000000..7a0cd60c483 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/CategoricalStops.java @@ -0,0 +1,98 @@ +package com.mapbox.mapboxsdk.style.functions.stops; + +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.Size; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.Map; + +/** + * {@link Stops} implementation for categorical functions + * + * @param the {@link Stop} input type + * @param the {@link Stop} output type + */ +public class CategoricalStops extends IterableStops> { + + private final Stop[] stops; + private I defaultValue; + + /** + * Create a categorical {@link Stops} implementation. Use through {@link Stops#categorical(Stop[])} + * + * @param stops the stops + */ + @SafeVarargs + public CategoricalStops(@NonNull @Size(min = 1) Stop... stops) { + this(null, stops); + } + + /** + * Create a categorical {@link Stops} implementation. Use through {@link Stops#categorical(Stop[])} + * + * @param stops the stops + */ + @SafeVarargs + public CategoricalStops(I defaultValue, @NonNull @Size(min = 1) Stop... stops) { + this.defaultValue = defaultValue; + this.stops = stops; + } + + /** + * {@inheritDoc} + */ + @Override + public Map toValueObject() { + Map map = super.toValueObject(); + map.put("stops", toValueObjects(stops)); + if (defaultValue != null) { + map.put("defaultValue", defaultValue); + } + return map; + } + + /** + * {@inheritDoc} + */ + @Override + public String getTypeName() { + return "categorical"; + } + + /** + * {@inheritDoc} + */ + @Override + public Iterator> iterator() { + return Arrays.asList(stops).iterator(); + } + + /** + * {@inheritDoc} + */ + @Override + public int size() { + return stops.length; + } + + /** + * Set the default value + * + * @param defaultValue the default value to use when no other applies + * @return this (for chaining) + */ + public CategoricalStops withDefaultValue(I defaultValue) { + this.defaultValue = defaultValue; + return this; + } + + /** + * @return the default value or null + */ + @Nullable + public I getDefaultValue() { + return defaultValue; + } +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/CompositeStops.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/CompositeStops.java new file mode 100644 index 00000000000..7e2ce94fe1d --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/CompositeStops.java @@ -0,0 +1,151 @@ +package com.mapbox.mapboxsdk.style.functions.stops; + +import android.support.annotation.Keep; +import android.support.annotation.NonNull; +import android.support.annotation.Size; + +import com.mapbox.mapboxsdk.style.functions.stops.Stop.CompositeValue; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * The {@link Stops} implementation for composite functions + * + * @param the zoom type (usually Float) + * @param the input type (the feature property type) + * @param the output type (the property type) + * @param the {@link Stops} implementation (eg CategoricalStops, {@link ExponentialStops} or {@link IntervalStops}) + */ +public class CompositeStops>> + extends IterableStops, O, Map.Entry> { + + private final Map stops; + + /** + * JNI Constructor + * + * @param stops the stops {@link Map} + */ + @Keep + private CompositeStops(@NonNull @Size(min = 1) Map stops) { + this.stops = stops; + } + + /** + * Create composite stops for {@link ExponentialStops}. Use + * {@link com.mapbox.mapboxsdk.style.functions.Function#composite(String, ExponentialStops)} + * + * @param stops the stops + */ + public CompositeStops(@NonNull ExponentialStops, O> stops) { + this.stops = new HashMap<>(); + + for (Map.Entry>> entry : collect(stops).entrySet()) { + // noinspection unchecked + this.stops.put(entry.getKey(), + (S) new ExponentialStops<>(stops.getBase(), entry.getValue().toArray(new Stop[0]))); + } + } + + /** + * Create composite stops for {@link IntervalStops}. + * Use {@link com.mapbox.mapboxsdk.style.functions.Function#composite(String, IntervalStops)} + * + * @param stops the stops + */ + public CompositeStops(@NonNull IntervalStops, O> stops) { + this.stops = new HashMap<>(); + + for (Map.Entry>> entry : collect(stops).entrySet()) { + // noinspection unchecked + this.stops.put(entry.getKey(), (S) new IntervalStops<>(entry.getValue().toArray(new Stop[0]))); + } + } + + /** + * Create composite stops for {@link CategoricalStops}. + * Use {@link com.mapbox.mapboxsdk.style.functions.Function#composite(String, CategoricalStops)} + * + * @param stops the stops + */ + public CompositeStops(@NonNull CategoricalStops, O> stops) { + this.stops = new HashMap<>(); + + for (Map.Entry>> entry : collect(stops).entrySet()) { + // noinspection unchecked + this.stops.put(entry.getKey(), (S) new CategoricalStops<>(entry.getValue().toArray(new Stop[0]))); + } + } + + /** + * {@inheritDoc} + */ + @Override + protected String getTypeName() { + return stops.values().iterator().next().getTypeName(); + } + + /** + * {@inheritDoc} + */ + @Override + public Map toValueObject() { + Map map = super.toValueObject(); + + // Flatten and toValueObjects stops + // noinspection unchecked + map.put("stops", toValueObjects(flatten(this.stops).toArray(new Stop[0]))); + + return map; + } + + @NonNull + private List, O>> flatten(Map stops) { + List, O>> flattenedStops = new ArrayList<>(); + for (Map.Entry entry : stops.entrySet()) { + for (Stop stop : entry.getValue()) { + flattenedStops.add(new Stop<>(new CompositeValue<>(entry.getKey(), stop.in), stop.out)); + } + } + return flattenedStops; + } + + @NonNull + private Map>> collect( + @NonNull IterableStops, O, Stop, O>> stops) { + Map>> converted = new HashMap<>(); + + for (Stop, O> stop : stops) { + List> stopsForZ = converted.get(stop.in.zoom); + if (stopsForZ == null) { + stopsForZ = new ArrayList<>(); + converted.put(stop.in.zoom, stopsForZ); + } + + stopsForZ.add(new Stop<>(stop.in.value, stop.out)); + } + + return converted; + } + + /** + * {@inheritDoc} + */ + @Override + public Iterator> iterator() { + return stops.entrySet().iterator(); + } + + /** + * {@inheritDoc} + */ + @Override + public int size() { + return stops.size(); + } + +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/ExponentialStops.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/ExponentialStops.java new file mode 100644 index 00000000000..d47aa1fc914 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/ExponentialStops.java @@ -0,0 +1,97 @@ +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 the input type + * @param the output type + */ +public class ExponentialStops extends IterableStops> { + + private float base; + private final Stop[] 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... 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... stops) { + this(null, stops); + } + + /** + * Set the exponential base + * + * @param base the base to use in the exponential function + * @return this (for chaining) + */ + public ExponentialStops withBase(float base) { + this.base = base; + return this; + } + + /** + * @return The exponential base + */ + public float getBase() { + return base; + } + + /** + * {@inheritDoc} + */ + @Override + public Map toValueObject() { + Map 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> iterator() { + return Arrays.asList(stops).iterator(); + } + + /** + * {@inheritDoc} + */ + @Override + public int size() { + return stops.length; + } +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IdentityStops.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IdentityStops.java new file mode 100644 index 00000000000..2c0b198dc2f --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IdentityStops.java @@ -0,0 +1,18 @@ +package com.mapbox.mapboxsdk.style.functions.stops; + +/** + * The {@link Stops} implementation for identity functions + * + * @param the input/output type + */ +public class IdentityStops extends Stops { + + /** + * {@inheritDoc} + */ + @Override + protected String getTypeName() { + return "identity"; + } + +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IntervalStops.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IntervalStops.java new file mode 100644 index 00000000000..9d95b3f8c1a --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IntervalStops.java @@ -0,0 +1,58 @@ +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 the input type + * @param the output type + */ +public class IntervalStops extends IterableStops> { + + private final Stop[] stops; + + @SafeVarargs + public IntervalStops(@NonNull @Size(min = 1) Stop... stops) { + this.stops = stops; + } + + /** + * {@inheritDoc} + */ + @Override + public String getTypeName() { + return "interval"; + } + + /** + * {@inheritDoc} + */ + @Override + public Map toValueObject() { + Map map = super.toValueObject(); + map.put("stops", toValueObjects(stops)); + return map; + } + + /** + * @return an {@link Iterator} for the contained stops + */ + @Override + public Iterator> iterator() { + return Arrays.asList(stops).iterator(); + } + + /** + * @return The number of contained stops + */ + @Override + public int size() { + return stops.length; + } +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IterableStops.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IterableStops.java new file mode 100644 index 00000000000..8c5a6e89136 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/IterableStops.java @@ -0,0 +1,52 @@ +package com.mapbox.mapboxsdk.style.functions.stops; + +import java.util.Iterator; + +/** + * Base class for {@link Stops} implementations with a collection of stops + * + * @param the {@link Stops} input type + * @param the {@link Stops} output type + * @param the {@link Iterable} element type (usually {@link Stop}) + */ +public abstract class IterableStops extends Stops implements Iterable { + + /** + * @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[] 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 iterator = iterator(); + while (iterator.hasNext()) { + S stop = iterator.next(); + buffer.append(stop); + if (iterator.hasNext()) { + buffer.append(","); + } + } + return String.format("%s: [%s]", super.toString(), buffer.toString()); + } +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stop.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stop.java new file mode 100644 index 00000000000..80825ccf6d0 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stop.java @@ -0,0 +1,109 @@ +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 input the stop (function) input type + * @param output the stop (function) output type + * @see The style specification + */ +public class Stop { + /** + * 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 the input property type + * @param the output property type + * @return the {@link Stop} + */ + public static Stop stop(I in, PropertyValue 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 the zoom type + * @param the feature property input type + * @param the output property type + * @return the {@link Stop} + * @see Function#composite(String, ExponentialStops) + */ + public static Stop, O> stop(Z zoom, + I value, + PropertyValue 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 the zoom input type (typically Float) + * @param the feature property input type + */ + public static class CompositeValue { + Z zoom; + 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 toValueObject() { + HashMap map = new HashMap<>(); + map.put("zoom", zoom); + map.put("value", value); + return map; + } + + @Override + public String toString() { + return String.format("[zoom: %s, value: %s]", zoom, value); + } + } + + /** + * The input type + */ + public final I in; + + /** + * The output type + */ + public final O out; + + Stop(I in, O out) { + this.in = in; + this.out = out; + } + + /** + * INTERNAL USAGE ONLY + * + * @return an array representation of the Stop + */ + Object[] toValueObject() { + return new Object[] {in instanceof CompositeValue ? ((CompositeValue) in).toValueObject() : in, out}; + } + + @Override + public String toString() { + return String.format("[%s, %s]", in, out); + } +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stops.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stops.java new file mode 100644 index 00000000000..a9d8055084b --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/Stops.java @@ -0,0 +1,97 @@ +package com.mapbox.mapboxsdk.style.functions.stops; + +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 the input type + * @param the output type + * @see The style specification + */ +public abstract class Stops { + + /** + * Convenience method for use in function declarations + * + * @param stops the collections of discrete stops + * @param the Stops input type + * @param the Stops output type + * @return the {@link Stops} implementation + * @see Stop#stop + * @see CategoricalStops + */ + @SafeVarargs + public static CategoricalStops categorical(@NonNull @Size(min = 1) Stop... stops) { + return new CategoricalStops<>(stops); + } + + /** + * Convenience method for use in function declarations + * + * @param stops the collections of discrete stops + * @param the Stops input type + * @param the Stops output type + * @return the {@link Stops} implementation + * @see Stop#stop + * @see ExponentialStops + */ + @SafeVarargs + public static ExponentialStops exponential(@NonNull @Size(min = 1) Stop... stops) { + return new ExponentialStops<>(stops); + } + + /** + * Convenience method for use in function declarations + * + * @param the Stops input/output type + * @return the {@link IdentityStops} implementation + * @see Stop#stop + * @see IdentityStops + */ + public static IdentityStops identity() { + return new IdentityStops<>(); + } + + /** + * Convenience method for use in function declarations + * + * @param stops the collections of discrete stops + * @param the Stops input type + * @param the Stops output type + * @return the {@link Stops} implementation + * @see Stop#stop + * @see IntervalStops + */ + @SafeVarargs + public static IntervalStops interval(@NonNull @Size(min = 1) Stop... stops) { + return new IntervalStops<>(stops); + } + + /** + * INTERNAL USAGE ONLY + * + * @return the value object representation for conversion to core + */ + public Map toValueObject() { + HashMap map = new HashMap<>(); + map.put("type", getTypeName()); + return map; + } + + /** + * INTERNAL USAGE ONLY + * + * @return the unique type name as a string according to the style specification + */ + protected abstract String getTypeName(); + + @Override + public String toString() { + return getTypeName(); + } +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/package-info.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/package-info.java new file mode 100644 index 00000000000..fa388a9589f --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/stops/package-info.java @@ -0,0 +1,6 @@ +/** + * Contains the Mapbox Maps Android Style Function Stop implementation API classes. + * + * @see The style specification + */ +package com.mapbox.mapboxsdk.style.functions.stops; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java index 45523b41abe..0f1265f1a16 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java @@ -1,6 +1,7 @@ -package com.mapbox.mapboxsdk.style.layers; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.style.layers; + import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.UiThread; @@ -41,7 +42,7 @@ public BackgroundLayer(String layerId) { * @param properties the var-args properties * @return This */ - public BackgroundLayer withProperties(@NonNull Property... properties) { + public BackgroundLayer withProperties(@NonNull PropertyValue... properties) { setProperties(properties); return this; } @@ -55,7 +56,7 @@ public BackgroundLayer withProperties(@NonNull Property... properties) { */ @SuppressWarnings("unchecked") public PropertyValue getBackgroundColor() { - return (PropertyValue) new PropertyValue(nativeGetBackgroundColor()); + return (PropertyValue) new PropertyValue("background-color", nativeGetBackgroundColor()); } /** @@ -82,7 +83,7 @@ public int getBackgroundColorAsInt() { */ @SuppressWarnings("unchecked") public PropertyValue getBackgroundPattern() { - return (PropertyValue) new PropertyValue(nativeGetBackgroundPattern()); + return (PropertyValue) new PropertyValue("background-pattern", nativeGetBackgroundPattern()); } /** @@ -92,7 +93,7 @@ public PropertyValue getBackgroundPattern() { */ @SuppressWarnings("unchecked") public PropertyValue getBackgroundOpacity() { - return (PropertyValue) new PropertyValue(nativeGetBackgroundOpacity()); + return (PropertyValue) new PropertyValue("background-opacity", nativeGetBackgroundOpacity()); } private native Object nativeGetBackgroundColor(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java index f16ab688d64..81ac67dfaf3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java @@ -1,6 +1,7 @@ -package com.mapbox.mapboxsdk.style.layers; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.style.layers; + import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.UiThread; @@ -96,14 +97,13 @@ public CircleLayer withFilter(Filter.Statement filter) { return this; } - /** * Set a property or properties. * * @param properties the var-args properties * @return This */ - public CircleLayer withProperties(@NonNull Property... properties) { + public CircleLayer withProperties(@NonNull PropertyValue... properties) { setProperties(properties); return this; } @@ -117,7 +117,7 @@ public CircleLayer withProperties(@NonNull Property... properties) { */ @SuppressWarnings("unchecked") public PropertyValue getCircleRadius() { - return (PropertyValue) new PropertyValue(nativeGetCircleRadius()); + return (PropertyValue) new PropertyValue("circle-radius", nativeGetCircleRadius()); } /** @@ -127,7 +127,7 @@ public PropertyValue getCircleRadius() { */ @SuppressWarnings("unchecked") public PropertyValue getCircleColor() { - return (PropertyValue) new PropertyValue(nativeGetCircleColor()); + return (PropertyValue) new PropertyValue("circle-color", nativeGetCircleColor()); } /** @@ -154,7 +154,7 @@ public int getCircleColorAsInt() { */ @SuppressWarnings("unchecked") public PropertyValue getCircleBlur() { - return (PropertyValue) new PropertyValue(nativeGetCircleBlur()); + return (PropertyValue) new PropertyValue("circle-blur", nativeGetCircleBlur()); } /** @@ -164,7 +164,7 @@ public PropertyValue getCircleBlur() { */ @SuppressWarnings("unchecked") public PropertyValue getCircleOpacity() { - return (PropertyValue) new PropertyValue(nativeGetCircleOpacity()); + return (PropertyValue) new PropertyValue("circle-opacity", nativeGetCircleOpacity()); } /** @@ -174,7 +174,7 @@ public PropertyValue getCircleOpacity() { */ @SuppressWarnings("unchecked") public PropertyValue getCircleTranslate() { - return (PropertyValue) new PropertyValue(nativeGetCircleTranslate()); + return (PropertyValue) new PropertyValue("circle-translate", nativeGetCircleTranslate()); } /** @@ -184,7 +184,7 @@ public PropertyValue getCircleTranslate() { */ @SuppressWarnings("unchecked") public PropertyValue getCircleTranslateAnchor() { - return (PropertyValue) new PropertyValue(nativeGetCircleTranslateAnchor()); + return (PropertyValue) new PropertyValue("circle-translate-anchor", nativeGetCircleTranslateAnchor()); } /** @@ -194,7 +194,7 @@ public PropertyValue getCircleTranslateAnchor() { */ @SuppressWarnings("unchecked") public PropertyValue getCirclePitchScale() { - return (PropertyValue) new PropertyValue(nativeGetCirclePitchScale()); + return (PropertyValue) new PropertyValue("circle-pitch-scale", nativeGetCirclePitchScale()); } /** @@ -204,7 +204,7 @@ public PropertyValue getCirclePitchScale() { */ @SuppressWarnings("unchecked") public PropertyValue getCircleStrokeWidth() { - return (PropertyValue) new PropertyValue(nativeGetCircleStrokeWidth()); + return (PropertyValue) new PropertyValue("circle-stroke-width", nativeGetCircleStrokeWidth()); } /** @@ -214,7 +214,7 @@ public PropertyValue getCircleStrokeWidth() { */ @SuppressWarnings("unchecked") public PropertyValue getCircleStrokeColor() { - return (PropertyValue) new PropertyValue(nativeGetCircleStrokeColor()); + return (PropertyValue) new PropertyValue("circle-stroke-color", nativeGetCircleStrokeColor()); } /** @@ -241,7 +241,7 @@ public int getCircleStrokeColorAsInt() { */ @SuppressWarnings("unchecked") public PropertyValue getCircleStrokeOpacity() { - return (PropertyValue) new PropertyValue(nativeGetCircleStrokeOpacity()); + return (PropertyValue) new PropertyValue("circle-stroke-opacity", nativeGetCircleStrokeOpacity()); } private native Object nativeGetCircleRadius(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java index 3f79c9306a2..7a5eb7673ba 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java @@ -1,6 +1,7 @@ -package com.mapbox.mapboxsdk.style.layers; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.style.layers; + import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.UiThread; @@ -96,14 +97,13 @@ public FillLayer withFilter(Filter.Statement filter) { return this; } - /** * Set a property or properties. * * @param properties the var-args properties * @return This */ - public FillLayer withProperties(@NonNull Property... properties) { + public FillLayer withProperties(@NonNull PropertyValue... properties) { setProperties(properties); return this; } @@ -117,7 +117,7 @@ public FillLayer withProperties(@NonNull Property... properties) { */ @SuppressWarnings("unchecked") public PropertyValue getFillAntialias() { - return (PropertyValue) new PropertyValue(nativeGetFillAntialias()); + return (PropertyValue) new PropertyValue("fill-antialias", nativeGetFillAntialias()); } /** @@ -127,7 +127,7 @@ public PropertyValue getFillAntialias() { */ @SuppressWarnings("unchecked") public PropertyValue getFillOpacity() { - return (PropertyValue) new PropertyValue(nativeGetFillOpacity()); + return (PropertyValue) new PropertyValue("fill-opacity", nativeGetFillOpacity()); } /** @@ -137,12 +137,11 @@ public PropertyValue getFillOpacity() { */ @SuppressWarnings("unchecked") public PropertyValue getFillColor() { - return (PropertyValue) new PropertyValue(nativeGetFillColor()); + return (PropertyValue) new PropertyValue("fill-color", nativeGetFillColor()); } /** - * The color of the filled part of this layer. This color can be specified as `rgba` with an alpha component and the - * color's opacity will not affect the opacity of the 1px stroke, if it is used. + * The color of the filled part of this layer. This color can be specified as `rgba` with an alpha component and the color's opacity will not affect the opacity of the 1px stroke, if it is used. * * @return int representation of a rgba string color * @throws RuntimeException thrown if property isn't a value @@ -165,7 +164,7 @@ public int getFillColorAsInt() { */ @SuppressWarnings("unchecked") public PropertyValue getFillOutlineColor() { - return (PropertyValue) new PropertyValue(nativeGetFillOutlineColor()); + return (PropertyValue) new PropertyValue("fill-outline-color", nativeGetFillOutlineColor()); } /** @@ -192,7 +191,7 @@ public int getFillOutlineColorAsInt() { */ @SuppressWarnings("unchecked") public PropertyValue getFillTranslate() { - return (PropertyValue) new PropertyValue(nativeGetFillTranslate()); + return (PropertyValue) new PropertyValue("fill-translate", nativeGetFillTranslate()); } /** @@ -202,7 +201,7 @@ public PropertyValue getFillTranslate() { */ @SuppressWarnings("unchecked") public PropertyValue getFillTranslateAnchor() { - return (PropertyValue) new PropertyValue(nativeGetFillTranslateAnchor()); + return (PropertyValue) new PropertyValue("fill-translate-anchor", nativeGetFillTranslateAnchor()); } /** @@ -212,7 +211,7 @@ public PropertyValue getFillTranslateAnchor() { */ @SuppressWarnings("unchecked") public PropertyValue getFillPattern() { - return (PropertyValue) new PropertyValue(nativeGetFillPattern()); + return (PropertyValue) new PropertyValue("fill-pattern", nativeGetFillPattern()); } private native Object nativeGetFillAntialias(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Function.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Function.java deleted file mode 100644 index 900fe10476b..00000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Function.java +++ /dev/null @@ -1,137 +0,0 @@ -package com.mapbox.mapboxsdk.style.layers; - -import android.support.annotation.FloatRange; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.annotation.Size; - -import java.util.HashMap; -import java.util.Map; - -/** - * Functions are used to change properties in relation to the state of the map. - *

- * Currently, only zoom functions are supported. - *

- * - * @param the target property's value type. Make sure it matches. - * @see The online documentation - */ -public class Function { - - /** - * A stop represents a certain point in the range of this function - * - * @param input - * @param output - */ - public static class Stop { - public final I in; - public final O out; - - Stop(I in, O out) { - this.in = in; - this.out = out; - } - - /** - * @return an array representation of the Stop - */ - Object[] toValueObject() { - return new Object[] {in, out}; - } - - @Override - public String toString() { - return String.format("[%s, %s]", in, out); - } - } - - /** - * 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 stops the stops that define the function - * @param the property type - * @return the {@link Function} - */ - @SafeVarargs - public static Function zoom(@NonNull @Size(min = 1) Stop... stops) { - return new Function(stops); - } - - - /** - * 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 stops the stops that define the function - * @param base the exponential base of the interpolation curve - Default 1 - * @param the property type - * @return the {@link Function} - */ - @SafeVarargs - public static Function zoom( - @FloatRange(from = 0, to = 1, fromInclusive = false, toInclusive = false) float base, - @NonNull @Size(min = 1) Stop... stops) { - return new Function(stops) - .withBase(base); - } - - /** - * Creates a stop to use in a {@link Function} - * - * @param in the input for the stop - * @param output the output for the stop - * @param the output property type - * @return the {@link Stop} - */ - public static Stop stop(float in, Property output) { - return new Stop<>(in, output.value); - } - - private final Stop[] stops; - private Float base; - - Function(@NonNull @Size(min = 1) Stop[] stops) { - this.stops = stops; - } - - Function withBase(float base) { - this.base = base; - return this; - } - - /** - * @return the base - */ - @Nullable - public Float getBase() { - return base; - } - - /** - * @return the stops in this function - */ - public Stop[] getStops() { - return stops; - } - - Map toValueObject() { - Object[] stopsValue = new Object[stops.length]; - - for (int i = 0; i < stopsValue.length; i++) { - Stop stop = stops[i]; - stopsValue[i] = stop.toValueObject(); - } - - Map value = new HashMap<>(); - if (base != null) { - value.put("base", base); - } - value.put("stops", stopsValue); - return value; - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java index 2878d76430e..b4120f4f9ad 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java @@ -2,6 +2,8 @@ import android.support.annotation.NonNull; +import com.mapbox.mapboxsdk.style.functions.Function; + /** * Base class for the different Layer types */ @@ -17,14 +19,14 @@ public Layer(long nativePtr) { public Layer() { } - public void setProperties(@NonNull Property... properties) { + public void setProperties(@NonNull PropertyValue... properties) { if (properties.length == 0) { return; } - for (Property property : properties) { + for (PropertyValue property : properties) { Object converted = convertValue(property.value); - if (property instanceof PaintProperty) { + if (property instanceof PaintPropertyValue) { nativeSetPaintProperty(property.name, converted); } else { nativeSetLayoutProperty(property.name, converted); @@ -37,7 +39,7 @@ public String getId() { } public PropertyValue getVisibility() { - return new PropertyValue<>(nativeGetVisibility()); + return new PaintPropertyValue<>("visibility", (String) nativeGetVisibility()); } public float getMinZoom() { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LayoutProperty.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LayoutProperty.java deleted file mode 100644 index 4c0b52be55f..00000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LayoutProperty.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.mapbox.mapboxsdk.style.layers; - -class LayoutProperty extends Property { - - LayoutProperty(String name, T value) { - super(name, value); - } - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LayoutPropertyValue.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LayoutPropertyValue.java new file mode 100644 index 00000000000..ed88a859125 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LayoutPropertyValue.java @@ -0,0 +1,11 @@ +package com.mapbox.mapboxsdk.style.layers; + +import android.support.annotation.NonNull; + +class LayoutPropertyValue extends PropertyValue { + + LayoutPropertyValue(@NonNull String name, T value) { + super(name, value); + } + +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java index 4c52a40b051..0e028d48909 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java @@ -1,6 +1,7 @@ -package com.mapbox.mapboxsdk.style.layers; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.style.layers; + import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.UiThread; @@ -96,14 +97,13 @@ public LineLayer withFilter(Filter.Statement filter) { return this; } - /** * Set a property or properties. * * @param properties the var-args properties * @return This */ - public LineLayer withProperties(@NonNull Property... properties) { + public LineLayer withProperties(@NonNull PropertyValue... properties) { setProperties(properties); return this; } @@ -117,7 +117,7 @@ public LineLayer withProperties(@NonNull Property... properties) { */ @SuppressWarnings("unchecked") public PropertyValue getLineCap() { - return (PropertyValue) new PropertyValue(nativeGetLineCap()); + return (PropertyValue) new PropertyValue("line-cap", nativeGetLineCap()); } /** @@ -127,7 +127,7 @@ public PropertyValue getLineCap() { */ @SuppressWarnings("unchecked") public PropertyValue getLineJoin() { - return (PropertyValue) new PropertyValue(nativeGetLineJoin()); + return (PropertyValue) new PropertyValue("line-join", nativeGetLineJoin()); } /** @@ -137,7 +137,7 @@ public PropertyValue getLineJoin() { */ @SuppressWarnings("unchecked") public PropertyValue getLineMiterLimit() { - return (PropertyValue) new PropertyValue(nativeGetLineMiterLimit()); + return (PropertyValue) new PropertyValue("line-miter-limit", nativeGetLineMiterLimit()); } /** @@ -147,7 +147,7 @@ public PropertyValue getLineMiterLimit() { */ @SuppressWarnings("unchecked") public PropertyValue getLineRoundLimit() { - return (PropertyValue) new PropertyValue(nativeGetLineRoundLimit()); + return (PropertyValue) new PropertyValue("line-round-limit", nativeGetLineRoundLimit()); } /** @@ -157,7 +157,7 @@ public PropertyValue getLineRoundLimit() { */ @SuppressWarnings("unchecked") public PropertyValue getLineOpacity() { - return (PropertyValue) new PropertyValue(nativeGetLineOpacity()); + return (PropertyValue) new PropertyValue("line-opacity", nativeGetLineOpacity()); } /** @@ -167,7 +167,7 @@ public PropertyValue getLineOpacity() { */ @SuppressWarnings("unchecked") public PropertyValue getLineColor() { - return (PropertyValue) new PropertyValue(nativeGetLineColor()); + return (PropertyValue) new PropertyValue("line-color", nativeGetLineColor()); } /** @@ -194,7 +194,7 @@ public int getLineColorAsInt() { */ @SuppressWarnings("unchecked") public PropertyValue getLineTranslate() { - return (PropertyValue) new PropertyValue(nativeGetLineTranslate()); + return (PropertyValue) new PropertyValue("line-translate", nativeGetLineTranslate()); } /** @@ -204,7 +204,7 @@ public PropertyValue getLineTranslate() { */ @SuppressWarnings("unchecked") public PropertyValue getLineTranslateAnchor() { - return (PropertyValue) new PropertyValue(nativeGetLineTranslateAnchor()); + return (PropertyValue) new PropertyValue("line-translate-anchor", nativeGetLineTranslateAnchor()); } /** @@ -214,7 +214,7 @@ public PropertyValue getLineTranslateAnchor() { */ @SuppressWarnings("unchecked") public PropertyValue getLineWidth() { - return (PropertyValue) new PropertyValue(nativeGetLineWidth()); + return (PropertyValue) new PropertyValue("line-width", nativeGetLineWidth()); } /** @@ -224,7 +224,7 @@ public PropertyValue getLineWidth() { */ @SuppressWarnings("unchecked") public PropertyValue getLineGapWidth() { - return (PropertyValue) new PropertyValue(nativeGetLineGapWidth()); + return (PropertyValue) new PropertyValue("line-gap-width", nativeGetLineGapWidth()); } /** @@ -234,7 +234,7 @@ public PropertyValue getLineGapWidth() { */ @SuppressWarnings("unchecked") public PropertyValue getLineOffset() { - return (PropertyValue) new PropertyValue(nativeGetLineOffset()); + return (PropertyValue) new PropertyValue("line-offset", nativeGetLineOffset()); } /** @@ -244,7 +244,7 @@ public PropertyValue getLineOffset() { */ @SuppressWarnings("unchecked") public PropertyValue getLineBlur() { - return (PropertyValue) new PropertyValue(nativeGetLineBlur()); + return (PropertyValue) new PropertyValue("line-blur", nativeGetLineBlur()); } /** @@ -254,7 +254,7 @@ public PropertyValue getLineBlur() { */ @SuppressWarnings("unchecked") public PropertyValue getLineDasharray() { - return (PropertyValue) new PropertyValue(nativeGetLineDasharray()); + return (PropertyValue) new PropertyValue("line-dasharray", nativeGetLineDasharray()); } /** @@ -264,7 +264,7 @@ public PropertyValue getLineDasharray() { */ @SuppressWarnings("unchecked") public PropertyValue getLinePattern() { - return (PropertyValue) new PropertyValue(nativeGetLinePattern()); + return (PropertyValue) new PropertyValue("line-pattern", nativeGetLinePattern()); } private native Object nativeGetLineCap(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PaintProperty.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PaintProperty.java deleted file mode 100644 index 69405177d95..00000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PaintProperty.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.mapbox.mapboxsdk.style.layers; - -class PaintProperty extends Property { - - PaintProperty(String name, T value) { - super(name, value); - } - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PaintPropertyValue.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PaintPropertyValue.java new file mode 100644 index 00000000000..e6ac2d97630 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PaintPropertyValue.java @@ -0,0 +1,11 @@ +package com.mapbox.mapboxsdk.style.layers; + +import android.support.annotation.NonNull; + +class PaintPropertyValue extends PropertyValue { + + PaintPropertyValue(@NonNull String name, T value) { + super(name, value); + } + +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java index d298b62392c..641ee551a20 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java @@ -1,6 +1,7 @@ -package com.mapbox.mapboxsdk.style.layers; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.style.layers; + import android.support.annotation.StringDef; import java.lang.annotation.Retention; @@ -9,7 +10,7 @@ /** * Paint/Layout properties for Layer */ -public abstract class Property { +public final class Property { // VISIBILITY: Whether this layer is displayed. @@ -22,13 +23,12 @@ public abstract class Property { */ public static final String NONE = "none"; - @StringDef( { - VISIBLE, - NONE + @StringDef({ + VISIBLE, + NONE }) @Retention(RetentionPolicy.SOURCE) - public @interface VISIBILITY { - } + public @interface VISIBILITY {} // LINE_CAP: The display of line endings. @@ -37,57 +37,50 @@ public abstract class Property { */ public static final String LINE_CAP_BUTT = "butt"; /** - * A cap with a rounded end which is drawn beyond the endpoint of the line at a radius of one-half of the line's - * width and centered on the endpoint of the line. + * A cap with a rounded end which is drawn beyond the endpoint of the line at a radius of one-half of the line's width and centered on the endpoint of the line. */ public static final String LINE_CAP_ROUND = "round"; /** - * A cap with a squared-off end which is drawn beyond the endpoint of the line at a distance of one-half of the - * line's width. + * A cap with a squared-off end which is drawn beyond the endpoint of the line at a distance of one-half of the line's width. */ public static final String LINE_CAP_SQUARE = "square"; /** * The display of line endings. */ - @StringDef( { - LINE_CAP_BUTT, - LINE_CAP_ROUND, - LINE_CAP_SQUARE, - }) + @StringDef({ + LINE_CAP_BUTT, + LINE_CAP_ROUND, + LINE_CAP_SQUARE, + }) @Retention(RetentionPolicy.SOURCE) - public @interface LINE_CAP { - } + public @interface LINE_CAP {} // LINE_JOIN: The display of lines when joining. /** - * A join with a squared-off end which is drawn beyond the endpoint of the line at a distance of one-half of the - * line's width. + * A join with a squared-off end which is drawn beyond the endpoint of the line at a distance of one-half of the line's width. */ public static final String LINE_JOIN_BEVEL = "bevel"; /** - * A join with a rounded end which is drawn beyond the endpoint of the line at a radius of one-half of the line's - * width and centered on the endpoint of the line. + * A join with a rounded end which is drawn beyond the endpoint of the line at a radius of one-half of the line's width and centered on the endpoint of the line. */ public static final String LINE_JOIN_ROUND = "round"; /** - * A join with a sharp, angled corner which is drawn with the outer sides beyond the endpoint of the path until - * they meet. + * A join with a sharp, angled corner which is drawn with the outer sides beyond the endpoint of the path until they meet. */ public static final String LINE_JOIN_MITER = "miter"; /** * The display of lines when joining. */ - @StringDef( { - LINE_JOIN_BEVEL, - LINE_JOIN_ROUND, - LINE_JOIN_MITER, - }) + @StringDef({ + LINE_JOIN_BEVEL, + LINE_JOIN_ROUND, + LINE_JOIN_MITER, + }) @Retention(RetentionPolicy.SOURCE) - public @interface LINE_JOIN { - } + public @interface LINE_JOIN {} // SYMBOL_PLACEMENT: Label placement relative to its geometry. @@ -103,44 +96,38 @@ public abstract class Property { /** * Label placement relative to its geometry. */ - @StringDef( { - SYMBOL_PLACEMENT_POINT, - SYMBOL_PLACEMENT_LINE, - }) + @StringDef({ + SYMBOL_PLACEMENT_POINT, + SYMBOL_PLACEMENT_LINE, + }) @Retention(RetentionPolicy.SOURCE) - public @interface SYMBOL_PLACEMENT { - } + public @interface SYMBOL_PLACEMENT {} // ICON_ROTATION_ALIGNMENT: In combination with `symbol-placement`, determines the rotation behavior of icons. /** - * When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_POINT}, aligns icons east-west. When - * {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_LINE}, aligns icon x-axes with the line. + * When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_POINT}, aligns icons east-west. When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_LINE}, aligns icon x-axes with the line. */ public static final String ICON_ROTATION_ALIGNMENT_MAP = "map"; /** - * Produces icons whose x-axes are aligned with the x-axis of the viewport, regardless of the value of - * {@link SYMBOL_PLACEMENT}. + * Produces icons whose x-axes are aligned with the x-axis of the viewport, regardless of the value of {@link SYMBOL_PLACEMENT}. */ public static final String ICON_ROTATION_ALIGNMENT_VIEWPORT = "viewport"; /** - * When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_POINT}, this is equivalent to - * {@link Property#ICON_ROTATION_ALIGNMENT_VIEWPORT}. When {@link SYMBOL_PLACEMENT} is set to - * {@link Property#SYMBOL_PLACEMENT_LINE}, this is equivalent to {@link Property#ICON_ROTATION_ALIGNMENT_MAP}. + * When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_POINT}, this is equivalent to {@link Property#ICON_ROTATION_ALIGNMENT_VIEWPORT}. When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_LINE}, this is equivalent to {@link Property#ICON_ROTATION_ALIGNMENT_MAP}. */ public static final String ICON_ROTATION_ALIGNMENT_AUTO = "auto"; /** * In combination with `symbol-placement`, determines the rotation behavior of icons. */ - @StringDef( { - ICON_ROTATION_ALIGNMENT_MAP, - ICON_ROTATION_ALIGNMENT_VIEWPORT, - ICON_ROTATION_ALIGNMENT_AUTO, - }) + @StringDef({ + ICON_ROTATION_ALIGNMENT_MAP, + ICON_ROTATION_ALIGNMENT_VIEWPORT, + ICON_ROTATION_ALIGNMENT_AUTO, + }) @Retention(RetentionPolicy.SOURCE) - public @interface ICON_ROTATION_ALIGNMENT { - } + public @interface ICON_ROTATION_ALIGNMENT {} // ICON_TEXT_FIT: Scales the icon to fit around the associated text. @@ -164,15 +151,14 @@ public abstract class Property { /** * Scales the icon to fit around the associated text. */ - @StringDef( { - ICON_TEXT_FIT_NONE, - ICON_TEXT_FIT_WIDTH, - ICON_TEXT_FIT_HEIGHT, - ICON_TEXT_FIT_BOTH, - }) + @StringDef({ + ICON_TEXT_FIT_NONE, + ICON_TEXT_FIT_WIDTH, + ICON_TEXT_FIT_HEIGHT, + ICON_TEXT_FIT_BOTH, + }) @Retention(RetentionPolicy.SOURCE) - public @interface ICON_TEXT_FIT { - } + public @interface ICON_TEXT_FIT {} // TEXT_PITCH_ALIGNMENT: Orientation of text when map is pitched. @@ -192,46 +178,39 @@ public abstract class Property { /** * Orientation of text when map is pitched. */ - @StringDef( { - TEXT_PITCH_ALIGNMENT_MAP, - TEXT_PITCH_ALIGNMENT_VIEWPORT, - TEXT_PITCH_ALIGNMENT_AUTO, - }) + @StringDef({ + TEXT_PITCH_ALIGNMENT_MAP, + TEXT_PITCH_ALIGNMENT_VIEWPORT, + TEXT_PITCH_ALIGNMENT_AUTO, + }) @Retention(RetentionPolicy.SOURCE) - public @interface TEXT_PITCH_ALIGNMENT { - } + public @interface TEXT_PITCH_ALIGNMENT {} - // TEXT_ROTATION_ALIGNMENT: In combination with `symbol-placement`, determines the rotation behavior of the individual - // glyphs forming the text. + // TEXT_ROTATION_ALIGNMENT: In combination with `symbol-placement`, determines the rotation behavior of the individual glyphs forming the text. /** - * When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_POINT}, aligns text east-west. When - * {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_LINE}, aligns text x-axes with the line. + * When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_POINT}, aligns text east-west. When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_LINE}, aligns text x-axes with the line. */ public static final String TEXT_ROTATION_ALIGNMENT_MAP = "map"; /** - * Produces glyphs whose x-axes are aligned with the x-axis of the viewport, regardless of the value of - * {@link SYMBOL_PLACEMENT}. + * Produces glyphs whose x-axes are aligned with the x-axis of the viewport, regardless of the value of {@link SYMBOL_PLACEMENT}. */ public static final String TEXT_ROTATION_ALIGNMENT_VIEWPORT = "viewport"; /** - * When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_POINT}, this is equivalent to - * {@link Property#TEXT_ROTATION_ALIGNMENT_VIEWPORT}. When {@link SYMBOL_PLACEMENT} is set to - * {@link Property#SYMBOL_PLACEMENT_LINE}, this is equivalent to {@link Property#TEXT_ROTATION_ALIGNMENT_MAP}. + * When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_POINT}, this is equivalent to {@link Property#TEXT_ROTATION_ALIGNMENT_VIEWPORT}. When {@link SYMBOL_PLACEMENT} is set to {@link Property#SYMBOL_PLACEMENT_LINE}, this is equivalent to {@link Property#TEXT_ROTATION_ALIGNMENT_MAP}. */ public static final String TEXT_ROTATION_ALIGNMENT_AUTO = "auto"; /** * In combination with `symbol-placement`, determines the rotation behavior of the individual glyphs forming the text. */ - @StringDef( { - TEXT_ROTATION_ALIGNMENT_MAP, - TEXT_ROTATION_ALIGNMENT_VIEWPORT, - TEXT_ROTATION_ALIGNMENT_AUTO, - }) + @StringDef({ + TEXT_ROTATION_ALIGNMENT_MAP, + TEXT_ROTATION_ALIGNMENT_VIEWPORT, + TEXT_ROTATION_ALIGNMENT_AUTO, + }) @Retention(RetentionPolicy.SOURCE) - public @interface TEXT_ROTATION_ALIGNMENT { - } + public @interface TEXT_ROTATION_ALIGNMENT {} // TEXT_JUSTIFY: Text justification options. @@ -251,14 +230,13 @@ public abstract class Property { /** * Text justification options. */ - @StringDef( { - TEXT_JUSTIFY_LEFT, - TEXT_JUSTIFY_CENTER, - TEXT_JUSTIFY_RIGHT, - }) + @StringDef({ + TEXT_JUSTIFY_LEFT, + TEXT_JUSTIFY_CENTER, + TEXT_JUSTIFY_RIGHT, + }) @Retention(RetentionPolicy.SOURCE) - public @interface TEXT_JUSTIFY { - } + public @interface TEXT_JUSTIFY {} // TEXT_ANCHOR: Part of the text placed closest to the anchor. @@ -302,20 +280,19 @@ public abstract class Property { /** * Part of the text placed closest to the anchor. */ - @StringDef( { - TEXT_ANCHOR_CENTER, - TEXT_ANCHOR_LEFT, - TEXT_ANCHOR_RIGHT, - TEXT_ANCHOR_TOP, - TEXT_ANCHOR_BOTTOM, - TEXT_ANCHOR_TOP_LEFT, - TEXT_ANCHOR_TOP_RIGHT, - TEXT_ANCHOR_BOTTOM_LEFT, - TEXT_ANCHOR_BOTTOM_RIGHT, - }) + @StringDef({ + TEXT_ANCHOR_CENTER, + TEXT_ANCHOR_LEFT, + TEXT_ANCHOR_RIGHT, + TEXT_ANCHOR_TOP, + TEXT_ANCHOR_BOTTOM, + TEXT_ANCHOR_TOP_LEFT, + TEXT_ANCHOR_TOP_RIGHT, + TEXT_ANCHOR_BOTTOM_LEFT, + TEXT_ANCHOR_BOTTOM_RIGHT, + }) @Retention(RetentionPolicy.SOURCE) - public @interface TEXT_ANCHOR { - } + public @interface TEXT_ANCHOR {} // TEXT_TRANSFORM: Specifies how to capitalize text, similar to the CSS `text-transform` property. @@ -335,14 +312,13 @@ public abstract class Property { /** * Specifies how to capitalize text, similar to the CSS `text-transform` property. */ - @StringDef( { - TEXT_TRANSFORM_NONE, - TEXT_TRANSFORM_UPPERCASE, - TEXT_TRANSFORM_LOWERCASE, - }) + @StringDef({ + TEXT_TRANSFORM_NONE, + TEXT_TRANSFORM_UPPERCASE, + TEXT_TRANSFORM_LOWERCASE, + }) @Retention(RetentionPolicy.SOURCE) - public @interface TEXT_TRANSFORM { - } + public @interface TEXT_TRANSFORM {} // FILL_TRANSLATE_ANCHOR: Controls the translation reference point. @@ -358,13 +334,12 @@ public abstract class Property { /** * Controls the translation reference point. */ - @StringDef( { - FILL_TRANSLATE_ANCHOR_MAP, - FILL_TRANSLATE_ANCHOR_VIEWPORT, - }) + @StringDef({ + FILL_TRANSLATE_ANCHOR_MAP, + FILL_TRANSLATE_ANCHOR_VIEWPORT, + }) @Retention(RetentionPolicy.SOURCE) - public @interface FILL_TRANSLATE_ANCHOR { - } + public @interface FILL_TRANSLATE_ANCHOR {} // LINE_TRANSLATE_ANCHOR: Controls the translation reference point. @@ -380,13 +355,12 @@ public abstract class Property { /** * Controls the translation reference point. */ - @StringDef( { - LINE_TRANSLATE_ANCHOR_MAP, - LINE_TRANSLATE_ANCHOR_VIEWPORT, - }) + @StringDef({ + LINE_TRANSLATE_ANCHOR_MAP, + LINE_TRANSLATE_ANCHOR_VIEWPORT, + }) @Retention(RetentionPolicy.SOURCE) - public @interface LINE_TRANSLATE_ANCHOR { - } + public @interface LINE_TRANSLATE_ANCHOR {} // ICON_TRANSLATE_ANCHOR: Controls the translation reference point. @@ -402,13 +376,12 @@ public abstract class Property { /** * Controls the translation reference point. */ - @StringDef( { - ICON_TRANSLATE_ANCHOR_MAP, - ICON_TRANSLATE_ANCHOR_VIEWPORT, - }) + @StringDef({ + ICON_TRANSLATE_ANCHOR_MAP, + ICON_TRANSLATE_ANCHOR_VIEWPORT, + }) @Retention(RetentionPolicy.SOURCE) - public @interface ICON_TRANSLATE_ANCHOR { - } + public @interface ICON_TRANSLATE_ANCHOR {} // TEXT_TRANSLATE_ANCHOR: Controls the translation reference point. @@ -424,13 +397,12 @@ public abstract class Property { /** * Controls the translation reference point. */ - @StringDef( { - TEXT_TRANSLATE_ANCHOR_MAP, - TEXT_TRANSLATE_ANCHOR_VIEWPORT, - }) + @StringDef({ + TEXT_TRANSLATE_ANCHOR_MAP, + TEXT_TRANSLATE_ANCHOR_VIEWPORT, + }) @Retention(RetentionPolicy.SOURCE) - public @interface TEXT_TRANSLATE_ANCHOR { - } + public @interface TEXT_TRANSLATE_ANCHOR {} // CIRCLE_TRANSLATE_ANCHOR: Controls the translation reference point. @@ -446,13 +418,12 @@ public abstract class Property { /** * Controls the translation reference point. */ - @StringDef( { - CIRCLE_TRANSLATE_ANCHOR_MAP, - CIRCLE_TRANSLATE_ANCHOR_VIEWPORT, - }) + @StringDef({ + CIRCLE_TRANSLATE_ANCHOR_MAP, + CIRCLE_TRANSLATE_ANCHOR_VIEWPORT, + }) @Retention(RetentionPolicy.SOURCE) - public @interface CIRCLE_TRANSLATE_ANCHOR { - } + public @interface CIRCLE_TRANSLATE_ANCHOR {} // CIRCLE_PITCH_SCALE: Controls the scaling behavior of the circle when the map is pitched. @@ -468,20 +439,14 @@ public abstract class Property { /** * Controls the scaling behavior of the circle when the map is pitched. */ - @StringDef( { - CIRCLE_PITCH_SCALE_MAP, - CIRCLE_PITCH_SCALE_VIEWPORT, - }) + @StringDef({ + CIRCLE_PITCH_SCALE_MAP, + CIRCLE_PITCH_SCALE_VIEWPORT, + }) @Retention(RetentionPolicy.SOURCE) - public @interface CIRCLE_PITCH_SCALE { - } + public @interface CIRCLE_PITCH_SCALE {} - // Class definition - public final String name; - public final T value; - /* package */ Property(String name, T value) { - this.name = name; - this.value = value; + private Property() { } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java index 8e7d516a39d..1d14ece01b4 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java @@ -1,9 +1,13 @@ -package com.mapbox.mapboxsdk.style.layers; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.style.layers; + import android.annotation.SuppressLint; import android.support.annotation.ColorInt; +import com.mapbox.mapboxsdk.style.functions.Function; +import com.mapbox.mapboxsdk.style.functions.CameraFunction; + /** * Constructs paint/layout properties for Layers * @@ -17,18 +21,19 @@ public class PropertyFactory { * @param value the visibility value * @return property wrapper around visibility */ - public static Property visibility(@Property.VISIBILITY String value) { - return new LayoutProperty<>("visibility", value); + public static PropertyValue visibility(@Property.VISIBILITY String value) { + return new LayoutPropertyValue<>("visibility", value); } /** * Set the property visibility. * + * @param the function input type * @param function the visibility function * @return property wrapper around a String function */ - public static Property> visibility(Function function) { - return new LayoutProperty<>("visibility", function); + public static PropertyValue> visibility(Function function) { + return new LayoutPropertyValue<>("visibility", function); } /** @@ -37,73 +42,74 @@ public static Property> visibility(Function function) { * @param value a Boolean value * @return property wrapper around Boolean */ - public static Property fillAntialias(Boolean value) { - return new PaintProperty<>("fill-antialias", value); + public static PropertyValue fillAntialias(Boolean value) { + return new PaintPropertyValue<>("fill-antialias", value); } + /** * Whether or not the fill should be antialiased. * - * @param function a wrapper function for Boolean + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Boolean * @return property wrapper around a Boolean function */ - public static Property> fillAntialias(Function function) { - return new PaintProperty<>("fill-antialias", function); + public static PropertyValue> fillAntialias(CameraFunction function) { + return new PaintPropertyValue<>("fill-antialias", function); } /** - * The opacity of the entire fill layer. In contrast to the {@link PropertyFactory#fillColor}, this value will also - * affect the 1px stroke around the fill, if the stroke is used. + * The opacity of the entire fill layer. In contrast to the {@link PropertyFactory#fillColor}, this value will also affect the 1px stroke around the fill, if the stroke is used. * * @param value a Float value * @return property wrapper around Float */ - public static Property fillOpacity(Float value) { - return new PaintProperty<>("fill-opacity", value); + public static PropertyValue fillOpacity(Float value) { + return new PaintPropertyValue<>("fill-opacity", value); } + /** - * The opacity of the entire fill layer. In contrast to the {@link PropertyFactory#fillColor}, this value will also - * affect the 1px stroke around the fill, if the stroke is used. + * The opacity of the entire fill layer. In contrast to the {@link PropertyFactory#fillColor}, this value will also affect the 1px stroke around the fill, if the stroke is used. * + * @param the function input type * @param function a wrapper function for Float * @return property wrapper around a Float function */ - public static Property> fillOpacity(Function function) { - return new PaintProperty<>("fill-opacity", function); + public static PropertyValue> fillOpacity(Function function) { + return new PaintPropertyValue<>("fill-opacity", function); } /** - * The color of the filled part of this layer. This color can be specified as `rgba` with an alpha component and the - * color's opacity will not affect the opacity of the 1px stroke, if it is used. + * The color of the filled part of this layer. This color can be specified as `rgba` with an alpha component and the color's opacity will not affect the opacity of the 1px stroke, if it is used. * * @param value a int color value * @return property wrapper around String color */ - public static Property fillColor(@ColorInt int value) { - return new PaintProperty<>("fill-color", colorToRgbaString(value)); + public static PropertyValue fillColor(@ColorInt int value) { + return new PaintPropertyValue<>("fill-color", colorToRgbaString(value)); } /** - * The color of the filled part of this layer. This color can be specified as `rgba` with an alpha component and the - * color's opacity will not affect the opacity of the 1px stroke, if it is used. + * The color of the filled part of this layer. This color can be specified as `rgba` with an alpha component and the color's opacity will not affect the opacity of the 1px stroke, if it is used. * * @param value a String value * @return property wrapper around String */ - public static Property fillColor(String value) { - return new PaintProperty<>("fill-color", value); + public static PropertyValue fillColor(String value) { + return new PaintPropertyValue<>("fill-color", value); } + /** - * The color of the filled part of this layer. This color can be specified as `rgba` with an alpha component and the - * color's opacity will not affect the opacity of the 1px stroke, if it is used. + * The color of the filled part of this layer. This color can be specified as `rgba` with an alpha component and the color's opacity will not affect the opacity of the 1px stroke, if it is used. * + * @param the function input type * @param function a wrapper function for String * @return property wrapper around a String function */ - public static Property> fillColor(Function function) { - return new PaintProperty<>("fill-color", function); + public static PropertyValue> fillColor(Function function) { + return new PaintPropertyValue<>("fill-color", function); } /** @@ -112,8 +118,8 @@ public static Property> fillColor(Function function) { * @param value a int color value * @return property wrapper around String color */ - public static Property fillOutlineColor(@ColorInt int value) { - return new PaintProperty<>("fill-outline-color", colorToRgbaString(value)); + public static PropertyValue fillOutlineColor(@ColorInt int value) { + return new PaintPropertyValue<>("fill-outline-color", colorToRgbaString(value)); } /** @@ -122,18 +128,20 @@ public static Property fillOutlineColor(@ColorInt int value) { * @param value a String value * @return property wrapper around String */ - public static Property fillOutlineColor(String value) { - return new PaintProperty<>("fill-outline-color", value); + public static PropertyValue fillOutlineColor(String value) { + return new PaintPropertyValue<>("fill-outline-color", value); } + /** * The outline color of the fill. Matches the value of {@link PropertyFactory#fillColor} if unspecified. * + * @param the function input type * @param function a wrapper function for String * @return property wrapper around a String function */ - public static Property> fillOutlineColor(Function function) { - return new PaintProperty<>("fill-outline-color", function); + public static PropertyValue> fillOutlineColor(Function function) { + return new PaintPropertyValue<>("fill-outline-color", function); } /** @@ -142,18 +150,20 @@ public static Property> fillOutlineColor(Function funct * @param value a Float[] value * @return property wrapper around Float[] */ - public static Property fillTranslate(Float[] value) { - return new PaintProperty<>("fill-translate", value); + public static PropertyValue fillTranslate(Float[] value) { + return new PaintPropertyValue<>("fill-translate", value); } + /** * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. * - * @param function a wrapper function for Float[] + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float[] * @return property wrapper around a Float[] function */ - public static Property> fillTranslate(Function function) { - return new PaintProperty<>("fill-translate", function); + public static PropertyValue> fillTranslate(CameraFunction function) { + return new PaintPropertyValue<>("fill-translate", function); } /** @@ -162,40 +172,42 @@ public static Property> fillTranslate(Function functi * @param value a String value * @return property wrapper around String */ - public static Property fillTranslateAnchor(@Property.FILL_TRANSLATE_ANCHOR String value) { - return new PaintProperty<>("fill-translate-anchor", value); + public static PropertyValue fillTranslateAnchor(@Property.FILL_TRANSLATE_ANCHOR String value) { + return new PaintPropertyValue<>("fill-translate-anchor", value); } + /** * Controls the translation reference point. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> fillTranslateAnchor(Function function) { - return new PaintProperty<>("fill-translate-anchor", function); + public static PropertyValue> fillTranslateAnchor(CameraFunction function) { + return new PaintPropertyValue<>("fill-translate-anchor", function); } /** - * Name of image in sprite to use for drawing image fills. For seamless patterns, image width and height must be a - * factor of two (2, 4, 8, ..., 512). + * Name of image in sprite to use for drawing image fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). * * @param value a String value * @return property wrapper around String */ - public static Property fillPattern(String value) { - return new PaintProperty<>("fill-pattern", value); + public static PropertyValue fillPattern(String value) { + return new PaintPropertyValue<>("fill-pattern", value); } + /** - * Name of image in sprite to use for drawing image fills. For seamless patterns, image width and height must be a - * factor of two (2, 4, 8, ..., 512). + * Name of image in sprite to use for drawing image fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> fillPattern(Function function) { - return new PaintProperty<>("fill-pattern", function); + public static PropertyValue> fillPattern(CameraFunction function) { + return new PaintPropertyValue<>("fill-pattern", function); } /** @@ -204,18 +216,20 @@ public static Property> fillPattern(Function function) * @param value a Float value * @return property wrapper around Float */ - public static Property lineOpacity(Float value) { - return new PaintProperty<>("line-opacity", value); + public static PropertyValue lineOpacity(Float value) { + return new PaintPropertyValue<>("line-opacity", value); } + /** * The opacity at which the line will be drawn. * + * @param the function input type * @param function a wrapper function for Float * @return property wrapper around a Float function */ - public static Property> lineOpacity(Function function) { - return new PaintProperty<>("line-opacity", function); + public static PropertyValue> lineOpacity(Function function) { + return new PaintPropertyValue<>("line-opacity", function); } /** @@ -224,8 +238,8 @@ public static Property> lineOpacity(Function function) { * @param value a int color value * @return property wrapper around String color */ - public static Property lineColor(@ColorInt int value) { - return new PaintProperty<>("line-color", colorToRgbaString(value)); + public static PropertyValue lineColor(@ColorInt int value) { + return new PaintPropertyValue<>("line-color", colorToRgbaString(value)); } /** @@ -234,18 +248,20 @@ public static Property lineColor(@ColorInt int value) { * @param value a String value * @return property wrapper around String */ - public static Property lineColor(String value) { - return new PaintProperty<>("line-color", value); + public static PropertyValue lineColor(String value) { + return new PaintPropertyValue<>("line-color", value); } + /** * The color with which the line will be drawn. * + * @param the function input type * @param function a wrapper function for String * @return property wrapper around a String function */ - public static Property> lineColor(Function function) { - return new PaintProperty<>("line-color", function); + public static PropertyValue> lineColor(Function function) { + return new PaintPropertyValue<>("line-color", function); } /** @@ -254,18 +270,20 @@ public static Property> lineColor(Function function) { * @param value a Float[] value * @return property wrapper around Float[] */ - public static Property lineTranslate(Float[] value) { - return new PaintProperty<>("line-translate", value); + public static PropertyValue lineTranslate(Float[] value) { + return new PaintPropertyValue<>("line-translate", value); } + /** * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. * - * @param function a wrapper function for Float[] + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float[] * @return property wrapper around a Float[] function */ - public static Property> lineTranslate(Function function) { - return new PaintProperty<>("line-translate", function); + public static PropertyValue> lineTranslate(CameraFunction function) { + return new PaintPropertyValue<>("line-translate", function); } /** @@ -274,18 +292,20 @@ public static Property> lineTranslate(Function functi * @param value a String value * @return property wrapper around String */ - public static Property lineTranslateAnchor(@Property.LINE_TRANSLATE_ANCHOR String value) { - return new PaintProperty<>("line-translate-anchor", value); + public static PropertyValue lineTranslateAnchor(@Property.LINE_TRANSLATE_ANCHOR String value) { + return new PaintPropertyValue<>("line-translate-anchor", value); } + /** * Controls the translation reference point. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> lineTranslateAnchor(Function function) { - return new PaintProperty<>("line-translate-anchor", function); + public static PropertyValue> lineTranslateAnchor(CameraFunction function) { + return new PaintPropertyValue<>("line-translate-anchor", function); } /** @@ -294,18 +314,20 @@ public static Property> lineTranslateAnchor(Function fu * @param value a Float value * @return property wrapper around Float */ - public static Property lineWidth(Float value) { - return new PaintProperty<>("line-width", value); + public static PropertyValue lineWidth(Float value) { + return new PaintPropertyValue<>("line-width", value); } + /** * Stroke thickness. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> lineWidth(Function function) { - return new PaintProperty<>("line-width", function); + public static PropertyValue> lineWidth(CameraFunction function) { + return new PaintPropertyValue<>("line-width", function); } /** @@ -314,42 +336,42 @@ public static Property> lineWidth(Function function) { * @param value a Float value * @return property wrapper around Float */ - public static Property lineGapWidth(Float value) { - return new PaintProperty<>("line-gap-width", value); + public static PropertyValue lineGapWidth(Float value) { + return new PaintPropertyValue<>("line-gap-width", value); } + /** * Draws a line casing outside of a line's actual path. Value indicates the width of the inner gap. * + * @param the function input type * @param function a wrapper function for Float * @return property wrapper around a Float function */ - public static Property> lineGapWidth(Function function) { - return new PaintProperty<>("line-gap-width", function); + public static PropertyValue> lineGapWidth(Function function) { + return new PaintPropertyValue<>("line-gap-width", function); } /** - * The line's offset. For linear features, a positive value offsets the line to the right, relative to the direction - * of the line, and a negative value to the left. For polygon features, a positive value results in an inset, and a - * negative value results in an outset. + * The line's offset. For linear features, a positive value offsets the line to the right, relative to the direction of the line, and a negative value to the left. For polygon features, a positive value results in an inset, and a negative value results in an outset. * * @param value a Float value * @return property wrapper around Float */ - public static Property lineOffset(Float value) { - return new PaintProperty<>("line-offset", value); + public static PropertyValue lineOffset(Float value) { + return new PaintPropertyValue<>("line-offset", value); } + /** - * The line's offset. For linear features, a positive value offsets the line to the right, relative to the direction - * of the line, and a negative value to the left. For polygon features, a positive value results in an inset, and a - * negative value results in an outset. + * The line's offset. For linear features, a positive value offsets the line to the right, relative to the direction of the line, and a negative value to the left. For polygon features, a positive value results in an inset, and a negative value results in an outset. * + * @param the function input type * @param function a wrapper function for Float * @return property wrapper around a Float function */ - public static Property> lineOffset(Function function) { - return new PaintProperty<>("line-offset", function); + public static PropertyValue> lineOffset(Function function) { + return new PaintPropertyValue<>("line-offset", function); } /** @@ -358,62 +380,64 @@ public static Property> lineOffset(Function function) { * @param value a Float value * @return property wrapper around Float */ - public static Property lineBlur(Float value) { - return new PaintProperty<>("line-blur", value); + public static PropertyValue lineBlur(Float value) { + return new PaintPropertyValue<>("line-blur", value); } + /** * Blur applied to the line, in pixels. * + * @param the function input type * @param function a wrapper function for Float * @return property wrapper around a Float function */ - public static Property> lineBlur(Function function) { - return new PaintProperty<>("line-blur", function); + public static PropertyValue> lineBlur(Function function) { + return new PaintPropertyValue<>("line-blur", function); } /** - * Specifies the lengths of the alternating dashes and gaps that form the dash pattern. The lengths are later scaled - * by the line width. To convert a dash length to pixels, multiply the length by the current line width. + * Specifies the lengths of the alternating dashes and gaps that form the dash pattern. The lengths are later scaled by the line width. To convert a dash length to pixels, multiply the length by the current line width. * * @param value a Float[] value * @return property wrapper around Float[] */ - public static Property lineDasharray(Float[] value) { - return new PaintProperty<>("line-dasharray", value); + public static PropertyValue lineDasharray(Float[] value) { + return new PaintPropertyValue<>("line-dasharray", value); } + /** - * Specifies the lengths of the alternating dashes and gaps that form the dash pattern. The lengths are later scaled - * by the line width. To convert a dash length to pixels, multiply the length by the current line width. + * Specifies the lengths of the alternating dashes and gaps that form the dash pattern. The lengths are later scaled by the line width. To convert a dash length to pixels, multiply the length by the current line width. * - * @param function a wrapper function for Float[] + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float[] * @return property wrapper around a Float[] function */ - public static Property> lineDasharray(Function function) { - return new PaintProperty<>("line-dasharray", function); + public static PropertyValue> lineDasharray(CameraFunction function) { + return new PaintPropertyValue<>("line-dasharray", function); } /** - * Name of image in sprite to use for drawing image lines. For seamless patterns, image width must be a factor of two - * (2, 4, 8, ..., 512). + * Name of image in sprite to use for drawing image lines. For seamless patterns, image width must be a factor of two (2, 4, 8, ..., 512). * * @param value a String value * @return property wrapper around String */ - public static Property linePattern(String value) { - return new PaintProperty<>("line-pattern", value); + public static PropertyValue linePattern(String value) { + return new PaintPropertyValue<>("line-pattern", value); } + /** - * Name of image in sprite to use for drawing image lines. For seamless patterns, image width must be a factor of two - * (2, 4, 8, ..., 512). + * Name of image in sprite to use for drawing image lines. For seamless patterns, image width must be a factor of two (2, 4, 8, ..., 512). * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> linePattern(Function function) { - return new PaintProperty<>("line-pattern", function); + public static PropertyValue> linePattern(CameraFunction function) { + return new PaintPropertyValue<>("line-pattern", function); } /** @@ -422,18 +446,20 @@ public static Property> linePattern(Function function) * @param value a Float value * @return property wrapper around Float */ - public static Property iconOpacity(Float value) { - return new PaintProperty<>("icon-opacity", value); + public static PropertyValue iconOpacity(Float value) { + return new PaintPropertyValue<>("icon-opacity", value); } + /** * The opacity at which the icon will be drawn. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> iconOpacity(Function function) { - return new PaintProperty<>("icon-opacity", function); + public static PropertyValue> iconOpacity(CameraFunction function) { + return new PaintPropertyValue<>("icon-opacity", function); } /** @@ -442,8 +468,8 @@ public static Property> iconOpacity(Function function) { * @param value a int color value * @return property wrapper around String color */ - public static Property iconColor(@ColorInt int value) { - return new PaintProperty<>("icon-color", colorToRgbaString(value)); + public static PropertyValue iconColor(@ColorInt int value) { + return new PaintPropertyValue<>("icon-color", colorToRgbaString(value)); } /** @@ -452,18 +478,20 @@ public static Property iconColor(@ColorInt int value) { * @param value a String value * @return property wrapper around String */ - public static Property iconColor(String value) { - return new PaintProperty<>("icon-color", value); + public static PropertyValue iconColor(String value) { + return new PaintPropertyValue<>("icon-color", value); } + /** * The color of the icon. This can only be used with sdf icons. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> iconColor(Function function) { - return new PaintProperty<>("icon-color", function); + public static PropertyValue> iconColor(CameraFunction function) { + return new PaintPropertyValue<>("icon-color", function); } /** @@ -472,8 +500,8 @@ public static Property> iconColor(Function function) { * @param value a int color value * @return property wrapper around String color */ - public static Property iconHaloColor(@ColorInt int value) { - return new PaintProperty<>("icon-halo-color", colorToRgbaString(value)); + public static PropertyValue iconHaloColor(@ColorInt int value) { + return new PaintPropertyValue<>("icon-halo-color", colorToRgbaString(value)); } /** @@ -482,18 +510,20 @@ public static Property iconHaloColor(@ColorInt int value) { * @param value a String value * @return property wrapper around String */ - public static Property iconHaloColor(String value) { - return new PaintProperty<>("icon-halo-color", value); + public static PropertyValue iconHaloColor(String value) { + return new PaintPropertyValue<>("icon-halo-color", value); } + /** * The color of the icon's halo. Icon halos can only be used with SDF icons. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> iconHaloColor(Function function) { - return new PaintProperty<>("icon-halo-color", function); + public static PropertyValue> iconHaloColor(CameraFunction function) { + return new PaintPropertyValue<>("icon-halo-color", function); } /** @@ -502,18 +532,20 @@ public static Property> iconHaloColor(Function function * @param value a Float value * @return property wrapper around Float */ - public static Property iconHaloWidth(Float value) { - return new PaintProperty<>("icon-halo-width", value); + public static PropertyValue iconHaloWidth(Float value) { + return new PaintPropertyValue<>("icon-halo-width", value); } + /** * Distance of halo to the icon outline. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> iconHaloWidth(Function function) { - return new PaintProperty<>("icon-halo-width", function); + public static PropertyValue> iconHaloWidth(CameraFunction function) { + return new PaintPropertyValue<>("icon-halo-width", function); } /** @@ -522,40 +554,42 @@ public static Property> iconHaloWidth(Function function) * @param value a Float value * @return property wrapper around Float */ - public static Property iconHaloBlur(Float value) { - return new PaintProperty<>("icon-halo-blur", value); + public static PropertyValue iconHaloBlur(Float value) { + return new PaintPropertyValue<>("icon-halo-blur", value); } + /** * Fade out the halo towards the outside. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> iconHaloBlur(Function function) { - return new PaintProperty<>("icon-halo-blur", function); + public static PropertyValue> iconHaloBlur(CameraFunction function) { + return new PaintPropertyValue<>("icon-halo-blur", function); } /** - * Distance that the icon's anchor is moved from its original placement. Positive values indicate right and down, - * while negative values indicate left and up. + * Distance that the icon's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up. * * @param value a Float[] value * @return property wrapper around Float[] */ - public static Property iconTranslate(Float[] value) { - return new PaintProperty<>("icon-translate", value); + public static PropertyValue iconTranslate(Float[] value) { + return new PaintPropertyValue<>("icon-translate", value); } + /** - * Distance that the icon's anchor is moved from its original placement. Positive values indicate right and down, - * while negative values indicate left and up. + * Distance that the icon's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up. * - * @param function a wrapper function for Float[] + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float[] * @return property wrapper around a Float[] function */ - public static Property> iconTranslate(Function function) { - return new PaintProperty<>("icon-translate", function); + public static PropertyValue> iconTranslate(CameraFunction function) { + return new PaintPropertyValue<>("icon-translate", function); } /** @@ -564,18 +598,20 @@ public static Property> iconTranslate(Function functi * @param value a String value * @return property wrapper around String */ - public static Property iconTranslateAnchor(@Property.ICON_TRANSLATE_ANCHOR String value) { - return new PaintProperty<>("icon-translate-anchor", value); + public static PropertyValue iconTranslateAnchor(@Property.ICON_TRANSLATE_ANCHOR String value) { + return new PaintPropertyValue<>("icon-translate-anchor", value); } + /** * Controls the translation reference point. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> iconTranslateAnchor(Function function) { - return new PaintProperty<>("icon-translate-anchor", function); + public static PropertyValue> iconTranslateAnchor(CameraFunction function) { + return new PaintPropertyValue<>("icon-translate-anchor", function); } /** @@ -584,18 +620,20 @@ public static Property> iconTranslateAnchor(Function fu * @param value a Float value * @return property wrapper around Float */ - public static Property textOpacity(Float value) { - return new PaintProperty<>("text-opacity", value); + public static PropertyValue textOpacity(Float value) { + return new PaintPropertyValue<>("text-opacity", value); } + /** * The opacity at which the text will be drawn. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> textOpacity(Function function) { - return new PaintProperty<>("text-opacity", function); + public static PropertyValue> textOpacity(CameraFunction function) { + return new PaintPropertyValue<>("text-opacity", function); } /** @@ -604,8 +642,8 @@ public static Property> textOpacity(Function function) { * @param value a int color value * @return property wrapper around String color */ - public static Property textColor(@ColorInt int value) { - return new PaintProperty<>("text-color", colorToRgbaString(value)); + public static PropertyValue textColor(@ColorInt int value) { + return new PaintPropertyValue<>("text-color", colorToRgbaString(value)); } /** @@ -614,18 +652,20 @@ public static Property textColor(@ColorInt int value) { * @param value a String value * @return property wrapper around String */ - public static Property textColor(String value) { - return new PaintProperty<>("text-color", value); + public static PropertyValue textColor(String value) { + return new PaintPropertyValue<>("text-color", value); } + /** * The color with which the text will be drawn. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> textColor(Function function) { - return new PaintProperty<>("text-color", function); + public static PropertyValue> textColor(CameraFunction function) { + return new PaintPropertyValue<>("text-color", function); } /** @@ -634,8 +674,8 @@ public static Property> textColor(Function function) { * @param value a int color value * @return property wrapper around String color */ - public static Property textHaloColor(@ColorInt int value) { - return new PaintProperty<>("text-halo-color", colorToRgbaString(value)); + public static PropertyValue textHaloColor(@ColorInt int value) { + return new PaintPropertyValue<>("text-halo-color", colorToRgbaString(value)); } /** @@ -644,18 +684,20 @@ public static Property textHaloColor(@ColorInt int value) { * @param value a String value * @return property wrapper around String */ - public static Property textHaloColor(String value) { - return new PaintProperty<>("text-halo-color", value); + public static PropertyValue textHaloColor(String value) { + return new PaintPropertyValue<>("text-halo-color", value); } + /** * The color of the text's halo, which helps it stand out from backgrounds. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> textHaloColor(Function function) { - return new PaintProperty<>("text-halo-color", function); + public static PropertyValue> textHaloColor(CameraFunction function) { + return new PaintPropertyValue<>("text-halo-color", function); } /** @@ -664,18 +706,20 @@ public static Property> textHaloColor(Function function * @param value a Float value * @return property wrapper around Float */ - public static Property textHaloWidth(Float value) { - return new PaintProperty<>("text-halo-width", value); + public static PropertyValue textHaloWidth(Float value) { + return new PaintPropertyValue<>("text-halo-width", value); } + /** * Distance of halo to the font outline. Max text halo width is 1/4 of the font-size. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> textHaloWidth(Function function) { - return new PaintProperty<>("text-halo-width", function); + public static PropertyValue> textHaloWidth(CameraFunction function) { + return new PaintPropertyValue<>("text-halo-width", function); } /** @@ -684,40 +728,42 @@ public static Property> textHaloWidth(Function function) * @param value a Float value * @return property wrapper around Float */ - public static Property textHaloBlur(Float value) { - return new PaintProperty<>("text-halo-blur", value); + public static PropertyValue textHaloBlur(Float value) { + return new PaintPropertyValue<>("text-halo-blur", value); } + /** * The halo's fadeout distance towards the outside. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> textHaloBlur(Function function) { - return new PaintProperty<>("text-halo-blur", function); + public static PropertyValue> textHaloBlur(CameraFunction function) { + return new PaintPropertyValue<>("text-halo-blur", function); } /** - * Distance that the text's anchor is moved from its original placement. Positive values indicate right and down, - * while negative values indicate left and up. + * Distance that the text's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up. * * @param value a Float[] value * @return property wrapper around Float[] */ - public static Property textTranslate(Float[] value) { - return new PaintProperty<>("text-translate", value); + public static PropertyValue textTranslate(Float[] value) { + return new PaintPropertyValue<>("text-translate", value); } + /** - * Distance that the text's anchor is moved from its original placement. Positive values indicate right and down, - * while negative values indicate left and up. + * Distance that the text's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up. * - * @param function a wrapper function for Float[] + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float[] * @return property wrapper around a Float[] function */ - public static Property> textTranslate(Function function) { - return new PaintProperty<>("text-translate", function); + public static PropertyValue> textTranslate(CameraFunction function) { + return new PaintPropertyValue<>("text-translate", function); } /** @@ -726,18 +772,20 @@ public static Property> textTranslate(Function functi * @param value a String value * @return property wrapper around String */ - public static Property textTranslateAnchor(@Property.TEXT_TRANSLATE_ANCHOR String value) { - return new PaintProperty<>("text-translate-anchor", value); + public static PropertyValue textTranslateAnchor(@Property.TEXT_TRANSLATE_ANCHOR String value) { + return new PaintPropertyValue<>("text-translate-anchor", value); } + /** * Controls the translation reference point. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> textTranslateAnchor(Function function) { - return new PaintProperty<>("text-translate-anchor", function); + public static PropertyValue> textTranslateAnchor(CameraFunction function) { + return new PaintPropertyValue<>("text-translate-anchor", function); } /** @@ -746,18 +794,20 @@ public static Property> textTranslateAnchor(Function fu * @param value a Float value * @return property wrapper around Float */ - public static Property circleRadius(Float value) { - return new PaintProperty<>("circle-radius", value); + public static PropertyValue circleRadius(Float value) { + return new PaintPropertyValue<>("circle-radius", value); } + /** * Circle radius. * + * @param the function input type * @param function a wrapper function for Float * @return property wrapper around a Float function */ - public static Property> circleRadius(Function function) { - return new PaintProperty<>("circle-radius", function); + public static PropertyValue> circleRadius(Function function) { + return new PaintPropertyValue<>("circle-radius", function); } /** @@ -766,8 +816,8 @@ public static Property> circleRadius(Function function) { * @param value a int color value * @return property wrapper around String color */ - public static Property circleColor(@ColorInt int value) { - return new PaintProperty<>("circle-color", colorToRgbaString(value)); + public static PropertyValue circleColor(@ColorInt int value) { + return new PaintPropertyValue<>("circle-color", colorToRgbaString(value)); } /** @@ -776,18 +826,20 @@ public static Property circleColor(@ColorInt int value) { * @param value a String value * @return property wrapper around String */ - public static Property circleColor(String value) { - return new PaintProperty<>("circle-color", value); + public static PropertyValue circleColor(String value) { + return new PaintPropertyValue<>("circle-color", value); } + /** * The fill color of the circle. * + * @param the function input type * @param function a wrapper function for String * @return property wrapper around a String function */ - public static Property> circleColor(Function function) { - return new PaintProperty<>("circle-color", function); + public static PropertyValue> circleColor(Function function) { + return new PaintPropertyValue<>("circle-color", function); } /** @@ -796,18 +848,20 @@ public static Property> circleColor(Function function) * @param value a Float value * @return property wrapper around Float */ - public static Property circleBlur(Float value) { - return new PaintProperty<>("circle-blur", value); + public static PropertyValue circleBlur(Float value) { + return new PaintPropertyValue<>("circle-blur", value); } + /** * Amount to blur the circle. 1 blurs the circle such that only the centerpoint is full opacity. * + * @param the function input type * @param function a wrapper function for Float * @return property wrapper around a Float function */ - public static Property> circleBlur(Function function) { - return new PaintProperty<>("circle-blur", function); + public static PropertyValue> circleBlur(Function function) { + return new PaintPropertyValue<>("circle-blur", function); } /** @@ -816,18 +870,20 @@ public static Property> circleBlur(Function function) { * @param value a Float value * @return property wrapper around Float */ - public static Property circleOpacity(Float value) { - return new PaintProperty<>("circle-opacity", value); + public static PropertyValue circleOpacity(Float value) { + return new PaintPropertyValue<>("circle-opacity", value); } + /** * The opacity at which the circle will be drawn. * + * @param the function input type * @param function a wrapper function for Float * @return property wrapper around a Float function */ - public static Property> circleOpacity(Function function) { - return new PaintProperty<>("circle-opacity", function); + public static PropertyValue> circleOpacity(Function function) { + return new PaintPropertyValue<>("circle-opacity", function); } /** @@ -836,18 +892,20 @@ public static Property> circleOpacity(Function function) * @param value a Float[] value * @return property wrapper around Float[] */ - public static Property circleTranslate(Float[] value) { - return new PaintProperty<>("circle-translate", value); + public static PropertyValue circleTranslate(Float[] value) { + return new PaintPropertyValue<>("circle-translate", value); } + /** * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. * - * @param function a wrapper function for Float[] + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float[] * @return property wrapper around a Float[] function */ - public static Property> circleTranslate(Function function) { - return new PaintProperty<>("circle-translate", function); + public static PropertyValue> circleTranslate(CameraFunction function) { + return new PaintPropertyValue<>("circle-translate", function); } /** @@ -856,18 +914,20 @@ public static Property> circleTranslate(Function func * @param value a String value * @return property wrapper around String */ - public static Property circleTranslateAnchor(@Property.CIRCLE_TRANSLATE_ANCHOR String value) { - return new PaintProperty<>("circle-translate-anchor", value); + public static PropertyValue circleTranslateAnchor(@Property.CIRCLE_TRANSLATE_ANCHOR String value) { + return new PaintPropertyValue<>("circle-translate-anchor", value); } + /** * Controls the translation reference point. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> circleTranslateAnchor(Function function) { - return new PaintProperty<>("circle-translate-anchor", function); + public static PropertyValue> circleTranslateAnchor(CameraFunction function) { + return new PaintPropertyValue<>("circle-translate-anchor", function); } /** @@ -876,38 +936,42 @@ public static Property> circleTranslateAnchor(Function * @param value a String value * @return property wrapper around String */ - public static Property circlePitchScale(@Property.CIRCLE_PITCH_SCALE String value) { - return new PaintProperty<>("circle-pitch-scale", value); + public static PropertyValue circlePitchScale(@Property.CIRCLE_PITCH_SCALE String value) { + return new PaintPropertyValue<>("circle-pitch-scale", value); } + /** * Controls the scaling behavior of the circle when the map is pitched. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> circlePitchScale(Function function) { - return new PaintProperty<>("circle-pitch-scale", function); + public static PropertyValue> circlePitchScale(CameraFunction function) { + return new PaintPropertyValue<>("circle-pitch-scale", function); } /** - * The width of the circle's stroke. Strokes are placed outside of the "circle-radius". + * The width of the circle's stroke. Strokes are placed outside of the {@link PropertyFactory#circleRadius}. * * @param value a Float value * @return property wrapper around Float */ - public static Property circleStrokeWidth(Float value) { - return new PaintProperty<>("circle-stroke-width", value); + public static PropertyValue circleStrokeWidth(Float value) { + return new PaintPropertyValue<>("circle-stroke-width", value); } + /** - * The width of the circle's stroke. Strokes are placed outside of the "circle-radius". + * The width of the circle's stroke. Strokes are placed outside of the {@link PropertyFactory#circleRadius}. * + * @param the function input type * @param function a wrapper function for Float * @return property wrapper around a Float function */ - public static Property> circleStrokeWidth(Function function) { - return new PaintProperty<>("circle-stroke-width", function); + public static PropertyValue> circleStrokeWidth(Function function) { + return new PaintPropertyValue<>("circle-stroke-width", function); } /** @@ -916,8 +980,8 @@ public static Property> circleStrokeWidth(Function functi * @param value a int color value * @return property wrapper around String color */ - public static Property circleStrokeColor(@ColorInt int value) { - return new PaintProperty<>("circle-stroke-color", colorToRgbaString(value)); + public static PropertyValue circleStrokeColor(@ColorInt int value) { + return new PaintPropertyValue<>("circle-stroke-color", colorToRgbaString(value)); } /** @@ -926,18 +990,20 @@ public static Property circleStrokeColor(@ColorInt int value) { * @param value a String value * @return property wrapper around String */ - public static Property circleStrokeColor(String value) { - return new PaintProperty<>("circle-stroke-color", value); + public static PropertyValue circleStrokeColor(String value) { + return new PaintPropertyValue<>("circle-stroke-color", value); } + /** * The stroke color of the circle. * + * @param the function input type * @param function a wrapper function for String * @return property wrapper around a String function */ - public static Property> circleStrokeColor(Function function) { - return new PaintProperty<>("circle-stroke-color", function); + public static PropertyValue> circleStrokeColor(Function function) { + return new PaintPropertyValue<>("circle-stroke-color", function); } /** @@ -946,18 +1012,20 @@ public static Property> circleStrokeColor(Function func * @param value a Float value * @return property wrapper around Float */ - public static Property circleStrokeOpacity(Float value) { - return new PaintProperty<>("circle-stroke-opacity", value); + public static PropertyValue circleStrokeOpacity(Float value) { + return new PaintPropertyValue<>("circle-stroke-opacity", value); } + /** * The opacity of the circle's stroke. * + * @param the function input type * @param function a wrapper function for Float * @return property wrapper around a Float function */ - public static Property> circleStrokeOpacity(Function function) { - return new PaintProperty<>("circle-stroke-opacity", function); + public static PropertyValue> circleStrokeOpacity(Function function) { + return new PaintPropertyValue<>("circle-stroke-opacity", function); } /** @@ -966,18 +1034,20 @@ public static Property> circleStrokeOpacity(Function func * @param value a Float value * @return property wrapper around Float */ - public static Property rasterOpacity(Float value) { - return new PaintProperty<>("raster-opacity", value); + public static PropertyValue rasterOpacity(Float value) { + return new PaintPropertyValue<>("raster-opacity", value); } + /** * The opacity at which the image will be drawn. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> rasterOpacity(Function function) { - return new PaintProperty<>("raster-opacity", function); + public static PropertyValue> rasterOpacity(CameraFunction function) { + return new PaintPropertyValue<>("raster-opacity", function); } /** @@ -986,18 +1056,20 @@ public static Property> rasterOpacity(Function function) * @param value a Float value * @return property wrapper around Float */ - public static Property rasterHueRotate(Float value) { - return new PaintProperty<>("raster-hue-rotate", value); + public static PropertyValue rasterHueRotate(Float value) { + return new PaintPropertyValue<>("raster-hue-rotate", value); } + /** * Rotates hues around the color wheel. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> rasterHueRotate(Function function) { - return new PaintProperty<>("raster-hue-rotate", function); + public static PropertyValue> rasterHueRotate(CameraFunction function) { + return new PaintPropertyValue<>("raster-hue-rotate", function); } /** @@ -1006,18 +1078,20 @@ public static Property> rasterHueRotate(Function function * @param value a Float value * @return property wrapper around Float */ - public static Property rasterBrightnessMin(Float value) { - return new PaintProperty<>("raster-brightness-min", value); + public static PropertyValue rasterBrightnessMin(Float value) { + return new PaintPropertyValue<>("raster-brightness-min", value); } + /** * Increase or reduce the brightness of the image. The value is the minimum brightness. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> rasterBrightnessMin(Function function) { - return new PaintProperty<>("raster-brightness-min", function); + public static PropertyValue> rasterBrightnessMin(CameraFunction function) { + return new PaintPropertyValue<>("raster-brightness-min", function); } /** @@ -1026,18 +1100,20 @@ public static Property> rasterBrightnessMin(Function func * @param value a Float value * @return property wrapper around Float */ - public static Property rasterBrightnessMax(Float value) { - return new PaintProperty<>("raster-brightness-max", value); + public static PropertyValue rasterBrightnessMax(Float value) { + return new PaintPropertyValue<>("raster-brightness-max", value); } + /** * Increase or reduce the brightness of the image. The value is the maximum brightness. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> rasterBrightnessMax(Function function) { - return new PaintProperty<>("raster-brightness-max", function); + public static PropertyValue> rasterBrightnessMax(CameraFunction function) { + return new PaintPropertyValue<>("raster-brightness-max", function); } /** @@ -1046,18 +1122,20 @@ public static Property> rasterBrightnessMax(Function func * @param value a Float value * @return property wrapper around Float */ - public static Property rasterSaturation(Float value) { - return new PaintProperty<>("raster-saturation", value); + public static PropertyValue rasterSaturation(Float value) { + return new PaintPropertyValue<>("raster-saturation", value); } + /** * Increase or reduce the saturation of the image. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> rasterSaturation(Function function) { - return new PaintProperty<>("raster-saturation", function); + public static PropertyValue> rasterSaturation(CameraFunction function) { + return new PaintPropertyValue<>("raster-saturation", function); } /** @@ -1066,18 +1144,20 @@ public static Property> rasterSaturation(Function functio * @param value a Float value * @return property wrapper around Float */ - public static Property rasterContrast(Float value) { - return new PaintProperty<>("raster-contrast", value); + public static PropertyValue rasterContrast(Float value) { + return new PaintPropertyValue<>("raster-contrast", value); } + /** * Increase or reduce the contrast of the image. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> rasterContrast(Function function) { - return new PaintProperty<>("raster-contrast", function); + public static PropertyValue> rasterContrast(CameraFunction function) { + return new PaintPropertyValue<>("raster-contrast", function); } /** @@ -1086,18 +1166,20 @@ public static Property> rasterContrast(Function function) * @param value a Float value * @return property wrapper around Float */ - public static Property rasterFadeDuration(Float value) { - return new PaintProperty<>("raster-fade-duration", value); + public static PropertyValue rasterFadeDuration(Float value) { + return new PaintPropertyValue<>("raster-fade-duration", value); } + /** * Fade duration when a new tile is added. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> rasterFadeDuration(Function function) { - return new PaintProperty<>("raster-fade-duration", function); + public static PropertyValue> rasterFadeDuration(CameraFunction function) { + return new PaintPropertyValue<>("raster-fade-duration", function); } /** @@ -1106,8 +1188,8 @@ public static Property> rasterFadeDuration(Function funct * @param value a int color value * @return property wrapper around String color */ - public static Property backgroundColor(@ColorInt int value) { - return new PaintProperty<>("background-color", colorToRgbaString(value)); + public static PropertyValue backgroundColor(@ColorInt int value) { + return new PaintPropertyValue<>("background-color", colorToRgbaString(value)); } /** @@ -1116,40 +1198,42 @@ public static Property backgroundColor(@ColorInt int value) { * @param value a String value * @return property wrapper around String */ - public static Property backgroundColor(String value) { - return new PaintProperty<>("background-color", value); + public static PropertyValue backgroundColor(String value) { + return new PaintPropertyValue<>("background-color", value); } + /** * The color with which the background will be drawn. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> backgroundColor(Function function) { - return new PaintProperty<>("background-color", function); + public static PropertyValue> backgroundColor(CameraFunction function) { + return new PaintPropertyValue<>("background-color", function); } /** - * Name of image in sprite to use for drawing an image background. For seamless patterns, image width and height must - * be a factor of two (2, 4, 8, ..., 512). + * Name of image in sprite to use for drawing an image background. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). * * @param value a String value * @return property wrapper around String */ - public static Property backgroundPattern(String value) { - return new PaintProperty<>("background-pattern", value); + public static PropertyValue backgroundPattern(String value) { + return new PaintPropertyValue<>("background-pattern", value); } + /** - * Name of image in sprite to use for drawing an image background. For seamless patterns, image width and height must - * be a factor of two (2, 4, 8, ..., 512). + * Name of image in sprite to use for drawing an image background. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> backgroundPattern(Function function) { - return new PaintProperty<>("background-pattern", function); + public static PropertyValue> backgroundPattern(CameraFunction function) { + return new PaintPropertyValue<>("background-pattern", function); } /** @@ -1158,18 +1242,20 @@ public static Property> backgroundPattern(Function func * @param value a Float value * @return property wrapper around Float */ - public static Property backgroundOpacity(Float value) { - return new PaintProperty<>("background-opacity", value); + public static PropertyValue backgroundOpacity(Float value) { + return new PaintPropertyValue<>("background-opacity", value); } + /** * The opacity at which the background will be drawn. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> backgroundOpacity(Function function) { - return new PaintProperty<>("background-opacity", function); + public static PropertyValue> backgroundOpacity(CameraFunction function) { + return new PaintPropertyValue<>("background-opacity", function); } /** @@ -1178,18 +1264,21 @@ public static Property> backgroundOpacity(Function functi * @param value a String value * @return property wrapper around String */ - public static Property lineCap(@Property.LINE_CAP String value) { - return new LayoutProperty<>("line-cap", value); + public static PropertyValue lineCap(@Property.LINE_CAP String value) { + return new LayoutPropertyValue<>("line-cap", value); } + + /** * The display of line endings. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> lineCap(Function function) { - return new LayoutProperty<>("line-cap", function); + public static PropertyValue> lineCap(CameraFunction function) { + return new LayoutPropertyValue<>("line-cap", function); } /** @@ -1198,18 +1287,21 @@ public static Property> lineCap(Function function) { * @param value a String value * @return property wrapper around String */ - public static Property lineJoin(@Property.LINE_JOIN String value) { - return new LayoutProperty<>("line-join", value); + public static PropertyValue lineJoin(@Property.LINE_JOIN String value) { + return new LayoutPropertyValue<>("line-join", value); } + + /** * The display of lines when joining. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> lineJoin(Function function) { - return new LayoutProperty<>("line-join", function); + public static PropertyValue> lineJoin(CameraFunction function) { + return new LayoutPropertyValue<>("line-join", function); } /** @@ -1218,18 +1310,21 @@ public static Property> lineJoin(Function function) { * @param value a Float value * @return property wrapper around Float */ - public static Property lineMiterLimit(Float value) { - return new LayoutProperty<>("line-miter-limit", value); + public static PropertyValue lineMiterLimit(Float value) { + return new LayoutPropertyValue<>("line-miter-limit", value); } + + /** * Used to automatically convert miter joins to bevel joins for sharp angles. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> lineMiterLimit(Function function) { - return new LayoutProperty<>("line-miter-limit", function); + public static PropertyValue> lineMiterLimit(CameraFunction function) { + return new LayoutPropertyValue<>("line-miter-limit", function); } /** @@ -1238,18 +1333,21 @@ public static Property> lineMiterLimit(Function function) * @param value a Float value * @return property wrapper around Float */ - public static Property lineRoundLimit(Float value) { - return new LayoutProperty<>("line-round-limit", value); + public static PropertyValue lineRoundLimit(Float value) { + return new LayoutPropertyValue<>("line-round-limit", value); } + + /** * Used to automatically convert round joins to miter joins for shallow angles. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> lineRoundLimit(Function function) { - return new LayoutProperty<>("line-round-limit", function); + public static PropertyValue> lineRoundLimit(CameraFunction function) { + return new LayoutPropertyValue<>("line-round-limit", function); } /** @@ -1258,18 +1356,21 @@ public static Property> lineRoundLimit(Function function) * @param value a String value * @return property wrapper around String */ - public static Property symbolPlacement(@Property.SYMBOL_PLACEMENT String value) { - return new LayoutProperty<>("symbol-placement", value); + public static PropertyValue symbolPlacement(@Property.SYMBOL_PLACEMENT String value) { + return new LayoutPropertyValue<>("symbol-placement", value); } + + /** * Label placement relative to its geometry. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> symbolPlacement(Function function) { - return new LayoutProperty<>("symbol-placement", function); + public static PropertyValue> symbolPlacement(CameraFunction function) { + return new LayoutPropertyValue<>("symbol-placement", function); } /** @@ -1278,42 +1379,44 @@ public static Property> symbolPlacement(Function functi * @param value a Float value * @return property wrapper around Float */ - public static Property symbolSpacing(Float value) { - return new LayoutProperty<>("symbol-spacing", value); + public static PropertyValue symbolSpacing(Float value) { + return new LayoutPropertyValue<>("symbol-spacing", value); } + + /** * Distance between two symbol anchors. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> symbolSpacing(Function function) { - return new LayoutProperty<>("symbol-spacing", function); + public static PropertyValue> symbolSpacing(CameraFunction function) { + return new LayoutPropertyValue<>("symbol-spacing", function); } /** - * If true, the symbols will not cross tile edges to avoid mutual collisions. Recommended in layers that don't have - * enough padding in the vector tile to prevent collisions, or if it is a point symbol layer placed after a line - * symbol layer. + * If true, the symbols will not cross tile edges to avoid mutual collisions. Recommended in layers that don't have enough padding in the vector tile to prevent collisions, or if it is a point symbol layer placed after a line symbol layer. * * @param value a Boolean value * @return property wrapper around Boolean */ - public static Property symbolAvoidEdges(Boolean value) { - return new LayoutProperty<>("symbol-avoid-edges", value); + public static PropertyValue symbolAvoidEdges(Boolean value) { + return new LayoutPropertyValue<>("symbol-avoid-edges", value); } + + /** - * If true, the symbols will not cross tile edges to avoid mutual collisions. Recommended in layers that don't have - * enough padding in the vector tile to prevent collisions, or if it is a point symbol layer placed after a line - * symbol layer. + * If true, the symbols will not cross tile edges to avoid mutual collisions. Recommended in layers that don't have enough padding in the vector tile to prevent collisions, or if it is a point symbol layer placed after a line symbol layer. * - * @param function a wrapper function for Boolean + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Boolean * @return property wrapper around a Boolean function */ - public static Property> symbolAvoidEdges(Function function) { - return new LayoutProperty<>("symbol-avoid-edges", function); + public static PropertyValue> symbolAvoidEdges(CameraFunction function) { + return new LayoutPropertyValue<>("symbol-avoid-edges", function); } /** @@ -1322,18 +1425,21 @@ public static Property> symbolAvoidEdges(Function fun * @param value a Boolean value * @return property wrapper around Boolean */ - public static Property iconAllowOverlap(Boolean value) { - return new LayoutProperty<>("icon-allow-overlap", value); + public static PropertyValue iconAllowOverlap(Boolean value) { + return new LayoutPropertyValue<>("icon-allow-overlap", value); } + + /** * If true, the icon will be visible even if it collides with other previously drawn symbols. * - * @param function a wrapper function for Boolean + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Boolean * @return property wrapper around a Boolean function */ - public static Property> iconAllowOverlap(Function function) { - return new LayoutProperty<>("icon-allow-overlap", function); + public static PropertyValue> iconAllowOverlap(CameraFunction function) { + return new LayoutPropertyValue<>("icon-allow-overlap", function); } /** @@ -1342,40 +1448,44 @@ public static Property> iconAllowOverlap(Function fun * @param value a Boolean value * @return property wrapper around Boolean */ - public static Property iconIgnorePlacement(Boolean value) { - return new LayoutProperty<>("icon-ignore-placement", value); + public static PropertyValue iconIgnorePlacement(Boolean value) { + return new LayoutPropertyValue<>("icon-ignore-placement", value); } + + /** * If true, other symbols can be visible even if they collide with the icon. * - * @param function a wrapper function for Boolean + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Boolean * @return property wrapper around a Boolean function */ - public static Property> iconIgnorePlacement(Function function) { - return new LayoutProperty<>("icon-ignore-placement", function); + public static PropertyValue> iconIgnorePlacement(CameraFunction function) { + return new LayoutPropertyValue<>("icon-ignore-placement", function); } /** - * If true, text will display without their corresponding icons when the icon collides with other symbols and the - * text does not. + * If true, text will display without their corresponding icons when the icon collides with other symbols and the text does not. * * @param value a Boolean value * @return property wrapper around Boolean */ - public static Property iconOptional(Boolean value) { - return new LayoutProperty<>("icon-optional", value); + public static PropertyValue iconOptional(Boolean value) { + return new LayoutPropertyValue<>("icon-optional", value); } + + /** - * If true, text will display without their corresponding icons when the icon collides with other symbols and the - * text does not. + * If true, text will display without their corresponding icons when the icon collides with other symbols and the text does not. * - * @param function a wrapper function for Boolean + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Boolean * @return property wrapper around a Boolean function */ - public static Property> iconOptional(Function function) { - return new LayoutProperty<>("icon-optional", function); + public static PropertyValue> iconOptional(CameraFunction function) { + return new LayoutPropertyValue<>("icon-optional", function); } /** @@ -1384,18 +1494,21 @@ public static Property> iconOptional(Function functio * @param value a String value * @return property wrapper around String */ - public static Property iconRotationAlignment(@Property.ICON_ROTATION_ALIGNMENT String value) { - return new LayoutProperty<>("icon-rotation-alignment", value); + public static PropertyValue iconRotationAlignment(@Property.ICON_ROTATION_ALIGNMENT String value) { + return new LayoutPropertyValue<>("icon-rotation-alignment", value); } + + /** * In combination with {@link Property.SYMBOL_PLACEMENT}, determines the rotation behavior of icons. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> iconRotationAlignment(Function function) { - return new LayoutProperty<>("icon-rotation-alignment", function); + public static PropertyValue> iconRotationAlignment(CameraFunction function) { + return new LayoutPropertyValue<>("icon-rotation-alignment", function); } /** @@ -1404,18 +1517,21 @@ public static Property> iconRotationAlignment(Function * @param value a Float value * @return property wrapper around Float */ - public static Property iconSize(Float value) { - return new LayoutProperty<>("icon-size", value); + public static PropertyValue iconSize(Float value) { + return new LayoutPropertyValue<>("icon-size", value); } + + /** * Scale factor for icon. 1 is original size, 3 triples the size. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> iconSize(Function function) { - return new LayoutProperty<>("icon-size", function); + public static PropertyValue> iconSize(CameraFunction function) { + return new LayoutPropertyValue<>("icon-size", function); } /** @@ -1424,40 +1540,44 @@ public static Property> iconSize(Function function) { * @param value a String value * @return property wrapper around String */ - public static Property iconTextFit(@Property.ICON_TEXT_FIT String value) { - return new LayoutProperty<>("icon-text-fit", value); + public static PropertyValue iconTextFit(@Property.ICON_TEXT_FIT String value) { + return new LayoutPropertyValue<>("icon-text-fit", value); } + + /** * Scales the icon to fit around the associated text. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> iconTextFit(Function function) { - return new LayoutProperty<>("icon-text-fit", function); + public static PropertyValue> iconTextFit(CameraFunction function) { + return new LayoutPropertyValue<>("icon-text-fit", function); } /** - * Size of the additional area added to dimensions determined by {@link Property.ICON_TEXT_FIT}, in clockwise order: - * top, right, bottom, left. + * Size of the additional area added to dimensions determined by {@link Property.ICON_TEXT_FIT}, in clockwise order: top, right, bottom, left. * * @param value a Float[] value * @return property wrapper around Float[] */ - public static Property iconTextFitPadding(Float[] value) { - return new LayoutProperty<>("icon-text-fit-padding", value); + public static PropertyValue iconTextFitPadding(Float[] value) { + return new LayoutPropertyValue<>("icon-text-fit-padding", value); } + + /** - * Size of the additional area added to dimensions determined by {@link Property.ICON_TEXT_FIT}, in clockwise order: - * top, right, bottom, left. + * Size of the additional area added to dimensions determined by {@link Property.ICON_TEXT_FIT}, in clockwise order: top, right, bottom, left. * - * @param function a wrapper function for Float[] + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float[] * @return property wrapper around a Float[] function */ - public static Property> iconTextFitPadding(Function function) { - return new LayoutProperty<>("icon-text-fit-padding", function); + public static PropertyValue> iconTextFitPadding(CameraFunction function) { + return new LayoutPropertyValue<>("icon-text-fit-padding", function); } /** @@ -1466,18 +1586,21 @@ public static Property> iconTextFitPadding(Function f * @param value a String value * @return property wrapper around String */ - public static Property iconImage(String value) { - return new LayoutProperty<>("icon-image", value); + public static PropertyValue iconImage(String value) { + return new LayoutPropertyValue<>("icon-image", value); } + + /** * A string with {tokens} replaced, referencing the data property to pull from. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> iconImage(Function function) { - return new LayoutProperty<>("icon-image", function); + public static PropertyValue> iconImage(CameraFunction function) { + return new LayoutPropertyValue<>("icon-image", function); } /** @@ -1486,18 +1609,21 @@ public static Property> iconImage(Function function) { * @param value a Float value * @return property wrapper around Float */ - public static Property iconRotate(Float value) { - return new LayoutProperty<>("icon-rotate", value); + public static PropertyValue iconRotate(Float value) { + return new LayoutPropertyValue<>("icon-rotate", value); } + + /** * Rotates the icon clockwise. * + * @param the function input type * @param function a wrapper function for Float * @return property wrapper around a Float function */ - public static Property> iconRotate(Function function) { - return new LayoutProperty<>("icon-rotate", function); + public static PropertyValue> iconRotate(Function function) { + return new LayoutPropertyValue<>("icon-rotate", function); } /** @@ -1506,18 +1632,21 @@ public static Property> iconRotate(Function function) { * @param value a Float value * @return property wrapper around Float */ - public static Property iconPadding(Float value) { - return new LayoutProperty<>("icon-padding", value); + public static PropertyValue iconPadding(Float value) { + return new LayoutPropertyValue<>("icon-padding", value); } + + /** * Size of the additional area around the icon bounding box used for detecting symbol collisions. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> iconPadding(Function function) { - return new LayoutProperty<>("icon-padding", function); + public static PropertyValue> iconPadding(CameraFunction function) { + return new LayoutPropertyValue<>("icon-padding", function); } /** @@ -1526,40 +1655,44 @@ public static Property> iconPadding(Function function) { * @param value a Boolean value * @return property wrapper around Boolean */ - public static Property iconKeepUpright(Boolean value) { - return new LayoutProperty<>("icon-keep-upright", value); + public static PropertyValue iconKeepUpright(Boolean value) { + return new LayoutPropertyValue<>("icon-keep-upright", value); } + + /** * If true, the icon may be flipped to prevent it from being rendered upside-down. * - * @param function a wrapper function for Boolean + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Boolean * @return property wrapper around a Boolean function */ - public static Property> iconKeepUpright(Function function) { - return new LayoutProperty<>("icon-keep-upright", function); + public static PropertyValue> iconKeepUpright(CameraFunction function) { + return new LayoutPropertyValue<>("icon-keep-upright", function); } /** - * Offset distance of icon from its anchor. Positive values indicate right and down, while negative values indicate - * left and up. + * Offset distance of icon from its anchor. Positive values indicate right and down, while negative values indicate left and up. When combined with {@link PropertyFactory#iconRotate} the offset will be as if the rotated direction was up. * * @param value a Float[] value * @return property wrapper around Float[] */ - public static Property iconOffset(Float[] value) { - return new LayoutProperty<>("icon-offset", value); + public static PropertyValue iconOffset(Float[] value) { + return new LayoutPropertyValue<>("icon-offset", value); } + + /** - * Offset distance of icon from its anchor. Positive values indicate right and down, while negative values indicate - * left and up. + * Offset distance of icon from its anchor. Positive values indicate right and down, while negative values indicate left and up. When combined with {@link PropertyFactory#iconRotate} the offset will be as if the rotated direction was up. * + * @param the function input type * @param function a wrapper function for Float[] * @return property wrapper around a Float[] function */ - public static Property> iconOffset(Function function) { - return new LayoutProperty<>("icon-offset", function); + public static PropertyValue> iconOffset(Function function) { + return new LayoutPropertyValue<>("icon-offset", function); } /** @@ -1568,40 +1701,44 @@ public static Property> iconOffset(Function function) * @param value a String value * @return property wrapper around String */ - public static Property textPitchAlignment(@Property.TEXT_PITCH_ALIGNMENT String value) { - return new LayoutProperty<>("text-pitch-alignment", value); + public static PropertyValue textPitchAlignment(@Property.TEXT_PITCH_ALIGNMENT String value) { + return new LayoutPropertyValue<>("text-pitch-alignment", value); } + + /** * Orientation of text when map is pitched. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> textPitchAlignment(Function function) { - return new LayoutProperty<>("text-pitch-alignment", function); + public static PropertyValue> textPitchAlignment(CameraFunction function) { + return new LayoutPropertyValue<>("text-pitch-alignment", function); } /** - * In combination with {@link Property.SYMBOL_PLACEMENT}, determines the rotation behavior of the individual glyphs - * forming the text. + * In combination with {@link Property.SYMBOL_PLACEMENT}, determines the rotation behavior of the individual glyphs forming the text. * * @param value a String value * @return property wrapper around String */ - public static Property textRotationAlignment(@Property.TEXT_ROTATION_ALIGNMENT String value) { - return new LayoutProperty<>("text-rotation-alignment", value); + public static PropertyValue textRotationAlignment(@Property.TEXT_ROTATION_ALIGNMENT String value) { + return new LayoutPropertyValue<>("text-rotation-alignment", value); } + + /** - * In combination with {@link Property.SYMBOL_PLACEMENT}, determines the rotation behavior of the individual glyphs - * forming the text. + * In combination with {@link Property.SYMBOL_PLACEMENT}, determines the rotation behavior of the individual glyphs forming the text. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> textRotationAlignment(Function function) { - return new LayoutProperty<>("text-rotation-alignment", function); + public static PropertyValue> textRotationAlignment(CameraFunction function) { + return new LayoutPropertyValue<>("text-rotation-alignment", function); } /** @@ -1610,18 +1747,21 @@ public static Property> textRotationAlignment(Function * @param value a String value * @return property wrapper around String */ - public static Property textField(String value) { - return new LayoutProperty<>("text-field", value); + public static PropertyValue textField(String value) { + return new LayoutPropertyValue<>("text-field", value); } + + /** * Value to use for a text label. Feature properties are specified using tokens like {field_name}. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> textField(Function function) { - return new LayoutProperty<>("text-field", function); + public static PropertyValue> textField(CameraFunction function) { + return new LayoutPropertyValue<>("text-field", function); } /** @@ -1630,18 +1770,21 @@ public static Property> textField(Function function) { * @param value a String[] value * @return property wrapper around String[] */ - public static Property textFont(String[] value) { - return new LayoutProperty<>("text-font", value); + public static PropertyValue textFont(String[] value) { + return new LayoutPropertyValue<>("text-font", value); } + + /** * Font stack to use for displaying text. * - * @param function a wrapper function for String[] + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String[] * @return property wrapper around a String[] function */ - public static Property> textFont(Function function) { - return new LayoutProperty<>("text-font", function); + public static PropertyValue> textFont(CameraFunction function) { + return new LayoutPropertyValue<>("text-font", function); } /** @@ -1650,18 +1793,21 @@ public static Property> textFont(Function function) * @param value a Float value * @return property wrapper around Float */ - public static Property textSize(Float value) { - return new LayoutProperty<>("text-size", value); + public static PropertyValue textSize(Float value) { + return new LayoutPropertyValue<>("text-size", value); } + + /** * Font size. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> textSize(Function function) { - return new LayoutProperty<>("text-size", function); + public static PropertyValue> textSize(CameraFunction function) { + return new LayoutPropertyValue<>("text-size", function); } /** @@ -1670,18 +1816,21 @@ public static Property> textSize(Function function) { * @param value a Float value * @return property wrapper around Float */ - public static Property textMaxWidth(Float value) { - return new LayoutProperty<>("text-max-width", value); + public static PropertyValue textMaxWidth(Float value) { + return new LayoutPropertyValue<>("text-max-width", value); } + + /** * The maximum line width for text wrapping. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> textMaxWidth(Function function) { - return new LayoutProperty<>("text-max-width", function); + public static PropertyValue> textMaxWidth(CameraFunction function) { + return new LayoutPropertyValue<>("text-max-width", function); } /** @@ -1690,18 +1839,21 @@ public static Property> textMaxWidth(Function function) { * @param value a Float value * @return property wrapper around Float */ - public static Property textLineHeight(Float value) { - return new LayoutProperty<>("text-line-height", value); + public static PropertyValue textLineHeight(Float value) { + return new LayoutPropertyValue<>("text-line-height", value); } + + /** * Text leading value for multi-line text. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> textLineHeight(Function function) { - return new LayoutProperty<>("text-line-height", function); + public static PropertyValue> textLineHeight(CameraFunction function) { + return new LayoutPropertyValue<>("text-line-height", function); } /** @@ -1710,18 +1862,21 @@ public static Property> textLineHeight(Function function) * @param value a Float value * @return property wrapper around Float */ - public static Property textLetterSpacing(Float value) { - return new LayoutProperty<>("text-letter-spacing", value); + public static PropertyValue textLetterSpacing(Float value) { + return new LayoutPropertyValue<>("text-letter-spacing", value); } + + /** * Text tracking amount. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> textLetterSpacing(Function function) { - return new LayoutProperty<>("text-letter-spacing", function); + public static PropertyValue> textLetterSpacing(CameraFunction function) { + return new LayoutPropertyValue<>("text-letter-spacing", function); } /** @@ -1730,18 +1885,21 @@ public static Property> textLetterSpacing(Function functi * @param value a String value * @return property wrapper around String */ - public static Property textJustify(@Property.TEXT_JUSTIFY String value) { - return new LayoutProperty<>("text-justify", value); + public static PropertyValue textJustify(@Property.TEXT_JUSTIFY String value) { + return new LayoutPropertyValue<>("text-justify", value); } + + /** * Text justification options. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> textJustify(Function function) { - return new LayoutProperty<>("text-justify", function); + public static PropertyValue> textJustify(CameraFunction function) { + return new LayoutPropertyValue<>("text-justify", function); } /** @@ -1750,18 +1908,21 @@ public static Property> textJustify(Function function) * @param value a String value * @return property wrapper around String */ - public static Property textAnchor(@Property.TEXT_ANCHOR String value) { - return new LayoutProperty<>("text-anchor", value); + public static PropertyValue textAnchor(@Property.TEXT_ANCHOR String value) { + return new LayoutPropertyValue<>("text-anchor", value); } + + /** * Part of the text placed closest to the anchor. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> textAnchor(Function function) { - return new LayoutProperty<>("text-anchor", function); + public static PropertyValue> textAnchor(CameraFunction function) { + return new LayoutPropertyValue<>("text-anchor", function); } /** @@ -1770,18 +1931,21 @@ public static Property> textAnchor(Function function) { * @param value a Float value * @return property wrapper around Float */ - public static Property textMaxAngle(Float value) { - return new LayoutProperty<>("text-max-angle", value); + public static PropertyValue textMaxAngle(Float value) { + return new LayoutPropertyValue<>("text-max-angle", value); } + + /** * Maximum angle change between adjacent characters. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> textMaxAngle(Function function) { - return new LayoutProperty<>("text-max-angle", function); + public static PropertyValue> textMaxAngle(CameraFunction function) { + return new LayoutPropertyValue<>("text-max-angle", function); } /** @@ -1790,18 +1954,21 @@ public static Property> textMaxAngle(Function function) { * @param value a Float value * @return property wrapper around Float */ - public static Property textRotate(Float value) { - return new LayoutProperty<>("text-rotate", value); + public static PropertyValue textRotate(Float value) { + return new LayoutPropertyValue<>("text-rotate", value); } + + /** * Rotates the text clockwise. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> textRotate(Function function) { - return new LayoutProperty<>("text-rotate", function); + public static PropertyValue> textRotate(CameraFunction function) { + return new LayoutPropertyValue<>("text-rotate", function); } /** @@ -1810,18 +1977,21 @@ public static Property> textRotate(Function function) { * @param value a Float value * @return property wrapper around Float */ - public static Property textPadding(Float value) { - return new LayoutProperty<>("text-padding", value); + public static PropertyValue textPadding(Float value) { + return new LayoutPropertyValue<>("text-padding", value); } + + /** * Size of the additional area around the text bounding box used for detecting symbol collisions. * - * @param function a wrapper function for Float + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float * @return property wrapper around a Float function */ - public static Property> textPadding(Function function) { - return new LayoutProperty<>("text-padding", function); + public static PropertyValue> textPadding(CameraFunction function) { + return new LayoutPropertyValue<>("text-padding", function); } /** @@ -1830,18 +2000,21 @@ public static Property> textPadding(Function function) { * @param value a Boolean value * @return property wrapper around Boolean */ - public static Property textKeepUpright(Boolean value) { - return new LayoutProperty<>("text-keep-upright", value); + public static PropertyValue textKeepUpright(Boolean value) { + return new LayoutPropertyValue<>("text-keep-upright", value); } + + /** * If true, the text may be flipped vertically to prevent it from being rendered upside-down. * - * @param function a wrapper function for Boolean + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Boolean * @return property wrapper around a Boolean function */ - public static Property> textKeepUpright(Function function) { - return new LayoutProperty<>("text-keep-upright", function); + public static PropertyValue> textKeepUpright(CameraFunction function) { + return new LayoutPropertyValue<>("text-keep-upright", function); } /** @@ -1850,40 +2023,44 @@ public static Property> textKeepUpright(Function func * @param value a String value * @return property wrapper around String */ - public static Property textTransform(@Property.TEXT_TRANSFORM String value) { - return new LayoutProperty<>("text-transform", value); + public static PropertyValue textTransform(@Property.TEXT_TRANSFORM String value) { + return new LayoutPropertyValue<>("text-transform", value); } + + /** * Specifies how to capitalize text, similar to the CSS {@link PropertyFactory#textTransform} property. * - * @param function a wrapper function for String + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for String * @return property wrapper around a String function */ - public static Property> textTransform(Function function) { - return new LayoutProperty<>("text-transform", function); + public static PropertyValue> textTransform(CameraFunction function) { + return new LayoutPropertyValue<>("text-transform", function); } /** - * Offset distance of text from its anchor. Positive values indicate right and down, while negative values indicate - * left and up. + * Offset distance of text from its anchor. Positive values indicate right and down, while negative values indicate left and up. * * @param value a Float[] value * @return property wrapper around Float[] */ - public static Property textOffset(Float[] value) { - return new LayoutProperty<>("text-offset", value); + public static PropertyValue textOffset(Float[] value) { + return new LayoutPropertyValue<>("text-offset", value); } + + /** - * Offset distance of text from its anchor. Positive values indicate right and down, while negative values indicate - * left and up. + * Offset distance of text from its anchor. Positive values indicate right and down, while negative values indicate left and up. * - * @param function a wrapper function for Float[] + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Float[] * @return property wrapper around a Float[] function */ - public static Property> textOffset(Function function) { - return new LayoutProperty<>("text-offset", function); + public static PropertyValue> textOffset(CameraFunction function) { + return new LayoutPropertyValue<>("text-offset", function); } /** @@ -1892,18 +2069,21 @@ public static Property> textOffset(Function function) * @param value a Boolean value * @return property wrapper around Boolean */ - public static Property textAllowOverlap(Boolean value) { - return new LayoutProperty<>("text-allow-overlap", value); + public static PropertyValue textAllowOverlap(Boolean value) { + return new LayoutPropertyValue<>("text-allow-overlap", value); } + + /** * If true, the text will be visible even if it collides with other previously drawn symbols. * - * @param function a wrapper function for Boolean + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Boolean * @return property wrapper around a Boolean function */ - public static Property> textAllowOverlap(Function function) { - return new LayoutProperty<>("text-allow-overlap", function); + public static PropertyValue> textAllowOverlap(CameraFunction function) { + return new LayoutPropertyValue<>("text-allow-overlap", function); } /** @@ -1912,46 +2092,49 @@ public static Property> textAllowOverlap(Function fun * @param value a Boolean value * @return property wrapper around Boolean */ - public static Property textIgnorePlacement(Boolean value) { - return new LayoutProperty<>("text-ignore-placement", value); + public static PropertyValue textIgnorePlacement(Boolean value) { + return new LayoutPropertyValue<>("text-ignore-placement", value); } + + /** * If true, other symbols can be visible even if they collide with the text. * - * @param function a wrapper function for Boolean + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Boolean * @return property wrapper around a Boolean function */ - public static Property> textIgnorePlacement(Function function) { - return new LayoutProperty<>("text-ignore-placement", function); + public static PropertyValue> textIgnorePlacement(CameraFunction function) { + return new LayoutPropertyValue<>("text-ignore-placement", function); } /** - * If true, icons will display without their corresponding text when the text collides with other symbols and the - * icon does not. + * If true, icons will display without their corresponding text when the text collides with other symbols and the icon does not. * * @param value a Boolean value * @return property wrapper around Boolean */ - public static Property textOptional(Boolean value) { - return new LayoutProperty<>("text-optional", value); + public static PropertyValue textOptional(Boolean value) { + return new LayoutPropertyValue<>("text-optional", value); } + + /** - * If true, icons will display without their corresponding text when the text collides with other symbols and the - * icon does not. + * If true, icons will display without their corresponding text when the text collides with other symbols and the icon does not. * - * @param function a wrapper function for Boolean + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for Boolean * @return property wrapper around a Boolean function */ - public static Property> textOptional(Function function) { - return new LayoutProperty<>("text-optional", function); + public static PropertyValue> textOptional(CameraFunction function) { + return new LayoutPropertyValue<>("text-optional", function); } @SuppressLint("DefaultLocale") - static String colorToRgbaString(@ColorInt int value) { - return String.format("rgba(%d, %d, %d, %d)", (value >> 16) & 0xFF, (value >> 8) & 0xFF, value & 0xFF, - (value >> 24) & 0xFF); + public static String colorToRgbaString(@ColorInt int value) { + return String.format("rgba(%d, %d, %d, %d)", (value >> 16) & 0xFF, (value >> 8) & 0xFF, value & 0xFF, (value >> 24) & 0xFF); } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java index 582a0bc74f5..5286e6916d7 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java @@ -1,7 +1,10 @@ package com.mapbox.mapboxsdk.style.layers; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import com.mapbox.mapboxsdk.style.functions.Function; + import timber.log.Timber; /** @@ -9,9 +12,11 @@ */ public class PropertyValue { - private final Object value; + public final String name; + public final T value; - /* package */ PropertyValue(Object value) { + /* package */ PropertyValue(@NonNull String name, T value) { + this.name = name; this.value = value; } @@ -28,10 +33,10 @@ public boolean isValue() { } @Nullable - public Function getFunction() { + public Function getFunction() { if (isFunction()) { // noinspection unchecked - return (Function) value; + return (Function) value; } else { Timber.w("not a function, try value"); return null; @@ -51,7 +56,6 @@ public T getValue() { @Override public String toString() { - return String.format("%s (%s)", getClass().getSimpleName(), value != null - ? value.getClass().getSimpleName() : null); + return String.format("%s: %s", name, value); } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java index 785106c3942..18716864296 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java @@ -1,9 +1,13 @@ -package com.mapbox.mapboxsdk.style.layers; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.style.layers; + +import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.UiThread; +import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; + /** * Raster map textures such as satellite imagery. * @@ -59,7 +63,7 @@ public RasterLayer withSourceLayer(String sourceLayer) { * @param properties the var-args properties * @return This */ - public RasterLayer withProperties(@NonNull Property... properties) { + public RasterLayer withProperties(@NonNull PropertyValue... properties) { setProperties(properties); return this; } @@ -73,7 +77,7 @@ public RasterLayer withProperties(@NonNull Property... properties) { */ @SuppressWarnings("unchecked") public PropertyValue getRasterOpacity() { - return (PropertyValue) new PropertyValue(nativeGetRasterOpacity()); + return (PropertyValue) new PropertyValue("raster-opacity", nativeGetRasterOpacity()); } /** @@ -83,7 +87,7 @@ public PropertyValue getRasterOpacity() { */ @SuppressWarnings("unchecked") public PropertyValue getRasterHueRotate() { - return (PropertyValue) new PropertyValue(nativeGetRasterHueRotate()); + return (PropertyValue) new PropertyValue("raster-hue-rotate", nativeGetRasterHueRotate()); } /** @@ -93,7 +97,7 @@ public PropertyValue getRasterHueRotate() { */ @SuppressWarnings("unchecked") public PropertyValue getRasterBrightnessMin() { - return (PropertyValue) new PropertyValue(nativeGetRasterBrightnessMin()); + return (PropertyValue) new PropertyValue("raster-brightness-min", nativeGetRasterBrightnessMin()); } /** @@ -103,7 +107,7 @@ public PropertyValue getRasterBrightnessMin() { */ @SuppressWarnings("unchecked") public PropertyValue getRasterBrightnessMax() { - return (PropertyValue) new PropertyValue(nativeGetRasterBrightnessMax()); + return (PropertyValue) new PropertyValue("raster-brightness-max", nativeGetRasterBrightnessMax()); } /** @@ -113,7 +117,7 @@ public PropertyValue getRasterBrightnessMax() { */ @SuppressWarnings("unchecked") public PropertyValue getRasterSaturation() { - return (PropertyValue) new PropertyValue(nativeGetRasterSaturation()); + return (PropertyValue) new PropertyValue("raster-saturation", nativeGetRasterSaturation()); } /** @@ -123,7 +127,7 @@ public PropertyValue getRasterSaturation() { */ @SuppressWarnings("unchecked") public PropertyValue getRasterContrast() { - return (PropertyValue) new PropertyValue(nativeGetRasterContrast()); + return (PropertyValue) new PropertyValue("raster-contrast", nativeGetRasterContrast()); } /** @@ -133,7 +137,7 @@ public PropertyValue getRasterContrast() { */ @SuppressWarnings("unchecked") public PropertyValue getRasterFadeDuration() { - return (PropertyValue) new PropertyValue(nativeGetRasterFadeDuration()); + return (PropertyValue) new PropertyValue("raster-fade-duration", nativeGetRasterFadeDuration()); } private native Object nativeGetRasterOpacity(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java index abc516d6d0f..2ed6dfa582f 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java @@ -1,6 +1,7 @@ -package com.mapbox.mapboxsdk.style.layers; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.style.layers; + import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.UiThread; @@ -96,14 +97,13 @@ public SymbolLayer withFilter(Filter.Statement filter) { return this; } - /** * Set a property or properties. * * @param properties the var-args properties * @return This */ - public SymbolLayer withProperties(@NonNull Property... properties) { + public SymbolLayer withProperties(@NonNull PropertyValue... properties) { setProperties(properties); return this; } @@ -117,7 +117,7 @@ public SymbolLayer withProperties(@NonNull Property... properties) { */ @SuppressWarnings("unchecked") public PropertyValue getSymbolPlacement() { - return (PropertyValue) new PropertyValue(nativeGetSymbolPlacement()); + return (PropertyValue) new PropertyValue("symbol-placement", nativeGetSymbolPlacement()); } /** @@ -127,7 +127,7 @@ public PropertyValue getSymbolPlacement() { */ @SuppressWarnings("unchecked") public PropertyValue getSymbolSpacing() { - return (PropertyValue) new PropertyValue(nativeGetSymbolSpacing()); + return (PropertyValue) new PropertyValue("symbol-spacing", nativeGetSymbolSpacing()); } /** @@ -137,7 +137,7 @@ public PropertyValue getSymbolSpacing() { */ @SuppressWarnings("unchecked") public PropertyValue getSymbolAvoidEdges() { - return (PropertyValue) new PropertyValue(nativeGetSymbolAvoidEdges()); + return (PropertyValue) new PropertyValue("symbol-avoid-edges", nativeGetSymbolAvoidEdges()); } /** @@ -147,7 +147,7 @@ public PropertyValue getSymbolAvoidEdges() { */ @SuppressWarnings("unchecked") public PropertyValue getIconAllowOverlap() { - return (PropertyValue) new PropertyValue(nativeGetIconAllowOverlap()); + return (PropertyValue) new PropertyValue("icon-allow-overlap", nativeGetIconAllowOverlap()); } /** @@ -157,7 +157,7 @@ public PropertyValue getIconAllowOverlap() { */ @SuppressWarnings("unchecked") public PropertyValue getIconIgnorePlacement() { - return (PropertyValue) new PropertyValue(nativeGetIconIgnorePlacement()); + return (PropertyValue) new PropertyValue("icon-ignore-placement", nativeGetIconIgnorePlacement()); } /** @@ -167,7 +167,7 @@ public PropertyValue getIconIgnorePlacement() { */ @SuppressWarnings("unchecked") public PropertyValue getIconOptional() { - return (PropertyValue) new PropertyValue(nativeGetIconOptional()); + return (PropertyValue) new PropertyValue("icon-optional", nativeGetIconOptional()); } /** @@ -177,7 +177,7 @@ public PropertyValue getIconOptional() { */ @SuppressWarnings("unchecked") public PropertyValue getIconRotationAlignment() { - return (PropertyValue) new PropertyValue(nativeGetIconRotationAlignment()); + return (PropertyValue) new PropertyValue("icon-rotation-alignment", nativeGetIconRotationAlignment()); } /** @@ -187,7 +187,7 @@ public PropertyValue getIconRotationAlignment() { */ @SuppressWarnings("unchecked") public PropertyValue getIconSize() { - return (PropertyValue) new PropertyValue(nativeGetIconSize()); + return (PropertyValue) new PropertyValue("icon-size", nativeGetIconSize()); } /** @@ -197,7 +197,7 @@ public PropertyValue getIconSize() { */ @SuppressWarnings("unchecked") public PropertyValue getIconTextFit() { - return (PropertyValue) new PropertyValue(nativeGetIconTextFit()); + return (PropertyValue) new PropertyValue("icon-text-fit", nativeGetIconTextFit()); } /** @@ -207,7 +207,7 @@ public PropertyValue getIconTextFit() { */ @SuppressWarnings("unchecked") public PropertyValue getIconTextFitPadding() { - return (PropertyValue) new PropertyValue(nativeGetIconTextFitPadding()); + return (PropertyValue) new PropertyValue("icon-text-fit-padding", nativeGetIconTextFitPadding()); } /** @@ -217,7 +217,7 @@ public PropertyValue getIconTextFitPadding() { */ @SuppressWarnings("unchecked") public PropertyValue getIconImage() { - return (PropertyValue) new PropertyValue(nativeGetIconImage()); + return (PropertyValue) new PropertyValue("icon-image", nativeGetIconImage()); } /** @@ -227,7 +227,7 @@ public PropertyValue getIconImage() { */ @SuppressWarnings("unchecked") public PropertyValue getIconRotate() { - return (PropertyValue) new PropertyValue(nativeGetIconRotate()); + return (PropertyValue) new PropertyValue("icon-rotate", nativeGetIconRotate()); } /** @@ -237,7 +237,7 @@ public PropertyValue getIconRotate() { */ @SuppressWarnings("unchecked") public PropertyValue getIconPadding() { - return (PropertyValue) new PropertyValue(nativeGetIconPadding()); + return (PropertyValue) new PropertyValue("icon-padding", nativeGetIconPadding()); } /** @@ -247,7 +247,7 @@ public PropertyValue getIconPadding() { */ @SuppressWarnings("unchecked") public PropertyValue getIconKeepUpright() { - return (PropertyValue) new PropertyValue(nativeGetIconKeepUpright()); + return (PropertyValue) new PropertyValue("icon-keep-upright", nativeGetIconKeepUpright()); } /** @@ -257,7 +257,7 @@ public PropertyValue getIconKeepUpright() { */ @SuppressWarnings("unchecked") public PropertyValue getIconOffset() { - return (PropertyValue) new PropertyValue(nativeGetIconOffset()); + return (PropertyValue) new PropertyValue("icon-offset", nativeGetIconOffset()); } /** @@ -267,7 +267,7 @@ public PropertyValue getIconOffset() { */ @SuppressWarnings("unchecked") public PropertyValue getTextPitchAlignment() { - return (PropertyValue) new PropertyValue(nativeGetTextPitchAlignment()); + return (PropertyValue) new PropertyValue("text-pitch-alignment", nativeGetTextPitchAlignment()); } /** @@ -277,7 +277,7 @@ public PropertyValue getTextPitchAlignment() { */ @SuppressWarnings("unchecked") public PropertyValue getTextRotationAlignment() { - return (PropertyValue) new PropertyValue(nativeGetTextRotationAlignment()); + return (PropertyValue) new PropertyValue("text-rotation-alignment", nativeGetTextRotationAlignment()); } /** @@ -287,7 +287,7 @@ public PropertyValue getTextRotationAlignment() { */ @SuppressWarnings("unchecked") public PropertyValue getTextField() { - return (PropertyValue) new PropertyValue(nativeGetTextField()); + return (PropertyValue) new PropertyValue("text-field", nativeGetTextField()); } /** @@ -297,7 +297,7 @@ public PropertyValue getTextField() { */ @SuppressWarnings("unchecked") public PropertyValue getTextFont() { - return (PropertyValue) new PropertyValue(nativeGetTextFont()); + return (PropertyValue) new PropertyValue("text-font", nativeGetTextFont()); } /** @@ -307,7 +307,7 @@ public PropertyValue getTextFont() { */ @SuppressWarnings("unchecked") public PropertyValue getTextSize() { - return (PropertyValue) new PropertyValue(nativeGetTextSize()); + return (PropertyValue) new PropertyValue("text-size", nativeGetTextSize()); } /** @@ -317,7 +317,7 @@ public PropertyValue getTextSize() { */ @SuppressWarnings("unchecked") public PropertyValue getTextMaxWidth() { - return (PropertyValue) new PropertyValue(nativeGetTextMaxWidth()); + return (PropertyValue) new PropertyValue("text-max-width", nativeGetTextMaxWidth()); } /** @@ -327,7 +327,7 @@ public PropertyValue getTextMaxWidth() { */ @SuppressWarnings("unchecked") public PropertyValue getTextLineHeight() { - return (PropertyValue) new PropertyValue(nativeGetTextLineHeight()); + return (PropertyValue) new PropertyValue("text-line-height", nativeGetTextLineHeight()); } /** @@ -337,7 +337,7 @@ public PropertyValue getTextLineHeight() { */ @SuppressWarnings("unchecked") public PropertyValue getTextLetterSpacing() { - return (PropertyValue) new PropertyValue(nativeGetTextLetterSpacing()); + return (PropertyValue) new PropertyValue("text-letter-spacing", nativeGetTextLetterSpacing()); } /** @@ -347,7 +347,7 @@ public PropertyValue getTextLetterSpacing() { */ @SuppressWarnings("unchecked") public PropertyValue getTextJustify() { - return (PropertyValue) new PropertyValue(nativeGetTextJustify()); + return (PropertyValue) new PropertyValue("text-justify", nativeGetTextJustify()); } /** @@ -357,7 +357,7 @@ public PropertyValue getTextJustify() { */ @SuppressWarnings("unchecked") public PropertyValue getTextAnchor() { - return (PropertyValue) new PropertyValue(nativeGetTextAnchor()); + return (PropertyValue) new PropertyValue("text-anchor", nativeGetTextAnchor()); } /** @@ -367,7 +367,7 @@ public PropertyValue getTextAnchor() { */ @SuppressWarnings("unchecked") public PropertyValue getTextMaxAngle() { - return (PropertyValue) new PropertyValue(nativeGetTextMaxAngle()); + return (PropertyValue) new PropertyValue("text-max-angle", nativeGetTextMaxAngle()); } /** @@ -377,7 +377,7 @@ public PropertyValue getTextMaxAngle() { */ @SuppressWarnings("unchecked") public PropertyValue getTextRotate() { - return (PropertyValue) new PropertyValue(nativeGetTextRotate()); + return (PropertyValue) new PropertyValue("text-rotate", nativeGetTextRotate()); } /** @@ -387,7 +387,7 @@ public PropertyValue getTextRotate() { */ @SuppressWarnings("unchecked") public PropertyValue getTextPadding() { - return (PropertyValue) new PropertyValue(nativeGetTextPadding()); + return (PropertyValue) new PropertyValue("text-padding", nativeGetTextPadding()); } /** @@ -397,7 +397,7 @@ public PropertyValue getTextPadding() { */ @SuppressWarnings("unchecked") public PropertyValue getTextKeepUpright() { - return (PropertyValue) new PropertyValue(nativeGetTextKeepUpright()); + return (PropertyValue) new PropertyValue("text-keep-upright", nativeGetTextKeepUpright()); } /** @@ -407,7 +407,7 @@ public PropertyValue getTextKeepUpright() { */ @SuppressWarnings("unchecked") public PropertyValue getTextTransform() { - return (PropertyValue) new PropertyValue(nativeGetTextTransform()); + return (PropertyValue) new PropertyValue("text-transform", nativeGetTextTransform()); } /** @@ -417,7 +417,7 @@ public PropertyValue getTextTransform() { */ @SuppressWarnings("unchecked") public PropertyValue getTextOffset() { - return (PropertyValue) new PropertyValue(nativeGetTextOffset()); + return (PropertyValue) new PropertyValue("text-offset", nativeGetTextOffset()); } /** @@ -427,7 +427,7 @@ public PropertyValue getTextOffset() { */ @SuppressWarnings("unchecked") public PropertyValue getTextAllowOverlap() { - return (PropertyValue) new PropertyValue(nativeGetTextAllowOverlap()); + return (PropertyValue) new PropertyValue("text-allow-overlap", nativeGetTextAllowOverlap()); } /** @@ -437,7 +437,7 @@ public PropertyValue getTextAllowOverlap() { */ @SuppressWarnings("unchecked") public PropertyValue getTextIgnorePlacement() { - return (PropertyValue) new PropertyValue(nativeGetTextIgnorePlacement()); + return (PropertyValue) new PropertyValue("text-ignore-placement", nativeGetTextIgnorePlacement()); } /** @@ -447,7 +447,7 @@ public PropertyValue getTextIgnorePlacement() { */ @SuppressWarnings("unchecked") public PropertyValue getTextOptional() { - return (PropertyValue) new PropertyValue(nativeGetTextOptional()); + return (PropertyValue) new PropertyValue("text-optional", nativeGetTextOptional()); } /** @@ -457,7 +457,7 @@ public PropertyValue getTextOptional() { */ @SuppressWarnings("unchecked") public PropertyValue getIconOpacity() { - return (PropertyValue) new PropertyValue(nativeGetIconOpacity()); + return (PropertyValue) new PropertyValue("icon-opacity", nativeGetIconOpacity()); } /** @@ -467,7 +467,7 @@ public PropertyValue getIconOpacity() { */ @SuppressWarnings("unchecked") public PropertyValue getIconColor() { - return (PropertyValue) new PropertyValue(nativeGetIconColor()); + return (PropertyValue) new PropertyValue("icon-color", nativeGetIconColor()); } /** @@ -494,7 +494,7 @@ public int getIconColorAsInt() { */ @SuppressWarnings("unchecked") public PropertyValue getIconHaloColor() { - return (PropertyValue) new PropertyValue(nativeGetIconHaloColor()); + return (PropertyValue) new PropertyValue("icon-halo-color", nativeGetIconHaloColor()); } /** @@ -521,7 +521,7 @@ public int getIconHaloColorAsInt() { */ @SuppressWarnings("unchecked") public PropertyValue getIconHaloWidth() { - return (PropertyValue) new PropertyValue(nativeGetIconHaloWidth()); + return (PropertyValue) new PropertyValue("icon-halo-width", nativeGetIconHaloWidth()); } /** @@ -531,7 +531,7 @@ public PropertyValue getIconHaloWidth() { */ @SuppressWarnings("unchecked") public PropertyValue getIconHaloBlur() { - return (PropertyValue) new PropertyValue(nativeGetIconHaloBlur()); + return (PropertyValue) new PropertyValue("icon-halo-blur", nativeGetIconHaloBlur()); } /** @@ -541,7 +541,7 @@ public PropertyValue getIconHaloBlur() { */ @SuppressWarnings("unchecked") public PropertyValue getIconTranslate() { - return (PropertyValue) new PropertyValue(nativeGetIconTranslate()); + return (PropertyValue) new PropertyValue("icon-translate", nativeGetIconTranslate()); } /** @@ -551,7 +551,7 @@ public PropertyValue getIconTranslate() { */ @SuppressWarnings("unchecked") public PropertyValue getIconTranslateAnchor() { - return (PropertyValue) new PropertyValue(nativeGetIconTranslateAnchor()); + return (PropertyValue) new PropertyValue("icon-translate-anchor", nativeGetIconTranslateAnchor()); } /** @@ -561,7 +561,7 @@ public PropertyValue getIconTranslateAnchor() { */ @SuppressWarnings("unchecked") public PropertyValue getTextOpacity() { - return (PropertyValue) new PropertyValue(nativeGetTextOpacity()); + return (PropertyValue) new PropertyValue("text-opacity", nativeGetTextOpacity()); } /** @@ -571,7 +571,7 @@ public PropertyValue getTextOpacity() { */ @SuppressWarnings("unchecked") public PropertyValue getTextColor() { - return (PropertyValue) new PropertyValue(nativeGetTextColor()); + return (PropertyValue) new PropertyValue("text-color", nativeGetTextColor()); } /** @@ -598,7 +598,7 @@ public int getTextColorAsInt() { */ @SuppressWarnings("unchecked") public PropertyValue getTextHaloColor() { - return (PropertyValue) new PropertyValue(nativeGetTextHaloColor()); + return (PropertyValue) new PropertyValue("text-halo-color", nativeGetTextHaloColor()); } /** @@ -625,7 +625,7 @@ public int getTextHaloColorAsInt() { */ @SuppressWarnings("unchecked") public PropertyValue getTextHaloWidth() { - return (PropertyValue) new PropertyValue(nativeGetTextHaloWidth()); + return (PropertyValue) new PropertyValue("text-halo-width", nativeGetTextHaloWidth()); } /** @@ -635,7 +635,7 @@ public PropertyValue getTextHaloWidth() { */ @SuppressWarnings("unchecked") public PropertyValue getTextHaloBlur() { - return (PropertyValue) new PropertyValue(nativeGetTextHaloBlur()); + return (PropertyValue) new PropertyValue("text-halo-blur", nativeGetTextHaloBlur()); } /** @@ -645,7 +645,7 @@ public PropertyValue getTextHaloBlur() { */ @SuppressWarnings("unchecked") public PropertyValue getTextTranslate() { - return (PropertyValue) new PropertyValue(nativeGetTextTranslate()); + return (PropertyValue) new PropertyValue("text-translate", nativeGetTextTranslate()); } /** @@ -655,7 +655,7 @@ public PropertyValue getTextTranslate() { */ @SuppressWarnings("unchecked") public PropertyValue getTextTranslateAnchor() { - return (PropertyValue) new PropertyValue(nativeGetTextTranslateAnchor()); + return (PropertyValue) new PropertyValue("text-translate-anchor", nativeGetTextTranslateAnchor()); } private native Object nativeGetSymbolPlacement(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs index 4657037df8a..93c705e34cd 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs @@ -4,14 +4,14 @@ const doc = locals.doc; -%> // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. -package com.mapbox.mapboxsdk.style.layers; -import android.support.annotation.UiThread; +package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; +import android.support.annotation.UiThread; -import static com.mapbox.mapboxsdk.utils.ColorUtils.*; +import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor; /** * <%- doc %> @@ -21,151 +21,153 @@ import static com.mapbox.mapboxsdk.utils.ColorUtils.*; @UiThread public class <%- camelize(type) %>Layer extends Layer { - /** - * Creates a <%- camelize(type) %>Layer. - * - * @param nativePtr pointer used by core - */ - public <%- camelize(type) %>Layer(long nativePtr) { - super(nativePtr); - } + /** + * Creates a <%- camelize(type) %>Layer. + * + * @param nativePtr pointer used by core + */ + public <%- camelize(type) %>Layer(long nativePtr) { + super(nativePtr); + } <% if (type === 'background') { -%> - /** - * Creates a <%- camelize(type) %>Layer. - * - * @param layerId the id of the layer - */ - public <%- camelize(type) %>Layer(String layerId) { - initialize(layerId); - } + /** + * Creates a <%- camelize(type) %>Layer. + * + * @param layerId the id of the layer + */ + public <%- camelize(type) %>Layer(String layerId) { + initialize(layerId); + } - protected native void initialize(String layerId); -<% } else { -%> - /** - * Creates a <%- camelize(type) %>Layer. - * - * @param layerId the id of the layer - * @param sourceId the id of the source - */ - public <%- camelize(type) %>Layer(String layerId, String sourceId) { - initialize(layerId, sourceId); - } - - protected native void initialize(String layerId, String sourceId); + protected native void initialize(String layerId); - /** - * Set the source layer. - * - * @param sourceLayer the source layer to set - */ - public void setSourceLayer(String sourceLayer) { - nativeSetSourceLayer(sourceLayer); - } +<% } else { -%> + /** + * Creates a <%- camelize(type) %>Layer. + * + * @param layerId the id of the layer + * @param sourceId the id of the source + */ + public <%- camelize(type) %>Layer(String layerId, String sourceId) { + initialize(layerId, sourceId); + } + + protected native void initialize(String layerId, String sourceId); + + /** + * Set the source layer. + * + * @param sourceLayer the source layer to set + */ + public void setSourceLayer(String sourceLayer) { + nativeSetSourceLayer(sourceLayer); + } + + /** + * Set the source Layer. + * + * @param sourceLayer the source layer to set + * @return This + */ + public <%- camelize(type) %>Layer withSourceLayer(String sourceLayer) { + setSourceLayer(sourceLayer); + return this; + } - /** - * Set the source Layer. - * - * @param sourceLayer the source layer to set - * @return This - */ - public <%- camelize(type) %>Layer withSourceLayer(String sourceLayer) { - setSourceLayer(sourceLayer); - return this; - } <% } -%> <% if (type !== 'background' && type !== 'raster') { -%> - /** - * Set a single filter. - * - * @param filter the filter to set - */ - public void setFilter(Filter.Statement filter) { - this.setFilter(filter.toArray()); - } - - /** - * Set an array of filters. - * - * @param filter the filter array to set - */ - public void setFilter(Object[] filter) { - nativeSetFilter(filter); - } - - /** - * Set an array of filters. - * - * @param filter tthe filter array to set - * @return This - */ - public <%- camelize(type) %>Layer withFilter(Object[] filter) { - setFilter(filter); - return this; - } - - /** - * Set a single filter. - * - * @param filter the filter to set - * @return This - */ - public <%- camelize(type) %>Layer withFilter(Filter.Statement filter) { - setFilter(filter); - return this; - } + /** + * Set a single filter. + * + * @param filter the filter to set + */ + public void setFilter(Filter.Statement filter) { + this.setFilter(filter.toArray()); + } + + /** + * Set an array of filters. + * + * @param filter the filter array to set + */ + public void setFilter(Object[] filter) { + nativeSetFilter(filter); + } + + /** + * Set an array of filters. + * + * @param filter tthe filter array to set + * @return This + */ + public <%- camelize(type) %>Layer withFilter(Object[] filter) { + setFilter(filter); + return this; + } + + /** + * Set a single filter. + * + * @param filter the filter to set + * @return This + */ + public <%- camelize(type) %>Layer withFilter(Filter.Statement filter) { + setFilter(filter); + return this; + } <% } -%> - - /** - * Set a property or properties. - * - * @param properties the var-args properties - * @return This - */ - public <%- camelize(type) %>Layer withProperties(@NonNull Property... properties) { - setProperties(properties); - return this; - } - - // Property getters + /** + * Set a property or properties. + * + * @param properties the var-args properties + * @return This + */ + public <%- camelize(type) %>Layer withProperties(@NonNull PropertyValue... properties) { + setProperties(properties); + return this; + } + + // Property getters <% for (const property of properties) { -%> - /** - * Get the <%- camelize(property.name) %> property - * - * @return property wrapper value around <%- propertyType(property) %> - */ - @SuppressWarnings("unchecked") - public PropertyValue<<%- propertyType(property) %>> get<%- camelize(property.name) %>() { - return (PropertyValue<<%- propertyType(property) %>>) new PropertyValue(nativeGet<%- camelize(property.name) %>()); - } - <% if (property.type == 'color') { -%> - /** - * <%- property.doc %> - * - * @return int representation of a rgba string color - * @throws RuntimeException thrown if property isn't a value - */ - @ColorInt - public int get<%- camelize(property.name) %>AsInt() { - PropertyValue<<%- propertyType(property) %>> value = get<%- camelize(property.name) %>(); - if (value.isValue()) { - return rgbaToColor(value.getValue()); - } else { - throw new RuntimeException("<%- property.name %> was set as a Function"); - } + /** + * Get the <%- camelize(property.name) %> property + * + * @return property wrapper value around <%- propertyType(property) %> + */ + @SuppressWarnings("unchecked") + public PropertyValue<<%- propertyType(property) %>> get<%- camelize(property.name) %>() { + return (PropertyValue<<%- propertyType(property) %>>) new PropertyValue("<%- property.name %>", nativeGet<%- camelize(property.name) %>()); + } +<% if (property.type == 'color') { -%> + + /** + * <%- property.doc %> + * + * @return int representation of a rgba string color + * @throws RuntimeException thrown if property isn't a value + */ + @ColorInt + public int get<%- camelize(property.name) %>AsInt() { + PropertyValue<<%- propertyType(property) %>> value = get<%- camelize(property.name) %>(); + if (value.isValue()) { + return rgbaToColor(value.getValue()); + } else { + throw new RuntimeException("<%- property.name %> was set as a Function"); } + } - <% } -%> +<% } -%> <% } -%> <% for (const property of properties) { -%> - private native Object nativeGet<%- camelize(property.name) %>(); + private native Object nativeGet<%- camelize(property.name) %>(); <% } -%> - @Override - protected native void finalize() throws Throwable; + @Override + protected native void finalize() throws Throwable; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property.java.ejs index eb6a0a6938e..aaab1fe9f10 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property.java.ejs +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property.java.ejs @@ -2,6 +2,7 @@ const properties = locals.properties; -%> // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + package com.mapbox.mapboxsdk.style.layers; import android.support.annotation.StringDef; @@ -12,56 +13,49 @@ import java.lang.annotation.RetentionPolicy; /** * Paint/Layout properties for Layer */ -public abstract class Property { - - // VISIBILITY: Whether this layer is displayed. - - /** - * The layer is shown. - */ - public static final String VISIBLE = "visible"; - /** - * The layer is hidden. - */ - public static final String NONE = "none"; - - @StringDef({ - VISIBLE, - NONE - }) - @Retention(RetentionPolicy.SOURCE) - public @interface VISIBILITY {} +public final class Property { + + // VISIBILITY: Whether this layer is displayed. + + /** + * The layer is shown. + */ + public static final String VISIBLE = "visible"; + /** + * The layer is hidden. + */ + public static final String NONE = "none"; + + @StringDef({ + VISIBLE, + NONE + }) + @Retention(RetentionPolicy.SOURCE) + public @interface VISIBILITY {} <% for (const property of properties) { -%> - // <%- snakeCaseUpper(property.name) %>: <%- property.doc %> + // <%- snakeCaseUpper(property.name) %>: <%- property.doc %> <% for (const value in property.values) { -%> - /** - * <%- propertyValueDoc(property, value) %> - */ - public static final String <%- snakeCaseUpper(property.name) %>_<%- snakeCaseUpper(value) %> = "<%- value %>"; + /** + * <%- propertyValueDoc(property, value) %> + */ + public static final String <%- snakeCaseUpper(property.name) %>_<%- snakeCaseUpper(value) %> = "<%- value %>"; <% } -%> - /** - * <%- property.doc %> - */ - @StringDef({ - <% for (const value of Object.keys(property.values)) { -%> - <%- snakeCaseUpper(property.name) %>_<%- snakeCaseUpper(value) %>, - <% } -%> - }) - @Retention(RetentionPolicy.SOURCE) - public @interface <%- snakeCaseUpper(property.name) %> {} + /** + * <%- property.doc %> + */ + @StringDef({ + <% for (const value of Object.keys(property.values)) { -%> + <%- snakeCaseUpper(property.name) %>_<%- snakeCaseUpper(value) %>, + <% } -%> + }) + @Retention(RetentionPolicy.SOURCE) + public @interface <%- snakeCaseUpper(property.name) %> {} <% } -%> - // Class definition - public final String name; - public final T value; - - /* package */ Property(String name, T value) { - this.name = name; - this.value = value; - } - + private Property() { + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property_factory.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property_factory.java.ejs index e9b7b6dcd15..2d3421d1d92 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property_factory.java.ejs +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/property_factory.java.ejs @@ -3,11 +3,15 @@ const layoutProperties = locals.layoutProperties; -%> // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + package com.mapbox.mapboxsdk.style.layers; import android.annotation.SuppressLint; import android.support.annotation.ColorInt; +import com.mapbox.mapboxsdk.style.functions.Function; +import com.mapbox.mapboxsdk.style.functions.CameraFunction; + /** * Constructs paint/layout properties for Layers * @@ -15,85 +19,121 @@ import android.support.annotation.ColorInt; */ public class PropertyFactory { - /** - * Set the property visibility. - * - * @param value the visibility value - * @return property wrapper around visibility - */ - public static Property visibility(@Property.VISIBILITY String value) { - return new LayoutProperty<>("visibility", value); - } - - /** - * Set the property visibility. - * - * @param function the visibility function - * @return property wrapper around a String function - */ - public static Property> visibility(Function function) { - return new LayoutProperty<>("visibility", function); - } + /** + * Set the property visibility. + * + * @param value the visibility value + * @return property wrapper around visibility + */ + public static PropertyValue visibility(@Property.VISIBILITY String value) { + return new LayoutPropertyValue<>("visibility", value); + } + + /** + * Set the property visibility. + * + * @param the function input type + * @param function the visibility function + * @return property wrapper around a String function + */ + public static PropertyValue> visibility(Function function) { + return new LayoutPropertyValue<>("visibility", function); + } <% for (const property of paintProperties) { -%> <% if (property.type == 'color') { -%> - /** - * <%- propertyFactoryMethodDoc(property) %> - * - * @param value a int color value - * @return property wrapper around String color - */ - public static Property <%- camelizeWithLeadingLowercase(property.name) %>(@ColorInt int value) { - return new PaintProperty<>("<%- property.name %>", colorToRgbaString(value)); - } + /** + * <%- propertyFactoryMethodDoc(property) %> + * + * @param value a int color value + * @return property wrapper around String color + */ + public static PropertyValue <%- camelizeWithLeadingLowercase(property.name) %>(@ColorInt int value) { + return new PaintPropertyValue<>("<%- property.name %>", colorToRgbaString(value)); + } <% } -%> - /** - * <%- propertyFactoryMethodDoc(property) %> - * - * @param value a <%- propertyType(property) %> value - * @return property wrapper around <%- propertyType(property) %> - */ - public static Property<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %>(<%- propertyTypeAnnotation(property) %><%- iff(() => propertyTypeAnnotation(property), " ") %><%- propertyType(property) %> value) { - return new PaintProperty<>("<%- property.name %>", value); - } - - /** - * <%- propertyFactoryMethodDoc(property) %> - * - * @param function a wrapper function for <%- propertyType(property) %> - * @return property wrapper around a <%- propertyType(property) %> function - */ - public static Property>> <%- camelizeWithLeadingLowercase(property.name) %>(Function<<%- propertyType(property) %>> function) { - return new PaintProperty<>("<%- property.name %>", function); - } + /** + * <%- propertyFactoryMethodDoc(property) %> + * + * @param value a <%- propertyType(property) %> value + * @return property wrapper around <%- propertyType(property) %> + */ + public static PropertyValue<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %>(<%- propertyTypeAnnotation(property) %><%- iff(() => propertyTypeAnnotation(property), " ") %><%- propertyType(property) %> value) { + return new PaintPropertyValue<>("<%- property.name %>", value); + } + +<% if (supportsPropertyFunction(property)) { -%> + + /** + * <%- propertyFactoryMethodDoc(property) %> + * + * @param the function input type + * @param function a wrapper function for <%- propertyType(property) %> + * @return property wrapper around a <%- propertyType(property) %> function + */ + public static PropertyValue>> <%- camelizeWithLeadingLowercase(property.name) %>(Function> function) { + return new PaintPropertyValue<>("<%- property.name %>", function); + } + +<% } else if (supportsZoomFunction(property)) { -%> + + /** + * <%- propertyFactoryMethodDoc(property) %> + * + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for <%- propertyType(property) %> + * @return property wrapper around a <%- propertyType(property) %> function + */ + public static PropertyValue>> <%- camelizeWithLeadingLowercase(property.name) %>(CameraFunction> function) { + return new PaintPropertyValue<>("<%- property.name %>", function); + } +<% } -%> <% } -%> <% for (const property of layoutProperties) { -%> - /** - * <%- propertyFactoryMethodDoc(property) %> - * - * @param value a <%- propertyType(property) %> value - * @return property wrapper around <%- propertyType(property) %> - */ - public static Property<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %>(<%- propertyTypeAnnotation(property) %><%- iff(() => propertyTypeAnnotation(property), " ") %><%- propertyType(property) %> value) { - return new LayoutProperty<>("<%- property.name %>", value); - } - - /** - * <%- propertyFactoryMethodDoc(property) %> - * - * @param function a wrapper function for <%- propertyType(property) %> - * @return property wrapper around a <%- propertyType(property) %> function - */ - public static Property>> <%- camelizeWithLeadingLowercase(property.name) %>(Function<<%- propertyType(property) %>> function) { - return new LayoutProperty<>("<%- property.name %>", function); - } + /** + * <%- propertyFactoryMethodDoc(property) %> + * + * @param value a <%- propertyType(property) %> value + * @return property wrapper around <%- propertyType(property) %> + */ + public static PropertyValue<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %>(<%- propertyTypeAnnotation(property) %><%- iff(() => propertyTypeAnnotation(property), " ") %><%- propertyType(property) %> value) { + return new LayoutPropertyValue<>("<%- property.name %>", value); + } + + +<% if (supportsPropertyFunction(property)) { -%> + + /** + * <%- propertyFactoryMethodDoc(property) %> + * + * @param the function input type + * @param function a wrapper function for <%- propertyType(property) %> + * @return property wrapper around a <%- propertyType(property) %> function + */ + public static PropertyValue>> <%- camelizeWithLeadingLowercase(property.name) %>(Function> function) { + return new LayoutPropertyValue<>("<%- property.name %>", function); + } +<% } else if (supportsZoomFunction(property)) { -%> + + /** + * <%- propertyFactoryMethodDoc(property) %> + * + * @param the zoom parameter type + * @param function a wrapper {@link CameraFunction} for <%- propertyType(property) %> + * @return property wrapper around a <%- propertyType(property) %> function + */ + public static PropertyValue>> <%- camelizeWithLeadingLowercase(property.name) %>(CameraFunction> function) { + return new LayoutPropertyValue<>("<%- property.name %>", function); + } + +<% } -%> <% } -%> - @SuppressLint("DefaultLocale") - static String colorToRgbaString(@ColorInt int value) { - return String.format("rgba(%d, %d, %d, %d)", (value >> 16) & 0xFF, (value >> 8) & 0xFF, value & 0xFF, (value >> 24) & 0xFF); - } + @SuppressLint("DefaultLocale") + public static String colorToRgbaString(@ColorInt int value) { + return String.format("rgba(%d, %d, %d, %d)", (value >> 16) & 0xFF, (value >> 8) & 0xFF, value & 0xFF, (value >> 24) & 0xFF); + } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/gradle-checkstyle.gradle b/platform/android/MapboxGLAndroidSDKTestApp/gradle-checkstyle.gradle index bfb8341dbc9..fdc4399f167 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/gradle-checkstyle.gradle +++ b/platform/android/MapboxGLAndroidSDKTestApp/gradle-checkstyle.gradle @@ -12,6 +12,7 @@ task checkstyle(type: Checkstyle) { source 'src' include '**/*.java' exclude '**/gen/**' + exclude '**/style/*LayerTest.java' classpath = files() ignoreFailures = false } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerStyleTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerStyleTest.java deleted file mode 100644 index d9e006ae42f..00000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerStyleTest.java +++ /dev/null @@ -1,141 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.style; -// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. - -import android.graphics.Color; -import android.support.test.espresso.Espresso; -import android.support.test.rule.ActivityTestRule; -import android.support.test.runner.AndroidJUnit4; - -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.style.layers.BackgroundLayer; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; -import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundPattern; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * Basic smoke tests for BackgroundLayer - */ -@RunWith(AndroidJUnit4.class) -public class BackgroundLayerStyleTest extends BaseStyleTest { - - @Rule - public final ActivityTestRule rule = new ActivityTestRule<>(RuntimeStyleTestActivity.class); - - private BackgroundLayer layer; - - private OnMapReadyIdlingResource idlingResource; - - private MapboxMap mapboxMap; - - @Before - public void setup() { - idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); - Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); - Timber.i("visibility"); - assertNotNull(layer); - - // Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); - - // Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } - - @Test - public void testBackgroundColor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); - Timber.i("background-color"); - 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 testBackgroundColorAsInt() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); - Timber.i("background-color"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(backgroundColor(Color.RED)); - assertEquals(layer.getBackgroundColorAsInt(), Color.RED); - } - - @Test - public void testBackgroundPattern() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); - Timber.i("background-pattern"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(backgroundPattern("pedestrian-polygon")); - assertEquals((String) layer.getBackgroundPattern().getValue(), (String) "pedestrian-polygon"); - } - - @Test - public void testBackgroundOpacity() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); - Timber.i("background-opacity"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(backgroundOpacity(0.3f)); - assertEquals((Float) layer.getBackgroundOpacity().getValue(), (Float) 0.3f); - } - - - @After - public void unregisterIntentServiceIdlingResource() { - Espresso.unregisterIdlingResources(idlingResource); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java index 82d2ecfa394..4637989dd51 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/BackgroundLayerTest.java @@ -1,12 +1,23 @@ -package com.mapbox.mapboxsdk.testapp.style; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.testapp.style; + import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; 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.CompositeStops; +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.Stops; import com.mapbox.mapboxsdk.style.layers.BackgroundLayer; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; @@ -18,16 +29,14 @@ import org.junit.Test; import org.junit.runner.RunWith; -import timber.log.Timber; +import java.util.Map; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundPattern; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +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 org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; /** * Basic smoke tests for BackgroundLayer @@ -48,17 +57,16 @@ public class BackgroundLayerTest extends BaseStyleTest { public void setup() { idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); Espresso.registerIdlingResources(idlingResource); + mapboxMap = rule.getActivity().getMapboxMap(); + + Timber.i("Retrieving layer"); + layer = mapboxMap.getLayerAs("background"); } @Test public void testSetVisibility() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); - Timber.i("visibility"); + Timber.i("Visibility"); assertNotNull(layer); // Get initial @@ -70,13 +78,8 @@ public void testSetVisibility() { } @Test - public void testBackgroundColor() { + public void testBackgroundColorAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); Timber.i("background-color"); assertNotNull(layer); @@ -86,13 +89,34 @@ public void testBackgroundColor() { } @Test - public void testBackgroundColorAsInt() { + public void testBackgroundColorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("background-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // 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()); + } - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); + @Test + public void testBackgroundColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("background-color"); assertNotNull(layer); @@ -102,13 +126,8 @@ public void testBackgroundColorAsInt() { } @Test - public void testBackgroundPattern() { + public void testBackgroundPatternAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); Timber.i("background-pattern"); assertNotNull(layer); @@ -118,13 +137,33 @@ public void testBackgroundPattern() { } @Test - public void testBackgroundOpacity() { + public void testBackgroundPatternAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("background-pattern"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // 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()); + } - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); + @Test + public void testBackgroundOpacityAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("background-opacity"); assertNotNull(layer); @@ -133,6 +172,32 @@ public void testBackgroundOpacity() { assertEquals((Float) layer.getBackgroundOpacity().getValue(), (Float) 0.3f); } + @Test + public void testBackgroundOpacityAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("background-opacity"); + 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()); + } + @After public void unregisterIntentServiceIdlingResource() { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerStyleTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerStyleTest.java deleted file mode 100644 index 15645970096..00000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerStyleTest.java +++ /dev/null @@ -1,265 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.style; -// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. - -import android.graphics.Color; -import android.support.test.espresso.Espresso; -import android.support.test.rule.ActivityTestRule; -import android.support.test.runner.AndroidJUnit4; - -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.style.layers.CircleLayer; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; -import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.layers.Property.CIRCLE_PITCH_SCALE_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.CIRCLE_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleBlur; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circlePitchScale; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * Basic smoke tests for CircleLayer - */ -@RunWith(AndroidJUnit4.class) -public class CircleLayerStyleTest extends BaseStyleTest { - - @Rule - public final ActivityTestRule rule = new ActivityTestRule<>(RuntimeStyleTestActivity.class); - - private CircleLayer layer; - - private OnMapReadyIdlingResource idlingResource; - - private MapboxMap mapboxMap; - - @Before - public void setup() { - idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); - Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("visibility"); - assertNotNull(layer); - - // Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); - - // Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } - - @Test - public void testCircleRadius() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("circle-radius"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(circleRadius(0.3f)); - assertEquals((Float) layer.getCircleRadius().getValue(), (Float) 0.3f); - } - - @Test - public void testCircleColor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("circle-color"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(circleColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getCircleColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - - @Test - public void testCircleColorAsInt() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("circle-color"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(circleColor(Color.RED)); - assertEquals(layer.getCircleColorAsInt(), Color.RED); - } - - @Test - public void testCircleBlur() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("circle-blur"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(circleBlur(0.3f)); - assertEquals((Float) layer.getCircleBlur().getValue(), (Float) 0.3f); - } - - @Test - public void testCircleOpacity() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("circle-opacity"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(circleOpacity(0.3f)); - assertEquals((Float) layer.getCircleOpacity().getValue(), (Float) 0.3f); - } - - @Test - public void testCircleTranslate() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("circle-translate"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(circleTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getCircleTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); - } - - @Test - public void testCircleTranslateAnchor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("circle-translate-anchor"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(circleTranslateAnchor(CIRCLE_TRANSLATE_ANCHOR_MAP)); - assertEquals((String) layer.getCircleTranslateAnchor().getValue(), (String) CIRCLE_TRANSLATE_ANCHOR_MAP); - } - - @Test - public void testCirclePitchScale() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("circle-pitch-scale"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(circlePitchScale(CIRCLE_PITCH_SCALE_MAP)); - assertEquals((String) layer.getCirclePitchScale().getValue(), (String) CIRCLE_PITCH_SCALE_MAP); - } - - - @After - public void unregisterIntentServiceIdlingResource() { - Espresso.unregisterIdlingResources(idlingResource); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java index 15a0813fa1a..4860af15d5a 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/CircleLayerTest.java @@ -1,12 +1,23 @@ -package com.mapbox.mapboxsdk.testapp.style; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.testapp.style; + import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; 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.CompositeStops; +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.Stops; import com.mapbox.mapboxsdk.style.layers.CircleLayer; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; @@ -18,25 +29,14 @@ import org.junit.Test; import org.junit.runner.RunWith; -import timber.log.Timber; +import java.util.Map; -import static com.mapbox.mapboxsdk.style.layers.Property.CIRCLE_PITCH_SCALE_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.CIRCLE_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleBlur; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circlePitchScale; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleStrokeColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleStrokeOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleStrokeWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +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 org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; /** * Basic smoke tests for CircleLayer @@ -57,12 +57,6 @@ public class CircleLayerTest extends BaseStyleTest { public void setup() { idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - mapboxMap = rule.getActivity().getMapboxMap(); if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { @@ -73,7 +67,12 @@ public void testSetVisibility() { // Layer reference is now stale, get new reference layer = mapboxMap.getLayerAs("my-layer"); } - Timber.i("visibility"); + } + + @Test + public void testSetVisibility() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("Visibility"); assertNotNull(layer); // Get initial @@ -85,19 +84,8 @@ public void testSetVisibility() { } @Test - public void testCircleRadius() { + public void testCircleRadiusAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } Timber.i("circle-radius"); assertNotNull(layer); @@ -107,19 +95,142 @@ public void testCircleRadius() { } @Test - public void testCircleColor() { + public void testCircleRadiusAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-radius"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circleRadius( + zoom( + exponential( + stop(2, circleRadius(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleRadius()); + assertNotNull(layer.getCircleRadius().getFunction()); + assertEquals(CameraFunction.class, layer.getCircleRadius().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getCircleRadius().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getCircleRadius().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getCircleRadius().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCircleRadiusAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-radius"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleRadius(property("FeaturePropertyA", Stops.identity())) + ); + + // Verify + assertNotNull(layer.getCircleRadius()); + assertNotNull(layer.getCircleRadius().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleRadius().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleRadius().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getCircleRadius().getFunction().getStops().getClass()); + } + + @Test + public void testCircleRadiusAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-radius"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleRadius( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, circleRadius(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleRadius()); + assertNotNull(layer.getCircleRadius().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleRadius().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleRadius().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getCircleRadius().getFunction().getStops().getClass()); + } + + @Test + public void testCircleRadiusAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-radius"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleRadius( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, circleRadius(0.3f)) + ).withDefaultValue(0.3f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleRadius()); + assertNotNull(layer.getCircleRadius().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleRadius().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleRadius().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getCircleRadius().getFunction().getStops().getClass()); + assertEquals(0.3f, ((CategoricalStops) layer.getCircleRadius().getFunction().getStops()).getDefaultValue()); + } + + @Test + public void testCircleRadiusAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-radius"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleRadius( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, circleRadius(0.9f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleRadius()); + assertNotNull(layer.getCircleRadius().getFunction()); + assertEquals(CompositeFunction.class, layer.getCircleRadius().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getCircleRadius().getFunction()).getProperty()); + assertEquals(CompositeStops.class, layer.getCircleRadius().getFunction().getStops().getClass()); + assertEquals(1, ((CompositeStops) layer.getCircleRadius().getFunction().getStops()).size()); + + CompositeStops> stops = + (CompositeStops>) layer.getCircleRadius().getFunction().getStops(); + Map.Entry> stop = stops.iterator().next(); + assertEquals(ExponentialStops.class, stop.getValue().getClass()); + assertEquals(0f, stop.getKey(), 0.001); + assertEquals(1, stop.getValue().size()); + assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); + assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + } + + @Test + public void testCircleColorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-color"); assertNotNull(layer); @@ -129,19 +240,105 @@ public void testCircleColor() { } @Test - public void testCircleColorAsInt() { + public void testCircleColorAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleColor( + zoom( + exponential( + stop(2, circleColor("rgba(0, 0, 0, 1)")) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleColor()); + assertNotNull(layer.getCircleColor().getFunction()); + assertEquals(CameraFunction.class, layer.getCircleColor().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getCircleColor().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getCircleColor().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getCircleColor().getFunction().getStops()).size()); + } + + @Test + public void testCircleColorAsIdentitySourceFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circleColor(property("FeaturePropertyA", Stops.identity())) + ); + + // Verify + assertNotNull(layer.getCircleColor()); + assertNotNull(layer.getCircleColor().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleColor().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getCircleColor().getFunction().getStops().getClass()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCircleColorAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleColor( + property( + "FeaturePropertyA", + exponential( + stop(Color.RED, circleColor(Color.RED)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleColor()); + assertNotNull(layer.getCircleColor().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleColor().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getCircleColor().getFunction().getStops().getClass()); + } + + @Test + public void testCircleColorAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleColor( + property( + "FeaturePropertyA", + categorical( + stop("valueA", circleColor(Color.RED)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleColor()); + assertNotNull(layer.getCircleColor().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleColor().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getCircleColor().getFunction().getStops().getClass()); + } + + @Test + public void testCircleColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-color"); assertNotNull(layer); @@ -151,19 +348,8 @@ public void testCircleColorAsInt() { } @Test - public void testCircleBlur() { + public void testCircleBlurAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } Timber.i("circle-blur"); assertNotNull(layer); @@ -173,19 +359,142 @@ public void testCircleBlur() { } @Test - public void testCircleOpacity() { + public void testCircleBlurAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleBlur( + zoom( + exponential( + stop(2, circleBlur(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleBlur()); + assertNotNull(layer.getCircleBlur().getFunction()); + assertEquals(CameraFunction.class, layer.getCircleBlur().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getCircleBlur().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getCircleBlur().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getCircleBlur().getFunction().getStops()).size()); + } + + @Test + public void testCircleBlurAsIdentitySourceFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-blur"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circleBlur(property("FeaturePropertyA", Stops.identity())) + ); + + // Verify + assertNotNull(layer.getCircleBlur()); + assertNotNull(layer.getCircleBlur().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleBlur().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getCircleBlur().getFunction().getStops().getClass()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCircleBlurAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleBlur( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, circleBlur(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleBlur()); + assertNotNull(layer.getCircleBlur().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleBlur().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getCircleBlur().getFunction().getStops().getClass()); + } + + @Test + public void testCircleBlurAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleBlur( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, circleBlur(0.3f)) + ).withDefaultValue(0.3f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleBlur()); + assertNotNull(layer.getCircleBlur().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleBlur().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getCircleBlur().getFunction().getStops().getClass()); + assertEquals(0.3f, ((CategoricalStops) layer.getCircleBlur().getFunction().getStops()).getDefaultValue()); + } + + @Test + public void testCircleBlurAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleBlur( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, circleBlur(0.9f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleBlur()); + assertNotNull(layer.getCircleBlur().getFunction()); + assertEquals(CompositeFunction.class, layer.getCircleBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getCircleBlur().getFunction()).getProperty()); + assertEquals(CompositeStops.class, layer.getCircleBlur().getFunction().getStops().getClass()); + assertEquals(1, ((CompositeStops) layer.getCircleBlur().getFunction().getStops()).size()); + + CompositeStops> stops = + (CompositeStops>) layer.getCircleBlur().getFunction().getStops(); + Map.Entry> stop = stops.iterator().next(); + assertEquals(ExponentialStops.class, stop.getValue().getClass()); + assertEquals(0f, stop.getKey(), 0.001); + assertEquals(1, stop.getValue().size()); + assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); + assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + } + + @Test + public void testCircleOpacityAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-opacity"); assertNotNull(layer); @@ -195,41 +504,179 @@ public void testCircleOpacity() { } @Test - public void testCircleTranslate() { + public void testCircleOpacityAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-opacity"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circleOpacity( + zoom( + exponential( + stop(2, circleOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleOpacity()); + assertNotNull(layer.getCircleOpacity().getFunction()); + assertEquals(CameraFunction.class, layer.getCircleOpacity().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getCircleOpacity().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getCircleOpacity().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getCircleOpacity().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCircleOpacityAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleOpacity(property("FeaturePropertyA", Stops.identity())) + ); + + // Verify + assertNotNull(layer.getCircleOpacity()); + assertNotNull(layer.getCircleOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleOpacity().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getCircleOpacity().getFunction().getStops().getClass()); + } + + @Test + public void testCircleOpacityAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleOpacity( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, circleOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleOpacity()); + assertNotNull(layer.getCircleOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleOpacity().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getCircleOpacity().getFunction().getStops().getClass()); + } + + @Test + public void testCircleOpacityAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleOpacity( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, circleOpacity(0.3f)) + ).withDefaultValue(0.3f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleOpacity()); + assertNotNull(layer.getCircleOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleOpacity().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getCircleOpacity().getFunction().getStops().getClass()); + assertEquals(0.3f, ((CategoricalStops) layer.getCircleOpacity().getFunction().getStops()).getDefaultValue()); + } + + @Test + public void testCircleOpacityAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleOpacity( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, circleOpacity(0.9f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleOpacity()); + assertNotNull(layer.getCircleOpacity().getFunction()); + assertEquals(CompositeFunction.class, layer.getCircleOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getCircleOpacity().getFunction()).getProperty()); + assertEquals(CompositeStops.class, layer.getCircleOpacity().getFunction().getStops().getClass()); + assertEquals(1, ((CompositeStops) layer.getCircleOpacity().getFunction().getStops()).size()); + + CompositeStops> stops = + (CompositeStops>) layer.getCircleOpacity().getFunction().getStops(); + Map.Entry> stop = stops.iterator().next(); + assertEquals(ExponentialStops.class, stop.getValue().getClass()); + assertEquals(0f, stop.getKey(), 0.001); + assertEquals(1, stop.getValue().size()); + assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); + assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + } + + @Test + public void testCircleTranslateAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-translate"); assertNotNull(layer); // Set and Get - layer.setProperties(circleTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getCircleTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); + layer.setProperties(circleTranslate(new Float[]{0f,0f})); + assertEquals((Float[]) layer.getCircleTranslate().getValue(), (Float[]) new Float[]{0f,0f}); } @Test - public void testCircleTranslateAnchor() { + public void testCircleTranslateAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-translate"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circleTranslate( + zoom( + exponential( + stop(2, circleTranslate(new Float[]{0f,0f})) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleTranslate()); + assertNotNull(layer.getCircleTranslate().getFunction()); + assertEquals(CameraFunction.class, layer.getCircleTranslate().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getCircleTranslate().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getCircleTranslate().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getCircleTranslate().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCircleTranslateAnchorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-translate-anchor"); assertNotNull(layer); @@ -239,19 +686,33 @@ public void testCircleTranslateAnchor() { } @Test - public void testCirclePitchScale() { + public void testCircleTranslateAnchorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-translate-anchor"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circleTranslateAnchor( + zoom( + interval( + stop(2, circleTranslateAnchor(CIRCLE_TRANSLATE_ANCHOR_MAP)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleTranslateAnchor()); + assertNotNull(layer.getCircleTranslateAnchor().getFunction()); + assertEquals(CameraFunction.class, layer.getCircleTranslateAnchor().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getCircleTranslateAnchor().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getCircleTranslateAnchor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCirclePitchScaleAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-pitch-scale"); assertNotNull(layer); @@ -261,19 +722,33 @@ public void testCirclePitchScale() { } @Test - public void testCircleStrokeWidth() { + public void testCirclePitchScaleAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-pitch-scale"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circlePitchScale( + zoom( + interval( + stop(2, circlePitchScale(CIRCLE_PITCH_SCALE_MAP)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getCirclePitchScale()); + assertNotNull(layer.getCirclePitchScale().getFunction()); + assertEquals(CameraFunction.class, layer.getCirclePitchScale().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getCirclePitchScale().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getCirclePitchScale().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCircleStrokeWidthAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-stroke-width"); assertNotNull(layer); @@ -283,19 +758,142 @@ public void testCircleStrokeWidth() { } @Test - public void testCircleStrokeColor() { + public void testCircleStrokeWidthAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-width"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circleStrokeWidth( + zoom( + exponential( + stop(2, circleStrokeWidth(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeWidth()); + assertNotNull(layer.getCircleStrokeWidth().getFunction()); + assertEquals(CameraFunction.class, layer.getCircleStrokeWidth().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getCircleStrokeWidth().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getCircleStrokeWidth().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getCircleStrokeWidth().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCircleStrokeWidthAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeWidth(property("FeaturePropertyA", Stops.identity())) + ); + + // Verify + assertNotNull(layer.getCircleStrokeWidth()); + assertNotNull(layer.getCircleStrokeWidth().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleStrokeWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeWidth().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getCircleStrokeWidth().getFunction().getStops().getClass()); + } + + @Test + public void testCircleStrokeWidthAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeWidth( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, circleStrokeWidth(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeWidth()); + assertNotNull(layer.getCircleStrokeWidth().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleStrokeWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeWidth().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getCircleStrokeWidth().getFunction().getStops().getClass()); + } + + @Test + public void testCircleStrokeWidthAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeWidth( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, circleStrokeWidth(0.3f)) + ).withDefaultValue(0.3f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeWidth()); + assertNotNull(layer.getCircleStrokeWidth().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleStrokeWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeWidth().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getCircleStrokeWidth().getFunction().getStops().getClass()); + assertEquals(0.3f, ((CategoricalStops) layer.getCircleStrokeWidth().getFunction().getStops()).getDefaultValue()); + } + + @Test + public void testCircleStrokeWidthAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeWidth( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, circleStrokeWidth(0.9f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeWidth()); + assertNotNull(layer.getCircleStrokeWidth().getFunction()); + assertEquals(CompositeFunction.class, layer.getCircleStrokeWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getCircleStrokeWidth().getFunction()).getProperty()); + assertEquals(CompositeStops.class, layer.getCircleStrokeWidth().getFunction().getStops().getClass()); + assertEquals(1, ((CompositeStops) layer.getCircleStrokeWidth().getFunction().getStops()).size()); + + CompositeStops> stops = + (CompositeStops>) layer.getCircleStrokeWidth().getFunction().getStops(); + Map.Entry> stop = stops.iterator().next(); + assertEquals(ExponentialStops.class, stop.getValue().getClass()); + assertEquals(0f, stop.getKey(), 0.001); + assertEquals(1, stop.getValue().size()); + assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); + assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + } + + @Test + public void testCircleStrokeColorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-stroke-color"); assertNotNull(layer); @@ -305,19 +903,105 @@ public void testCircleStrokeColor() { } @Test - public void testCircleStrokeColorAsInt() { + public void testCircleStrokeColorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + circleStrokeColor( + zoom( + exponential( + stop(2, circleStrokeColor("rgba(0, 0, 0, 1)")) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeColor()); + assertNotNull(layer.getCircleStrokeColor().getFunction()); + assertEquals(CameraFunction.class, layer.getCircleStrokeColor().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getCircleStrokeColor().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getCircleStrokeColor().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getCircleStrokeColor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testCircleStrokeColorAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeColor(property("FeaturePropertyA", Stops.identity())) + ); + + // Verify + assertNotNull(layer.getCircleStrokeColor()); + assertNotNull(layer.getCircleStrokeColor().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleStrokeColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeColor().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getCircleStrokeColor().getFunction().getStops().getClass()); + } + + @Test + public void testCircleStrokeColorAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeColor( + property( + "FeaturePropertyA", + exponential( + stop(Color.RED, circleStrokeColor(Color.RED)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeColor()); + assertNotNull(layer.getCircleStrokeColor().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleStrokeColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeColor().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getCircleStrokeColor().getFunction().getStops().getClass()); + } + + @Test + public void testCircleStrokeColorAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeColor( + property( + "FeaturePropertyA", + categorical( + stop("valueA", circleStrokeColor(Color.RED)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeColor()); + assertNotNull(layer.getCircleStrokeColor().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleStrokeColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeColor().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getCircleStrokeColor().getFunction().getStops().getClass()); + } + + @Test + public void testCircleStrokeColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("circle-stroke-color"); assertNotNull(layer); @@ -327,19 +1011,8 @@ public void testCircleStrokeColorAsInt() { } @Test - public void testCircleStrokeOpacity() { + public void testCircleStrokeOpacityAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new CircleLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } Timber.i("circle-stroke-opacity"); assertNotNull(layer); @@ -348,6 +1021,140 @@ public void testCircleStrokeOpacity() { assertEquals((Float) layer.getCircleStrokeOpacity().getValue(), (Float) 0.3f); } + @Test + public void testCircleStrokeOpacityAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeOpacity( + zoom( + exponential( + stop(2, circleStrokeOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeOpacity()); + assertNotNull(layer.getCircleStrokeOpacity().getFunction()); + assertEquals(CameraFunction.class, layer.getCircleStrokeOpacity().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getCircleStrokeOpacity().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getCircleStrokeOpacity().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getCircleStrokeOpacity().getFunction().getStops()).size()); + } + + @Test + public void testCircleStrokeOpacityAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeOpacity(property("FeaturePropertyA", Stops.identity())) + ); + + // Verify + assertNotNull(layer.getCircleStrokeOpacity()); + assertNotNull(layer.getCircleStrokeOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleStrokeOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeOpacity().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getCircleStrokeOpacity().getFunction().getStops().getClass()); + } + + @Test + public void testCircleStrokeOpacityAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeOpacity( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, circleStrokeOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeOpacity()); + assertNotNull(layer.getCircleStrokeOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleStrokeOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeOpacity().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getCircleStrokeOpacity().getFunction().getStops().getClass()); + } + + @Test + public void testCircleStrokeOpacityAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeOpacity( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, circleStrokeOpacity(0.3f)) + ).withDefaultValue(0.3f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeOpacity()); + assertNotNull(layer.getCircleStrokeOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getCircleStrokeOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getCircleStrokeOpacity().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getCircleStrokeOpacity().getFunction().getStops().getClass()); + assertEquals(0.3f, ((CategoricalStops) layer.getCircleStrokeOpacity().getFunction().getStops()).getDefaultValue()); + } + + @Test + public void testCircleStrokeOpacityAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("circle-stroke-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + circleStrokeOpacity( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, circleStrokeOpacity(0.9f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getCircleStrokeOpacity()); + assertNotNull(layer.getCircleStrokeOpacity().getFunction()); + assertEquals(CompositeFunction.class, layer.getCircleStrokeOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getCircleStrokeOpacity().getFunction()).getProperty()); + assertEquals(CompositeStops.class, layer.getCircleStrokeOpacity().getFunction().getStops().getClass()); + assertEquals(1, ((CompositeStops) layer.getCircleStrokeOpacity().getFunction().getStops()).size()); + + CompositeStops> stops = + (CompositeStops>) layer.getCircleStrokeOpacity().getFunction().getStops(); + Map.Entry> stop = stops.iterator().next(); + assertEquals(ExponentialStops.class, stop.getValue().getClass()); + assertEquals(0f, stop.getKey(), 0.001); + assertEquals(1, stop.getValue().size()); + assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); + assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + } + @After public void unregisterIntentServiceIdlingResource() { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerStyleTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerStyleTest.java deleted file mode 100644 index 6897048e9b5..00000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerStyleTest.java +++ /dev/null @@ -1,286 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.style; -// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. - -import android.graphics.Color; -import android.support.test.espresso.Espresso; -import android.support.test.rule.ActivityTestRule; -import android.support.test.runner.AndroidJUnit4; - -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.style.layers.FillLayer; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; -import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.layers.Property.FILL_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -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.fillOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillOutlineColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillPattern; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * Basic smoke tests for FillLayer - */ -@RunWith(AndroidJUnit4.class) -public class FillLayerStyleTest extends BaseStyleTest { - - @Rule - public final ActivityTestRule rule = new ActivityTestRule<>(RuntimeStyleTestActivity.class); - - private FillLayer layer; - - private OnMapReadyIdlingResource idlingResource; - - private MapboxMap mapboxMap; - - @Before - public void setup() { - idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); - Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } - Timber.i("visibility"); - assertNotNull(layer); - - // Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); - - // Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } - - @Test - public void testFillAntialias() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } - Timber.i("fill-antialias"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillAntialias(true)); - assertEquals((Boolean) layer.getFillAntialias().getValue(), (Boolean) true); - } - - @Test - public void testFillOpacity() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } - Timber.i("fill-opacity"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillOpacity(0.3f)); - assertEquals((Float) layer.getFillOpacity().getValue(), (Float) 0.3f); - } - - @Test - public void testFillColor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } - Timber.i("fill-color"); - assertNotNull(layer); - - // 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 testFillColorAsInt() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } - Timber.i("fill-color"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillColor(Color.RED)); - assertEquals(layer.getFillColorAsInt(), Color.RED); - } - - @Test - public void testFillOutlineColor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } - Timber.i("fill-outline-color"); - assertNotNull(layer); - - // 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 testFillOutlineColorAsInt() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } - Timber.i("fill-outline-color"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillOutlineColor(Color.RED)); - assertEquals(layer.getFillOutlineColorAsInt(), Color.RED); - } - - @Test - public void testFillTranslate() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } - Timber.i("fill-translate"); - 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 testFillTranslateAnchor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } - Timber.i("fill-translate-anchor"); - 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 testFillPattern() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } - Timber.i("fill-pattern"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(fillPattern("pedestrian-polygon")); - assertEquals((String) layer.getFillPattern().getValue(), (String) "pedestrian-polygon"); - } - - - @After - public void unregisterIntentServiceIdlingResource() { - Espresso.unregisterIdlingResources(idlingResource); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerTest.java index 45fb243ded2..bc9cec608b6 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/FillLayerTest.java @@ -1,12 +1,23 @@ -package com.mapbox.mapboxsdk.testapp.style; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.testapp.style; + import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; 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.CompositeStops; +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.Stops; import com.mapbox.mapboxsdk.style.layers.FillLayer; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; @@ -18,21 +29,14 @@ import org.junit.Test; import org.junit.runner.RunWith; -import timber.log.Timber; +import java.util.Map; -import static com.mapbox.mapboxsdk.style.layers.Property.FILL_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -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.fillOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillOutlineColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillPattern; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +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 org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; /** * Basic smoke tests for FillLayer @@ -53,12 +57,6 @@ public class FillLayerTest extends BaseStyleTest { public void setup() { idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - mapboxMap = rule.getActivity().getMapboxMap(); if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { @@ -69,7 +67,12 @@ public void testSetVisibility() { // Layer reference is now stale, get new reference layer = mapboxMap.getLayerAs("my-layer"); } - Timber.i("visibility"); + } + + @Test + public void testSetVisibility() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("Visibility"); assertNotNull(layer); // Get initial @@ -81,19 +84,8 @@ public void testSetVisibility() { } @Test - public void testFillAntialias() { + public void testFillAntialiasAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } Timber.i("fill-antialias"); assertNotNull(layer); @@ -103,19 +95,33 @@ public void testFillAntialias() { } @Test - public void testFillOpacity() { + public void testFillAntialiasAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-antialias"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // 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()); + } - 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"); - } + @Test + public void testFillOpacityAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("fill-opacity"); assertNotNull(layer); @@ -125,19 +131,142 @@ public void testFillOpacity() { } @Test - public void testFillColor() { + public void testFillOpacityAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-opacity"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // 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()); + } - 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"); - } + @Test + public void testFillOpacityAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + fillOpacity(property("FeaturePropertyA", Stops.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() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-opacity"); + 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() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + fillOpacity( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, fillOpacity(0.3f)) + ).withDefaultValue(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()); + assertEquals(0.3f, ((CategoricalStops) layer.getFillOpacity().getFunction().getStops()).getDefaultValue()); + } + + @Test + public void testFillOpacityAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + fillOpacity( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, fillOpacity(0.9f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getFillOpacity()); + assertNotNull(layer.getFillOpacity().getFunction()); + assertEquals(CompositeFunction.class, layer.getFillOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getFillOpacity().getFunction()).getProperty()); + assertEquals(CompositeStops.class, layer.getFillOpacity().getFunction().getStops().getClass()); + assertEquals(1, ((CompositeStops) layer.getFillOpacity().getFunction().getStops()).size()); + + CompositeStops> stops = + (CompositeStops>) layer.getFillOpacity().getFunction().getStops(); + Map.Entry> stop = stops.iterator().next(); + assertEquals(ExponentialStops.class, stop.getValue().getClass()); + assertEquals(0f, stop.getKey(), 0.001); + assertEquals(1, stop.getValue().size()); + assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); + assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + } + + @Test + public void testFillColorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("fill-color"); assertNotNull(layer); @@ -147,19 +276,105 @@ public void testFillColor() { } @Test - public void testFillColorAsInt() { + public void testFillColorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // 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()); + } - 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"); - } + @Test + public void testFillColorAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + fillColor(property("FeaturePropertyA", Stops.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() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-color"); + 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() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + fillColor( + property( + "FeaturePropertyA", + categorical( + stop("valueA", fillColor(Color.RED)) + ) + ) + ) + ); + + // 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()); + } + + @Test + public void testFillColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("fill-color"); assertNotNull(layer); @@ -169,19 +384,8 @@ public void testFillColorAsInt() { } @Test - public void testFillOutlineColor() { + public void testFillOutlineColorAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } Timber.i("fill-outline-color"); assertNotNull(layer); @@ -191,19 +395,105 @@ public void testFillOutlineColor() { } @Test - public void testFillOutlineColorAsInt() { + public void testFillOutlineColorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-outline-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // 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()); + } - 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"); - } + @Test + public void testFillOutlineColorAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-outline-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + fillOutlineColor(property("FeaturePropertyA", Stops.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() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-outline-color"); + 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() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-outline-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + fillOutlineColor( + property( + "FeaturePropertyA", + categorical( + stop("valueA", fillOutlineColor(Color.RED)) + ) + ) + ) + ); + + // 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()); + } + + @Test + public void testFillOutlineColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("fill-outline-color"); assertNotNull(layer); @@ -213,41 +503,45 @@ public void testFillOutlineColorAsInt() { } @Test - public void testFillTranslate() { + public void testFillTranslateAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } Timber.i("fill-translate"); assertNotNull(layer); // Set and Get - layer.setProperties(fillTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getFillTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); + layer.setProperties(fillTranslate(new Float[]{0f,0f})); + assertEquals((Float[]) layer.getFillTranslate().getValue(), (Float[]) new Float[]{0f,0f}); } @Test - public void testFillTranslateAnchor() { + public void testFillTranslateAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-translate"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // 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()); + } - 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"); - } + @Test + public void testFillTranslateAnchorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("fill-translate-anchor"); assertNotNull(layer); @@ -257,19 +551,33 @@ public void testFillTranslateAnchor() { } @Test - public void testFillPattern() { + public void testFillTranslateAnchorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-translate-anchor"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // 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()); + } - 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"); - } + @Test + public void testFillPatternAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("fill-pattern"); assertNotNull(layer); @@ -278,6 +586,31 @@ public void testFillPattern() { assertEquals((String) layer.getFillPattern().getValue(), (String) "pedestrian-polygon"); } + @Test + public void testFillPatternAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("fill-pattern"); + 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()); + } + @After public void unregisterIntentServiceIdlingResource() { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerStyleTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerStyleTest.java deleted file mode 100644 index 011e49dbf97..00000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerStyleTest.java +++ /dev/null @@ -1,427 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.style; -// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. - -import android.graphics.Color; -import android.support.test.espresso.Espresso; -import android.support.test.rule.ActivityTestRule; -import android.support.test.runner.AndroidJUnit4; - -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.style.layers.LineLayer; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; -import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.layers.Property.LINE_CAP_BUTT; -import static com.mapbox.mapboxsdk.style.layers.Property.LINE_JOIN_BEVEL; -import static com.mapbox.mapboxsdk.style.layers.Property.LINE_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineBlur; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineCap; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineDasharray; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineGapWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineJoin; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineMiterLimit; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineOffset; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.linePattern; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineRoundLimit; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * Basic smoke tests for LineLayer - */ -@RunWith(AndroidJUnit4.class) -public class LineLayerStyleTest extends BaseStyleTest { - - @Rule - public final ActivityTestRule rule = new ActivityTestRule<>(RuntimeStyleTestActivity.class); - - private LineLayer layer; - - private OnMapReadyIdlingResource idlingResource; - - private MapboxMap mapboxMap; - - @Before - public void setup() { - idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); - Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("visibility"); - assertNotNull(layer); - - // Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); - - // Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } - - @Test - public void testLineCap() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-cap"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineCap(LINE_CAP_BUTT)); - assertEquals((String) layer.getLineCap().getValue(), (String) LINE_CAP_BUTT); - } - - @Test - public void testLineJoin() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-join"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineJoin(LINE_JOIN_BEVEL)); - assertEquals((String) layer.getLineJoin().getValue(), (String) LINE_JOIN_BEVEL); - } - - @Test - public void testLineMiterLimit() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-miter-limit"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineMiterLimit(0.3f)); - assertEquals((Float) layer.getLineMiterLimit().getValue(), (Float) 0.3f); - } - - @Test - public void testLineRoundLimit() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-round-limit"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineRoundLimit(0.3f)); - assertEquals((Float) layer.getLineRoundLimit().getValue(), (Float) 0.3f); - } - - @Test - public void testLineOpacity() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-opacity"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineOpacity(0.3f)); - assertEquals((Float) layer.getLineOpacity().getValue(), (Float) 0.3f); - } - - @Test - public void testLineColor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-color"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getLineColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - - @Test - public void testLineColorAsInt() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-color"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineColor(Color.RED)); - assertEquals(layer.getLineColorAsInt(), Color.RED); - } - - @Test - public void testLineTranslate() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-translate"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getLineTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); - } - - @Test - public void testLineTranslateAnchor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-translate-anchor"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineTranslateAnchor(LINE_TRANSLATE_ANCHOR_MAP)); - assertEquals((String) layer.getLineTranslateAnchor().getValue(), (String) LINE_TRANSLATE_ANCHOR_MAP); - } - - @Test - public void testLineWidth() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-width"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineWidth(0.3f)); - assertEquals((Float) layer.getLineWidth().getValue(), (Float) 0.3f); - } - - @Test - public void testLineGapWidth() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-gap-width"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineGapWidth(0.3f)); - assertEquals((Float) layer.getLineGapWidth().getValue(), (Float) 0.3f); - } - - @Test - public void testLineOffset() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-offset"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineOffset(0.3f)); - assertEquals((Float) layer.getLineOffset().getValue(), (Float) 0.3f); - } - - @Test - public void testLineBlur() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-blur"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineBlur(0.3f)); - assertEquals((Float) layer.getLineBlur().getValue(), (Float) 0.3f); - } - - @Test - public void testLineDasharray() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-dasharray"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(lineDasharray(new Float[] {})); - assertEquals((Float[]) layer.getLineDasharray().getValue(), (Float[]) new Float[] {}); - } - - @Test - public void testLinePattern() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("line-pattern"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(linePattern("pedestrian-polygon")); - assertEquals((String) layer.getLinePattern().getValue(), (String) "pedestrian-polygon"); - } - - - @After - public void unregisterIntentServiceIdlingResource() { - Espresso.unregisterIdlingResources(idlingResource); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java index db474748149..391f98945c8 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/LineLayerTest.java @@ -1,12 +1,23 @@ -package com.mapbox.mapboxsdk.testapp.style; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.testapp.style; + import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; 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.CompositeStops; +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.Stops; import com.mapbox.mapboxsdk.style.layers.LineLayer; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; @@ -18,30 +29,14 @@ import org.junit.Test; import org.junit.runner.RunWith; -import timber.log.Timber; +import java.util.Map; -import static com.mapbox.mapboxsdk.style.layers.Property.LINE_CAP_BUTT; -import static com.mapbox.mapboxsdk.style.layers.Property.LINE_JOIN_BEVEL; -import static com.mapbox.mapboxsdk.style.layers.Property.LINE_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineBlur; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineCap; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineDasharray; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineGapWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineJoin; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineMiterLimit; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineOffset; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.linePattern; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineRoundLimit; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +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 org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; /** * Basic smoke tests for LineLayer @@ -62,12 +57,6 @@ public class LineLayerTest extends BaseStyleTest { public void setup() { idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - mapboxMap = rule.getActivity().getMapboxMap(); if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { @@ -78,7 +67,12 @@ public void testSetVisibility() { // Layer reference is now stale, get new reference layer = mapboxMap.getLayerAs("my-layer"); } - Timber.i("visibility"); + } + + @Test + public void testSetVisibility() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("Visibility"); assertNotNull(layer); // Get initial @@ -90,19 +84,8 @@ public void testSetVisibility() { } @Test - public void testLineCap() { + public void testLineCapAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } Timber.i("line-cap"); assertNotNull(layer); @@ -112,19 +95,33 @@ public void testLineCap() { } @Test - public void testLineJoin() { + public void testLineCapAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-cap"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineCap( + zoom( + interval( + stop(2, lineCap(LINE_CAP_BUTT)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineCap()); + assertNotNull(layer.getLineCap().getFunction()); + assertEquals(CameraFunction.class, layer.getLineCap().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getLineCap().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getLineCap().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineJoinAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-join"); assertNotNull(layer); @@ -134,19 +131,33 @@ public void testLineJoin() { } @Test - public void testLineMiterLimit() { + public void testLineJoinAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-join"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineJoin( + zoom( + interval( + stop(2, lineJoin(LINE_JOIN_BEVEL)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineJoin()); + assertNotNull(layer.getLineJoin().getFunction()); + assertEquals(CameraFunction.class, layer.getLineJoin().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getLineJoin().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getLineJoin().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineMiterLimitAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-miter-limit"); assertNotNull(layer); @@ -156,19 +167,34 @@ public void testLineMiterLimit() { } @Test - public void testLineRoundLimit() { + public void testLineMiterLimitAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-miter-limit"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineMiterLimit( + zoom( + exponential( + stop(2, lineMiterLimit(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineMiterLimit()); + assertNotNull(layer.getLineMiterLimit().getFunction()); + assertEquals(CameraFunction.class, layer.getLineMiterLimit().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getLineMiterLimit().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getLineMiterLimit().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getLineMiterLimit().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineRoundLimitAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-round-limit"); assertNotNull(layer); @@ -178,19 +204,34 @@ public void testLineRoundLimit() { } @Test - public void testLineOpacity() { + public void testLineRoundLimitAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-round-limit"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineRoundLimit( + zoom( + exponential( + stop(2, lineRoundLimit(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineRoundLimit()); + assertNotNull(layer.getLineRoundLimit().getFunction()); + assertEquals(CameraFunction.class, layer.getLineRoundLimit().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getLineRoundLimit().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getLineRoundLimit().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getLineRoundLimit().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineOpacityAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-opacity"); assertNotNull(layer); @@ -200,19 +241,142 @@ public void testLineOpacity() { } @Test - public void testLineColor() { + public void testLineOpacityAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-opacity"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineOpacity( + zoom( + exponential( + stop(2, lineOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineOpacity()); + assertNotNull(layer.getLineOpacity().getFunction()); + assertEquals(CameraFunction.class, layer.getLineOpacity().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getLineOpacity().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getLineOpacity().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getLineOpacity().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineOpacityAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineOpacity(property("FeaturePropertyA", Stops.identity())) + ); + + // Verify + assertNotNull(layer.getLineOpacity()); + assertNotNull(layer.getLineOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getLineOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineOpacity().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getLineOpacity().getFunction().getStops().getClass()); + } + + @Test + public void testLineOpacityAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineOpacity( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, lineOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineOpacity()); + assertNotNull(layer.getLineOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getLineOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineOpacity().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getLineOpacity().getFunction().getStops().getClass()); + } + + @Test + public void testLineOpacityAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineOpacity( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, lineOpacity(0.3f)) + ).withDefaultValue(0.3f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineOpacity()); + assertNotNull(layer.getLineOpacity().getFunction()); + assertEquals(SourceFunction.class, layer.getLineOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineOpacity().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getLineOpacity().getFunction().getStops().getClass()); + assertEquals(0.3f, ((CategoricalStops) layer.getLineOpacity().getFunction().getStops()).getDefaultValue()); + } + + @Test + public void testLineOpacityAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-opacity"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineOpacity( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, lineOpacity(0.9f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineOpacity()); + assertNotNull(layer.getLineOpacity().getFunction()); + assertEquals(CompositeFunction.class, layer.getLineOpacity().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getLineOpacity().getFunction()).getProperty()); + assertEquals(CompositeStops.class, layer.getLineOpacity().getFunction().getStops().getClass()); + assertEquals(1, ((CompositeStops) layer.getLineOpacity().getFunction().getStops()).size()); + + CompositeStops> stops = + (CompositeStops>) layer.getLineOpacity().getFunction().getStops(); + Map.Entry> stop = stops.iterator().next(); + assertEquals(ExponentialStops.class, stop.getValue().getClass()); + assertEquals(0f, stop.getKey(), 0.001); + assertEquals(1, stop.getValue().size()); + assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); + assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + } + + @Test + public void testLineColorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-color"); assertNotNull(layer); @@ -222,19 +386,105 @@ public void testLineColor() { } @Test - public void testLineColorAsInt() { + public void testLineColorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineColor( + zoom( + exponential( + stop(2, lineColor("rgba(0, 0, 0, 1)")) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineColor()); + assertNotNull(layer.getLineColor().getFunction()); + assertEquals(CameraFunction.class, layer.getLineColor().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getLineColor().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getLineColor().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getLineColor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineColorAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineColor(property("FeaturePropertyA", Stops.identity())) + ); + + // Verify + assertNotNull(layer.getLineColor()); + assertNotNull(layer.getLineColor().getFunction()); + assertEquals(SourceFunction.class, layer.getLineColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineColor().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getLineColor().getFunction().getStops().getClass()); + } + + @Test + public void testLineColorAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineColor( + property( + "FeaturePropertyA", + exponential( + stop(Color.RED, lineColor(Color.RED)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineColor()); + assertNotNull(layer.getLineColor().getFunction()); + assertEquals(SourceFunction.class, layer.getLineColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineColor().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getLineColor().getFunction().getStops().getClass()); + } + + @Test + public void testLineColorAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-color"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineColor( + property( + "FeaturePropertyA", + categorical( + stop("valueA", lineColor(Color.RED)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineColor()); + assertNotNull(layer.getLineColor().getFunction()); + assertEquals(SourceFunction.class, layer.getLineColor().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineColor().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getLineColor().getFunction().getStops().getClass()); + } + + @Test + public void testLineColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-color"); assertNotNull(layer); @@ -244,41 +494,45 @@ public void testLineColorAsInt() { } @Test - public void testLineTranslate() { + public void testLineTranslateAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } Timber.i("line-translate"); assertNotNull(layer); // Set and Get - layer.setProperties(lineTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getLineTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); + layer.setProperties(lineTranslate(new Float[]{0f,0f})); + assertEquals((Float[]) layer.getLineTranslate().getValue(), (Float[]) new Float[]{0f,0f}); } @Test - public void testLineTranslateAnchor() { + public void testLineTranslateAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-translate"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineTranslate( + zoom( + exponential( + stop(2, lineTranslate(new Float[]{0f,0f})) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineTranslate()); + assertNotNull(layer.getLineTranslate().getFunction()); + assertEquals(CameraFunction.class, layer.getLineTranslate().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getLineTranslate().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getLineTranslate().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getLineTranslate().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineTranslateAnchorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-translate-anchor"); assertNotNull(layer); @@ -288,19 +542,33 @@ public void testLineTranslateAnchor() { } @Test - public void testLineWidth() { + public void testLineTranslateAnchorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-translate-anchor"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineTranslateAnchor( + zoom( + interval( + stop(2, lineTranslateAnchor(LINE_TRANSLATE_ANCHOR_MAP)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineTranslateAnchor()); + assertNotNull(layer.getLineTranslateAnchor().getFunction()); + assertEquals(CameraFunction.class, layer.getLineTranslateAnchor().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getLineTranslateAnchor().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getLineTranslateAnchor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineWidthAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-width"); assertNotNull(layer); @@ -310,19 +578,34 @@ public void testLineWidth() { } @Test - public void testLineGapWidth() { + public void testLineWidthAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-width"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineWidth( + zoom( + exponential( + stop(2, lineWidth(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineWidth()); + assertNotNull(layer.getLineWidth().getFunction()); + assertEquals(CameraFunction.class, layer.getLineWidth().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getLineWidth().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getLineWidth().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineGapWidthAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-gap-width"); assertNotNull(layer); @@ -332,19 +615,142 @@ public void testLineGapWidth() { } @Test - public void testLineOffset() { + public void testLineGapWidthAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-gap-width"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineGapWidth( + zoom( + exponential( + stop(2, lineGapWidth(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineGapWidth()); + assertNotNull(layer.getLineGapWidth().getFunction()); + assertEquals(CameraFunction.class, layer.getLineGapWidth().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getLineGapWidth().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getLineGapWidth().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getLineGapWidth().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineGapWidthAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-gap-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineGapWidth(property("FeaturePropertyA", Stops.identity())) + ); + + // Verify + assertNotNull(layer.getLineGapWidth()); + assertNotNull(layer.getLineGapWidth().getFunction()); + assertEquals(SourceFunction.class, layer.getLineGapWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineGapWidth().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getLineGapWidth().getFunction().getStops().getClass()); + } + + @Test + public void testLineGapWidthAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-gap-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineGapWidth( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, lineGapWidth(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineGapWidth()); + assertNotNull(layer.getLineGapWidth().getFunction()); + assertEquals(SourceFunction.class, layer.getLineGapWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineGapWidth().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getLineGapWidth().getFunction().getStops().getClass()); + } + + @Test + public void testLineGapWidthAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-gap-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineGapWidth( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, lineGapWidth(0.3f)) + ).withDefaultValue(0.3f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineGapWidth()); + assertNotNull(layer.getLineGapWidth().getFunction()); + assertEquals(SourceFunction.class, layer.getLineGapWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineGapWidth().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getLineGapWidth().getFunction().getStops().getClass()); + assertEquals(0.3f, ((CategoricalStops) layer.getLineGapWidth().getFunction().getStops()).getDefaultValue()); + } + + @Test + public void testLineGapWidthAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-gap-width"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineGapWidth( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, lineGapWidth(0.9f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineGapWidth()); + assertNotNull(layer.getLineGapWidth().getFunction()); + assertEquals(CompositeFunction.class, layer.getLineGapWidth().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getLineGapWidth().getFunction()).getProperty()); + assertEquals(CompositeStops.class, layer.getLineGapWidth().getFunction().getStops().getClass()); + assertEquals(1, ((CompositeStops) layer.getLineGapWidth().getFunction().getStops()).size()); + + CompositeStops> stops = + (CompositeStops>) layer.getLineGapWidth().getFunction().getStops(); + Map.Entry> stop = stops.iterator().next(); + assertEquals(ExponentialStops.class, stop.getValue().getClass()); + assertEquals(0f, stop.getKey(), 0.001); + assertEquals(1, stop.getValue().size()); + assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); + assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + } + + @Test + public void testLineOffsetAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-offset"); assertNotNull(layer); @@ -354,19 +760,142 @@ public void testLineOffset() { } @Test - public void testLineBlur() { + public void testLineOffsetAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-offset"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineOffset( + zoom( + exponential( + stop(2, lineOffset(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineOffset()); + assertNotNull(layer.getLineOffset().getFunction()); + assertEquals(CameraFunction.class, layer.getLineOffset().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getLineOffset().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineOffsetAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-offset"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineOffset(property("FeaturePropertyA", Stops.identity())) + ); + + // Verify + assertNotNull(layer.getLineOffset()); + assertNotNull(layer.getLineOffset().getFunction()); + assertEquals(SourceFunction.class, layer.getLineOffset().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineOffset().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getLineOffset().getFunction().getStops().getClass()); + } + + @Test + public void testLineOffsetAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-offset"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineOffset( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, lineOffset(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineOffset()); + assertNotNull(layer.getLineOffset().getFunction()); + assertEquals(SourceFunction.class, layer.getLineOffset().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineOffset().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getLineOffset().getFunction().getStops().getClass()); + } + + @Test + public void testLineOffsetAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-offset"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineOffset( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, lineOffset(0.3f)) + ).withDefaultValue(0.3f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineOffset()); + assertNotNull(layer.getLineOffset().getFunction()); + assertEquals(SourceFunction.class, layer.getLineOffset().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineOffset().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getLineOffset().getFunction().getStops().getClass()); + assertEquals(0.3f, ((CategoricalStops) layer.getLineOffset().getFunction().getStops()).getDefaultValue()); + } + + @Test + public void testLineOffsetAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-offset"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineOffset( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, lineOffset(0.9f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineOffset()); + assertNotNull(layer.getLineOffset().getFunction()); + assertEquals(CompositeFunction.class, layer.getLineOffset().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getLineOffset().getFunction()).getProperty()); + assertEquals(CompositeStops.class, layer.getLineOffset().getFunction().getStops().getClass()); + assertEquals(1, ((CompositeStops) layer.getLineOffset().getFunction().getStops()).size()); + + CompositeStops> stops = + (CompositeStops>) layer.getLineOffset().getFunction().getStops(); + Map.Entry> stop = stops.iterator().next(); + assertEquals(ExponentialStops.class, stop.getValue().getClass()); + assertEquals(0f, stop.getKey(), 0.001); + assertEquals(1, stop.getValue().size()); + assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); + assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + } + + @Test + public void testLineBlurAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-blur"); assertNotNull(layer); @@ -376,41 +905,178 @@ public void testLineBlur() { } @Test - public void testLineDasharray() { + public void testLineBlurAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-blur"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineBlur( + zoom( + exponential( + stop(2, lineBlur(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineBlur()); + assertNotNull(layer.getLineBlur().getFunction()); + assertEquals(CameraFunction.class, layer.getLineBlur().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getLineBlur().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getLineBlur().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getLineBlur().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLineBlurAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineBlur(property("FeaturePropertyA", Stops.identity())) + ); + + // Verify + assertNotNull(layer.getLineBlur()); + assertNotNull(layer.getLineBlur().getFunction()); + assertEquals(SourceFunction.class, layer.getLineBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineBlur().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getLineBlur().getFunction().getStops().getClass()); + } + + @Test + public void testLineBlurAsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineBlur( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, lineBlur(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineBlur()); + assertNotNull(layer.getLineBlur().getFunction()); + assertEquals(SourceFunction.class, layer.getLineBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineBlur().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getLineBlur().getFunction().getStops().getClass()); + } + + @Test + public void testLineBlurAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineBlur( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, lineBlur(0.3f)) + ).withDefaultValue(0.3f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineBlur()); + assertNotNull(layer.getLineBlur().getFunction()); + assertEquals(SourceFunction.class, layer.getLineBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getLineBlur().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getLineBlur().getFunction().getStops().getClass()); + assertEquals(0.3f, ((CategoricalStops) layer.getLineBlur().getFunction().getStops()).getDefaultValue()); + } + + @Test + public void testLineBlurAsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-blur"); + assertNotNull(layer); + + // Set + layer.setProperties( + lineBlur( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, lineBlur(0.9f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineBlur()); + assertNotNull(layer.getLineBlur().getFunction()); + assertEquals(CompositeFunction.class, layer.getLineBlur().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getLineBlur().getFunction()).getProperty()); + assertEquals(CompositeStops.class, layer.getLineBlur().getFunction().getStops().getClass()); + assertEquals(1, ((CompositeStops) layer.getLineBlur().getFunction().getStops()).size()); + + CompositeStops> stops = + (CompositeStops>) layer.getLineBlur().getFunction().getStops(); + Map.Entry> stop = stops.iterator().next(); + assertEquals(ExponentialStops.class, stop.getValue().getClass()); + assertEquals(0f, stop.getKey(), 0.001); + assertEquals(1, stop.getValue().size()); + assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); + assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + } + + @Test + public void testLineDasharrayAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-dasharray"); assertNotNull(layer); // Set and Get - layer.setProperties(lineDasharray(new Float[] {})); - assertEquals((Float[]) layer.getLineDasharray().getValue(), (Float[]) new Float[] {}); + layer.setProperties(lineDasharray(new Float[]{})); + assertEquals((Float[]) layer.getLineDasharray().getValue(), (Float[]) new Float[]{}); } @Test - public void testLinePattern() { + public void testLineDasharrayAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("line-dasharray"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + lineDasharray( + zoom( + interval( + stop(2, lineDasharray(new Float[]{})) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getLineDasharray()); + assertNotNull(layer.getLineDasharray().getFunction()); + assertEquals(CameraFunction.class, layer.getLineDasharray().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getLineDasharray().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getLineDasharray().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new LineLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testLinePatternAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("line-pattern"); assertNotNull(layer); @@ -419,6 +1085,31 @@ public void testLinePattern() { assertEquals((String) layer.getLinePattern().getValue(), (String) "pedestrian-polygon"); } + @Test + public void testLinePatternAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("line-pattern"); + assertNotNull(layer); + + // Set + layer.setProperties( + linePattern( + zoom( + interval( + stop(2, linePattern("pedestrian-polygon")) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getLinePattern()); + assertNotNull(layer.getLinePattern().getFunction()); + assertEquals(CameraFunction.class, layer.getLinePattern().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getLinePattern().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getLinePattern().getFunction().getStops()).size()); + } + @After public void unregisterIntentServiceIdlingResource() { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerStyleTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerStyleTest.java deleted file mode 100644 index 7f412320d43..00000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerStyleTest.java +++ /dev/null @@ -1,240 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.style; -// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. - -import android.support.test.espresso.Espresso; -import android.support.test.rule.ActivityTestRule; -import android.support.test.runner.AndroidJUnit4; - -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.style.layers.RasterLayer; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; -import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterBrightnessMax; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterBrightnessMin; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterContrast; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterFadeDuration; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterHueRotate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterSaturation; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * Basic smoke tests for RasterLayer - */ -@RunWith(AndroidJUnit4.class) -public class RasterLayerStyleTest extends BaseStyleTest { - - @Rule - public final ActivityTestRule rule = new ActivityTestRule<>(RuntimeStyleTestActivity.class); - - private RasterLayer layer; - - private OnMapReadyIdlingResource idlingResource; - - private MapboxMap mapboxMap; - - @Before - public void setup() { - idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); - Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } - Timber.i("visibility"); - assertNotNull(layer); - - // Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); - - // Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } - - @Test - public void testRasterOpacity() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } - Timber.i("raster-opacity"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(rasterOpacity(0.3f)); - assertEquals((Float) layer.getRasterOpacity().getValue(), (Float) 0.3f); - } - - @Test - public void testRasterHueRotate() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } - Timber.i("raster-hue-rotate"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(rasterHueRotate(0.3f)); - assertEquals((Float) layer.getRasterHueRotate().getValue(), (Float) 0.3f); - } - - @Test - public void testRasterBrightnessMin() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } - Timber.i("raster-brightness-min"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(rasterBrightnessMin(0.3f)); - assertEquals((Float) layer.getRasterBrightnessMin().getValue(), (Float) 0.3f); - } - - @Test - public void testRasterBrightnessMax() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } - Timber.i("raster-brightness-max"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(rasterBrightnessMax(0.3f)); - assertEquals((Float) layer.getRasterBrightnessMax().getValue(), (Float) 0.3f); - } - - @Test - public void testRasterSaturation() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } - Timber.i("raster-saturation"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(rasterSaturation(0.3f)); - assertEquals((Float) layer.getRasterSaturation().getValue(), (Float) 0.3f); - } - - @Test - public void testRasterContrast() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } - Timber.i("raster-contrast"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(rasterContrast(0.3f)); - assertEquals((Float) layer.getRasterContrast().getValue(), (Float) 0.3f); - } - - @Test - public void testRasterFadeDuration() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } - Timber.i("raster-fade-duration"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(rasterFadeDuration(0.3f)); - assertEquals((Float) layer.getRasterFadeDuration().getValue(), (Float) 0.3f); - } - - - @After - public void unregisterIntentServiceIdlingResource() { - Espresso.unregisterIdlingResources(idlingResource); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java index 5d230a1c477..cc9597ab78e 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java @@ -1,11 +1,23 @@ -package com.mapbox.mapboxsdk.testapp.style; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.testapp.style; + +import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; 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.CompositeStops; +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.Stops; import com.mapbox.mapboxsdk.style.layers.RasterLayer; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; @@ -17,20 +29,14 @@ import org.junit.Test; import org.junit.runner.RunWith; -import timber.log.Timber; +import java.util.Map; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterBrightnessMax; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterBrightnessMin; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterContrast; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterFadeDuration; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterHueRotate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.rasterSaturation; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +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 org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; /** * Basic smoke tests for RasterLayer @@ -51,12 +57,6 @@ public class RasterLayerTest extends BaseStyleTest { public void setup() { idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - mapboxMap = rule.getActivity().getMapboxMap(); if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { @@ -67,7 +67,12 @@ public void testSetVisibility() { // Layer reference is now stale, get new reference layer = mapboxMap.getLayerAs("my-layer"); } - Timber.i("visibility"); + } + + @Test + public void testSetVisibility() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("Visibility"); assertNotNull(layer); // Get initial @@ -79,19 +84,8 @@ public void testSetVisibility() { } @Test - public void testRasterOpacity() { + public void testRasterOpacityAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - 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"); - } Timber.i("raster-opacity"); assertNotNull(layer); @@ -101,19 +95,34 @@ public void testRasterOpacity() { } @Test - public void testRasterHueRotate() { + public void testRasterOpacityAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("raster-opacity"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // 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()); + } - 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"); - } + @Test + public void testRasterHueRotateAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("raster-hue-rotate"); assertNotNull(layer); @@ -123,19 +132,34 @@ public void testRasterHueRotate() { } @Test - public void testRasterBrightnessMin() { + public void testRasterHueRotateAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("raster-hue-rotate"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // 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()); + } - 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"); - } + @Test + public void testRasterBrightnessMinAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("raster-brightness-min"); assertNotNull(layer); @@ -145,19 +169,34 @@ public void testRasterBrightnessMin() { } @Test - public void testRasterBrightnessMax() { + public void testRasterBrightnessMinAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("raster-brightness-min"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // 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()); + } - 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"); - } + @Test + public void testRasterBrightnessMaxAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("raster-brightness-max"); assertNotNull(layer); @@ -167,19 +206,34 @@ public void testRasterBrightnessMax() { } @Test - public void testRasterSaturation() { + public void testRasterBrightnessMaxAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("raster-brightness-max"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // 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()); + } - 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"); - } + @Test + public void testRasterSaturationAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("raster-saturation"); assertNotNull(layer); @@ -189,19 +243,34 @@ public void testRasterSaturation() { } @Test - public void testRasterContrast() { + public void testRasterSaturationAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("raster-saturation"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // 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()); + } - 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"); - } + @Test + public void testRasterContrastAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("raster-contrast"); assertNotNull(layer); @@ -211,19 +280,34 @@ public void testRasterContrast() { } @Test - public void testRasterFadeDuration() { + public void testRasterContrastAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("raster-contrast"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // 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()); + } - 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"); - } + @Test + public void testRasterFadeDurationAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("raster-fade-duration"); assertNotNull(layer); @@ -232,6 +316,32 @@ public void testRasterFadeDuration() { assertEquals((Float) layer.getRasterFadeDuration().getValue(), (Float) 0.3f); } + @Test + public void testRasterFadeDurationAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("raster-fade-duration"); + 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()); + } + @After public void unregisterIntentServiceIdlingResource() { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerStyleTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerStyleTest.java deleted file mode 100644 index 30ef3c96740..00000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerStyleTest.java +++ /dev/null @@ -1,1283 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.style; -// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`. - -import android.graphics.Color; -import android.support.test.espresso.Espresso; -import android.support.test.rule.ActivityTestRule; -import android.support.test.runner.AndroidJUnit4; - -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.style.layers.SymbolLayer; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; -import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.layers.Property.ICON_ROTATION_ALIGNMENT_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.ICON_TEXT_FIT_NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.ICON_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.SYMBOL_PLACEMENT_POINT; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_ANCHOR_CENTER; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_JUSTIFY_LEFT; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_PITCH_ALIGNMENT_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_ROTATION_ALIGNMENT_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_TRANSFORM_NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconAllowOverlap; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconHaloBlur; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconHaloColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconHaloWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconIgnorePlacement; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconKeepUpright; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconOffset; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconOptional; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconPadding; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconRotate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconRotationAlignment; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconSize; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconTextFit; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconTextFitPadding; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.symbolAvoidEdges; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.symbolPlacement; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.symbolSpacing; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textAllowOverlap; -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.textFont; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textHaloBlur; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textHaloColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textHaloWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textIgnorePlacement; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textJustify; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textKeepUpright; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textLetterSpacing; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textLineHeight; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textMaxAngle; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textMaxWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textOffset; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textOptional; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textPadding; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textPitchAlignment; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textRotate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textRotationAlignment; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textSize; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textTransform; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * Basic smoke tests for SymbolLayer - */ -@RunWith(AndroidJUnit4.class) -public class SymbolLayerStyleTest extends BaseStyleTest { - - @Rule - public final ActivityTestRule rule = new ActivityTestRule<>(RuntimeStyleTestActivity.class); - - private SymbolLayer layer; - - private OnMapReadyIdlingResource idlingResource; - - private MapboxMap mapboxMap; - - @Before - public void setup() { - idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); - Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("visibility"); - assertNotNull(layer); - - // Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); - - // Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } - - @Test - public void testSymbolPlacement() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("symbol-placement"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(symbolPlacement(SYMBOL_PLACEMENT_POINT)); - assertEquals((String) layer.getSymbolPlacement().getValue(), (String) SYMBOL_PLACEMENT_POINT); - } - - @Test - public void testSymbolSpacing() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("symbol-spacing"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(symbolSpacing(0.3f)); - assertEquals((Float) layer.getSymbolSpacing().getValue(), (Float) 0.3f); - } - - @Test - public void testSymbolAvoidEdges() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("symbol-avoid-edges"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(symbolAvoidEdges(true)); - assertEquals((Boolean) layer.getSymbolAvoidEdges().getValue(), (Boolean) true); - } - - @Test - public void testIconAllowOverlap() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-allow-overlap"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconAllowOverlap(true)); - assertEquals((Boolean) layer.getIconAllowOverlap().getValue(), (Boolean) true); - } - - @Test - public void testIconIgnorePlacement() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-ignore-placement"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconIgnorePlacement(true)); - assertEquals((Boolean) layer.getIconIgnorePlacement().getValue(), (Boolean) true); - } - - @Test - public void testIconOptional() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-optional"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconOptional(true)); - assertEquals((Boolean) layer.getIconOptional().getValue(), (Boolean) true); - } - - @Test - public void testIconRotationAlignment() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-rotation-alignment"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconRotationAlignment(ICON_ROTATION_ALIGNMENT_MAP)); - assertEquals((String) layer.getIconRotationAlignment().getValue(), (String) ICON_ROTATION_ALIGNMENT_MAP); - } - - @Test - public void testIconSize() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-size"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconSize(0.3f)); - assertEquals((Float) layer.getIconSize().getValue(), (Float) 0.3f); - } - - @Test - public void testIconTextFit() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-text-fit"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconTextFit(ICON_TEXT_FIT_NONE)); - assertEquals((String) layer.getIconTextFit().getValue(), (String) ICON_TEXT_FIT_NONE); - } - - @Test - public void testIconTextFitPadding() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-text-fit-padding"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconTextFitPadding(new Float[] {0f, 0f, 0f, 0f})); - assertEquals((Float[]) layer.getIconTextFitPadding().getValue(), (Float[]) new Float[] {0f, 0f, 0f, 0f}); - } - - @Test - public void testIconImage() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-image"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconImage("undefined")); - assertEquals((String) layer.getIconImage().getValue(), (String) "undefined"); - } - - @Test - public void testIconRotate() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-rotate"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconRotate(0.3f)); - assertEquals((Float) layer.getIconRotate().getValue(), (Float) 0.3f); - } - - @Test - public void testIconPadding() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-padding"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconPadding(0.3f)); - assertEquals((Float) layer.getIconPadding().getValue(), (Float) 0.3f); - } - - @Test - public void testIconKeepUpright() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-keep-upright"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconKeepUpright(true)); - assertEquals((Boolean) layer.getIconKeepUpright().getValue(), (Boolean) true); - } - - @Test - public void testIconOffset() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-offset"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconOffset(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getIconOffset().getValue(), (Float[]) new Float[] {0f, 0f}); - } - - @Test - public void testTextPitchAlignment() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-pitch-alignment"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textPitchAlignment(TEXT_PITCH_ALIGNMENT_MAP)); - assertEquals((String) layer.getTextPitchAlignment().getValue(), (String) TEXT_PITCH_ALIGNMENT_MAP); - } - - @Test - public void testTextRotationAlignment() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-rotation-alignment"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textRotationAlignment(TEXT_ROTATION_ALIGNMENT_MAP)); - assertEquals((String) layer.getTextRotationAlignment().getValue(), (String) TEXT_ROTATION_ALIGNMENT_MAP); - } - - @Test - public void testTextField() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-field"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textField("")); - assertEquals((String) layer.getTextField().getValue(), (String) ""); - } - - @Test - public void testTextFont() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-font"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textFont(new String[] {"Open Sans Regular", "Arial Unicode MS Regular"})); - assertEquals((String[]) layer.getTextFont().getValue(), (String[]) new String[] {"Open Sans Regular", - "Arial Unicode MS Regular"}); - } - - @Test - public void testTextSize() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-size"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textSize(0.3f)); - assertEquals((Float) layer.getTextSize().getValue(), (Float) 0.3f); - } - - @Test - public void testTextMaxWidth() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-max-width"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textMaxWidth(0.3f)); - assertEquals((Float) layer.getTextMaxWidth().getValue(), (Float) 0.3f); - } - - @Test - public void testTextLineHeight() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-line-height"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textLineHeight(0.3f)); - assertEquals((Float) layer.getTextLineHeight().getValue(), (Float) 0.3f); - } - - @Test - public void testTextLetterSpacing() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-letter-spacing"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textLetterSpacing(0.3f)); - assertEquals((Float) layer.getTextLetterSpacing().getValue(), (Float) 0.3f); - } - - @Test - public void testTextJustify() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-justify"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textJustify(TEXT_JUSTIFY_LEFT)); - assertEquals((String) layer.getTextJustify().getValue(), (String) TEXT_JUSTIFY_LEFT); - } - - @Test - public void testTextAnchor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-anchor"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textAnchor(TEXT_ANCHOR_CENTER)); - assertEquals((String) layer.getTextAnchor().getValue(), (String) TEXT_ANCHOR_CENTER); - } - - @Test - public void testTextMaxAngle() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-max-angle"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textMaxAngle(0.3f)); - assertEquals((Float) layer.getTextMaxAngle().getValue(), (Float) 0.3f); - } - - @Test - public void testTextRotate() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-rotate"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textRotate(0.3f)); - assertEquals((Float) layer.getTextRotate().getValue(), (Float) 0.3f); - } - - @Test - public void testTextPadding() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-padding"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textPadding(0.3f)); - assertEquals((Float) layer.getTextPadding().getValue(), (Float) 0.3f); - } - - @Test - public void testTextKeepUpright() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-keep-upright"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textKeepUpright(true)); - assertEquals((Boolean) layer.getTextKeepUpright().getValue(), (Boolean) true); - } - - @Test - public void testTextTransform() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-transform"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textTransform(TEXT_TRANSFORM_NONE)); - assertEquals((String) layer.getTextTransform().getValue(), (String) TEXT_TRANSFORM_NONE); - } - - @Test - public void testTextOffset() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-offset"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textOffset(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getTextOffset().getValue(), (Float[]) new Float[] {0f, 0f}); - } - - @Test - public void testTextAllowOverlap() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-allow-overlap"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textAllowOverlap(true)); - assertEquals((Boolean) layer.getTextAllowOverlap().getValue(), (Boolean) true); - } - - @Test - public void testTextIgnorePlacement() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-ignore-placement"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textIgnorePlacement(true)); - assertEquals((Boolean) layer.getTextIgnorePlacement().getValue(), (Boolean) true); - } - - @Test - public void testTextOptional() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-optional"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textOptional(true)); - assertEquals((Boolean) layer.getTextOptional().getValue(), (Boolean) true); - } - - @Test - public void testIconOpacity() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-opacity"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconOpacity(0.3f)); - assertEquals((Float) layer.getIconOpacity().getValue(), (Float) 0.3f); - } - - @Test - public void testIconColor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-color"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getIconColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - - @Test - public void testIconColorAsInt() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-color"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconColor(Color.RED)); - assertEquals(layer.getIconColorAsInt(), Color.RED); - } - - @Test - public void testIconHaloColor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-halo-color"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconHaloColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getIconHaloColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - - @Test - public void testIconHaloColorAsInt() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-halo-color"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconHaloColor(Color.RED)); - assertEquals(layer.getIconHaloColorAsInt(), Color.RED); - } - - @Test - public void testIconHaloWidth() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-halo-width"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconHaloWidth(0.3f)); - assertEquals((Float) layer.getIconHaloWidth().getValue(), (Float) 0.3f); - } - - @Test - public void testIconHaloBlur() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-halo-blur"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconHaloBlur(0.3f)); - assertEquals((Float) layer.getIconHaloBlur().getValue(), (Float) 0.3f); - } - - @Test - public void testIconTranslate() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-translate"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getIconTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); - } - - @Test - public void testIconTranslateAnchor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-translate-anchor"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(iconTranslateAnchor(ICON_TRANSLATE_ANCHOR_MAP)); - assertEquals((String) layer.getIconTranslateAnchor().getValue(), (String) ICON_TRANSLATE_ANCHOR_MAP); - } - - @Test - public void testTextOpacity() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-opacity"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textOpacity(0.3f)); - assertEquals((Float) layer.getTextOpacity().getValue(), (Float) 0.3f); - } - - @Test - public void testTextColor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-color"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getTextColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - - @Test - public void testTextColorAsInt() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-color"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textColor(Color.RED)); - assertEquals(layer.getTextColorAsInt(), Color.RED); - } - - @Test - public void testTextHaloColor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-halo-color"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textHaloColor("rgba(0, 0, 0, 1)")); - assertEquals((String) layer.getTextHaloColor().getValue(), (String) "rgba(0, 0, 0, 1)"); - } - - @Test - public void testTextHaloColorAsInt() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-halo-color"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textHaloColor(Color.RED)); - assertEquals(layer.getTextHaloColorAsInt(), Color.RED); - } - - @Test - public void testTextHaloWidth() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-halo-width"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textHaloWidth(0.3f)); - assertEquals((Float) layer.getTextHaloWidth().getValue(), (Float) 0.3f); - } - - @Test - public void testTextHaloBlur() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-halo-blur"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textHaloBlur(0.3f)); - assertEquals((Float) layer.getTextHaloBlur().getValue(), (Float) 0.3f); - } - - @Test - public void testTextTranslate() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-translate"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getTextTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); - } - - @Test - public void testTextTranslateAnchor() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("text-translate-anchor"); - assertNotNull(layer); - - // Set and Get - layer.setProperties(textTranslateAnchor(TEXT_TRANSLATE_ANCHOR_MAP)); - assertEquals((String) layer.getTextTranslateAnchor().getValue(), (String) TEXT_TRANSLATE_ANCHOR_MAP); - } - - - @After - public void unregisterIntentServiceIdlingResource() { - Espresso.unregisterIdlingResources(idlingResource); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java index d9ec462656d..43815bb8442 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java @@ -1,12 +1,23 @@ -package com.mapbox.mapboxsdk.testapp.style; // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. +package com.mapbox.mapboxsdk.testapp.style; + import android.graphics.Color; import android.support.test.espresso.Espresso; import android.support.test.rule.ActivityTestRule; 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.CompositeStops; +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.Stops; import com.mapbox.mapboxsdk.style.layers.SymbolLayer; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; @@ -18,71 +29,14 @@ import org.junit.Test; import org.junit.runner.RunWith; -import timber.log.Timber; +import java.util.Map; -import static com.mapbox.mapboxsdk.style.layers.Property.ICON_ROTATION_ALIGNMENT_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.ICON_TEXT_FIT_NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.ICON_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.SYMBOL_PLACEMENT_POINT; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_ANCHOR_CENTER; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_JUSTIFY_LEFT; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_PITCH_ALIGNMENT_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_ROTATION_ALIGNMENT_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_TRANSFORM_NONE; -import static com.mapbox.mapboxsdk.style.layers.Property.TEXT_TRANSLATE_ANCHOR_MAP; -import static com.mapbox.mapboxsdk.style.layers.Property.VISIBLE; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconAllowOverlap; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconHaloBlur; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconHaloColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconHaloWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconIgnorePlacement; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconKeepUpright; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconOffset; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconOptional; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconPadding; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconRotate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconRotationAlignment; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconSize; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconTextFit; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconTextFitPadding; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.symbolAvoidEdges; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.symbolPlacement; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.symbolSpacing; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textAllowOverlap; -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.textFont; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textHaloBlur; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textHaloColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textHaloWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textIgnorePlacement; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textJustify; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textKeepUpright; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textLetterSpacing; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textLineHeight; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textMaxAngle; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textMaxWidth; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textOffset; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textOpacity; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textOptional; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textPadding; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textPitchAlignment; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textRotate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textRotationAlignment; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textSize; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textTransform; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textTranslate; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.textTranslateAnchor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +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 org.junit.Assert.*; +import static com.mapbox.mapboxsdk.style.layers.Property.*; +import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; /** * Basic smoke tests for SymbolLayer @@ -103,12 +57,6 @@ public class SymbolLayerTest extends BaseStyleTest { public void setup() { idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); - mapboxMap = rule.getActivity().getMapboxMap(); if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { @@ -119,7 +67,12 @@ public void testSetVisibility() { // Layer reference is now stale, get new reference layer = mapboxMap.getLayerAs("my-layer"); } - Timber.i("visibility"); + } + + @Test + public void testSetVisibility() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("Visibility"); assertNotNull(layer); // Get initial @@ -131,19 +84,8 @@ public void testSetVisibility() { } @Test - public void testSymbolPlacement() { + public void testSymbolPlacementAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } Timber.i("symbol-placement"); assertNotNull(layer); @@ -153,19 +95,33 @@ public void testSymbolPlacement() { } @Test - public void testSymbolSpacing() { + public void testSymbolPlacementAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("symbol-placement"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + symbolPlacement( + zoom( + interval( + stop(2, symbolPlacement(SYMBOL_PLACEMENT_POINT)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getSymbolPlacement()); + assertNotNull(layer.getSymbolPlacement().getFunction()); + assertEquals(CameraFunction.class, layer.getSymbolPlacement().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getSymbolPlacement().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getSymbolPlacement().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testSymbolSpacingAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("symbol-spacing"); assertNotNull(layer); @@ -175,19 +131,34 @@ public void testSymbolSpacing() { } @Test - public void testSymbolAvoidEdges() { + public void testSymbolSpacingAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("symbol-spacing"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + symbolSpacing( + zoom( + exponential( + stop(2, symbolSpacing(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getSymbolSpacing()); + assertNotNull(layer.getSymbolSpacing().getFunction()); + assertEquals(CameraFunction.class, layer.getSymbolSpacing().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getSymbolSpacing().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getSymbolSpacing().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getSymbolSpacing().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testSymbolAvoidEdgesAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("symbol-avoid-edges"); assertNotNull(layer); @@ -197,19 +168,33 @@ public void testSymbolAvoidEdges() { } @Test - public void testIconAllowOverlap() { + public void testSymbolAvoidEdgesAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("symbol-avoid-edges"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + symbolAvoidEdges( + zoom( + interval( + stop(2, symbolAvoidEdges(true)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getSymbolAvoidEdges()); + assertNotNull(layer.getSymbolAvoidEdges().getFunction()); + assertEquals(CameraFunction.class, layer.getSymbolAvoidEdges().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getSymbolAvoidEdges().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getSymbolAvoidEdges().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconAllowOverlapAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-allow-overlap"); assertNotNull(layer); @@ -219,19 +204,33 @@ public void testIconAllowOverlap() { } @Test - public void testIconIgnorePlacement() { + public void testIconAllowOverlapAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-allow-overlap"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconAllowOverlap( + zoom( + interval( + stop(2, iconAllowOverlap(true)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconAllowOverlap()); + assertNotNull(layer.getIconAllowOverlap().getFunction()); + assertEquals(CameraFunction.class, layer.getIconAllowOverlap().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getIconAllowOverlap().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getIconAllowOverlap().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconIgnorePlacementAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-ignore-placement"); assertNotNull(layer); @@ -241,19 +240,33 @@ public void testIconIgnorePlacement() { } @Test - public void testIconOptional() { + public void testIconIgnorePlacementAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-ignore-placement"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconIgnorePlacement( + zoom( + interval( + stop(2, iconIgnorePlacement(true)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconIgnorePlacement()); + assertNotNull(layer.getIconIgnorePlacement().getFunction()); + assertEquals(CameraFunction.class, layer.getIconIgnorePlacement().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getIconIgnorePlacement().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getIconIgnorePlacement().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconOptionalAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-optional"); assertNotNull(layer); @@ -263,19 +276,33 @@ public void testIconOptional() { } @Test - public void testIconRotationAlignment() { + public void testIconOptionalAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-optional"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconOptional( + zoom( + interval( + stop(2, iconOptional(true)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconOptional()); + assertNotNull(layer.getIconOptional().getFunction()); + assertEquals(CameraFunction.class, layer.getIconOptional().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getIconOptional().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getIconOptional().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconRotationAlignmentAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-rotation-alignment"); assertNotNull(layer); @@ -285,19 +312,33 @@ public void testIconRotationAlignment() { } @Test - public void testIconSize() { + public void testIconRotationAlignmentAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-rotation-alignment"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconRotationAlignment( + zoom( + interval( + stop(2, iconRotationAlignment(ICON_ROTATION_ALIGNMENT_MAP)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconRotationAlignment()); + assertNotNull(layer.getIconRotationAlignment().getFunction()); + assertEquals(CameraFunction.class, layer.getIconRotationAlignment().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getIconRotationAlignment().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getIconRotationAlignment().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconSizeAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-size"); assertNotNull(layer); @@ -307,19 +348,34 @@ public void testIconSize() { } @Test - public void testIconTextFit() { + public void testIconSizeAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-size"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconSize( + zoom( + exponential( + stop(2, iconSize(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconSize()); + assertNotNull(layer.getIconSize().getFunction()); + assertEquals(CameraFunction.class, layer.getIconSize().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconSize().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconSize().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconSize().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconTextFitAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-text-fit"); assertNotNull(layer); @@ -329,41 +385,70 @@ public void testIconTextFit() { } @Test - public void testIconTextFitPadding() { + public void testIconTextFitAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-text-fit"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconTextFit( + zoom( + interval( + stop(2, iconTextFit(ICON_TEXT_FIT_NONE)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconTextFit()); + assertNotNull(layer.getIconTextFit().getFunction()); + assertEquals(CameraFunction.class, layer.getIconTextFit().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getIconTextFit().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getIconTextFit().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconTextFitPaddingAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-text-fit-padding"); assertNotNull(layer); // Set and Get - layer.setProperties(iconTextFitPadding(new Float[] {0f, 0f, 0f, 0f})); - assertEquals((Float[]) layer.getIconTextFitPadding().getValue(), (Float[]) new Float[] {0f, 0f, 0f, 0f}); + layer.setProperties(iconTextFitPadding(new Float[]{0f,0f,0f,0f})); + assertEquals((Float[]) layer.getIconTextFitPadding().getValue(), (Float[]) new Float[]{0f,0f,0f,0f}); } @Test - public void testIconImage() { + public void testIconTextFitPaddingAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-text-fit-padding"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconTextFitPadding( + zoom( + exponential( + stop(2, iconTextFitPadding(new Float[]{0f,0f,0f,0f})) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconTextFitPadding()); + assertNotNull(layer.getIconTextFitPadding().getFunction()); + assertEquals(CameraFunction.class, layer.getIconTextFitPadding().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconTextFitPadding().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconTextFitPadding().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconTextFitPadding().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconImageAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-image"); assertNotNull(layer); @@ -373,19 +458,33 @@ public void testIconImage() { } @Test - public void testIconRotate() { + public void testIconImageAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-image"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconImage( + zoom( + interval( + stop(2, iconImage("undefined")) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconImage()); + assertNotNull(layer.getIconImage().getFunction()); + assertEquals(CameraFunction.class, layer.getIconImage().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getIconImage().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getIconImage().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconRotateAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-rotate"); assertNotNull(layer); @@ -395,85 +494,297 @@ public void testIconRotate() { } @Test - public void testIconPadding() { + public void testIconRotateAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-rotate"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconRotate( + zoom( + exponential( + stop(2, iconRotate(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconRotate()); + assertNotNull(layer.getIconRotate().getFunction()); + assertEquals(CameraFunction.class, layer.getIconRotate().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconRotate().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconRotate().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconRotate().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-padding"); + @Test + public void testIconRotateAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-rotate"); assertNotNull(layer); - // Set and Get - layer.setProperties(iconPadding(0.3f)); - assertEquals((Float) layer.getIconPadding().getValue(), (Float) 0.3f); + // Set + layer.setProperties( + iconRotate(property("FeaturePropertyA", Stops.identity())) + ); + + // Verify + assertNotNull(layer.getIconRotate()); + assertNotNull(layer.getIconRotate().getFunction()); + assertEquals(SourceFunction.class, layer.getIconRotate().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconRotate().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getIconRotate().getFunction().getStops().getClass()); } @Test - public void testIconKeepUpright() { + public void testIconRotateAsExponentialSourceFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-rotate"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconRotate( + property( + "FeaturePropertyA", + exponential( + stop(0.3f, iconRotate(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconRotate()); + assertNotNull(layer.getIconRotate().getFunction()); + assertEquals(SourceFunction.class, layer.getIconRotate().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconRotate().getFunction()).getProperty()); + assertEquals(ExponentialStops.class, layer.getIconRotate().getFunction().getStops().getClass()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-keep-upright"); + @Test + public void testIconRotateAsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-rotate"); assertNotNull(layer); - // Set and Get - layer.setProperties(iconKeepUpright(true)); - assertEquals((Boolean) layer.getIconKeepUpright().getValue(), (Boolean) true); + // Set + layer.setProperties( + iconRotate( + property( + "FeaturePropertyA", + categorical( + stop(1.0f, iconRotate(0.3f)) + ).withDefaultValue(0.3f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconRotate()); + assertNotNull(layer.getIconRotate().getFunction()); + assertEquals(SourceFunction.class, layer.getIconRotate().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconRotate().getFunction()).getProperty()); + assertEquals(CategoricalStops.class, layer.getIconRotate().getFunction().getStops().getClass()); + assertEquals(0.3f, ((CategoricalStops) layer.getIconRotate().getFunction().getStops()).getDefaultValue()); } @Test - public void testIconOffset() { + public void testIconRotateAsCompositeFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-rotate"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconRotate( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, iconRotate(0.9f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconRotate()); + assertNotNull(layer.getIconRotate().getFunction()); + assertEquals(CompositeFunction.class, layer.getIconRotate().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((CompositeFunction) layer.getIconRotate().getFunction()).getProperty()); + assertEquals(CompositeStops.class, layer.getIconRotate().getFunction().getStops().getClass()); + assertEquals(1, ((CompositeStops) layer.getIconRotate().getFunction().getStops()).size()); + + CompositeStops> stops = + (CompositeStops>) layer.getIconRotate().getFunction().getStops(); + Map.Entry> stop = stops.iterator().next(); + assertEquals(ExponentialStops.class, stop.getValue().getClass()); + assertEquals(0f, stop.getKey(), 0.001); + assertEquals(1, stop.getValue().size()); + assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); + assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } - Timber.i("icon-offset"); + @Test + public void testIconPaddingAsConstant() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-padding"); assertNotNull(layer); // Set and Get - layer.setProperties(iconOffset(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getIconOffset().getValue(), (Float[]) new Float[] {0f, 0f}); + layer.setProperties(iconPadding(0.3f)); + assertEquals((Float) layer.getIconPadding().getValue(), (Float) 0.3f); } @Test - public void testTextPitchAlignment() { + public void testIconPaddingAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-padding"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconPadding( + zoom( + exponential( + stop(2, iconPadding(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconPadding()); + assertNotNull(layer.getIconPadding().getFunction()); + assertEquals(CameraFunction.class, layer.getIconPadding().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconPadding().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconPadding().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconPadding().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconKeepUprightAsConstant() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-keep-upright"); + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconKeepUpright(true)); + assertEquals((Boolean) layer.getIconKeepUpright().getValue(), (Boolean) true); + } + + @Test + public void testIconKeepUprightAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-keep-upright"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconKeepUpright( + zoom( + interval( + stop(2, iconKeepUpright(true)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconKeepUpright()); + assertNotNull(layer.getIconKeepUpright().getFunction()); + assertEquals(CameraFunction.class, layer.getIconKeepUpright().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getIconKeepUpright().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getIconKeepUpright().getFunction().getStops()).size()); + } + + @Test + public void testIconOffsetAsConstant() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-offset"); + assertNotNull(layer); + + // Set and Get + layer.setProperties(iconOffset(new Float[]{0f,0f})); + assertEquals((Float[]) layer.getIconOffset().getValue(), (Float[]) new Float[]{0f,0f}); + } + + @Test + public void testIconOffsetAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-offset"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconOffset( + zoom( + exponential( + stop(2, iconOffset(new Float[]{0f,0f})) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconOffset()); + assertNotNull(layer.getIconOffset().getFunction()); + assertEquals(CameraFunction.class, layer.getIconOffset().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconOffset().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconOffset().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconOffset().getFunction().getStops()).size()); + } + + @Test + public void testIconOffsetAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-offset"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconOffset(property("FeaturePropertyA", Stops.identity())) + ); + + // Verify + assertNotNull(layer.getIconOffset()); + assertNotNull(layer.getIconOffset().getFunction()); + assertEquals(SourceFunction.class, layer.getIconOffset().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconOffset().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getIconOffset().getFunction().getStops().getClass()); + } + + @Test + public void testIconOffsetAsIntervalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-offset"); + assertNotNull(layer); + + // Set + layer.setProperties( + iconOffset( + property( + "FeaturePropertyA", + interval( + stop(1, iconOffset(new Float[]{0f,0f})) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconOffset()); + assertNotNull(layer.getIconOffset().getFunction()); + assertEquals(SourceFunction.class, layer.getIconOffset().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getIconOffset().getFunction()).getProperty()); + assertEquals(IntervalStops.class, layer.getIconOffset().getFunction().getStops().getClass()); + } + + @Test + public void testTextPitchAlignmentAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-pitch-alignment"); assertNotNull(layer); @@ -483,19 +794,33 @@ public void testTextPitchAlignment() { } @Test - public void testTextRotationAlignment() { + public void testTextPitchAlignmentAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-pitch-alignment"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textPitchAlignment( + zoom( + interval( + stop(2, textPitchAlignment(TEXT_PITCH_ALIGNMENT_MAP)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextPitchAlignment()); + assertNotNull(layer.getTextPitchAlignment().getFunction()); + assertEquals(CameraFunction.class, layer.getTextPitchAlignment().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextPitchAlignment().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextPitchAlignment().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextRotationAlignmentAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-rotation-alignment"); assertNotNull(layer); @@ -505,19 +830,33 @@ public void testTextRotationAlignment() { } @Test - public void testTextField() { + public void testTextRotationAlignmentAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-rotation-alignment"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textRotationAlignment( + zoom( + interval( + stop(2, textRotationAlignment(TEXT_ROTATION_ALIGNMENT_MAP)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextRotationAlignment()); + assertNotNull(layer.getTextRotationAlignment().getFunction()); + assertEquals(CameraFunction.class, layer.getTextRotationAlignment().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextRotationAlignment().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextRotationAlignment().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextFieldAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-field"); assertNotNull(layer); @@ -527,42 +866,69 @@ public void testTextField() { } @Test - public void testTextFont() { + public void testTextFieldAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-field"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textField( + zoom( + interval( + stop(2, textField("")) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextField()); + assertNotNull(layer.getTextField().getFunction()); + assertEquals(CameraFunction.class, layer.getTextField().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextField().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextField().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextFontAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-font"); assertNotNull(layer); // Set and Get - layer.setProperties(textFont(new String[] {"Open Sans Regular", "Arial Unicode MS Regular"})); - assertEquals((String[]) layer.getTextFont().getValue(), (String[]) new String[] {"Open Sans Regular", - "Arial Unicode MS Regular"}); + layer.setProperties(textFont(new String[]{"Open Sans Regular", "Arial Unicode MS Regular"})); + assertEquals((String[]) layer.getTextFont().getValue(), (String[]) new String[]{"Open Sans Regular", "Arial Unicode MS Regular"}); } @Test - public void testTextSize() { + public void testTextFontAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-font"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textFont( + zoom( + interval( + stop(2, textFont(new String[]{"Open Sans Regular", "Arial Unicode MS Regular"})) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextFont()); + assertNotNull(layer.getTextFont().getFunction()); + assertEquals(CameraFunction.class, layer.getTextFont().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextFont().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextFont().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextSizeAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-size"); assertNotNull(layer); @@ -572,19 +938,34 @@ public void testTextSize() { } @Test - public void testTextMaxWidth() { + public void testTextSizeAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-size"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textSize( + zoom( + exponential( + stop(2, textSize(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextSize()); + assertNotNull(layer.getTextSize().getFunction()); + assertEquals(CameraFunction.class, layer.getTextSize().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextSize().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextSize().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextSize().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextMaxWidthAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-max-width"); assertNotNull(layer); @@ -594,19 +975,34 @@ public void testTextMaxWidth() { } @Test - public void testTextLineHeight() { + public void testTextMaxWidthAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-max-width"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textMaxWidth( + zoom( + exponential( + stop(2, textMaxWidth(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextMaxWidth()); + assertNotNull(layer.getTextMaxWidth().getFunction()); + assertEquals(CameraFunction.class, layer.getTextMaxWidth().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextMaxWidth().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextMaxWidth().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextMaxWidth().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextLineHeightAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-line-height"); assertNotNull(layer); @@ -616,19 +1012,34 @@ public void testTextLineHeight() { } @Test - public void testTextLetterSpacing() { + public void testTextLineHeightAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-line-height"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textLineHeight( + zoom( + exponential( + stop(2, textLineHeight(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextLineHeight()); + assertNotNull(layer.getTextLineHeight().getFunction()); + assertEquals(CameraFunction.class, layer.getTextLineHeight().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextLineHeight().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextLineHeight().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextLineHeight().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextLetterSpacingAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-letter-spacing"); assertNotNull(layer); @@ -638,19 +1049,34 @@ public void testTextLetterSpacing() { } @Test - public void testTextJustify() { + public void testTextLetterSpacingAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-letter-spacing"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textLetterSpacing( + zoom( + exponential( + stop(2, textLetterSpacing(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextLetterSpacing()); + assertNotNull(layer.getTextLetterSpacing().getFunction()); + assertEquals(CameraFunction.class, layer.getTextLetterSpacing().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextLetterSpacing().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextLetterSpacing().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextLetterSpacing().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextJustifyAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-justify"); assertNotNull(layer); @@ -660,19 +1086,33 @@ public void testTextJustify() { } @Test - public void testTextAnchor() { + public void testTextJustifyAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-justify"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textJustify( + zoom( + interval( + stop(2, textJustify(TEXT_JUSTIFY_LEFT)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextJustify()); + assertNotNull(layer.getTextJustify().getFunction()); + assertEquals(CameraFunction.class, layer.getTextJustify().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextJustify().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextJustify().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextAnchorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-anchor"); assertNotNull(layer); @@ -682,19 +1122,33 @@ public void testTextAnchor() { } @Test - public void testTextMaxAngle() { + public void testTextAnchorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-anchor"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textAnchor( + zoom( + interval( + stop(2, textAnchor(TEXT_ANCHOR_CENTER)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextAnchor()); + assertNotNull(layer.getTextAnchor().getFunction()); + assertEquals(CameraFunction.class, layer.getTextAnchor().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextAnchor().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextAnchor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextMaxAngleAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-max-angle"); assertNotNull(layer); @@ -704,19 +1158,34 @@ public void testTextMaxAngle() { } @Test - public void testTextRotate() { + public void testTextMaxAngleAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-max-angle"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textMaxAngle( + zoom( + exponential( + stop(2, textMaxAngle(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextMaxAngle()); + assertNotNull(layer.getTextMaxAngle().getFunction()); + assertEquals(CameraFunction.class, layer.getTextMaxAngle().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextMaxAngle().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextMaxAngle().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextMaxAngle().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextRotateAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-rotate"); assertNotNull(layer); @@ -726,19 +1195,34 @@ public void testTextRotate() { } @Test - public void testTextPadding() { + public void testTextRotateAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-rotate"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textRotate( + zoom( + exponential( + stop(2, textRotate(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextRotate()); + assertNotNull(layer.getTextRotate().getFunction()); + assertEquals(CameraFunction.class, layer.getTextRotate().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextRotate().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextRotate().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextRotate().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextPaddingAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-padding"); assertNotNull(layer); @@ -748,19 +1232,34 @@ public void testTextPadding() { } @Test - public void testTextKeepUpright() { + public void testTextPaddingAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-padding"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textPadding( + zoom( + exponential( + stop(2, textPadding(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextPadding()); + assertNotNull(layer.getTextPadding().getFunction()); + assertEquals(CameraFunction.class, layer.getTextPadding().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextPadding().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextPadding().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextPadding().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextKeepUprightAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-keep-upright"); assertNotNull(layer); @@ -770,19 +1269,33 @@ public void testTextKeepUpright() { } @Test - public void testTextTransform() { + public void testTextKeepUprightAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-keep-upright"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textKeepUpright( + zoom( + interval( + stop(2, textKeepUpright(true)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextKeepUpright()); + assertNotNull(layer.getTextKeepUpright().getFunction()); + assertEquals(CameraFunction.class, layer.getTextKeepUpright().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextKeepUpright().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextKeepUpright().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextTransformAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-transform"); assertNotNull(layer); @@ -792,41 +1305,70 @@ public void testTextTransform() { } @Test - public void testTextOffset() { + public void testTextTransformAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-transform"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textTransform( + zoom( + interval( + stop(2, textTransform(TEXT_TRANSFORM_NONE)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextTransform()); + assertNotNull(layer.getTextTransform().getFunction()); + assertEquals(CameraFunction.class, layer.getTextTransform().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextTransform().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextTransform().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextOffsetAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-offset"); assertNotNull(layer); // Set and Get - layer.setProperties(textOffset(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getTextOffset().getValue(), (Float[]) new Float[] {0f, 0f}); + layer.setProperties(textOffset(new Float[]{0f,0f})); + assertEquals((Float[]) layer.getTextOffset().getValue(), (Float[]) new Float[]{0f,0f}); } @Test - public void testTextAllowOverlap() { + public void testTextOffsetAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-offset"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textOffset( + zoom( + exponential( + stop(2, textOffset(new Float[]{0f,0f})) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextOffset()); + assertNotNull(layer.getTextOffset().getFunction()); + assertEquals(CameraFunction.class, layer.getTextOffset().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextOffset().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextOffset().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextOffset().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextAllowOverlapAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-allow-overlap"); assertNotNull(layer); @@ -836,19 +1378,33 @@ public void testTextAllowOverlap() { } @Test - public void testTextIgnorePlacement() { + public void testTextAllowOverlapAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-allow-overlap"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textAllowOverlap( + zoom( + interval( + stop(2, textAllowOverlap(true)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextAllowOverlap()); + assertNotNull(layer.getTextAllowOverlap().getFunction()); + assertEquals(CameraFunction.class, layer.getTextAllowOverlap().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextAllowOverlap().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextAllowOverlap().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextIgnorePlacementAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-ignore-placement"); assertNotNull(layer); @@ -858,19 +1414,33 @@ public void testTextIgnorePlacement() { } @Test - public void testTextOptional() { + public void testTextIgnorePlacementAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-ignore-placement"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textIgnorePlacement( + zoom( + interval( + stop(2, textIgnorePlacement(true)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextIgnorePlacement()); + assertNotNull(layer.getTextIgnorePlacement().getFunction()); + assertEquals(CameraFunction.class, layer.getTextIgnorePlacement().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextIgnorePlacement().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextIgnorePlacement().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextOptionalAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-optional"); assertNotNull(layer); @@ -880,19 +1450,33 @@ public void testTextOptional() { } @Test - public void testIconOpacity() { - checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + public void testTextOptionalAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-optional"); + assertNotNull(layer); + + // Set + layer.setProperties( + textOptional( + zoom( + interval( + stop(2, textOptional(true)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextOptional()); + assertNotNull(layer.getTextOptional().getFunction()); + assertEquals(CameraFunction.class, layer.getTextOptional().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextOptional().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextOptional().getFunction().getStops()).size()); + } + + @Test + public void testIconOpacityAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-opacity"); assertNotNull(layer); @@ -902,19 +1486,34 @@ public void testIconOpacity() { } @Test - public void testIconColor() { + public void testIconOpacityAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-opacity"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconOpacity( + zoom( + exponential( + stop(2, iconOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconOpacity()); + assertNotNull(layer.getIconOpacity().getFunction()); + assertEquals(CameraFunction.class, layer.getIconOpacity().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconOpacity().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconOpacity().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconOpacity().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconColorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-color"); assertNotNull(layer); @@ -924,19 +1523,34 @@ public void testIconColor() { } @Test - public void testIconColorAsInt() { + public void testIconColorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconColor( + zoom( + exponential( + stop(2, iconColor("rgba(0, 0, 0, 1)")) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconColor()); + assertNotNull(layer.getIconColor().getFunction()); + assertEquals(CameraFunction.class, layer.getIconColor().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconColor().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconColor().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconColor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-color"); assertNotNull(layer); @@ -946,19 +1560,8 @@ public void testIconColorAsInt() { } @Test - public void testIconHaloColor() { + public void testIconHaloColorAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } Timber.i("icon-halo-color"); assertNotNull(layer); @@ -968,19 +1571,34 @@ public void testIconHaloColor() { } @Test - public void testIconHaloColorAsInt() { + public void testIconHaloColorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-halo-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconHaloColor( + zoom( + exponential( + stop(2, iconHaloColor("rgba(0, 0, 0, 1)")) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconHaloColor()); + assertNotNull(layer.getIconHaloColor().getFunction()); + assertEquals(CameraFunction.class, layer.getIconHaloColor().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconHaloColor().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconHaloColor().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconHaloColor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconHaloColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-halo-color"); assertNotNull(layer); @@ -990,19 +1608,8 @@ public void testIconHaloColorAsInt() { } @Test - public void testIconHaloWidth() { + public void testIconHaloWidthAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } Timber.i("icon-halo-width"); assertNotNull(layer); @@ -1012,19 +1619,34 @@ public void testIconHaloWidth() { } @Test - public void testIconHaloBlur() { + public void testIconHaloWidthAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-halo-width"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconHaloWidth( + zoom( + exponential( + stop(2, iconHaloWidth(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconHaloWidth()); + assertNotNull(layer.getIconHaloWidth().getFunction()); + assertEquals(CameraFunction.class, layer.getIconHaloWidth().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconHaloWidth().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconHaloWidth().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconHaloWidth().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconHaloBlurAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-halo-blur"); assertNotNull(layer); @@ -1034,41 +1656,71 @@ public void testIconHaloBlur() { } @Test - public void testIconTranslate() { + public void testIconHaloBlurAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-halo-blur"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconHaloBlur( + zoom( + exponential( + stop(2, iconHaloBlur(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconHaloBlur()); + assertNotNull(layer.getIconHaloBlur().getFunction()); + assertEquals(CameraFunction.class, layer.getIconHaloBlur().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconHaloBlur().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconHaloBlur().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconHaloBlur().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconTranslateAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-translate"); assertNotNull(layer); // Set and Get - layer.setProperties(iconTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getIconTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); + layer.setProperties(iconTranslate(new Float[]{0f,0f})); + assertEquals((Float[]) layer.getIconTranslate().getValue(), (Float[]) new Float[]{0f,0f}); } @Test - public void testIconTranslateAnchor() { + public void testIconTranslateAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-translate"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconTranslate( + zoom( + exponential( + stop(2, iconTranslate(new Float[]{0f,0f})) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconTranslate()); + assertNotNull(layer.getIconTranslate().getFunction()); + assertEquals(CameraFunction.class, layer.getIconTranslate().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getIconTranslate().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getIconTranslate().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getIconTranslate().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testIconTranslateAnchorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("icon-translate-anchor"); assertNotNull(layer); @@ -1078,19 +1730,33 @@ public void testIconTranslateAnchor() { } @Test - public void testTextOpacity() { + public void testIconTranslateAnchorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("icon-translate-anchor"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + iconTranslateAnchor( + zoom( + interval( + stop(2, iconTranslateAnchor(ICON_TRANSLATE_ANCHOR_MAP)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getIconTranslateAnchor()); + assertNotNull(layer.getIconTranslateAnchor().getFunction()); + assertEquals(CameraFunction.class, layer.getIconTranslateAnchor().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getIconTranslateAnchor().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getIconTranslateAnchor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextOpacityAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-opacity"); assertNotNull(layer); @@ -1100,19 +1766,34 @@ public void testTextOpacity() { } @Test - public void testTextColor() { + public void testTextOpacityAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-opacity"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textOpacity( + zoom( + exponential( + stop(2, textOpacity(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextOpacity()); + assertNotNull(layer.getTextOpacity().getFunction()); + assertEquals(CameraFunction.class, layer.getTextOpacity().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextOpacity().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextOpacity().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextOpacity().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextColorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-color"); assertNotNull(layer); @@ -1122,19 +1803,34 @@ public void testTextColor() { } @Test - public void testTextColorAsInt() { + public void testTextColorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textColor( + zoom( + exponential( + stop(2, textColor("rgba(0, 0, 0, 1)")) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextColor()); + assertNotNull(layer.getTextColor().getFunction()); + assertEquals(CameraFunction.class, layer.getTextColor().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextColor().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextColor().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextColor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-color"); assertNotNull(layer); @@ -1144,19 +1840,8 @@ public void testTextColorAsInt() { } @Test - public void testTextHaloColor() { + public void testTextHaloColorAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } Timber.i("text-halo-color"); assertNotNull(layer); @@ -1166,19 +1851,34 @@ public void testTextHaloColor() { } @Test - public void testTextHaloColorAsInt() { + public void testTextHaloColorAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-halo-color"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textHaloColor( + zoom( + exponential( + stop(2, textHaloColor("rgba(0, 0, 0, 1)")) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextHaloColor()); + assertNotNull(layer.getTextHaloColor().getFunction()); + assertEquals(CameraFunction.class, layer.getTextHaloColor().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextHaloColor().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextHaloColor().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextHaloColor().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextHaloColorAsIntConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-halo-color"); assertNotNull(layer); @@ -1188,19 +1888,8 @@ public void testTextHaloColorAsInt() { } @Test - public void testTextHaloWidth() { + public void testTextHaloWidthAsConstant() { checkViewIsDisplayed(R.id.mapView); - - mapboxMap = rule.getActivity().getMapboxMap(); - - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } Timber.i("text-halo-width"); assertNotNull(layer); @@ -1210,19 +1899,34 @@ public void testTextHaloWidth() { } @Test - public void testTextHaloBlur() { + public void testTextHaloWidthAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-halo-width"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textHaloWidth( + zoom( + exponential( + stop(2, textHaloWidth(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextHaloWidth()); + assertNotNull(layer.getTextHaloWidth().getFunction()); + assertEquals(CameraFunction.class, layer.getTextHaloWidth().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextHaloWidth().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextHaloWidth().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextHaloWidth().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextHaloBlurAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-halo-blur"); assertNotNull(layer); @@ -1232,41 +1936,71 @@ public void testTextHaloBlur() { } @Test - public void testTextTranslate() { + public void testTextHaloBlurAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-halo-blur"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textHaloBlur( + zoom( + exponential( + stop(2, textHaloBlur(0.3f)) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextHaloBlur()); + assertNotNull(layer.getTextHaloBlur().getFunction()); + assertEquals(CameraFunction.class, layer.getTextHaloBlur().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextHaloBlur().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextHaloBlur().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextHaloBlur().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextTranslateAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-translate"); assertNotNull(layer); // Set and Get - layer.setProperties(textTranslate(new Float[] {0f, 0f})); - assertEquals((Float[]) layer.getTextTranslate().getValue(), (Float[]) new Float[] {0f, 0f}); + layer.setProperties(textTranslate(new Float[]{0f,0f})); + assertEquals((Float[]) layer.getTextTranslate().getValue(), (Float[]) new Float[]{0f,0f}); } @Test - public void testTextTranslateAnchor() { + public void testTextTranslateAsCameraFunction() { checkViewIsDisplayed(R.id.mapView); + Timber.i("text-translate"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // Set + layer.setProperties( + textTranslate( + zoom( + exponential( + stop(2, textTranslate(new Float[]{0f,0f})) + ).withBase(0.5f) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextTranslate()); + assertNotNull(layer.getTextTranslate().getFunction()); + assertEquals(CameraFunction.class, layer.getTextTranslate().getFunction().getClass()); + assertEquals(ExponentialStops.class, layer.getTextTranslate().getFunction().getStops().getClass()); + assertEquals(0.5f, ((ExponentialStops) layer.getTextTranslate().getFunction().getStops()).getBase(), 0.001); + assertEquals(1, ((ExponentialStops) layer.getTextTranslate().getFunction().getStops()).size()); + } - if ((layer = mapboxMap.getLayerAs("my-layer")) == null) { - Timber.i("Adding layer"); - layer = new SymbolLayer("my-layer", "composite"); - layer.setSourceLayer("composite"); - mapboxMap.addLayer(layer); - // Layer reference is now stale, get new reference - layer = mapboxMap.getLayerAs("my-layer"); - } + @Test + public void testTextTranslateAnchorAsConstant() { + checkViewIsDisplayed(R.id.mapView); Timber.i("text-translate-anchor"); assertNotNull(layer); @@ -1275,6 +2009,31 @@ public void testTextTranslateAnchor() { assertEquals((String) layer.getTextTranslateAnchor().getValue(), (String) TEXT_TRANSLATE_ANCHOR_MAP); } + @Test + public void testTextTranslateAnchorAsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-translate-anchor"); + assertNotNull(layer); + + // Set + layer.setProperties( + textTranslateAnchor( + zoom( + interval( + stop(2, textTranslateAnchor(TEXT_TRANSLATE_ANCHOR_MAP)) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextTranslateAnchor()); + assertNotNull(layer.getTextTranslateAnchor().getFunction()); + assertEquals(CameraFunction.class, layer.getTextTranslateAnchor().getFunction().getClass()); + assertEquals(IntervalStops.class, layer.getTextTranslateAnchor().getFunction().getStops().getClass()); + assertEquals(1, ((IntervalStops) layer.getTextTranslateAnchor().getFunction().getStops()).size()); + } + @After public void unregisterIntentServiceIdlingResource() { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs index c9afb8bdf9c..2feb79f33e7 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs @@ -3,6 +3,7 @@ const properties = locals.properties; -%> // This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + package com.mapbox.mapboxsdk.testapp.style; import android.graphics.Color; @@ -12,6 +13,15 @@ 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.CompositeStops; +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.Stops; import com.mapbox.mapboxsdk.style.layers.<%- camelize(type) %>Layer; import com.mapbox.mapboxsdk.testapp.R; import com.mapbox.mapboxsdk.testapp.activity.style.RuntimeStyleTestActivity; @@ -23,6 +33,11 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import java.util.Map; + +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 org.junit.Assert.*; import static com.mapbox.mapboxsdk.style.layers.Property.*; import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; @@ -33,112 +48,305 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.*; @RunWith(AndroidJUnit4.class) public class <%- camelize(type) %>LayerTest extends BaseStyleTest { - @Rule - public final ActivityTestRule rule = new ActivityTestRule<>(RuntimeStyleTestActivity.class); - - private <%- camelize(type) %>Layer layer; + @Rule + public final ActivityTestRule rule = new ActivityTestRule<>(RuntimeStyleTestActivity.class); - private OnMapReadyIdlingResource idlingResource; + private <%- camelize(type) %>Layer layer; - private MapboxMap mapboxMap; + private OnMapReadyIdlingResource idlingResource; - @Before - public void setup() { - idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); - Espresso.registerIdlingResources(idlingResource); - } - - @Test - public void testSetVisibility() { - checkViewIsDisplayed(R.id.mapView); + private MapboxMap mapboxMap; - mapboxMap = rule.getActivity().getMapboxMap(); + @Before + public void setup() { + idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); + Espresso.registerIdlingResources(idlingResource); + mapboxMap = rule.getActivity().getMapboxMap(); <% if (type === 'background') { -%> - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); + Timber.i("Retrieving layer"); + layer = mapboxMap.getLayerAs("background"); <% } else { -%> - 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"); - } + 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"); + } <% } -%> - Timber.i("visibility"); - assertNotNull(layer); + } - // Get initial - assertEquals(layer.getVisibility().getValue(), VISIBLE); + @Test + public void testSetVisibility() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("Visibility"); + assertNotNull(layer); - // Set - layer.setProperties(visibility(NONE)); - assertEquals(layer.getVisibility().getValue(), NONE); - } + // Get initial + assertEquals(layer.getVisibility().getValue(), VISIBLE); + + // Set + layer.setProperties(visibility(NONE)); + assertEquals(layer.getVisibility().getValue(), NONE); + } <% for (const property of properties) { -%> - @Test - public void test<%- camelize(property.name) %>() { - checkViewIsDisplayed(R.id.mapView); + @Test + public void test<%- camelize(property.name) %>AsConstant() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("<%- property.name %>"); + assertNotNull(layer); - mapboxMap = rule.getActivity().getMapboxMap(); + // 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 (type === 'background') { -%> - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); + @Test + public void test<%- camelize(property.name) %>AsCameraFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("<%- property.name %>"); + assertNotNull(layer); + + // Set + layer.setProperties( + <%- camelizeWithLeadingLowercase(property.name) %>( + zoom( +<% if (property.function == 'piecewise-constant') { -%> + interval( + stop(2, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)) + ) <% } else { -%> - 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"); - } + exponential( + stop(2, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)) + ).withBase(0.5f) <% } -%> - Timber.i("<%- property.name %>"); - 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) %>); - } + // 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() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("<%- property.name %>"); + 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() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("<%- property.name %>"); + assertNotNull(layer); + + // Set + layer.setProperties( + <%- camelizeWithLeadingLowercase(property.name) %>( + property( + "FeaturePropertyA", + interval( <% if (property.type == 'color') { -%> + stop(Color.RED, <%- camelizeWithLeadingLowercase(property.name) %>(Color.RED)) +<% } else {-%> + 1, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)) +<% } -%> + ) + ) + ) + ); - @Test - public void test<%- camelize(property.name) %>AsInt() { - checkViewIsDisplayed(R.id.mapView); + // 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()); + } +<% } else if (property.type === 'array') { -%> - mapboxMap = rule.getActivity().getMapboxMap(); + @Test + public void test<%- camelize(property.name) %>AsIntervalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("<%- property.name %>"); + assertNotNull(layer); -<% if (type === 'background') { -%> - Timber.i("Retrieving layer"); - layer = mapboxMap.getLayerAs("background"); + // 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 ((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"); - } + + @Test + public void test<%- camelize(property.name) %>AsExponentialSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("<%- property.name %>"); + 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) %>)) <% } -%> - Timber.i("<%- property.name %>"); - assertNotNull(layer); + ).withBase(0.5f) + ) + ) + ); - // Set and Get - layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(Color.RED)); - assertEquals(layer.get<%- camelize(property.name) %>AsInt(), Color.RED); - } + // 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()); + } + + @Test + public void test<%- camelize(property.name) %>AsCategoricalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("<%- property.name %>"); + assertNotNull(layer); + + // Set + layer.setProperties( + <%- camelizeWithLeadingLowercase(property.name) %>( + property( + "FeaturePropertyA", + categorical( +<% if (property.type == 'color') { -%> + stop("valueA", <%- camelizeWithLeadingLowercase(property.name) %>(Color.RED)) + ) +<% } else {-%> + stop(1.0f, <%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>)) + ).withDefaultValue(<%- 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()); +<% if (property.type !== 'color') { -%> + assertEquals(<%- defaultValueJava(property) %>, ((CategoricalStops) layer.get<%- camelize(property.name) %>().getFunction().getStops()).getDefaultValue()); +<% } -%> + } +<% if (property.type !== 'color') { -%> + + @Test + public void test<%- camelize(property.name) %>AsCompositeFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("<%- property.name %>"); + assertNotNull(layer); + + // Set + layer.setProperties( + <%- camelizeWithLeadingLowercase(property.name) %>( + composite( + "FeaturePropertyA", + exponential( + stop(0, 0.3f, <%- camelizeWithLeadingLowercase(property.name) %>(0.9f)) + ).withBase(0.5f) + ) + ) + ); + + // 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(CompositeStops.class, layer.get<%- camelize(property.name) %>().getFunction().getStops().getClass()); + assertEquals(1, ((CompositeStops) layer.get<%- camelize(property.name) %>().getFunction().getStops()).size()); + + CompositeStops, <%- propertyType(property) %>, ExponentialStops<<%- propertyType(property) %>, <%- propertyType(property) %>>> stops = + (CompositeStops, <%- propertyType(property) %>, ExponentialStops<<%- propertyType(property) %>, <%- propertyType(property) %>>>) layer.get<%- camelize(property.name) %>().getFunction().getStops(); + Map.Entry, <%- propertyType(property) %>>> stop = stops.iterator().next(); + assertEquals(ExponentialStops.class, stop.getValue().getClass()); + assertEquals(0f, stop.getKey(), 0.001); + assertEquals(1, stop.getValue().size()); + assertEquals(0.3f, stop.getValue().iterator().next().in, 0.001f); + assertEquals(0.9f, stop.getValue().iterator().next().out, 0.001f); + } +<% } -%> +<% } -%> +<% } -%> +<% if (property.type == 'color') { -%> + + @Test + public void test<%- camelize(property.name) %>AsIntConstant() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("<%- property.name %>"); + assertNotNull(layer); + + // Set and Get + layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(Color.RED)); + assertEquals(layer.get<%- camelize(property.name) %>AsInt(), Color.RED); + } <% } -%> <% } -%> - @After - public void unregisterIntentServiceIdlingResource() { - Espresso.unregisterIdlingResources(idlingResource); - } + @After + public void unregisterIntentServiceIdlingResource() { + Espresso.unregisterIdlingResources(idlingResource); + } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index ca2a96b0078..eabd8d5c9dc 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -406,6 +406,17 @@ android:name="android.support.PARENT_ACTIVITY" android:value=".activity.FeatureOverviewActivity"/> + + + + identity()) + ) + ); + + Timber.i("Fill opacity: %s", layer.getFillOpacity()); + } + + private void addIntervalSourceFunction() { + Timber.i("Add interval source function"); + FillLayer layer = mapboxMap.getLayerAs(AMSTERDAM_PARKS_LAYER); + assert layer != null; + layer.setProperties( + fillColor( + property( + "stroke-width", + interval( + stop(1f, fillColor(Color.RED)), + stop(5f, fillColor(Color.BLUE)), + stop(10f, fillColor(Color.GREEN)) + )) + ) + ); + + Timber.i("Fill color: %s", layer.getFillColor()); + } + + private void addCompositeExponentialFunction() { + Timber.i("Add composite exponential function"); + FillLayer layer = mapboxMap.getLayerAs(AMSTERDAM_PARKS_LAYER); + assert layer != null; + layer.setProperties( + fillColor( + composite( + "stroke-width", + exponential( + stop(1, 1, fillColor(Color.RED)), + stop(10, 2, fillColor(Color.BLUE)), + stop(22, 3, fillColor(Color.GREEN)), + stop(1, 1, fillColor(Color.CYAN)), + stop(10, 2, fillColor(Color.GRAY)), + stop(22, 3, fillColor(Color.YELLOW)) + ).withBase(1f) + ) + ) + ); + + Timber.i("Fill color: %s", layer.getFillColor()); + } + + private void addCompositeIntervalFunction() { + Timber.i("Add composite exponential function"); + FillLayer layer = mapboxMap.getLayerAs(AMSTERDAM_PARKS_LAYER); + assert layer != null; + layer.setProperties( + fillColor( + composite( + "stroke-width", + interval( + stop(1, 1, fillColor(Color.RED)), + stop(10, 2, fillColor(Color.BLUE)), + stop(22, 3, fillColor(Color.GREEN)), + stop(1, 1, fillColor(Color.CYAN)), + stop(10, 2, fillColor(Color.GRAY)), + stop(22, 3, fillColor(Color.YELLOW)) + )) + ) + ); + + Timber.i("Fill color: %s", layer.getFillColor()); + } + + private void addCompositeCategoricalFunction() { + Timber.i("Add composite categorical function"); + FillLayer layer = mapboxMap.getLayerAs(AMSTERDAM_PARKS_LAYER); + assert layer != null; + layer.setProperties( + fillColor( + composite( + "name", + categorical( + stop(7f, "Westerpark", fillColor(Color.RED)), + stop(8f, "Westerpark", fillColor(Color.BLUE)), + stop(9f, "Westerpark", fillColor(Color.RED)), + stop(10f, "Westerpark", fillColor(Color.BLUE)), + stop(11f, "Westerpark", fillColor(Color.RED)), + stop(12f, "Westerpark", fillColor(Color.BLUE)), + stop(13f, "Westerpark", fillColor(Color.RED)), + stop(14f, "Westerpark", fillColor(Color.BLUE)), + stop(15f, "Westerpark", fillColor(Color.RED)), + stop(16f, "Westerpark", fillColor(Color.BLUE)), + stop(17f, "Westerpark", fillColor(Color.RED)), + stop(18f, "Westerpark", fillColor(Color.BLUE)), + stop(19f, "Westerpark", fillColor(Color.RED)), + stop(20f, "Westerpark", fillColor(Color.BLUE)), + stop(21f, "Westerpark", fillColor(Color.RED)), + stop(22f, "Westerpark", fillColor(Color.BLUE)), + stop(14f, "Jordaan", fillColor(Color.GREEN)), + stop(18f, "Jordaan", fillColor(Color.CYAN)), + stop(14f, "Prinseneiland", fillColor(Color.WHITE)), + stop(18f, "Prinseneiland", fillColor(Color.BLACK)) + )) + ) + ); + + Timber.i("Fill color: %s", layer.getFillColor()); + } + + private void addParksLayer() { + // Add a source + Source source; + try { + source = new GeoJsonSource("amsterdam-parks-source", readRawResource(R.raw.amsterdam)); + mapboxMap.addSource(source); + } catch (IOException ioException) { + Toast.makeText( + DataDrivenStyleActivity.this, + "Couldn't add source: " + ioException.getMessage(), + Toast.LENGTH_SHORT).show(); + return; + } + + + // Add a fill layer + mapboxMap.addLayer(new FillLayer(AMSTERDAM_PARKS_LAYER, source.getId()) + .withProperties( + fillColor(Color.BLACK), + fillOutlineColor(Color.BLUE), + fillAntialias(true) + ) + ); + } + + private String readRawResource(@RawRes int rawResource) throws IOException { + InputStream is = getResources().openRawResource(rawResource); + Writer writer = new StringWriter(); + char[] buffer = new char[1024]; + try { + 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(); + } + + return writer.toString(); + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java index f49cf9a8bf0..e6650e83009 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java @@ -14,8 +14,10 @@ import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; +import com.mapbox.mapboxsdk.style.functions.Function; +import com.mapbox.mapboxsdk.style.functions.stops.ExponentialStops; +import com.mapbox.mapboxsdk.style.functions.stops.Stop; import com.mapbox.mapboxsdk.style.layers.FillLayer; -import com.mapbox.mapboxsdk.style.layers.Function; import com.mapbox.mapboxsdk.style.layers.Layer; import com.mapbox.mapboxsdk.style.layers.LineLayer; import com.mapbox.mapboxsdk.style.layers.NoSuchLayerException; @@ -43,13 +45,13 @@ import timber.log.Timber; +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.exponential; import static com.mapbox.mapboxsdk.style.layers.Filter.all; import static com.mapbox.mapboxsdk.style.layers.Filter.eq; import static com.mapbox.mapboxsdk.style.layers.Filter.gte; import static com.mapbox.mapboxsdk.style.layers.Filter.lt; -import static com.mapbox.mapboxsdk.style.layers.Function.Stop; -import static com.mapbox.mapboxsdk.style.layers.Function.stop; -import static com.mapbox.mapboxsdk.style.layers.Function.zoom; import static com.mapbox.mapboxsdk.style.layers.Property.FILL_TRANSLATE_ANCHOR_MAP; import static com.mapbox.mapboxsdk.style.layers.Property.NONE; import static com.mapbox.mapboxsdk.style.layers.Property.SYMBOL_PLACEMENT_POINT; @@ -412,23 +414,28 @@ private void updateWaterColorOnZoom() { } // Set a zoom function to update the color of the water - layer.setProperties(fillColor(zoom(0.8f, - stop(1, fillColor(Color.GREEN)), - stop(4, fillColor(Color.BLUE)), - stop(12, fillColor(Color.RED)), - stop(20, fillColor(Color.BLACK)) - ))); + layer.setProperties(fillColor( + zoom( + exponential( + stop(1, fillColor(Color.GREEN)), + stop(4, fillColor(Color.BLUE)), + stop(12, fillColor(Color.RED)), + stop(20, fillColor(Color.BLACK)) + ).withBase(0.8f) + ) + )); // do some animations to show it off properly mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(1), 1500); PropertyValue fillColor = layer.getFillColor(); - Function function = fillColor.getFunction(); + Function function = (Function) fillColor.getFunction(); if (function != null) { - Timber.d("Fill color base: " + function.getBase()); - Timber.d("Fill color #stops: " + function.getStops().length); + ExponentialStops stops = (ExponentialStops) function.getStops(); + Timber.d("Fill color base: " + stops.getBase()); + Timber.d("Fill color #stops: " + stops.size()); if (function.getStops() != null) { - for (Stop stop : function.getStops()) { + for (Stop stop : stops) { Timber.d("Fill color #stops: " + stop); } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_data_driven_style.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_data_driven_style.xml new file mode 100644 index 00000000000..7454ce58600 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_data_driven_style.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_data_driven_style.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_data_driven_style.xml new file mode 100644 index 00000000000..3eae56a273d --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_data_driven_style.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/raw/amsterdam.geojson b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/raw/amsterdam.geojson index c5585533a08..e433a509eba 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/raw/amsterdam.geojson +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/raw/amsterdam.geojson @@ -256,7 +256,7 @@ "stroke-width": 2, "stroke-opacity": 1, "fill": "#555555", - "fill-opacity": 0.5, + "fill-opacity": 1.0, "name": "Sarphatipark", "type": "park", "description": "Sarphatipark is a small park in the popular De Pijp neighbourhood. It was openend in late 19th century, and named after Samuel Sarphati." @@ -482,7 +482,7 @@ "stroke-width": 2, "stroke-opacity": 1, "fill": "#555555", - "fill-opacity": 0.5, + "fill-opacity": 0.1, "name": "Sloterdijk", "type": "area", "description": "To protect the area around Sloten from the as-yet undrained IJ the Spaarndammerdijk was laid along the south bank of this inlet. In this vicinity at the same time, a dam on the Slochter (or Slooter) river was built, the Slooterdam. Trade grew in the vicinity, and in the 15th century a weigh house and a church were built. The area is nowadays best known as a large intersection of train lines and a business and industrial centre north-west of Amsterdam." @@ -574,7 +574,7 @@ "stroke-width": 2, "stroke-opacity": 1, "fill": "#555555", - "fill-opacity": 0.5, + "fill-opacity": 0.7, "name": "Artis", "type": "poi", "description": "Artis, short for Natura Artis Magistra (Latin for \"Nature is the teacher of art and science\"), is a zoo in the centre of Amsterdam. It is the oldest zoo in the Netherlands and one of the oldest zoos of mainland Europe. Artis Royal Zoo is not just a zoo, it also contains an aquarium and a planetarium. Artis also has an arboretum and a fairly large art collection. A part of the art collection is on display in the Aquarium building of the zoo. Artis contains 27 monumental buildings, most of which are used as enclosures for the animals, making Artis a unique cultural heritage of the 19th century." diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml index fdfad800d67..aa366163738 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml @@ -49,6 +49,7 @@ Min/Max Zoom ViewPager Runtime Style + Data Driven Style Circle layer Local Style file GeoJson Clustering @@ -100,6 +101,7 @@ Learn how to create a dynamic custom InfoWindow Use SupportMapFragments in a ViewPager Adopt the map style on the fly + Use functions to change the map appearance Manipulate symbols at runtime Use a custom sprite in a Symbol Layer Use GeoJson sources and dynamic layers to cluster information diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/style/layers/FunctionTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/style/layers/FunctionTest.java index 4e82ca2318a..bac1154d62e 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/style/layers/FunctionTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/style/layers/FunctionTest.java @@ -1,9 +1,12 @@ package com.mapbox.mapboxsdk.style.layers; +import com.mapbox.mapboxsdk.style.functions.Function; + import org.junit.Test; -import static com.mapbox.mapboxsdk.style.layers.Function.stop; -import static com.mapbox.mapboxsdk.style.layers.Function.zoom; +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; @@ -15,9 +18,10 @@ public class FunctionTest { @Test public void testZoomFunction() { - Function zoomF = zoom( + Function zoomF = zoom(interval( stop(1f, lineBlur(1f)), stop(10f, lineBlur(20f)) + ) ); assertNotNull(zoomF.toValueObject()); diff --git a/platform/android/scripts/generate-style-code.js b/platform/android/scripts/generate-style-code.js index 634a4ce802c..b9e0d6dfd9a 100644 --- a/platform/android/scripts/generate-style-code.js +++ b/platform/android/scripts/generate-style-code.js @@ -10,7 +10,7 @@ require('../../../scripts/style-code'); // Specification parsing // // Collect layer types from spec -const layers = Object.keys(spec.layer.type.values).map((type) => { +var layers = Object.keys(spec.layer.type.values).map((type) => { const layoutProperties = Object.keys(spec[`layout_${type}`]).reduce((memo, name) => { if (name !== 'visibility') { spec[`layout_${type}`][name].name = name; @@ -34,6 +34,9 @@ const layers = Object.keys(spec.layer.type.values).map((type) => { }; }); +// XXX Remove fill-extrusion layer for now +layers = _(layers).filter(layer => layer.type != "fill-extrusion").value(); + // Process all layer properties const layoutProperties = _(layers).map('layoutProperties').flatten().value(); const paintProperties = _(layers).map('paintProperties').flatten().value(); @@ -212,6 +215,14 @@ global.propertyValueDoc = function (property, value) { return doc; }; +global.supportsZoomFunction = function (property) { + return property['zoom-function'] === true; +}; + +global.supportsPropertyFunction = function (property) { + return property['property-function'] === true; +}; + // Template processing // // Java + JNI Layers (Peer model) diff --git a/platform/android/src/style/conversion/function.hpp b/platform/android/src/style/conversion/function.hpp index ed383b7b56d..20777b2da0b 100644 --- a/platform/android/src/style/conversion/function.hpp +++ b/platform/android/src/style/conversion/function.hpp @@ -4,48 +4,206 @@ #include "../../conversion/conversion.hpp" #include "../../conversion/constant.hpp" #include "types.hpp" -#include "function.hpp" #include #include -#include +#include namespace mbgl { namespace android { namespace conversion { -template -inline jni::jobject* toFunctionStopJavaArray(jni::JNIEnv& env, std::vector> value) { - static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/layers/Function$Stop")).release(); +/** + * Conversion from core composite value to java type + */ +class CategoricalValueEvaluator { +public: + + CategoricalValueEvaluator(jni::JNIEnv& _env) : env(_env) {} + + template + jni::jobject* operator()(const T &value) const { + return *convert(env, value); + } + +private: + jni::JNIEnv& env; +}; + +/** + * Conversion from core composite value to java type + */ +template <> +struct Converter { + + Result operator()(jni::JNIEnv& env, const mbgl::style::CategoricalValue& value) const { + CategoricalValueEvaluator evaluator(env); + return apply_visitor(evaluator, value); + } +}; + +template +inline jni::jobject* toFunctionStopJavaArray(jni::JNIEnv& env, std::map 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, "", "(Ljava/lang/Object;Ljava/lang/Object;)V"); jni::jarray& jarray = jni::NewObjectArray(env, value.size(), *javaClass); - for(size_t i = 0; i < value.size(); i = i + 1) { - jni::jobject* in = *convert(env, value[i].first); - jni::jobject* out = *convert(env, value[i].second); + size_t i = 0; + for (auto const& stop : value) { + jni::jobject* in = *convert(env, stop.first); + jni::jobject* out = *convert(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 StopsEvaluator { +public: + + StopsEvaluator(jni::JNIEnv& _env) : env(_env) {} + + jni::jobject* operator()(const mbgl::style::CategoricalStops &value) const { + static jni::jclass* clazz = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/stops/CategoricalStops")).release(); + static jni::jmethodID* constructor = &jni::GetMethodID(env, *clazz, "", "(Ljava/lang/Object;[Lcom/mapbox/mapboxsdk/style/functions/stops/Stop;)V"); + + return &jni::NewObject(env, *clazz, *constructor, + *convert(env, value.defaultValue), + toFunctionStopJavaArray(env, value.stops)); + } + + jni::jobject* operator()(const mbgl::style::ExponentialStops &value) const { + static jni::jclass* clazz = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/stops/ExponentialStops")).release(); + static jni::jmethodID* constructor = &jni::GetMethodID(env, *clazz, "", "(Ljava/lang/Float;[Lcom/mapbox/mapboxsdk/style/functions/stops/Stop;)V"); + + return &jni::NewObject(env, *clazz, *constructor, + *convert(env, value.base), + toFunctionStopJavaArray(env, value.stops)); + } + + jni::jobject* operator()(const mbgl::style::IdentityStops &) const { + static jni::jclass* clazz = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/stops/IdentityStops")).release(); + static jni::jmethodID* constructor = &jni::GetMethodID(env, *clazz, "", "()V"); + + return &jni::NewObject(env, *clazz, *constructor); + } + + jni::jobject* operator()(const mbgl::style::IntervalStops &value) const { + static jni::jclass* clazz = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/stops/IntervalStops")).release(); + static jni::jmethodID* constructor = &jni::GetMethodID(env, *clazz, "", "([Lcom/mapbox/mapboxsdk/style/functions/stops/Stop;)V"); + + return &jni::NewObject(env, *clazz, *constructor, toFunctionStopJavaArray(env, value.stops)); + } + +private: + jni::JNIEnv& env; +}; + +template +inline jni::jobject* convertCompositeStopsArray(jni::JNIEnv& env, std::map value) { + // Create Java Map + static jni::jclass* mapClass = jni::NewGlobalRef(env, &jni::FindClass(env, "java/util/HashMap")).release(); + static jni::jmethodID* mapConstructor = &jni::GetMethodID(env, *mapClass, "", "()V"); + static jni::jmethodID* mapPutMethod = &jni::GetMethodID(env, *mapClass, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); + jni::jobject& map = jni::NewObject(env, *mapClass, *mapConstructor); + + // Add converted Stops for each zoom value + StopsEvaluator evaluator(env); + for (auto const& entry : value) { + jni::jobject* zoom = *convert(env, entry.first); + jni::jobject* stops = evaluator(entry.second); + jni::CallMethod(env, &map, *mapPutMethod, zoom, stops); + jni::DeleteLocalRef(env, zoom); + jni::DeleteLocalRef(env, stops); + } + + // Create CompositeStops from Java Map + static jni::jclass* compositeStopsClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/functions/stops/CompositeStops")).release(); + static jni::jmethodID* compositeStopsConstructor = &jni::GetMethodID(env, *compositeStopsClass, "", "(Ljava/util/Map;)V"); + jni::jobject& compositeStops = jni::NewObject(env, *compositeStopsClass, *compositeStopsConstructor, &map); + jni::DeleteLocalRef(env, &map); + + return &compositeStops; +} + +/** + * Conversion from core composite function stops to CompositeFunctionStops java type + */ +template +class CompositeStopsEvaluator { +public: + + CompositeStopsEvaluator(jni::JNIEnv& _env) : env(_env) {} + + jni::jobject* operator()(const std::map> &value) const { + return convertCompositeStopsArray, T>(env, value); + } + + jni::jobject* operator()(const std::map> &value) const { + return convertCompositeStopsArray, T>(env, value); + } + + jni::jobject* operator()(const std::map> &value) const { + return convertCompositeStopsArray, T>(env, value); + } + +private: + jni::JNIEnv& env; +}; + +template +struct Converter> { + + Result operator()(jni::JNIEnv& env, const mbgl::style::CameraFunction& 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, "", "(Lcom/mapbox/mapboxsdk/style/functions/stops/Stops;)V"); + + StopsEvaluator evaluator(env); + jni::jobject* stops = apply_visitor(evaluator, value.stops); + jni::jobject* converted = &jni::NewObject(env, *clazz, *constructor, stops); + + return { converted }; + } +}; + +template +struct Converter> { + + Result operator()(jni::JNIEnv& env, const mbgl::style::SourceFunction& 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, "", "(Ljava/lang/String;Lcom/mapbox/mapboxsdk/style/functions/stops/Stops;)V"); + + StopsEvaluator evaluator(env); + jni::jobject* stops = apply_visitor(evaluator, value.stops); + + jni::jobject* converted = &jni::NewObject(env, *clazz, *constructor, jni::Make(env, value.property).Get(), stops); + + return { converted }; + } +}; + template -struct Converter> { +struct Converter> { - Result operator()(jni::JNIEnv& env, const mbgl::style::Function& value) const { - static jni::jclass* javaClass = jni::NewGlobalRef(env, &jni::FindClass(env, "com/mapbox/mapboxsdk/style/layers/Function")).release(); - static jni::jmethodID* constructor = &jni::GetMethodID(env, *javaClass, "", "([Lcom/mapbox/mapboxsdk/style/layers/Function$Stop;)V"); - static jni::jmethodID* withBase = &jni::GetMethodID(env, *javaClass, "withBase", "(F)Lcom/mapbox/mapboxsdk/style/layers/Function;"); + Result operator()(jni::JNIEnv& env, const mbgl::style::CompositeFunction& 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, "", "(Ljava/lang/String;Lcom/mapbox/mapboxsdk/style/functions/stops/CompositeStops;)V"); - // Create object - jni::jobject* jfunction = &jni::NewObject(env, *javaClass, *constructor, *toFunctionStopJavaArray(env, value.getStops())); + CompositeStopsEvaluator evaluator(env); + jni::jobject* stops = apply_visitor(evaluator, value.stops); - // Set base - jni::CallMethod(env, jfunction, *withBase, value.getBase()); + jni::jobject* converted = &jni::NewObject(env, *clazz, *constructor, jni::Make(env, value.property).Get(), stops); - return {jfunction}; + return { converted }; } }; diff --git a/platform/android/src/style/conversion/property_value.hpp b/platform/android/src/style/conversion/property_value.hpp index a89b93794ad..a58cf975a73 100644 --- a/platform/android/src/style/conversion/property_value.hpp +++ b/platform/android/src/style/conversion/property_value.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include "../../conversion/conversion.hpp" #include "../../conversion/constant.hpp" #include "types.hpp" @@ -10,26 +11,62 @@ namespace mbgl { namespace android { namespace conversion { +/** + * Conversion from core property value types to Java property value types + */ +template +class PropertyValueEvaluator { +public: + + PropertyValueEvaluator(jni::JNIEnv& _env) : env(_env) {} + + jni::jobject* operator()(const mbgl::style::Undefined) const { + return nullptr; + } + + jni::jobject* operator()(const T &value) const { + Result result = convert(env, value); + return *result; + } + + jni::jobject* operator()(const mbgl::style::CameraFunction &value) const { + return *convert>(env, value); + } + + jni::jobject* operator()(const mbgl::style::SourceFunction &value) const { + return *convert>(env, value); + } + + jni::jobject* operator()(const mbgl::style::CompositeFunction &value) const { + return *convert>(env, value); + } + +private: + jni::JNIEnv& env; + +}; + +/** + * Convert core property values to java + */ template struct Converter> { Result operator()(jni::JNIEnv& env, const mbgl::style::PropertyValue& value) const { + PropertyValueEvaluator evaluator(env); + return value.evaluate(evaluator); + } +}; - if(value.isUndefined()) { - // Return a nullptr representing a Java null value - return {nullptr}; - } else if (value.isConstant()) { - // Time to convert the constant value - Result result = convert(env, value.asConstant()); - return {*result}; - // return converted; - } else if (value.isFunction()) { - // Must be a function than - return convert>(env, value.asFunction()); - } else { - throw std::runtime_error("Unknown property value type"); - } +/** + * Convert core data driven property values to java + */ +template +struct Converter> { + Result operator()(jni::JNIEnv& env, const mbgl::style::DataDrivenPropertyValue& value) const { + PropertyValueEvaluator evaluator(env); + return value.evaluate(evaluator); } };