summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2016-08-03 16:03:03 -0400
committerIvo van Dongen <info@ivovandongen.nl>2016-08-03 18:34:23 -0400
commit52cb6122f87a6769fad4c4d826b49cd95a37c83b (patch)
tree11d4548c3ee19639d72102b42ffd8d62ed9a6f66
parentf94c97988615071d7b03bacec015d667ee1b4116 (diff)
downloadqtlocation-mapboxgl-52cb6122f87a6769fad4c4d826b49cd95a37c83b.tar.gz
[android] #5858 - added convenience methods for color properties
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/ConversionException.java22
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java31
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java54
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java67
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java68
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java31
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java175
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs44
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java21
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java23
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java27
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/BackgroundLayerTest.java17
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/CircleLayerTest.java23
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/FillLayerTest.java45
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/LineLayerTest.java23
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/RasterLayerTest.java1
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/SymbolLayerTest.java89
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/layer.junit.ejs30
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.java7
19 files changed, 718 insertions, 80 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/ConversionException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/ConversionException.java
new file mode 100644
index 0000000000..87656db2a9
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/ConversionException.java
@@ -0,0 +1,22 @@
+package com.mapbox.mapboxsdk.exceptions;
+
+/**
+ * Thrown on conversion errors
+ */
+public class ConversionException extends RuntimeException {
+
+ public ConversionException() {
+ }
+
+ public ConversionException(String detailMessage) {
+ super(detailMessage);
+ }
+
+ public ConversionException(String detailMessage, Throwable throwable) {
+ super(detailMessage, throwable);
+ }
+
+ public ConversionException(Throwable throwable) {
+ super(throwable);
+ }
+}
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 f7a71155ad..fae68c518e 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,13 @@
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`.
package com.mapbox.mapboxsdk.style.layers;
+import com.mapbox.mapboxsdk.exceptions.ConversionException;
+
+import android.support.annotation.ColorInt;
+import android.support.annotation.NonNull;
+
+import static com.mapbox.mapboxsdk.utils.ColorUtils.*;
+
/**
* Background Layer
*/
@@ -17,6 +24,11 @@ public class BackgroundLayer extends Layer {
protected native void initialize(String layerId);
+ public BackgroundLayer withProperties(@NonNull Property<?>... properties) {
+ setProperties(properties);
+ return this;
+ }
+
// Property getters
@SuppressWarnings("unchecked")
@@ -24,19 +36,34 @@ public class BackgroundLayer extends Layer {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetBackgroundColor());
}
+ /**
+ * The color with which the background will be drawn.
+ * @throws RuntimeException
+ */
+ @ColorInt
+ public int getBackgroundColorAsInt() {
+ checkValidity();
+ PropertyValue<String> value = getBackgroundColor();
+ if (value.isValue()) {
+ return rgbaToColor(value.getValue());
+ } else {
+ throw new RuntimeException("background-color was set as a Function");
+ }
+ }
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getBackgroundPattern() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetBackgroundPattern());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getBackgroundOpacity() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetBackgroundOpacity());
}
-
+
private native Object nativeGetBackgroundColor();
private native Object nativeGetBackgroundPattern();
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 6628fee47a..ce0e9fd5bd 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,13 @@
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`.
package com.mapbox.mapboxsdk.style.layers;
+import com.mapbox.mapboxsdk.exceptions.ConversionException;
+
+import android.support.annotation.ColorInt;
+import android.support.annotation.NonNull;
+
+import static com.mapbox.mapboxsdk.utils.ColorUtils.*;
+
/**
* Circle Layer
*/
@@ -21,6 +28,11 @@ public class CircleLayer extends Layer {
nativeSetSourceLayer(sourceLayer);
}
+ public CircleLayer withSourceLayer(String sourceLayer) {
+ setSourceLayer(sourceLayer);
+ return this;
+ }
+
public void setFilter(Filter.Statement filter) {
checkValidity();
this.setFilter(filter.toArray());
@@ -31,6 +43,21 @@ public class CircleLayer extends Layer {
nativeSetFilter(filter);
}
+ public CircleLayer withFilter(Object[] filter) {
+ setFilter(filter);
+ return this;
+ }
+
+ public CircleLayer withFilter(Filter.Statement filter) {
+ setFilter(filter);
+ return this;
+ }
+
+
+ public CircleLayer withProperties(@NonNull Property<?>... properties) {
+ setProperties(properties);
+ return this;
+ }
// Property getters
@@ -39,43 +66,58 @@ public class CircleLayer extends Layer {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetCircleRadius());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getCircleColor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetCircleColor());
}
+ /**
+ * The color of the circle.
+ * @throws RuntimeException
+ */
+ @ColorInt
+ public int getCircleColorAsInt() {
+ checkValidity();
+ PropertyValue<String> value = getCircleColor();
+ if (value.isValue()) {
+ return rgbaToColor(value.getValue());
+ } else {
+ throw new RuntimeException("circle-color was set as a Function");
+ }
+ }
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getCircleBlur() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetCircleBlur());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getCircleOpacity() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetCircleOpacity());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getCircleTranslate() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetCircleTranslate());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getCircleTranslateAnchor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetCircleTranslateAnchor());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getCirclePitchScale() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetCirclePitchScale());
}
-
+
private native Object nativeGetCircleRadius();
private native Object nativeGetCircleColor();
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 7938af3c80..d188129e2a 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,13 @@
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`.
package com.mapbox.mapboxsdk.style.layers;
+import com.mapbox.mapboxsdk.exceptions.ConversionException;
+
+import android.support.annotation.ColorInt;
+import android.support.annotation.NonNull;
+
+import static com.mapbox.mapboxsdk.utils.ColorUtils.*;
+
/**
* Fill Layer
*/
@@ -21,6 +28,11 @@ public class FillLayer extends Layer {
nativeSetSourceLayer(sourceLayer);
}
+ public FillLayer withSourceLayer(String sourceLayer) {
+ setSourceLayer(sourceLayer);
+ return this;
+ }
+
public void setFilter(Filter.Statement filter) {
checkValidity();
this.setFilter(filter.toArray());
@@ -31,6 +43,21 @@ public class FillLayer extends Layer {
nativeSetFilter(filter);
}
+ public FillLayer withFilter(Object[] filter) {
+ setFilter(filter);
+ return this;
+ }
+
+ public FillLayer withFilter(Filter.Statement filter) {
+ setFilter(filter);
+ return this;
+ }
+
+
+ public FillLayer withProperties(@NonNull Property<?>... properties) {
+ setProperties(properties);
+ return this;
+ }
// Property getters
@@ -39,43 +66,73 @@ public class FillLayer extends Layer {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetFillAntialias());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getFillOpacity() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetFillOpacity());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getFillColor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(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.
+ * @throws RuntimeException
+ */
+ @ColorInt
+ public int getFillColorAsInt() {
+ checkValidity();
+ PropertyValue<String> value = getFillColor();
+ if (value.isValue()) {
+ return rgbaToColor(value.getValue());
+ } else {
+ throw new RuntimeException("fill-color was set as a Function");
+ }
+ }
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getFillOutlineColor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetFillOutlineColor());
}
+ /**
+ * The outline color of the fill. Matches the value of `fill-color` if unspecified.
+ * @throws RuntimeException
+ */
+ @ColorInt
+ public int getFillOutlineColorAsInt() {
+ checkValidity();
+ PropertyValue<String> value = getFillOutlineColor();
+ if (value.isValue()) {
+ return rgbaToColor(value.getValue());
+ } else {
+ throw new RuntimeException("fill-outline-color was set as a Function");
+ }
+ }
+
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getFillTranslate() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetFillTranslate());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getFillTranslateAnchor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetFillTranslateAnchor());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getFillPattern() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetFillPattern());
}
-
+
private native Object nativeGetFillAntialias();
private native Object nativeGetFillOpacity();
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 11cd709f49..ab5dd0815e 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,13 @@
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`.
package com.mapbox.mapboxsdk.style.layers;
+import com.mapbox.mapboxsdk.exceptions.ConversionException;
+
+import android.support.annotation.ColorInt;
+import android.support.annotation.NonNull;
+
+import static com.mapbox.mapboxsdk.utils.ColorUtils.*;
+
/**
* Line Layer
*/
@@ -21,6 +28,11 @@ public class LineLayer extends Layer {
nativeSetSourceLayer(sourceLayer);
}
+ public LineLayer withSourceLayer(String sourceLayer) {
+ setSourceLayer(sourceLayer);
+ return this;
+ }
+
public void setFilter(Filter.Statement filter) {
checkValidity();
this.setFilter(filter.toArray());
@@ -31,6 +43,21 @@ public class LineLayer extends Layer {
nativeSetFilter(filter);
}
+ public LineLayer withFilter(Object[] filter) {
+ setFilter(filter);
+ return this;
+ }
+
+ public LineLayer withFilter(Filter.Statement filter) {
+ setFilter(filter);
+ return this;
+ }
+
+
+ public LineLayer withProperties(@NonNull Property<?>... properties) {
+ setProperties(properties);
+ return this;
+ }
// Property getters
@@ -39,85 +66,100 @@ public class LineLayer extends Layer {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetLineCap());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getLineJoin() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetLineJoin());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineMiterLimit() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetLineMiterLimit());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineRoundLimit() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetLineRoundLimit());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineOpacity() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetLineOpacity());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getLineColor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetLineColor());
}
+ /**
+ * The color with which the line will be drawn.
+ * @throws RuntimeException
+ */
+ @ColorInt
+ public int getLineColorAsInt() {
+ checkValidity();
+ PropertyValue<String> value = getLineColor();
+ if (value.isValue()) {
+ return rgbaToColor(value.getValue());
+ } else {
+ throw new RuntimeException("line-color was set as a Function");
+ }
+ }
+
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getLineTranslate() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetLineTranslate());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getLineTranslateAnchor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetLineTranslateAnchor());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineWidth() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetLineWidth());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineGapWidth() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetLineGapWidth());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineOffset() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetLineOffset());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineBlur() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetLineBlur());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getLineDasharray() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetLineDasharray());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getLinePattern() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetLinePattern());
}
-
+
private native Object nativeGetLineCap();
private native Object nativeGetLineJoin();
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 1cbe5fb387..a6872cef0f 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,6 +1,13 @@
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`.
package com.mapbox.mapboxsdk.style.layers;
+import com.mapbox.mapboxsdk.exceptions.ConversionException;
+
+import android.support.annotation.ColorInt;
+import android.support.annotation.NonNull;
+
+import static com.mapbox.mapboxsdk.utils.ColorUtils.*;
+
/**
* Raster Layer
*/
@@ -21,6 +28,16 @@ public class RasterLayer extends Layer {
nativeSetSourceLayer(sourceLayer);
}
+ public RasterLayer withSourceLayer(String sourceLayer) {
+ setSourceLayer(sourceLayer);
+ return this;
+ }
+
+
+ public RasterLayer withProperties(@NonNull Property<?>... properties) {
+ setProperties(properties);
+ return this;
+ }
// Property getters
@@ -29,43 +46,43 @@ public class RasterLayer extends Layer {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetRasterOpacity());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getRasterHueRotate() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetRasterHueRotate());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getRasterBrightnessMin() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetRasterBrightnessMin());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getRasterBrightnessMax() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetRasterBrightnessMax());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getRasterSaturation() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetRasterSaturation());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getRasterContrast() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetRasterContrast());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getRasterFadeDuration() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetRasterFadeDuration());
}
-
+
private native Object nativeGetRasterOpacity();
private native Object nativeGetRasterHueRotate();
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 281b4fc028..ccbfdb411f 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,13 @@
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`.
package com.mapbox.mapboxsdk.style.layers;
+import com.mapbox.mapboxsdk.exceptions.ConversionException;
+
+import android.support.annotation.ColorInt;
+import android.support.annotation.NonNull;
+
+import static com.mapbox.mapboxsdk.utils.ColorUtils.*;
+
/**
* Symbol Layer
*/
@@ -21,6 +28,11 @@ public class SymbolLayer extends Layer {
nativeSetSourceLayer(sourceLayer);
}
+ public SymbolLayer withSourceLayer(String sourceLayer) {
+ setSourceLayer(sourceLayer);
+ return this;
+ }
+
public void setFilter(Filter.Statement filter) {
checkValidity();
this.setFilter(filter.toArray());
@@ -31,6 +43,21 @@ public class SymbolLayer extends Layer {
nativeSetFilter(filter);
}
+ public SymbolLayer withFilter(Object[] filter) {
+ setFilter(filter);
+ return this;
+ }
+
+ public SymbolLayer withFilter(Filter.Statement filter) {
+ setFilter(filter);
+ return this;
+ }
+
+
+ public SymbolLayer withProperties(@NonNull Property<?>... properties) {
+ setProperties(properties);
+ return this;
+ }
// Property getters
@@ -39,289 +66,349 @@ public class SymbolLayer extends Layer {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetSymbolPlacement());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getSymbolSpacing() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetSymbolSpacing());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getSymbolAvoidEdges() {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetSymbolAvoidEdges());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getIconAllowOverlap() {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetIconAllowOverlap());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getIconIgnorePlacement() {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetIconIgnorePlacement());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getIconOptional() {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetIconOptional());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconRotationAlignment() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetIconRotationAlignment());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getIconSize() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetIconSize());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconTextFit() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetIconTextFit());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getIconTextFitPadding() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetIconTextFitPadding());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconImage() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetIconImage());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getIconRotate() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetIconRotate());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getIconPadding() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetIconPadding());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getIconKeepUpright() {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetIconKeepUpright());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getIconOffset() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetIconOffset());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextPitchAlignment() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetTextPitchAlignment());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextRotationAlignment() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetTextRotationAlignment());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextField() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetTextField());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String[]> getTextFont() {
checkValidity();
return (PropertyValue<String[]>) new PropertyValue(nativeGetTextFont());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextSize() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextSize());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextMaxWidth() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextMaxWidth());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextLineHeight() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextLineHeight());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextLetterSpacing() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextLetterSpacing());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextJustify() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetTextJustify());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextAnchor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetTextAnchor());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextMaxAngle() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextMaxAngle());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextRotate() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextRotate());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextPadding() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextPadding());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getTextKeepUpright() {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetTextKeepUpright());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextTransform() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetTextTransform());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getTextOffset() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetTextOffset());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getTextAllowOverlap() {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetTextAllowOverlap());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getTextIgnorePlacement() {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetTextIgnorePlacement());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getTextOptional() {
checkValidity();
return (PropertyValue<Boolean>) new PropertyValue(nativeGetTextOptional());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getIconOpacity() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetIconOpacity());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconColor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetIconColor());
}
+ /**
+ * The color of the icon. This can only be used with sdf icons.
+ * @throws RuntimeException
+ */
+ @ColorInt
+ public int getIconColorAsInt() {
+ checkValidity();
+ PropertyValue<String> value = getIconColor();
+ if (value.isValue()) {
+ return rgbaToColor(value.getValue());
+ } else {
+ throw new RuntimeException("icon-color was set as a Function");
+ }
+ }
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconHaloColor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetIconHaloColor());
}
+ /**
+ * The color of the icon's halo. Icon halos can only be used with sdf icons.
+ * @throws RuntimeException
+ */
+ @ColorInt
+ public int getIconHaloColorAsInt() {
+ checkValidity();
+ PropertyValue<String> value = getIconHaloColor();
+ if (value.isValue()) {
+ return rgbaToColor(value.getValue());
+ } else {
+ throw new RuntimeException("icon-halo-color was set as a Function");
+ }
+ }
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getIconHaloWidth() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetIconHaloWidth());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getIconHaloBlur() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetIconHaloBlur());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getIconTranslate() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetIconTranslate());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconTranslateAnchor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetIconTranslateAnchor());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextOpacity() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextOpacity());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextColor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetTextColor());
}
+ /**
+ * The color with which the text will be drawn.
+ * @throws RuntimeException
+ */
+ @ColorInt
+ public int getTextColorAsInt() {
+ checkValidity();
+ PropertyValue<String> value = getTextColor();
+ if (value.isValue()) {
+ return rgbaToColor(value.getValue());
+ } else {
+ throw new RuntimeException("text-color was set as a Function");
+ }
+ }
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextHaloColor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetTextHaloColor());
}
+ /**
+ * The color of the text's halo, which helps it stand out from backgrounds.
+ * @throws RuntimeException
+ */
+ @ColorInt
+ public int getTextHaloColorAsInt() {
+ checkValidity();
+ PropertyValue<String> value = getTextHaloColor();
+ if (value.isValue()) {
+ return rgbaToColor(value.getValue());
+ } else {
+ throw new RuntimeException("text-halo-color was set as a Function");
+ }
+ }
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextHaloWidth() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextHaloWidth());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextHaloBlur() {
checkValidity();
return (PropertyValue<Float>) new PropertyValue(nativeGetTextHaloBlur());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getTextTranslate() {
checkValidity();
return (PropertyValue<Float[]>) new PropertyValue(nativeGetTextTranslate());
}
-
+
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextTranslateAnchor() {
checkValidity();
return (PropertyValue<String>) new PropertyValue(nativeGetTextTranslateAnchor());
}
-
+
private native Object nativeGetSymbolPlacement();
private native Object nativeGetSymbolSpacing();
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 79bf98d389..00d9f09124 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
@@ -5,6 +5,13 @@
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`.
package com.mapbox.mapboxsdk.style.layers;
+import com.mapbox.mapboxsdk.exceptions.ConversionException;
+
+import android.support.annotation.ColorInt;
+import android.support.annotation.NonNull;
+
+import static com.mapbox.mapboxsdk.utils.ColorUtils.*;
+
/**
* <%- camelize(type) %> Layer
*/
@@ -31,6 +38,11 @@ public class <%- camelize(type) %>Layer extends Layer {
checkValidity();
nativeSetSourceLayer(sourceLayer);
}
+
+ public <%- camelize(type) %>Layer withSourceLayer(String sourceLayer) {
+ setSourceLayer(sourceLayer);
+ return this;
+ }
<% } -%>
<% if (type !== 'background' && type !== 'raster') { -%>
@@ -44,8 +56,23 @@ public class <%- camelize(type) %>Layer extends Layer {
nativeSetFilter(filter);
}
+ public <%- camelize(type) %>Layer withFilter(Object[] filter) {
+ setFilter(filter);
+ return this;
+ }
+
+ public <%- camelize(type) %>Layer withFilter(Filter.Statement filter) {
+ setFilter(filter);
+ return this;
+ }
+
<% } -%>
+ public <%- camelize(type) %>Layer withProperties(@NonNull Property<?>... properties) {
+ setProperties(properties);
+ return this;
+ }
+
// Property getters
<% for (const property of properties) { -%>
@@ -54,6 +81,23 @@ public class <%- camelize(type) %>Layer extends Layer {
checkValidity();
return (PropertyValue<<%- propertyType(property) %>>) new PropertyValue(nativeGet<%- camelize(property.name) %>());
}
+ <% if (property.type == 'color') { -%>
+ /**
+ * <%- property.doc %>
+ * @throws RuntimeException
+ */
+ @ColorInt
+ public int get<%- camelize(property.name) %>AsInt() {
+ checkValidity();
+ 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) { -%>
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java
index f1399daf12..fc7928015e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java
@@ -3,12 +3,27 @@ package com.mapbox.mapboxsdk.style.sources;
import java.net.URL;
import java.util.HashMap;
+/**
+ * A GeoJson source.
+ *
+ * @see <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources-geojson">the style specification</a>
+ */
public class GeoJsonSource extends Source {
public static final String TYPE = "geojson";
private static final String DATA_KEY = "data";
+ /**
+ * Create a GeoJsonSource from a raw json string
+ *
+ * @param id the source id
+ * @param geoJson raw Json body
+ */
public GeoJsonSource(String id, String geoJson) {
super(id, TYPE);
+ if (geoJson == null || geoJson.startsWith("http")) {
+ throw new IllegalArgumentException("Expected a raw json body");
+ }
+
//Wrap the String in a map as an Object is expected by the
//style conversion template
HashMap<String, String> wrapper = new HashMap<>();
@@ -16,6 +31,12 @@ public class GeoJsonSource extends Source {
this.put(DATA_KEY, wrapper);
}
+ /**
+ * Create a GeoJsonSource from a remote geo json file
+ *
+ * @param id the source id
+ * @param url remote json file
+ */
public GeoJsonSource(String id, URL url) {
super(id, TYPE);
this.put(DATA_KEY, url.toExternalForm());
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java
index df3b73368c..381294083a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java
@@ -2,19 +2,42 @@ package com.mapbox.mapboxsdk.style.sources;
import java.net.URL;
+/**
+ * A vector source.
+ *
+ * @see <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources-vector">the style specification</a>
+ */
public class VectorSource extends Source {
public static final String TYPE = "vector";
private static final String URL_KEY = "url";
+ /**
+ * Create a vector source from a remote url
+ *
+ * @param id the source id
+ * @param url the url
+ */
public VectorSource(String id, URL url) {
this(id, url.toExternalForm());
}
+ /**
+ * Create a vector source from a remote url
+ *
+ * @param id the source id
+ * @param url the url
+ */
public VectorSource(String id, String url) {
super(id, TYPE);
this.put(URL_KEY, url);
}
+ /**
+ * Create a vector source from a tilset
+ *
+ * @param id the source id
+ * @param tileSet the tileset
+ */
public VectorSource(String id, TileSet tileSet) {
super(id, TYPE);
this.putAll(tileSet.toValueObject());
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java
index a0de07c5f1..ef404840e8 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java
@@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.utils;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
+import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
@@ -11,6 +12,10 @@ import android.util.TypedValue;
import android.widget.ImageView;
import com.mapbox.mapboxsdk.R;
+import com.mapbox.mapboxsdk.exceptions.ConversionException;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class ColorUtils {
@@ -87,4 +92,26 @@ public class ColorUtils {
Drawable wrappedDrawable = DrawableCompat.wrap(originalDrawable);
DrawableCompat.setTintList(wrappedDrawable, getSelector(tintColor));
}
+
+ static int normalizeColorComponent(String value) {
+ return (int) (Float.parseFloat(value) * 255);
+ }
+
+ /**
+ * Convert an rgba string to a Color int
+ *
+ * @throws ConversionException on illegal input
+ */
+ @ColorInt
+ public static int rgbaToColor(String value) {
+ Pattern c = Pattern.compile("rgba?\\s*\\(\\s*(\\d+\\.?\\d*)\\s*,\\s*(\\d+\\.?\\d*)\\s*,\\s*(\\d+\\.?\\d*)\\s*,?\\s*(\\d+\\.?\\d*)?\\s*\\)");
+ Matcher m = c.matcher(value);
+ if (m.matches() && m.groupCount() == 3) {
+ return Color.rgb(normalizeColorComponent(m.group(1)), normalizeColorComponent(m.group(2)), normalizeColorComponent(m.group(3)));
+ } else if (m.matches() && m.groupCount() == 4) {
+ return Color.argb(normalizeColorComponent(m.group(4)), normalizeColorComponent(m.group(1)), normalizeColorComponent(m.group(2)), normalizeColorComponent(m.group(3)));
+ } else {
+ throw new ConversionException("Not a valid rgb/rgba value");
+ }
+ }
} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/BackgroundLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/BackgroundLayerTest.java
index 1880d46ef3..009e07b00e 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/BackgroundLayerTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/BackgroundLayerTest.java
@@ -1,6 +1,7 @@
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`.
package com.mapbox.mapboxsdk.style;
+import android.graphics.Color;
import android.support.test.espresso.Espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
@@ -86,6 +87,22 @@ public class BackgroundLayerTest extends BaseTest {
}
@Test
+ public void testBackgroundColorAsInt() {
+ checkViewIsDisplayed(R.id.mapView);
+
+ mapboxMap = rule.getActivity().getMapboxMap();
+
+ Log.i(TAG, "Retrieving layer");
+ layer = mapboxMap.getLayerAs("background");
+ Log.i(TAG, "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);
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/CircleLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/CircleLayerTest.java
index 174c218a74..51d0cd94b1 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/CircleLayerTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/CircleLayerTest.java
@@ -1,6 +1,7 @@
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`.
package com.mapbox.mapboxsdk.style;
+import android.graphics.Color;
import android.support.test.espresso.Espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
@@ -115,6 +116,28 @@ public class CircleLayerTest extends BaseTest {
}
@Test
+ public void testCircleColorAsInt() {
+ checkViewIsDisplayed(R.id.mapView);
+
+ mapboxMap = rule.getActivity().getMapboxMap();
+
+ if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
+ Log.i(TAG, "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");
+ }
+ Log.i(TAG, "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);
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/FillLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/FillLayerTest.java
index 592eaa6c98..0773e28ae9 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/FillLayerTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/FillLayerTest.java
@@ -1,6 +1,7 @@
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`.
package com.mapbox.mapboxsdk.style;
+import android.graphics.Color;
import android.support.test.espresso.Espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
@@ -147,6 +148,28 @@ public class FillLayerTest extends BaseTest {
}
@Test
+ public void testFillColorAsInt() {
+ checkViewIsDisplayed(R.id.mapView);
+
+ mapboxMap = rule.getActivity().getMapboxMap();
+
+ if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
+ Log.i(TAG, "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");
+ }
+ Log.i(TAG, "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);
@@ -169,6 +192,28 @@ public class FillLayerTest extends BaseTest {
}
@Test
+ public void testFillOutlineColorAsInt() {
+ checkViewIsDisplayed(R.id.mapView);
+
+ mapboxMap = rule.getActivity().getMapboxMap();
+
+ if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
+ Log.i(TAG, "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");
+ }
+ Log.i(TAG, "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);
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/LineLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/LineLayerTest.java
index f4e0a1d929..5fee78bc63 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/LineLayerTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/LineLayerTest.java
@@ -1,6 +1,7 @@
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`.
package com.mapbox.mapboxsdk.style;
+import android.graphics.Color;
import android.support.test.espresso.Espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
@@ -222,6 +223,28 @@ public class LineLayerTest extends BaseTest {
}
@Test
+ public void testLineColorAsInt() {
+ checkViewIsDisplayed(R.id.mapView);
+
+ mapboxMap = rule.getActivity().getMapboxMap();
+
+ if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
+ Log.i(TAG, "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");
+ }
+ Log.i(TAG, "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);
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/RasterLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/RasterLayerTest.java
index 48d6d355f5..a40127148b 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/RasterLayerTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/RasterLayerTest.java
@@ -1,6 +1,7 @@
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`.
package com.mapbox.mapboxsdk.style;
+import android.graphics.Color;
import android.support.test.espresso.Espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/SymbolLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/SymbolLayerTest.java
index ef067c6ad9..3b860866a5 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/SymbolLayerTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/SymbolLayerTest.java
@@ -1,6 +1,7 @@
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`.
package com.mapbox.mapboxsdk.style;
+import android.graphics.Color;
import android.support.test.espresso.Espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
@@ -923,6 +924,28 @@ public class SymbolLayerTest extends BaseTest {
}
@Test
+ public void testIconColorAsInt() {
+ checkViewIsDisplayed(R.id.mapView);
+
+ mapboxMap = rule.getActivity().getMapboxMap();
+
+ if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
+ Log.i(TAG, "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");
+ }
+ Log.i(TAG, "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);
@@ -945,6 +968,28 @@ public class SymbolLayerTest extends BaseTest {
}
@Test
+ public void testIconHaloColorAsInt() {
+ checkViewIsDisplayed(R.id.mapView);
+
+ mapboxMap = rule.getActivity().getMapboxMap();
+
+ if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
+ Log.i(TAG, "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");
+ }
+ Log.i(TAG, "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);
@@ -1077,6 +1122,28 @@ public class SymbolLayerTest extends BaseTest {
}
@Test
+ public void testTextColorAsInt() {
+ checkViewIsDisplayed(R.id.mapView);
+
+ mapboxMap = rule.getActivity().getMapboxMap();
+
+ if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
+ Log.i(TAG, "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");
+ }
+ Log.i(TAG, "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);
@@ -1099,6 +1166,28 @@ public class SymbolLayerTest extends BaseTest {
}
@Test
+ public void testTextHaloColorAsInt() {
+ checkViewIsDisplayed(R.id.mapView);
+
+ mapboxMap = rule.getActivity().getMapboxMap();
+
+ if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
+ Log.i(TAG, "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");
+ }
+ Log.i(TAG, "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);
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/layer.junit.ejs b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/layer.junit.ejs
index 21106f3a33..115a27832b 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/layer.junit.ejs
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/layer.junit.ejs
@@ -5,6 +5,7 @@
// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make style-code-android`.
package com.mapbox.mapboxsdk.style;
+import android.graphics.Color;
import android.support.test.espresso.Espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
@@ -106,6 +107,35 @@ public class <%- camelize(type) %>LayerTest extends BaseTest {
layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(<%- defaultValueJava(property) %>));
assertEquals((<%- propertyType(property) %>) layer.get<%- camelize(property.name) %>().getValue(), (<%- propertyType(property) %>) <%- defaultValueJava(property) %>);
}
+<% if (property.type == 'color') { -%>
+
+ @Test
+ public void test<%- camelize(property.name) %>AsInt() {
+ checkViewIsDisplayed(R.id.mapView);
+
+ mapboxMap = rule.getActivity().getMapboxMap();
+
+<% if (type === 'background') { -%>
+ Log.i(TAG, "Retrieving layer");
+ layer = mapboxMap.getLayerAs("background");
+<% } else { -%>
+ if ((layer = mapboxMap.getLayerAs("my-layer")) == null) {
+ Log.i(TAG, "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");
+ }
+<% } -%>
+ Log.i(TAG, "<%- property.name %>");
+ assertNotNull(layer);
+
+ //Set and Get
+ layer.setProperties(<%- camelizeWithLeadingLowercase(property.name) %>(Color.RED));
+ assertEquals(layer.get<%- camelize(property.name) %>AsInt(), Color.RED);
+ }
+<% } -%>
<% } -%>
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 b104f9ea03..4e0f5f8c41 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
@@ -345,9 +345,10 @@ public class RuntimeStyleActivity extends AppCompatActivity {
mapboxMap.addSource(source);
//Add a layer
- FillLayer layer = new FillLayer("custom-tile-layers", "custom-tile-source");
- layer.setSourceLayer("water");
- mapboxMap.addLayer(layer);
+ mapboxMap.addLayer(
+ new FillLayer("custom-tile-layers", "custom-tile-source")
+ .withSourceLayer("water")
+ );
}
private static class DefaultCallback implements MapboxMap.CancelableCallback {