[android] query source features

This commit is contained in:
Ivo van Dongen
2017-03-05 16:55:58 -08:00
committed by Ivo van Dongen
parent 12568f21a3
commit b2b5f9e571
13 changed files with 282 additions and 20 deletions

View File

@@ -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 <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources-geojson">the style specification</a>
*/
@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<Feature> querySourceFeatures(@Nullable Filter.Statement filter) {
Feature[] features = querySourceFeatures(filter != null ? filter.toArray() : null);
return features != null ? Arrays.asList(features) : new ArrayList<Feature>();
}
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;

View File

@@ -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 <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources-vector">the style specification</a>
*/
@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<Feature> 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<Feature>();
}
protected native void initialize(String layerId, Object payload);
@Override
protected native void finalize() throws Throwable;
private native Feature[] querySourceFeatures(String[] sourceLayerId,
Object[] filter);
}