summaryrefslogtreecommitdiff
path: root/platform/android
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2018-08-08 15:09:27 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2018-08-23 19:01:40 +0300
commitfb5afd34b9b25e993a4b109385215eba0b83923f (patch)
tree61474b72e7d099808eb85ea60275e58da11bdd39 /platform/android
parent52275f835a38897ebf1aeb2158ccfca2272e4770 (diff)
downloadqtlocation-mapboxgl-fb5afd34b9b25e993a4b109385215eba0b83923f.tar.gz
[core] Add `line-gradient` property
Porting of https://github.com/mapbox/mapbox-gl-js/pull/6303 See the link above for the description of the feature and its limitations). Based on patch from @lbud (Lauren Budorick).
Diffstat (limited to 'platform/android')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java31
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java30
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/layer.junit.ejs2
-rw-r--r--platform/android/src/style/layers/line_layer.cpp9
-rw-r--r--platform/android/src/style/layers/line_layer.hpp2
5 files changed, 72 insertions, 2 deletions
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 d6519c991f..9130bfd76f 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
@@ -478,6 +478,34 @@ public class LineLayer extends Layer {
nativeSetLinePatternTransition(options.getDuration(), options.getDelay());
}
+ /**
+ * Get the LineGradient property
+ *
+ * @return property wrapper value around String
+ */
+ @SuppressWarnings("unchecked")
+ public PropertyValue<String> getLineGradient() {
+ checkThread();
+ return (PropertyValue<String>) new PropertyValue("line-gradient", nativeGetLineGradient());
+ }
+
+ /**
+ * Defines a gradient with which to color a line feature. Can only be used with GeoJSON sources that specify `"lineMetrics": true`.
+ *
+ * @return int representation of a rgba string color
+ * @throws RuntimeException thrown if property isn't a value
+ */
+ @ColorInt
+ public int getLineGradientAsInt() {
+ checkThread();
+ PropertyValue<String> value = getLineGradient();
+ if (value.isValue()) {
+ return rgbaToColor(value.getValue());
+ } else {
+ throw new RuntimeException("line-gradient was set as a Function");
+ }
+ }
+
@Keep
private native Object nativeGetLineCap();
@@ -574,6 +602,9 @@ public class LineLayer extends Layer {
@Keep
private native void nativeSetLinePatternTransition(long duration, long delay);
+ @Keep
+ private native Object nativeGetLineGradient();
+
@Override
@Keep
protected native void finalize() throws Throwable;
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 cd7bd473f3..c619d0141a 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
@@ -395,6 +395,36 @@ public class PropertyFactory {
}
/**
+ * Defines a gradient with which to color a line feature. Can only be used with GeoJSON sources that specify `"lineMetrics": true`.
+ *
+ * @param value a int color value
+ * @return property wrapper around String color
+ */
+ public static PropertyValue<String> lineGradient(@ColorInt int value) {
+ return new PaintPropertyValue<>("line-gradient", colorToRgbaString(value));
+ }
+
+ /**
+ * Defines a gradient with which to color a line feature. Can only be used with GeoJSON sources that specify `"lineMetrics": true`.
+ *
+ * @param value a String value
+ * @return property wrapper around String
+ */
+ public static PropertyValue<String> lineGradient(String value) {
+ return new PaintPropertyValue<>("line-gradient", value);
+ }
+
+ /**
+ * Defines a gradient with which to color a line feature. Can only be used with GeoJSON sources that specify `"lineMetrics": true`.
+ *
+ * @param expression an expression statement
+ * @return property wrapper around an expression statement
+ */
+ public static PropertyValue<Expression> lineGradient(Expression expression) {
+ return new PaintPropertyValue<>("line-gradient", expression);
+ }
+
+ /**
* The opacity at which the icon will be drawn.
*
* @param value a Float value
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 8acfc88dfa..a319d52ea3 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
@@ -118,7 +118,7 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest {
<% } -%>
<% for (const property of properties) { -%>
-<% if (property.name != 'heatmap-color') { -%>
+<% if (property['property-type'] !== 'color-ramp') { -%>
<% if (property.transition) { -%>
@Test
diff --git a/platform/android/src/style/layers/line_layer.cpp b/platform/android/src/style/layers/line_layer.cpp
index af4e24523e..f143ecc236 100644
--- a/platform/android/src/style/layers/line_layer.cpp
+++ b/platform/android/src/style/layers/line_layer.cpp
@@ -236,6 +236,12 @@ namespace android {
layer.as<mbgl::style::LineLayer>()->LineLayer::setLinePatternTransition(options);
}
+ jni::Object<jni::ObjectTag> LineLayer::getLineGradient(jni::JNIEnv& env) {
+ using namespace mbgl::android::conversion;
+ Result<jni::jobject*> converted = convert<jni::jobject*>(env, layer.as<mbgl::style::LineLayer>()->LineLayer::getLineGradient());
+ return jni::Object<jni::ObjectTag>(*converted);
+ }
+
jni::Class<LineLayer> LineLayer::javaClass;
@@ -287,7 +293,8 @@ namespace android {
METHOD(&LineLayer::getLineDasharray, "nativeGetLineDasharray"),
METHOD(&LineLayer::getLinePatternTransition, "nativeGetLinePatternTransition"),
METHOD(&LineLayer::setLinePatternTransition, "nativeSetLinePatternTransition"),
- METHOD(&LineLayer::getLinePattern, "nativeGetLinePattern"));
+ METHOD(&LineLayer::getLinePattern, "nativeGetLinePattern"),
+ METHOD(&LineLayer::getLineGradient, "nativeGetLineGradient"));
}
} // namespace android
diff --git a/platform/android/src/style/layers/line_layer.hpp b/platform/android/src/style/layers/line_layer.hpp
index 84ecc77139..9eef1349cb 100644
--- a/platform/android/src/style/layers/line_layer.hpp
+++ b/platform/android/src/style/layers/line_layer.hpp
@@ -74,6 +74,8 @@ public:
jni::Object<jni::ObjectTag> getLinePattern(jni::JNIEnv&);
void setLinePatternTransition(jni::JNIEnv&, jlong duration, jlong delay);
jni::Object<TransitionOptions> getLinePatternTransition(jni::JNIEnv&);
+
+ jni::Object<jni::ObjectTag> getLineGradient(jni::JNIEnv&);
jni::jobject* createJavaPeer(jni::JNIEnv&);
}; // class LineLayer