Expression filters (#11429)
* [android] - add expression filter integration
This commit is contained in:
@@ -40,7 +40,7 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.style.layers.Filter;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.light.Light;
|
||||
import com.mapbox.mapboxsdk.style.sources.Source;
|
||||
@@ -2079,13 +2079,13 @@ public final class MapboxMap {
|
||||
* Queries the map for rendered features
|
||||
*
|
||||
* @param coordinates the point to query
|
||||
* @param filter filters the returned features
|
||||
* @param filter filters the returned features with an expression
|
||||
* @param layerIds optionally - only query these layers
|
||||
* @return the list of feature
|
||||
*/
|
||||
@NonNull
|
||||
public List<Feature> queryRenderedFeatures(@NonNull PointF coordinates,
|
||||
@Nullable Filter.Statement filter,
|
||||
@Nullable Expression filter,
|
||||
@Nullable String... layerIds) {
|
||||
return nativeMapView.queryRenderedFeatures(coordinates, layerIds, filter);
|
||||
}
|
||||
@@ -2107,13 +2107,13 @@ public final class MapboxMap {
|
||||
* Queries the map for rendered features
|
||||
*
|
||||
* @param coordinates the box to query
|
||||
* @param filter filters the returned features
|
||||
* @param filter filters the returned features with an expression
|
||||
* @param layerIds optionally - only query these layers
|
||||
* @return the list of feature
|
||||
*/
|
||||
@NonNull
|
||||
public List<Feature> queryRenderedFeatures(@NonNull RectF coordinates,
|
||||
@Nullable Filter.Statement filter,
|
||||
@Nullable Expression filter,
|
||||
@Nullable String... layerIds) {
|
||||
return nativeMapView.queryRenderedFeatures(coordinates, layerIds, filter);
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
|
||||
import com.mapbox.mapboxsdk.maps.renderer.MapRenderer;
|
||||
import com.mapbox.mapboxsdk.storage.FileSource;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.CannotAddLayerException;
|
||||
import com.mapbox.mapboxsdk.style.layers.Filter;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.light.Light;
|
||||
import com.mapbox.mapboxsdk.style.sources.CannotAddSourceException;
|
||||
@@ -799,7 +799,7 @@ final class NativeMapView {
|
||||
@NonNull
|
||||
public List<Feature> queryRenderedFeatures(@NonNull PointF coordinates,
|
||||
@Nullable String[] layerIds,
|
||||
@Nullable Filter.Statement filter) {
|
||||
@Nullable Expression filter) {
|
||||
if (isDestroyedOn("queryRenderedFeatures")) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@@ -811,7 +811,7 @@ final class NativeMapView {
|
||||
@NonNull
|
||||
public List<Feature> queryRenderedFeatures(@NonNull RectF coordinates,
|
||||
@Nullable String[] layerIds,
|
||||
@Nullable Filter.Statement filter) {
|
||||
@Nullable Expression filter) {
|
||||
if (isDestroyedOn("queryRenderedFeatures")) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@@ -4,10 +4,13 @@ package com.mapbox.mapboxsdk.style.layers;
|
||||
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,10 +4,13 @@ package com.mapbox.mapboxsdk.style.layers;
|
||||
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
|
||||
|
||||
/**
|
||||
@@ -69,25 +72,40 @@ public class CircleLayer extends Layer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a single filter.
|
||||
* Set a single expression filter.
|
||||
*
|
||||
* @param filter the filter to set
|
||||
* @param filter the expression filter to set
|
||||
*/
|
||||
public void setFilter(Filter.Statement filter) {
|
||||
public void setFilter(Expression filter) {
|
||||
nativeSetFilter(filter.toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a single filter.
|
||||
* Set a single expression filter.
|
||||
*
|
||||
* @param filter the filter to set
|
||||
* @param filter the expression filter to set
|
||||
* @return This
|
||||
*/
|
||||
public CircleLayer withFilter(Filter.Statement filter) {
|
||||
public CircleLayer withFilter(Expression filter) {
|
||||
setFilter(filter);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single expression filter.
|
||||
*
|
||||
* @return the expression filter to get
|
||||
*/
|
||||
@Nullable
|
||||
public Expression getFilter() {
|
||||
Expression expression = null;
|
||||
JsonArray array = nativeGetFilter();
|
||||
if (array != null) {
|
||||
expression = Expression.Converter.convert(array);
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a property or properties.
|
||||
*
|
||||
|
||||
@@ -4,10 +4,13 @@ package com.mapbox.mapboxsdk.style.layers;
|
||||
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
|
||||
|
||||
/**
|
||||
@@ -69,25 +72,40 @@ public class FillExtrusionLayer extends Layer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a single filter.
|
||||
* Set a single expression filter.
|
||||
*
|
||||
* @param filter the filter to set
|
||||
* @param filter the expression filter to set
|
||||
*/
|
||||
public void setFilter(Filter.Statement filter) {
|
||||
public void setFilter(Expression filter) {
|
||||
nativeSetFilter(filter.toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a single filter.
|
||||
* Set a single expression filter.
|
||||
*
|
||||
* @param filter the filter to set
|
||||
* @param filter the expression filter to set
|
||||
* @return This
|
||||
*/
|
||||
public FillExtrusionLayer withFilter(Filter.Statement filter) {
|
||||
public FillExtrusionLayer withFilter(Expression filter) {
|
||||
setFilter(filter);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single expression filter.
|
||||
*
|
||||
* @return the expression filter to get
|
||||
*/
|
||||
@Nullable
|
||||
public Expression getFilter() {
|
||||
Expression expression = null;
|
||||
JsonArray array = nativeGetFilter();
|
||||
if (array != null) {
|
||||
expression = Expression.Converter.convert(array);
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a property or properties.
|
||||
*
|
||||
|
||||
@@ -4,10 +4,13 @@ package com.mapbox.mapboxsdk.style.layers;
|
||||
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
|
||||
|
||||
/**
|
||||
@@ -69,25 +72,40 @@ public class FillLayer extends Layer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a single filter.
|
||||
* Set a single expression filter.
|
||||
*
|
||||
* @param filter the filter to set
|
||||
* @param filter the expression filter to set
|
||||
*/
|
||||
public void setFilter(Filter.Statement filter) {
|
||||
public void setFilter(Expression filter) {
|
||||
nativeSetFilter(filter.toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a single filter.
|
||||
* Set a single expression filter.
|
||||
*
|
||||
* @param filter the filter to set
|
||||
* @param filter the expression filter to set
|
||||
* @return This
|
||||
*/
|
||||
public FillLayer withFilter(Filter.Statement filter) {
|
||||
public FillLayer withFilter(Expression filter) {
|
||||
setFilter(filter);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single expression filter.
|
||||
*
|
||||
* @return the expression filter to get
|
||||
*/
|
||||
@Nullable
|
||||
public Expression getFilter() {
|
||||
Expression expression = null;
|
||||
JsonArray array = nativeGetFilter();
|
||||
if (array != null) {
|
||||
expression = Expression.Converter.convert(array);
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a property or properties.
|
||||
*
|
||||
|
||||
@@ -1,230 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.style.layers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Utility to build filter expressions more easily.
|
||||
*
|
||||
* @see <a href="https://www.mapbox.com/mapbox-gl-style-spec/#types-filter">The online documentation</a>
|
||||
*/
|
||||
public class Filter {
|
||||
|
||||
/**
|
||||
* Base Filter statement. Subclassed to provide concrete statements.
|
||||
*/
|
||||
public abstract static class Statement {
|
||||
protected final String operator;
|
||||
|
||||
public Statement(String operator) {
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a raw array representation of the filter
|
||||
*
|
||||
* @return the filter represented as an array
|
||||
*/
|
||||
public abstract Object[] toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a {@link Filter} statement. Can be unary (eg `has()`, etc) or take any number of values.
|
||||
*/
|
||||
private static class SimpleStatement extends Statement {
|
||||
private final String key;
|
||||
private final Object[] values;
|
||||
|
||||
/**
|
||||
* @param operator the operator (eg `=`, etc)
|
||||
* @param key the property key
|
||||
* @param values the values to operate on, if any
|
||||
*/
|
||||
SimpleStatement(String operator, String key, Object... values) {
|
||||
super(operator);
|
||||
this.key = key;
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
ArrayList<Object> array = new ArrayList<>(2 + values.length);
|
||||
array.add(operator);
|
||||
array.add(key);
|
||||
Collections.addAll(array, values);
|
||||
return array.toArray();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a collection of {@link Statement}s with an operator that describes their relationship
|
||||
*/
|
||||
private static class CompoundStatement extends Statement {
|
||||
private final Statement[] statements;
|
||||
|
||||
/**
|
||||
* @param operator the relationship operator
|
||||
* @param statements the statements to compound
|
||||
*/
|
||||
CompoundStatement(String operator, Statement... statements) {
|
||||
super(operator);
|
||||
this.statements = statements;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
ArrayList<Object> array = new ArrayList<>(1 + statements.length);
|
||||
array.add(operator);
|
||||
for (Statement statement : statements) {
|
||||
array.add(statement.toArray());
|
||||
}
|
||||
return array.toArray();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups a collection of statements in an 'all' relationship
|
||||
*
|
||||
* @param statements the collection of statements
|
||||
* @return the statements compounded
|
||||
*/
|
||||
public static Statement all(Statement... statements) {
|
||||
return new CompoundStatement("all", statements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups a collection of statements in an 'any' relationship
|
||||
*
|
||||
* @param statements the collection of statements
|
||||
* @return the statements compounded
|
||||
*/
|
||||
public static Statement any(Statement... statements) {
|
||||
return new CompoundStatement("any", statements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups a collection of statements in an 'none' relationship
|
||||
*
|
||||
* @param statements the collection of statements
|
||||
* @return the statements compounded
|
||||
*/
|
||||
public static Statement none(Statement... statements) {
|
||||
return new CompoundStatement("none", statements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the property's existence
|
||||
*
|
||||
* @param key the property key
|
||||
* @return the statement
|
||||
*/
|
||||
public static Statement has(String key) {
|
||||
return new SimpleStatement("has", key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the property's existence, negated
|
||||
*
|
||||
* @param key the property key
|
||||
* @return the statement
|
||||
*/
|
||||
public static Statement notHas(String key) {
|
||||
return new SimpleStatement("!has", key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the property equals the given value
|
||||
*
|
||||
* @param key the property key
|
||||
* @param value the value to check against
|
||||
* @return the statement
|
||||
*/
|
||||
public static Statement eq(String key, Object value) {
|
||||
return new SimpleStatement("==", key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the property does not equals the given value
|
||||
*
|
||||
* @param key the property key
|
||||
* @param value the value to check against
|
||||
* @return the statement
|
||||
*/
|
||||
public static Statement neq(String key, Object value) {
|
||||
return new SimpleStatement("!=", key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the property exceeds the given value
|
||||
*
|
||||
* @param key the property key
|
||||
* @param value the value to check against
|
||||
* @return the statement
|
||||
*/
|
||||
public static Statement gt(String key, Object value) {
|
||||
return new SimpleStatement(">", key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the property exceeds or equals the given value
|
||||
*
|
||||
* @param key the property key
|
||||
* @param value the value to check against
|
||||
* @return the statement
|
||||
*/
|
||||
public static Statement gte(String key, Object value) {
|
||||
return new SimpleStatement(">=", key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the property does not exceeds the given value
|
||||
*
|
||||
* @param key the property key
|
||||
* @param value the value to check against
|
||||
* @return the statement
|
||||
*/
|
||||
public static Statement lt(String key, Object value) {
|
||||
return new SimpleStatement("<", key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the property equals or does not exceeds the given value
|
||||
*
|
||||
* @param key the property key
|
||||
* @param value the value to check against
|
||||
* @return the statement
|
||||
*/
|
||||
public static Statement lte(String key, Object value) {
|
||||
return new SimpleStatement("<=", key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the property is within the given set
|
||||
*
|
||||
* @param key the property key
|
||||
* @param values the set of values to check against
|
||||
* @return the statement
|
||||
*/
|
||||
public static Statement in(String key, Object... values) {
|
||||
return new SimpleStatement("in", key, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the property is not within the given set
|
||||
*
|
||||
* @param key the property key
|
||||
* @param values the set of values to check against
|
||||
* @return the statement
|
||||
*/
|
||||
public static Statement notIn(String key, Object... values) {
|
||||
return new SimpleStatement("!in", key, values);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,10 +4,13 @@ package com.mapbox.mapboxsdk.style.layers;
|
||||
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
|
||||
|
||||
/**
|
||||
@@ -69,25 +72,40 @@ public class HeatmapLayer extends Layer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a single filter.
|
||||
* Set a single expression filter.
|
||||
*
|
||||
* @param filter the filter to set
|
||||
* @param filter the expression filter to set
|
||||
*/
|
||||
public void setFilter(Filter.Statement filter) {
|
||||
public void setFilter(Expression filter) {
|
||||
nativeSetFilter(filter.toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a single filter.
|
||||
* Set a single expression filter.
|
||||
*
|
||||
* @param filter the filter to set
|
||||
* @param filter the expression filter to set
|
||||
* @return This
|
||||
*/
|
||||
public HeatmapLayer withFilter(Filter.Statement filter) {
|
||||
public HeatmapLayer withFilter(Expression filter) {
|
||||
setFilter(filter);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single expression filter.
|
||||
*
|
||||
* @return the expression filter to get
|
||||
*/
|
||||
@Nullable
|
||||
public Expression getFilter() {
|
||||
Expression expression = null;
|
||||
JsonArray array = nativeGetFilter();
|
||||
if (array != null) {
|
||||
expression = Expression.Converter.convert(array);
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a property or properties.
|
||||
*
|
||||
|
||||
@@ -4,10 +4,13 @@ package com.mapbox.mapboxsdk.style.layers;
|
||||
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.style.layers;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
|
||||
/**
|
||||
@@ -71,6 +72,8 @@ public abstract class Layer {
|
||||
|
||||
protected native void nativeSetFilter(Object[] filter);
|
||||
|
||||
protected native JsonArray nativeGetFilter();
|
||||
|
||||
protected native void nativeSetSourceLayer(String sourceLayer);
|
||||
|
||||
protected native String nativeGetSourceLayer();
|
||||
|
||||
@@ -4,10 +4,13 @@ package com.mapbox.mapboxsdk.style.layers;
|
||||
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
|
||||
|
||||
/**
|
||||
@@ -69,25 +72,40 @@ public class LineLayer extends Layer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a single filter.
|
||||
* Set a single expression filter.
|
||||
*
|
||||
* @param filter the filter to set
|
||||
* @param filter the expression filter to set
|
||||
*/
|
||||
public void setFilter(Filter.Statement filter) {
|
||||
public void setFilter(Expression filter) {
|
||||
nativeSetFilter(filter.toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a single filter.
|
||||
* Set a single expression filter.
|
||||
*
|
||||
* @param filter the filter to set
|
||||
* @param filter the expression filter to set
|
||||
* @return This
|
||||
*/
|
||||
public LineLayer withFilter(Filter.Statement filter) {
|
||||
public LineLayer withFilter(Expression filter) {
|
||||
setFilter(filter);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single expression filter.
|
||||
*
|
||||
* @return the expression filter to get
|
||||
*/
|
||||
@Nullable
|
||||
public Expression getFilter() {
|
||||
Expression expression = null;
|
||||
JsonArray array = nativeGetFilter();
|
||||
if (array != null) {
|
||||
expression = Expression.Converter.convert(array);
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a property or properties.
|
||||
*
|
||||
|
||||
@@ -4,10 +4,13 @@ package com.mapbox.mapboxsdk.style.layers;
|
||||
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,10 +4,13 @@ package com.mapbox.mapboxsdk.style.layers;
|
||||
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
|
||||
|
||||
/**
|
||||
@@ -69,25 +72,40 @@ public class SymbolLayer extends Layer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a single filter.
|
||||
* Set a single expression filter.
|
||||
*
|
||||
* @param filter the filter to set
|
||||
* @param filter the expression filter to set
|
||||
*/
|
||||
public void setFilter(Filter.Statement filter) {
|
||||
public void setFilter(Expression filter) {
|
||||
nativeSetFilter(filter.toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a single filter.
|
||||
* Set a single expression filter.
|
||||
*
|
||||
* @param filter the filter to set
|
||||
* @param filter the expression filter to set
|
||||
* @return This
|
||||
*/
|
||||
public SymbolLayer withFilter(Filter.Statement filter) {
|
||||
public SymbolLayer withFilter(Expression filter) {
|
||||
setFilter(filter);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single expression filter.
|
||||
*
|
||||
* @return the expression filter to get
|
||||
*/
|
||||
@Nullable
|
||||
public Expression getFilter() {
|
||||
Expression expression = null;
|
||||
JsonArray array = nativeGetFilter();
|
||||
if (array != null) {
|
||||
expression = Expression.Converter.convert(array);
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a property or properties.
|
||||
*
|
||||
|
||||
@@ -9,10 +9,13 @@ package com.mapbox.mapboxsdk.style.layers;
|
||||
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import static com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
|
||||
|
||||
/**
|
||||
@@ -89,25 +92,40 @@ public class <%- camelize(type) %>Layer extends Layer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a single filter.
|
||||
* Set a single expression filter.
|
||||
*
|
||||
* @param filter the filter to set
|
||||
* @param filter the expression filter to set
|
||||
*/
|
||||
public void setFilter(Filter.Statement filter) {
|
||||
public void setFilter(Expression filter) {
|
||||
nativeSetFilter(filter.toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a single filter.
|
||||
* Set a single expression filter.
|
||||
*
|
||||
* @param filter the filter to set
|
||||
* @param filter the expression filter to set
|
||||
* @return This
|
||||
*/
|
||||
public <%- camelize(type) %>Layer withFilter(Filter.Statement filter) {
|
||||
public <%- camelize(type) %>Layer withFilter(Expression filter) {
|
||||
setFilter(filter);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single expression filter.
|
||||
*
|
||||
* @return the expression filter to get
|
||||
*/
|
||||
@Nullable
|
||||
public Expression getFilter() {
|
||||
Expression expression = null;
|
||||
JsonArray array = nativeGetFilter();
|
||||
if (array != null) {
|
||||
expression = Expression.Converter.convert(array);
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
<% } -%>
|
||||
/**
|
||||
* Set a property or properties.
|
||||
|
||||
@@ -8,7 +8,7 @@ import android.support.annotation.WorkerThread;
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.geojson.FeatureCollection;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.style.layers.Filter;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
@@ -94,11 +94,11 @@ public class CustomGeometrySource extends Source {
|
||||
/**
|
||||
* Queries the source for features.
|
||||
*
|
||||
* @param filter an optional filter statement to filter the returned Features
|
||||
* @param filter an optional filter expression to filter the returned Features
|
||||
* @return the features
|
||||
*/
|
||||
@NonNull
|
||||
public List<Feature> querySourceFeatures(@Nullable Filter.Statement filter) {
|
||||
public List<Feature> querySourceFeatures(@Nullable Expression filter) {
|
||||
Feature[] features = querySourceFeatures(filter != null ? filter.toArray() : null);
|
||||
return features != null ? Arrays.asList(features) : new ArrayList<Feature>();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import android.support.annotation.UiThread;
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.geojson.FeatureCollection;
|
||||
import com.mapbox.geojson.Geometry;
|
||||
import com.mapbox.mapboxsdk.style.layers.Filter;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
@@ -238,11 +238,11 @@ public class GeoJsonSource extends Source {
|
||||
/**
|
||||
* Queries the source for features.
|
||||
*
|
||||
* @param filter an optional filter statement to filter the returned Features
|
||||
* @param filter an optional filter expression to filter the returned Features
|
||||
* @return the features
|
||||
*/
|
||||
@NonNull
|
||||
public List<Feature> querySourceFeatures(@Nullable Filter.Statement filter) {
|
||||
public List<Feature> querySourceFeatures(@Nullable Expression filter) {
|
||||
Feature[] features = querySourceFeatures(filter != null ? filter.toArray() : null);
|
||||
return features != null ? Arrays.asList(features) : new ArrayList<Feature>();
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import android.support.annotation.Size;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.mapboxsdk.style.layers.Filter;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
@@ -64,12 +64,12 @@ public class VectorSource extends Source {
|
||||
* Queries the source for features.
|
||||
*
|
||||
* @param sourceLayerIds the source layer identifiers. At least one must be specified.
|
||||
* @param filter an optional filter statement to filter the returned Features
|
||||
* @param filter an optional filter expression to filter the returned Features
|
||||
* @return the features
|
||||
*/
|
||||
@NonNull
|
||||
public List<Feature> querySourceFeatures(@Size(min = 1) String[] sourceLayerIds,
|
||||
@Nullable Filter.Statement filter) {
|
||||
@Nullable Expression filter) {
|
||||
Feature[] features = querySourceFeatures(
|
||||
sourceLayerIds,
|
||||
filter != null ? filter.toArray() : null);
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.style.layers;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.all;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.any;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.eq;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.gt;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.gte;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.has;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.in;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.lt;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.lte;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.neq;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.none;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.notHas;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.notIn;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
/**
|
||||
* Tests for Filter
|
||||
*/
|
||||
public class FilterTest {
|
||||
|
||||
@Test
|
||||
public void testAll() {
|
||||
assertArrayEquals(all().toArray(), new Object[] {"all"});
|
||||
assertArrayEquals(
|
||||
all(eq("key", 2), neq("key", 3)).toArray(),
|
||||
new Object[] {"all", new Object[] {"==", "key", 2}, new Object[] {"!=", "key", 3}}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAny() {
|
||||
assertArrayEquals(any().toArray(), new Object[] {"any"});
|
||||
assertArrayEquals(
|
||||
any(eq("key", 2), neq("key", 3)).toArray(),
|
||||
new Object[] {"any", new Object[] {"==", "key", 2}, new Object[] {"!=", "key", 3}}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNone() {
|
||||
assertArrayEquals(none().toArray(), new Object[] {"none"});
|
||||
assertArrayEquals(
|
||||
none(eq("key", 2), neq("key", 3)).toArray(),
|
||||
new Object[] {"none", new Object[] {"==", "key", 2}, new Object[] {"!=", "key", 3}}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHas() {
|
||||
assertArrayEquals(has("key").toArray(), new Object[] {"has", "key"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasNot() {
|
||||
assertArrayEquals(notHas("key").toArray(), new Object[] {"!has", "key"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEq() {
|
||||
assertArrayEquals(eq("key", 1).toArray(), new Object[] {"==", "key", 1});
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNeq() {
|
||||
assertArrayEquals(neq("key", 1).toArray(), new Object[] {"!=", "key", 1});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGt() {
|
||||
assertArrayEquals(gt("key", 1).toArray(), new Object[] {">", "key", 1});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGte() {
|
||||
assertArrayEquals(gte("key", 1).toArray(), new Object[] {">=", "key", 1});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLt() {
|
||||
assertArrayEquals(lt("key", 1).toArray(), new Object[] {"<", "key", 1});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLte() {
|
||||
assertArrayEquals(lte("key", 1).toArray(), new Object[] {"<=", "key", 1});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIn() {
|
||||
assertArrayEquals(in("key", 1, 2, "Aap").toArray(), new Object[] {"in", "key", 1, 2, "Aap"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotIn() {
|
||||
assertArrayEquals(notIn("key", 1, 2, "Noot").toArray(), new Object[] {"!in", "key", 1, 2, "Noot"});
|
||||
}
|
||||
}
|
||||
@@ -85,6 +85,26 @@ public class CircleLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilter() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("Filter");
|
||||
invoke(mapboxMap, (uiController, mapboxMap1) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Get initial
|
||||
assertEquals(layer.getFilter(), null);
|
||||
|
||||
// Set
|
||||
Expression filter = eq(get("undefined"), literal(1.0));
|
||||
layer.setFilter(filter);
|
||||
assertEquals(layer.getFilter().toString(), filter.toString());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testCircleRadiusTransition() {
|
||||
validateTestSetup();
|
||||
|
||||
@@ -85,6 +85,26 @@ public class FillExtrusionLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilter() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("Filter");
|
||||
invoke(mapboxMap, (uiController, mapboxMap1) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Get initial
|
||||
assertEquals(layer.getFilter(), null);
|
||||
|
||||
// Set
|
||||
Expression filter = eq(get("undefined"), literal(1.0));
|
||||
layer.setFilter(filter);
|
||||
assertEquals(layer.getFilter().toString(), filter.toString());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testFillExtrusionOpacityTransition() {
|
||||
validateTestSetup();
|
||||
|
||||
@@ -85,6 +85,26 @@ public class FillLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilter() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("Filter");
|
||||
invoke(mapboxMap, (uiController, mapboxMap1) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Get initial
|
||||
assertEquals(layer.getFilter(), null);
|
||||
|
||||
// Set
|
||||
Expression filter = eq(get("undefined"), literal(1.0));
|
||||
layer.setFilter(filter);
|
||||
assertEquals(layer.getFilter().toString(), filter.toString());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testFillAntialiasAsConstant() {
|
||||
validateTestSetup();
|
||||
|
||||
@@ -85,6 +85,26 @@ public class HeatmapLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilter() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("Filter");
|
||||
invoke(mapboxMap, (uiController, mapboxMap1) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Get initial
|
||||
assertEquals(layer.getFilter(), null);
|
||||
|
||||
// Set
|
||||
Expression filter = eq(get("undefined"), literal(1.0));
|
||||
layer.setFilter(filter);
|
||||
assertEquals(layer.getFilter().toString(), filter.toString());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testHeatmapRadiusTransition() {
|
||||
validateTestSetup();
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.junit.runner.RunWith;
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.eq;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.eq;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Property.ANCHOR_MAP;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionBase;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionColor;
|
||||
|
||||
@@ -85,6 +85,26 @@ public class LineLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilter() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("Filter");
|
||||
invoke(mapboxMap, (uiController, mapboxMap1) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Get initial
|
||||
assertEquals(layer.getFilter(), null);
|
||||
|
||||
// Set
|
||||
Expression filter = eq(get("undefined"), literal(1.0));
|
||||
layer.setFilter(filter);
|
||||
assertEquals(layer.getFilter().toString(), filter.toString());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testLineCapAsConstant() {
|
||||
validateTestSetup();
|
||||
|
||||
@@ -85,6 +85,26 @@ public class SymbolLayerTest extends BaseActivityTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilter() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("Filter");
|
||||
invoke(mapboxMap, (uiController, mapboxMap1) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Get initial
|
||||
assertEquals(layer.getFilter(), null);
|
||||
|
||||
// Set
|
||||
Expression filter = eq(get("undefined"), literal(1.0));
|
||||
layer.setFilter(filter);
|
||||
assertEquals(layer.getFilter().toString(), filter.toString());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testSymbolPlacementAsConstant() {
|
||||
validateTestSetup();
|
||||
|
||||
@@ -96,6 +96,26 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest {
|
||||
assertEquals(layer.getSourceLayer(), sourceLayer);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilter() {
|
||||
validateTestSetup();
|
||||
setupLayer();
|
||||
Timber.i("Filter");
|
||||
invoke(mapboxMap, (uiController, mapboxMap1) -> {
|
||||
assertNotNull(layer);
|
||||
|
||||
// Get initial
|
||||
assertEquals(layer.getFilter(), null);
|
||||
|
||||
// Set
|
||||
Expression filter = eq(get("undefined"), literal(1.0));
|
||||
layer.setFilter(filter);
|
||||
assertEquals(layer.getFilter().toString(), filter.toString());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
<% } -%>
|
||||
<% for (const property of properties) { -%>
|
||||
<% if (property.name != 'heatmap-color') { -%>
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.junit.runner.RunWith;
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.eq;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.eq;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Property.ANCHOR_MAP;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionBase;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionColor;
|
||||
|
||||
@@ -11,16 +11,19 @@ import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.geojson.FeatureCollection;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.FillLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.Filter;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.literal;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.lt;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.toNumber;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillColor;
|
||||
|
||||
/**
|
||||
@@ -58,7 +61,9 @@ public class QueryRenderedFeaturesBoxHighlightActivity extends AppCompatActivity
|
||||
int left = selectionBox.getLeft() - mapView.getLeft();
|
||||
RectF box = new RectF(left, top, left + selectionBox.getWidth(), top + selectionBox.getHeight());
|
||||
Timber.i("Querying box %s for buildings", box);
|
||||
List<Feature> features = mapboxMap.queryRenderedFeatures(box, Filter.lt("height", 10), "building");
|
||||
|
||||
Expression filter = lt(toNumber(get("height")), literal(10));
|
||||
List<Feature> features = mapboxMap.queryRenderedFeatures(box, filter, "building");
|
||||
|
||||
// Show count
|
||||
Toast.makeText(
|
||||
|
||||
@@ -11,13 +11,16 @@ import com.mapbox.geojson.Point;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.Filter;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.eq;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.literal;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.neq;
|
||||
|
||||
/**
|
||||
* Test activity showcasing using the query source features API to query feature counts
|
||||
*/
|
||||
@@ -31,8 +34,6 @@ public class QuerySourceFeaturesActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_query_source_features);
|
||||
|
||||
final float density = getResources().getDisplayMetrics().density;
|
||||
|
||||
// Initialize map as normal
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
@@ -47,12 +48,12 @@ public class QuerySourceFeaturesActivity extends AppCompatActivity {
|
||||
}));
|
||||
mapboxMap.addSource(source);
|
||||
|
||||
mapboxMap.addLayer(new CircleLayer("test-layer", source.getId()).withFilter(Filter.neq("key1", "value1")));
|
||||
mapboxMap.addLayer(new CircleLayer("test-layer", source.getId()).withFilter(neq(get("key1"), literal("value1"))));
|
||||
|
||||
// Add a click listener
|
||||
mapboxMap.setOnMapClickListener(point -> {
|
||||
// Query
|
||||
List<Feature> features = source.querySourceFeatures(Filter.eq("key1", "value1"));
|
||||
List<Feature> features = source.querySourceFeatures(eq(get("key1"), literal("value1")));
|
||||
Toast.makeText(QuerySourceFeaturesActivity.this, String.format("Found %s features",
|
||||
features.size()), Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
|
||||
@@ -16,7 +16,9 @@ import com.mapbox.mapboxsdk.style.light.Light;
|
||||
import com.mapbox.mapboxsdk.style.light.Position;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.eq;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.eq;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.literal;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionBase;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionColor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionHeight;
|
||||
@@ -52,7 +54,7 @@ public class BuildingFillExtrusionActivity extends AppCompatActivity {
|
||||
private void setupBuildings() {
|
||||
FillExtrusionLayer fillExtrusionLayer = new FillExtrusionLayer("3d-buildings", "composite");
|
||||
fillExtrusionLayer.setSourceLayer("building");
|
||||
fillExtrusionLayer.setFilter(eq("extrude", "true"));
|
||||
fillExtrusionLayer.setFilter(eq(get("extrude"), literal("true")));
|
||||
fillExtrusionLayer.setMinZoom(15);
|
||||
fillExtrusionLayer.setProperties(
|
||||
fillExtrusionColor(Color.LTGRAY),
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.LineLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
@@ -23,7 +24,10 @@ import java.net.URL;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.in;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.array;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.has;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.literal;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius;
|
||||
|
||||
@@ -117,7 +121,7 @@ public class CircleLayerActivity extends AppCompatActivity implements View.OnCli
|
||||
}
|
||||
|
||||
private void applyBusRouteFilterToBusStopSource() {
|
||||
layer.setFilter(in("number", (Object[]) Data.STOPS_FOR_ROUTE));
|
||||
layer.setFilter(has(Expression.toString(get("number")), array(literal(Data.STOPS_FOR_ROUTE))));
|
||||
}
|
||||
|
||||
private void addBusRouteSource() {
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions;
|
||||
@@ -21,9 +22,12 @@ import java.net.URL;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.all;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.gte;
|
||||
import static com.mapbox.mapboxsdk.style.layers.Filter.lt;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.all;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.gte;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.literal;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.lt;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.toNumber;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleColor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.circleRadius;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage;
|
||||
@@ -124,7 +128,7 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
)
|
||||
);
|
||||
} catch (MalformedURLException malformedUrlException) {
|
||||
Timber.e(malformedUrlException,"That's not an url... ");
|
||||
Timber.e(malformedUrlException, "That's not an url... ");
|
||||
}
|
||||
|
||||
// Add unclustered layer
|
||||
@@ -145,10 +149,15 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
circleColor(layers[i][1]),
|
||||
circleRadius(18f)
|
||||
);
|
||||
|
||||
Expression pointCount = toNumber(get("point_count"));
|
||||
circles.setFilter(
|
||||
i == 0
|
||||
? gte("point_count", layers[i][0]) :
|
||||
all(gte("point_count", layers[i][0]), lt("point_count", layers[i - 1][0]))
|
||||
? gte(pointCount, literal(layers[i][0])) :
|
||||
all(
|
||||
gte(pointCount, literal(layers[i][0])),
|
||||
lt(pointCount, literal(layers[i - 1][0]))
|
||||
)
|
||||
);
|
||||
mapboxMap.addLayer(circles);
|
||||
}
|
||||
@@ -156,7 +165,7 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
// Add the count labels
|
||||
SymbolLayer count = new SymbolLayer("count", "earthquakes");
|
||||
count.setProperties(
|
||||
textField("{point_count}"),
|
||||
textField(get("point_count")),
|
||||
textSize(12f),
|
||||
textColor(Color.WHITE)
|
||||
);
|
||||
|
||||
@@ -31,7 +31,6 @@ import com.mapbox.mapboxsdk.style.sources.VectorSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -39,15 +38,18 @@ import java.util.List;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.all;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.color;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.eq;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.exponential;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.gte;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.literal;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.lt;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.stop;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.toNumber;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom;
|
||||
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.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;
|
||||
@@ -295,7 +297,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
);
|
||||
|
||||
// Only show me parks (except westerpark with stroke-width == 3)
|
||||
layer.setFilter(all(eq("type", "park"), eq("stroke-width", 2)));
|
||||
layer.setFilter(all(eq(get("type"), literal("park")), eq(get("stroke-width"), literal(3))));
|
||||
|
||||
mapboxMap.addLayerBelow(layer, "building");
|
||||
// layer.setPaintProperty(fillColor(Color.RED)); // XXX But not after the object is attached
|
||||
@@ -345,7 +347,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
);
|
||||
|
||||
// Only show me parks
|
||||
layer.setFilter(all(eq("type", "park")));
|
||||
layer.setFilter(all(eq(get("type"), literal("park"))));
|
||||
|
||||
mapboxMap.addLayer(layer);
|
||||
|
||||
@@ -499,7 +501,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
FillLayer states = (FillLayer) mapboxMap.getLayer("states");
|
||||
|
||||
if (states != null) {
|
||||
states.setFilter(eq("name", "Texas"));
|
||||
states.setFilter(eq(get("name"), literal("Texas")));
|
||||
states.setFillOpacityTransition(new TransitionOptions(2500, 0));
|
||||
states.setFillColorTransition(new TransitionOptions(2500, 0));
|
||||
states.setProperties(
|
||||
@@ -555,7 +557,10 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
FillLayer regions = (FillLayer) mapboxMap.getLayer("regions");
|
||||
|
||||
if (regions != null) {
|
||||
regions.setFilter(all(gte("HRRNUM", 200), lt("HRRNUM", 300)));
|
||||
regions.setFilter(all(
|
||||
gte(toNumber(get("HRRNUM")), literal(200)),
|
||||
lt(toNumber(get("HRRNUM")), literal(300)))
|
||||
);
|
||||
|
||||
regions.setProperties(
|
||||
fillColor(Color.BLUE),
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.Filter;
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.style.sources.Source;
|
||||
@@ -38,6 +37,7 @@ import timber.log.Timber;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.concat;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.division;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.downcase;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.eq;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.get;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.literal;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.match;
|
||||
@@ -121,8 +121,8 @@ public class SymbolGeneratorActivity extends AppCompatActivity implements OnMapR
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.menu_action_filter) {
|
||||
SymbolLayer layer = mapboxMap.getLayerAs(LAYER_ID);
|
||||
layer.setFilter(Filter.eq(FEATURE_RANK, 1));
|
||||
//layer.setFilter(eq(get(FEATURE_RANK), 1));
|
||||
layer.setFilter(eq(get(FEATURE_RANK), literal(1)));
|
||||
Timber.e("Filter that was set: %s", layer.getFilter());
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
// C++ -> Java conversion
|
||||
#include "../conversion/property_value.hpp"
|
||||
#include <mbgl/style/filter.hpp>
|
||||
#include "../conversion/gson.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -134,6 +136,39 @@ namespace android {
|
||||
layer.accept(SetFilterEvaluator {std::move(*converted)});
|
||||
}
|
||||
|
||||
struct GetFilterEvaluator {
|
||||
mbgl::style::Filter noop(std::string layerType) {
|
||||
Log::Warning(mbgl::Event::JNI, "%s doesn't support filter", layerType.c_str());
|
||||
return {};
|
||||
}
|
||||
|
||||
mbgl::style::Filter operator()(style::BackgroundLayer&) { return noop("BackgroundLayer"); }
|
||||
mbgl::style::Filter operator()(style::CustomLayer&) { return noop("CustomLayer"); }
|
||||
mbgl::style::Filter operator()(style::RasterLayer&) { return noop("RasterLayer"); }
|
||||
mbgl::style::Filter operator()(style::HillshadeLayer&) { return noop("HillshadeLayer"); }
|
||||
|
||||
template <class LayerType>
|
||||
mbgl::style::Filter operator()(LayerType& layer) {
|
||||
return layer.getFilter();
|
||||
}
|
||||
};
|
||||
|
||||
jni::Object<gson::JsonArray> Layer::getFilter(jni::JNIEnv& env) {
|
||||
using namespace mbgl::style;
|
||||
using namespace mbgl::style::conversion;
|
||||
|
||||
Filter filter = layer.accept(GetFilterEvaluator());
|
||||
|
||||
jni::jobject* converted = nullptr;
|
||||
if (filter.is<ExpressionFilter>()) {
|
||||
ExpressionFilter filterExpression = filter.get<ExpressionFilter>();
|
||||
mbgl::Value expressionValue = filterExpression.expression.get()->serialize();
|
||||
conversion::JsonEvaluator jsonEvaluator{env};
|
||||
converted = apply_visitor(jsonEvaluator, expressionValue);
|
||||
}
|
||||
return jni::Object<gson::JsonArray>(converted);
|
||||
}
|
||||
|
||||
struct SetSourceLayerEvaluator {
|
||||
std::string sourceLayer;
|
||||
|
||||
@@ -208,6 +243,7 @@ namespace android {
|
||||
METHOD(&Layer::setLayoutProperty, "nativeSetLayoutProperty"),
|
||||
METHOD(&Layer::setPaintProperty, "nativeSetPaintProperty"),
|
||||
METHOD(&Layer::setFilter, "nativeSetFilter"),
|
||||
METHOD(&Layer::getFilter, "nativeGetFilter"),
|
||||
METHOD(&Layer::setSourceLayer, "nativeSetSourceLayer"),
|
||||
METHOD(&Layer::getSourceLayer, "nativeGetSourceLayer"),
|
||||
METHOD(&Layer::getMinZoom, "nativeGetMinZoom"),
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/map/map.hpp>
|
||||
#include <mbgl/style/layer.hpp>
|
||||
|
||||
#include "../../gson/json_array.hpp"
|
||||
#include "../value.hpp"
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
@@ -68,6 +68,8 @@ public:
|
||||
|
||||
void setFilter(jni::JNIEnv&, jni::Array<jni::Object<>>);
|
||||
|
||||
jni::Object<gson::JsonArray> getFilter(jni::JNIEnv&);
|
||||
|
||||
void setSourceLayer(jni::JNIEnv&, jni::String);
|
||||
|
||||
jni::String getSourceLayer(jni::JNIEnv&);
|
||||
|
||||
Reference in New Issue
Block a user