[android] #5869 - visible feature querying

This commit is contained in:
Ivo van Dongen
2016-08-04 14:45:50 -04:00
parent dcd9e1016c
commit 4e211548d5
17 changed files with 1340 additions and 54 deletions

View File

@@ -2,6 +2,8 @@ package com.mapbox.mapboxsdk.maps;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PointF;
import android.graphics.RectF;
import android.location.Location;
import android.os.SystemClock;
import android.support.annotation.FloatRange;
@@ -42,6 +44,7 @@ import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.layers.NoSuchLayerException;
import com.mapbox.mapboxsdk.style.sources.Source;
import com.mapbox.services.commons.geojson.Feature;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
@@ -1722,6 +1725,33 @@ public class MapboxMap {
mMapView.snapshot(callback, null);
}
/**
* Queries the map for rendered features
*
* @param coordinates the point to query
* @param layerIds optionally - only query these layers
* @return the list of feature
*/
@UiThread
@NonNull
public List<Feature> queryRenderedFeatures(@NonNull PointF coordinates, @Nullable String... layerIds) {
return mMapView.getNativeMapView().queryRenderedFeatures(coordinates, layerIds);
}
/**
* Queries the map for rendered features
*
* @param coordinates the box to query
* @param layerIds optionally - only query these layers
* @return the list of feature
*/
@UiThread
@NonNull
public List<Feature> queryRenderedFeatures(@NonNull RectF coordinates, @Nullable String... layerIds) {
return mMapView.getNativeMapView().queryRenderedFeatures(coordinates, layerIds);
}
//
// Interfaces
//

View File

@@ -20,7 +20,10 @@ import com.mapbox.mapboxsdk.offline.OfflineManager;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.layers.NoSuchLayerException;
import com.mapbox.mapboxsdk.style.sources.Source;
import com.mapbox.services.commons.geojson.Feature;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
// Class that wraps the native methods for convenience
@@ -42,6 +45,8 @@ final class NativeMapView {
// Used for callbacks
private MapView mMapView;
private final float pixelRatio;
//
// Static methods
//
@@ -63,7 +68,7 @@ final class NativeMapView {
// the system
String cachePath = dataPath;
float pixelRatio = context.getResources().getDisplayMetrics().density;
pixelRatio = context.getResources().getDisplayMetrics().density;
String apkPath = context.getPackageCodePath();
int availableProcessors = Runtime.getRuntime().availableProcessors();
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
@@ -501,6 +506,26 @@ final class NativeMapView {
nativeRemoveSource(mNativeMapViewPtr, sourceId);
}
// Feature querying
@NonNull
public List<Feature> queryRenderedFeatures(PointF coordinates, String... layerIds) {
Feature[] features = nativeQueryRenderedFeaturesForPoint(mNativeMapViewPtr, coordinates.x / pixelRatio, coordinates.y / pixelRatio, layerIds);
return features != null ? Arrays.asList(features) : new ArrayList<Feature>();
}
@NonNull
public List<Feature> queryRenderedFeatures(RectF coordinates, String... layerIds) {
Feature[] features = nativeQueryRenderedFeaturesForBox(
mNativeMapViewPtr,
coordinates.left / pixelRatio,
coordinates.top / pixelRatio,
coordinates.right / pixelRatio,
coordinates.bottom / pixelRatio,
layerIds);
return features != null ? Arrays.asList(features) : new ArrayList<Feature>();
}
public void scheduleTakeSnapshot() {
nativeScheduleTakeSnapshot(mNativeMapViewPtr);
}
@@ -696,4 +721,8 @@ final class NativeMapView {
private native long nativeUpdatePolyline(long nativeMapviewPtr, long polylineId, Polyline polyline);
private native void nativeScheduleTakeSnapshot(long nativeMapViewPtr);
private native Feature[] nativeQueryRenderedFeaturesForPoint(long nativeMapViewPtr, float x, float y, String[] layerIds);
private native Feature[] nativeQueryRenderedFeaturesForBox(long mNativeMapViewPtr, float left, float top, float right, float bottom, String[] layerIds);
}