From b2b5f9e571e9fedfd682081a3832db7618b1049a Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Sun, 5 Mar 2017 16:55:58 -0800 Subject: [android] query source features --- .../mapboxsdk/style/sources/GeoJsonSource.java | 22 +++++++++++++++ .../mapboxsdk/style/sources/VectorSource.java | 32 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) (limited to 'platform/android/MapboxGLAndroidSDK') 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 f9875c7242..9f957e7727 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 @@ -1,17 +1,25 @@ package com.mapbox.mapboxsdk.style.sources; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.UiThread; + +import com.mapbox.mapboxsdk.style.layers.Filter; import com.mapbox.services.commons.geojson.Feature; import com.mapbox.services.commons.geojson.FeatureCollection; import java.net.URL; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; /** * A GeoJson source. Exposes a {@link FeatureCollection} from Json. * * @see the style specification */ +@UiThread public class GeoJsonSource extends Source { /** @@ -159,6 +167,18 @@ public class GeoJsonSource extends Source { nativeSetUrl(url); } + /** + * Queries the source for features. + * + * @param filter an optional filter statement to filter the returned Features + * @return the features + */ + @NonNull + public List querySourceFeatures(@Nullable Filter.Statement filter) { + Feature[] features = querySourceFeatures(filter != null ? filter.toArray() : null); + return features != null ? Arrays.asList(features) : new ArrayList(); + } + protected void setRawJson(String geoJson) { // Wrap the String in a map as an Object is expected by the // style conversion template @@ -173,6 +193,8 @@ public class GeoJsonSource extends Source { private native void nativeSetGeoJson(Object geoJson); + private native Feature[] querySourceFeatures(Object[] filter); + @Override protected native void finalize() throws Throwable; 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 feaca839d3..68eb81b7f4 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 @@ -1,12 +1,24 @@ package com.mapbox.mapboxsdk.style.sources; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.Size; +import android.support.annotation.UiThread; + +import com.mapbox.mapboxsdk.style.layers.Filter; +import com.mapbox.services.commons.geojson.Feature; + import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; /** * Vector source enables the use of vector tiles. * * @see the style specification */ +@UiThread public class VectorSource extends Source { /** @@ -48,8 +60,28 @@ public class VectorSource extends Source { initialize(id, tileSet.toValueObject()); } + /** + * 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 + * @return the features + */ + @NonNull + public List querySourceFeatures(@Size(min = 1) String[] sourceLayerIds, + @Nullable Filter.Statement filter) { + Feature[] features = querySourceFeatures( + sourceLayerIds, + filter != null ? filter.toArray() : null); + return features != null ? Arrays.asList(features) : new ArrayList(); + } + protected native void initialize(String layerId, Object payload); @Override protected native void finalize() throws Throwable; + + private native Feature[] querySourceFeatures(String[] sourceLayerId, + Object[] filter); + } -- cgit v1.2.1