[android] bindings for aggregated cluster properties (#15425)

* [android] bindings for aggregated cluster properties

* [android] change the parameter type for adding clusterProperty

* [android] add changelog

* remove extra emplty line
This commit is contained in:
zmiao
2019-08-22 18:54:31 +03:00
committed by GitHub
parent 4a5475b1c6
commit 2a8359b028
9 changed files with 92 additions and 5 deletions

View File

@@ -1435,6 +1435,27 @@ public class Expression {
return new Expression("id");
}
/**
* 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.

View File

@@ -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;
}
}