diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style')
2 files changed, 48 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java index 0f5ce76725..d6cddea066 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java @@ -1436,6 +1436,27 @@ public class Expression { } /** + * Gets the value of a cluster property accumulated so far. Can only be used in the clusterProperties + * option of a clustered GeoJSON source. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * GeoJsonOptions options = new GeoJsonOptions() + * .withCluster(true) + * .withClusterProperty("max", max(accumulated(), get("max")).toArray(), get("mag").toArray()); + * } + * </pre> + * + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-accumulated">Style specification</a> + */ + public static Expression accumulated() { + return new Expression("accumulated"); + } + + /** * Gets the kernel density estimation of a pixel in a heatmap layer, * which is a relative measure of how many data points are crowded around a particular pixel. * Can only be used in the `heatmap-color` property. diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonOptions.java index 1e1b9bafa6..091079ab92 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonOptions.java @@ -1,9 +1,12 @@ package com.mapbox.mapboxsdk.style.sources; import android.support.annotation.NonNull; +import com.mapbox.mapboxsdk.style.expressions.Expression; import java.util.HashMap; +import static com.mapbox.mapboxsdk.style.expressions.Expression.ExpressionLiteral; + /** * Builder class for composing GeoJsonSource objects. * @@ -109,4 +112,28 @@ public class GeoJsonOptions extends HashMap<String, Object> { this.put("clusterRadius", clusterRadius); return this; } + + /** + * An object defining custom properties on the generated clusters if clustering is enabled, + * aggregating values from clustered points. Has the form {"property_name": [operator, [map_expression]]} or + * {"property_name": [[operator, accumulated, expression], [map_expression]]} + * + * @param propertyName name of the property + * @param operatorExpr operatorExpr is any expression function that accepts at least 2 operands (e.g. "+" or "max"). + * It accumulates the property value from clusters/points the cluster contains. It can either be + * a literal with single operator, or be a valid expression + * @param mapExpr map expression produces the value of a single point, it shall be a valid expression + * @return the current instance for chaining + */ + @NonNull + public GeoJsonOptions withClusterProperty(String propertyName, Expression operatorExpr, Expression mapExpr) { + HashMap<String, Object[]> properties = containsKey("clusterProperties") + ? (HashMap<String, Object[]>) get("clusterProperties") : new HashMap<String, Object[]>(); + Object operator = (operatorExpr instanceof ExpressionLiteral) + ? ((ExpressionLiteral)operatorExpr).toValue() : operatorExpr.toArray(); + Object map = mapExpr.toArray(); + properties.put(propertyName, new Object[]{operator, map}); + this.put("clusterProperties", properties); + return this; + } } |