Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] #5869 - visible feature querying
Browse files Browse the repository at this point in the history
  • Loading branch information
ivovandongen committed Aug 16, 2016
1 parent dcd9e10 commit 4e21154
Show file tree
Hide file tree
Showing 17 changed files with 1,340 additions and 54 deletions.
5 changes: 5 additions & 0 deletions platform/android/MapboxGLAndroidSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ dependencies {
compile "com.android.support:design:${supportLibVersion}"
compile 'com.squareup.okhttp3:okhttp:3.3.0'
compile 'com.mapzen.android:lost:1.1.0'

// Mapbox Android Services
compile('com.mapbox.mapboxsdk:mapbox-android-services:2.0.0-SNAPSHOT@aar') {
transitive = true
}
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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;
Expand Down Expand Up @@ -42,6 +44,7 @@
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;
Expand Down Expand Up @@ -1722,6 +1725,33 @@ public void snapshot(@NonNull SnapshotReadyCallback callback) {
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
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
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
Expand All @@ -42,6 +45,8 @@ final class NativeMapView {
// Used for callbacks
private MapView mMapView;

private final float pixelRatio;

//
// Static methods
//
Expand All @@ -63,7 +68,7 @@ public NativeMapView(MapView mapView) {
// 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();
Expand Down Expand Up @@ -501,6 +506,26 @@ public void removeSource(@NonNull String sourceId) {
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);
}
Expand Down Expand Up @@ -696,4 +721,8 @@ private native void nativeSetVisibleCoordinateBounds(long mNativeMapViewPtr, Lat
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);
}
Loading

0 comments on commit 4e21154

Please sign in to comment.