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

Commit

Permalink
[android] #352 - basic setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ivovandongen committed Aug 5, 2016
1 parent cf047b4 commit 28915d3
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mapbox.mapboxsdk.geojson;

/**
*
*/
public class Feature {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PointF;
import android.location.Location;
import android.os.SystemClock;
import android.support.annotation.FloatRange;
Expand All @@ -19,6 +20,7 @@
import com.mapbox.mapboxsdk.annotations.Annotation;
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
import com.mapbox.mapboxsdk.annotations.BaseMarkerViewOptions;
import com.mapbox.mapboxsdk.geojson.Feature;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.annotations.InfoWindow;
Expand Down Expand Up @@ -1710,6 +1712,20 @@ 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);
}


//
// Interfaces
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.support.annotation.Nullable;
import android.view.Surface;

import com.mapbox.mapboxsdk.geojson.Feature;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.Polygon;
Expand All @@ -21,6 +22,8 @@
import com.mapbox.mapboxsdk.style.layers.NoSuchLayerException;
import com.mapbox.mapboxsdk.style.sources.Source;

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,14 @@ public void removeSource(@NonNull String sourceId) {
nativeRemoveSource(mNativeMapViewPtr, sourceId);
}

// Feature querying

@NonNull
public List<Feature> queryRenderedFeatures(PointF coordinates, String... layerIds) {
Feature[] features = nativeQueryRenderedFeatures(mNativeMapViewPtr, coordinates.x / pixelRatio, coordinates.y / pixelRatio, layerIds);
return features != null ? Arrays.asList(features) : new ArrayList<Feature>();
}

public void scheduleTakeSnapshot() {
nativeScheduleTakeSnapshot(mNativeMapViewPtr);
}
Expand Down Expand Up @@ -696,4 +709,6 @@ 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[] nativeQueryRenderedFeatures(long nativeMapViewPtr, float x, float y, String[] layerIds);
}
Loading

0 comments on commit 28915d3

Please sign in to comment.