[android] #5869 - visible feature querying
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mapbox.mapboxsdk.testapp">
|
||||
<manifest package="com.mapbox.mapboxsdk.testapp"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
||||
<application
|
||||
android:name=".MapboxApplication"
|
||||
@@ -20,8 +20,8 @@
|
||||
android:name=".activity.FeatureOverviewActivity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
@@ -30,7 +30,7 @@
|
||||
android:label="@string/activity_info_window">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_infowindow" />
|
||||
android:value="@string/category_infowindow"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.infowindow.InfoWindowAdapterActivity"
|
||||
@@ -38,7 +38,7 @@
|
||||
android:label="@string/activity_infowindow_adapter">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_infowindow" />
|
||||
android:value="@string/category_infowindow"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.infowindow.DynamicInfoWindowAdapterActivity"
|
||||
@@ -46,7 +46,7 @@
|
||||
android:label="@string/activity_dynamic_infowindow_adapter">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_infowindow" />
|
||||
android:value="@string/category_infowindow"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.annotation.BulkMarkerActivity"
|
||||
@@ -55,7 +55,7 @@
|
||||
android:label="@string/activity_add_bulk_markers">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_annotation" />
|
||||
android:value="@string/category_annotation"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.annotation.AnimatedMarkerActivity"
|
||||
@@ -63,7 +63,7 @@
|
||||
android:label="@string/activity_animated_marker">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_annotation" />
|
||||
android:value="@string/category_annotation"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.annotation.DynamicMarkerChangeActivity"
|
||||
@@ -71,7 +71,7 @@
|
||||
android:label="@string/activity_dynamic_marker">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_annotation" />
|
||||
android:value="@string/category_annotation"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.annotation.PressForMarkerActivity"
|
||||
@@ -79,7 +79,7 @@
|
||||
android:label="@string/activity_press_for_marker">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_annotation" />
|
||||
android:value="@string/category_annotation"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.camera.CameraAnimationTypeActivity"
|
||||
@@ -87,7 +87,7 @@
|
||||
android:label="@string/activity_camera_animation_types">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_camera" />
|
||||
android:value="@string/category_camera"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.camera.CameraPositionActivity"
|
||||
@@ -95,7 +95,7 @@
|
||||
android:label="@string/activity_camera_position">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_camera" />
|
||||
android:value="@string/category_camera"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.camera.LatLngBoundsActivity"
|
||||
@@ -104,7 +104,7 @@
|
||||
android:screenOrientation="portrait">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_camera" />
|
||||
android:value="@string/category_camera"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.fragment.MapFragmentActivity"
|
||||
@@ -112,7 +112,7 @@
|
||||
android:label="@string/activity_map_fragment">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_fragment" />
|
||||
android:value="@string/category_fragment"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.fragment.SupportMapFragmentActivity"
|
||||
@@ -120,7 +120,7 @@
|
||||
android:label="@string/activity_map_fragment_suport">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_fragment" />
|
||||
android:value="@string/category_fragment"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.camera.ManualZoomActivity"
|
||||
@@ -128,7 +128,7 @@
|
||||
android:label="@string/activity_camera_zoom">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_camera" />
|
||||
android:value="@string/category_camera"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.camera.MaxMinZoomActivity"
|
||||
@@ -136,7 +136,7 @@
|
||||
android:label="@string/activity_minmax_zoom">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_camera" />
|
||||
android:value="@string/category_camera"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.customlayer.CustomLayerActivity"
|
||||
@@ -144,7 +144,7 @@
|
||||
android:label="@string/activity_custom_layer">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_custom_layer" />
|
||||
android:value="@string/category_custom_layer"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.userlocation.MyLocationTrackingModeActivity"
|
||||
@@ -152,7 +152,7 @@
|
||||
android:label="@string/activity_user_tracking_mode">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_userlocation" />
|
||||
android:value="@string/category_userlocation"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.userlocation.MyLocationDrawableActivity"
|
||||
@@ -160,7 +160,7 @@
|
||||
android:label="@string/activity_user_tracking_customization">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_userlocation" />
|
||||
android:value="@string/category_userlocation"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.userlocation.MyLocationTintActivity"
|
||||
@@ -168,7 +168,7 @@
|
||||
android:label="@string/activity_user_dot_color">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_userlocation" />
|
||||
android:value="@string/category_userlocation"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.userlocation.MyLocationToggleActivity"
|
||||
@@ -176,7 +176,7 @@
|
||||
android:label="@string/activity_user_location_toggle">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_userlocation" />
|
||||
android:value="@string/category_userlocation"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.annotation.PolygonActivity"
|
||||
@@ -184,7 +184,7 @@
|
||||
android:label="@string/activity_polygon">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_annotation" />
|
||||
android:value="@string/category_annotation"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.annotation.PolylineActivity"
|
||||
@@ -192,7 +192,7 @@
|
||||
android:label="@string/activity_polyline">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_annotation" />
|
||||
android:value="@string/category_annotation"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.directions.DirectionsActivity"
|
||||
@@ -200,7 +200,7 @@
|
||||
android:label="@string/activity_directions">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_directions" />
|
||||
android:value="@string/category_directions"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.geocoding.GeocoderActivity"
|
||||
@@ -208,7 +208,7 @@
|
||||
android:label="@string/activity_geocoder">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_geocoding" />
|
||||
android:value="@string/category_geocoding"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.camera.ScrollByActivity"
|
||||
@@ -216,7 +216,7 @@
|
||||
android:label="@string/activity_scroll_by">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_camera" />
|
||||
android:value="@string/category_camera"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.maplayout.MapPaddingActivity"
|
||||
@@ -225,7 +225,7 @@
|
||||
android:screenOrientation="portrait">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_maplayout" />
|
||||
android:value="@string/category_maplayout"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.maplayout.DebugModeActivity"
|
||||
@@ -233,7 +233,7 @@
|
||||
android:label="@string/activity_debug_mode">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_maplayout" />
|
||||
android:value="@string/category_maplayout"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.offline.OfflineActivity"
|
||||
@@ -241,7 +241,7 @@
|
||||
android:label="@string/activity_offline">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_offline" />
|
||||
android:value="@string/category_offline"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.imagegenerator.SnapshotActivity"
|
||||
@@ -249,7 +249,7 @@
|
||||
android:label="@string/activity_snapshot">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_imagegenerator" />
|
||||
android:value="@string/category_imagegenerator"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.maplayout.DoubleMapActivity"
|
||||
@@ -257,7 +257,7 @@
|
||||
android:label="@string/activity_double_map">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_maplayout" />
|
||||
android:value="@string/category_maplayout"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.annotation.MarkerViewActivity"
|
||||
@@ -265,7 +265,7 @@
|
||||
android:label="@string/activity_view_marker">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_annotation" />
|
||||
android:value="@string/category_annotation"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.annotation.MarkerViewScaleActivity"
|
||||
@@ -273,7 +273,7 @@
|
||||
android:label="@string/activity_view_marker_scale">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_annotation" />
|
||||
android:value="@string/category_annotation"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.navigation.LocationPickerActivity"
|
||||
@@ -281,7 +281,7 @@
|
||||
android:label="@string/activity_location_picker">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_navigation" />
|
||||
android:value="@string/category_navigation"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.fragment.ViewPagerActivity"
|
||||
@@ -289,7 +289,7 @@
|
||||
android:label="@string/activity_viewpager">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_fragment" />
|
||||
android:value="@string/category_fragment"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.maplayout.NavigationDrawerActivity"
|
||||
@@ -298,7 +298,7 @@
|
||||
android:theme="@style/AppTheme.ActionBar.Transparent">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_fragment" />
|
||||
android:value="@string/category_fragment"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.style.RuntimeStyleActivity"
|
||||
@@ -306,7 +306,7 @@
|
||||
android:label="@string/activity_runtime_style">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_style" />
|
||||
android:value="@string/category_style"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.style.GeoJsonClusteringActivity"
|
||||
@@ -323,7 +323,7 @@
|
||||
android:label="@string/activity_print">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_imagegenerator" />
|
||||
android:value="@string/category_imagegenerator"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.maplayout.SurfaceViewMediaControlActivity"
|
||||
@@ -331,27 +331,53 @@
|
||||
android:label="@string/activity_surfaceview_overlay">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_maplayout" />
|
||||
android:value="@string/category_maplayout"/>
|
||||
</activity>
|
||||
|
||||
<!-- Features -->
|
||||
<activity
|
||||
android:name=".activity.feature.QueryRenderedFeaturesPropertiesActivity"
|
||||
android:description="@string/description_query_rendered_feature_properties_point"
|
||||
android:label="@string/activity_query_rendered_feature_properties">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_features" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.feature.QueryRenderedFeaturesBoxCountActivity"
|
||||
android:description="@string/description_query_rendered_features_box_count"
|
||||
android:label="@string/activity_query_rendered_features_box_count">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_features" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.feature.QueryRenderedFeaturesBoxHighlightActivity"
|
||||
android:description="@string/description_query_rendered_features_box_highlight"
|
||||
android:label="@string/activity_query_rendered_features_box_highlight">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_features" />
|
||||
</activity>
|
||||
|
||||
<!-- For Unit tests -->
|
||||
<activity android:name=".activity.style.RuntimeStyleTestActivity" />
|
||||
<activity android:name=".activity.style.RuntimeStyleTimingTestActivity" />
|
||||
<activity android:name=".activity.style.RuntimeStyleTestActivity"/>
|
||||
<activity android:name=".activity.style.RuntimeStyleTimingTestActivity"/>
|
||||
|
||||
<!-- Configuration Settings -->
|
||||
<meta-data
|
||||
android:name="com.mapbox.TestEventsServer"
|
||||
android:value="https://cloudfront-staging.tilestream.net" />
|
||||
android:value="https://cloudfront-staging.tilestream.net"/>
|
||||
<meta-data
|
||||
android:name="com.mapbox.TestEventsAccessToken"
|
||||
android:value="sk.eyJ1IjoiYmxlZWdlIiwiYSI6InNpcml1c2x5In0.KyT-boMyC_xZYTYojTc8zg" />
|
||||
android:value="sk.eyJ1IjoiYmxlZWdlIiwiYSI6InNpcml1c2x5In0.KyT-boMyC_xZYTYojTc8zg"/>
|
||||
|
||||
<!-- Comment out this setting to switch to external storage (and disable internal) in your app -->
|
||||
<!-- <meta-data -->
|
||||
<!-- android:name="com.mapbox.SetStorageExternal" -->
|
||||
<!-- android:value="true" /> -->
|
||||
|
||||
<service android:name="com.mapbox.mapboxsdk.telemetry.TelemetryService" />
|
||||
<service android:name="com.mapbox.mapboxsdk.telemetry.TelemetryService"/>
|
||||
|
||||
</application>
|
||||
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.feature;
|
||||
|
||||
import android.graphics.RectF;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.services.commons.geojson.Feature;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Demo's query rendered features
|
||||
*/
|
||||
public class QueryRenderedFeaturesBoxCountActivity extends AppCompatActivity {
|
||||
private static final String TAG = QueryRenderedFeaturesBoxCountActivity.class.getSimpleName();
|
||||
|
||||
public MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
private Marker marker;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_query_features_box);
|
||||
setupActionBar();
|
||||
|
||||
final float density = getResources().getDisplayMetrics().density;
|
||||
|
||||
final View selectionBox = findViewById(R.id.selection_box);
|
||||
|
||||
//Initialize map as normal
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Override
|
||||
public void onMapReady(final MapboxMap mapboxMap) {
|
||||
QueryRenderedFeaturesBoxCountActivity.this.mapboxMap = mapboxMap;
|
||||
|
||||
|
||||
selectionBox.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//Query
|
||||
int top = selectionBox.getTop() - mapView.getTop();
|
||||
int left = selectionBox.getLeft() - mapView.getLeft();
|
||||
RectF box = new RectF(left, top, left + selectionBox.getWidth(), top + selectionBox.getHeight());
|
||||
Log.i(TAG, String.format("Querying box %s", box));
|
||||
List<Feature> features = mapboxMap.queryRenderedFeatures(box);
|
||||
|
||||
//Show count
|
||||
Toast.makeText(QueryRenderedFeaturesBoxCountActivity.this, String.format("%s features in box", features.size()), Toast.LENGTH_SHORT).show();
|
||||
|
||||
//Debug output
|
||||
debugOutput(features);
|
||||
}
|
||||
});
|
||||
|
||||
//Little taste of home
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(52.0907, 5.1214), 16));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void debugOutput(List<Feature> features) {
|
||||
Log.i(TAG, String.format("Got %s features", features.size()));
|
||||
for (Feature feature : features) {
|
||||
if (feature != null) {
|
||||
Log.i(TAG, String.format("Got feature %s with %s properties and Geometry %s",
|
||||
feature.getId(),
|
||||
feature.getProperties() != null ? feature.getProperties().entrySet().size() : "<null>",
|
||||
feature.getGeometry() != null ? feature.getGeometry().getClass().getSimpleName() : "<null>")
|
||||
);
|
||||
if (feature.getProperties() != null) {
|
||||
for (Map.Entry<String, JsonElement> entry : feature.getProperties().entrySet()) {
|
||||
Log.i(TAG, String.format("Prop %s - %s", entry.getKey(), entry.getValue()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log.i(TAG, "Got NULL feature %s");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MapboxMap getMapboxMap() {
|
||||
return mapboxMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mapView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mapView.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupActionBar() {
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.feature;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.RectF;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.services.commons.geojson.Feature;
|
||||
import com.mapbox.services.commons.geojson.Polygon;
|
||||
import com.mapbox.services.commons.models.Position;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Demo's query rendered features
|
||||
*/
|
||||
public class QueryRenderedFeaturesBoxHighlightActivity extends AppCompatActivity {
|
||||
private static final String TAG = QueryRenderedFeaturesBoxHighlightActivity.class.getSimpleName();
|
||||
|
||||
public MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
private Marker marker;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_query_features_box);
|
||||
setupActionBar();
|
||||
|
||||
final float density = getResources().getDisplayMetrics().density;
|
||||
|
||||
final View selectionBox = findViewById(R.id.selection_box);
|
||||
|
||||
//Initialize map as normal
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Override
|
||||
public void onMapReady(final MapboxMap mapboxMap) {
|
||||
QueryRenderedFeaturesBoxHighlightActivity.this.mapboxMap = mapboxMap;
|
||||
|
||||
|
||||
selectionBox.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//Query
|
||||
int top = selectionBox.getTop() - mapView.getTop();
|
||||
int left = selectionBox.getLeft() - mapView.getLeft();
|
||||
RectF box = new RectF(left, top, left + selectionBox.getWidth(), top + selectionBox.getHeight());
|
||||
Log.i(TAG, String.format("Querying box %s for buildings", box));
|
||||
List<Feature> features = mapboxMap.queryRenderedFeatures(box, "building");
|
||||
|
||||
//Show count
|
||||
Toast.makeText(QueryRenderedFeaturesBoxHighlightActivity.this, String.format("%s features in box", features.size()), Toast.LENGTH_SHORT).show();
|
||||
|
||||
for (Feature feature : features) {
|
||||
if (feature.getGeometry() instanceof Polygon) {
|
||||
Polygon building = (Polygon) feature.getGeometry();
|
||||
|
||||
//Convert outer ring
|
||||
List<List<Position>> coordinates = building.getCoordinates();
|
||||
List<Position> outerRing = coordinates.get(0);
|
||||
List<LatLng> points = new ArrayList<LatLng>();
|
||||
for (Position position : outerRing) {
|
||||
points.add(new LatLng(position.getLatitude(), position.getLongitude()));
|
||||
}
|
||||
|
||||
mapboxMap.addPolygon(new PolygonOptions().addAll(points).fillColor(Color.RED));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//Little taste of home
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(52.0907, 5.1214), 16));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public MapboxMap getMapboxMap() {
|
||||
return mapboxMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mapView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mapView.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupActionBar() {
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.feature;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PointF;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.services.commons.geojson.Feature;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Demo's query rendered features
|
||||
*/
|
||||
public class QueryRenderedFeaturesPropertiesActivity extends AppCompatActivity {
|
||||
private static final String TAG = QueryRenderedFeaturesPropertiesActivity.class.getSimpleName();
|
||||
|
||||
public MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
private Marker marker;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_query_features_point);
|
||||
setupActionBar();
|
||||
|
||||
final float density = getResources().getDisplayMetrics().density;
|
||||
|
||||
//Initialize map as normal
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(final MapboxMap mapboxMap) {
|
||||
QueryRenderedFeaturesPropertiesActivity.this.mapboxMap = mapboxMap;
|
||||
|
||||
//Add custom window adapter
|
||||
addCustomInfoWindowAdapter(mapboxMap);
|
||||
|
||||
//Add a click listener
|
||||
mapboxMap.setOnMapClickListener(new MapboxMap.OnMapClickListener() {
|
||||
@Override
|
||||
public void onMapClick(@NonNull LatLng point) {
|
||||
//Query
|
||||
final PointF pixel = mapboxMap.getProjection().toScreenLocation(point);
|
||||
Log.i(TAG, String.format("Requesting features for %sx%s (%sx%s adjusted for density)", pixel.x, pixel.y, pixel.x / density, pixel.y / density));
|
||||
List<Feature> features = mapboxMap.queryRenderedFeatures(pixel);
|
||||
|
||||
//Debug output
|
||||
debugOutput(features);
|
||||
|
||||
//Remove any previous markers
|
||||
if (marker != null) {
|
||||
mapboxMap.removeMarker(marker);
|
||||
}
|
||||
|
||||
//Add a marker on the clicked point
|
||||
marker = mapboxMap.addMarker(new CustomMarkerOptions().position(point).features(features));
|
||||
mapboxMap.selectMarker(marker);
|
||||
}
|
||||
});
|
||||
|
||||
//Little taste of home
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(52.0907, 5.1214), 16));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void debugOutput(List<Feature> features) {
|
||||
Log.i(TAG, String.format("Got %s features", features.size()));
|
||||
for (Feature feature : features) {
|
||||
if (feature != null) {
|
||||
Log.i(TAG, String.format("Got feature %s with %s properties and Geometry %s",
|
||||
feature.getId(),
|
||||
feature.getProperties() != null ? feature.getProperties().entrySet().size() : "<null>",
|
||||
feature.getGeometry() != null ? feature.getGeometry().getClass().getSimpleName() : "<null>")
|
||||
);
|
||||
if (feature.getProperties() != null) {
|
||||
for (Map.Entry<String, JsonElement> entry : feature.getProperties().entrySet()) {
|
||||
Log.i(TAG, String.format("Prop %s - %s", entry.getKey(), entry.getValue()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log.i(TAG, "Got NULL feature %s");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addCustomInfoWindowAdapter(MapboxMap mapboxMap) {
|
||||
mapboxMap.setInfoWindowAdapter(new MapboxMap.InfoWindowAdapter() {
|
||||
|
||||
private TextView row(String text) {
|
||||
TextView view = new TextView(QueryRenderedFeaturesPropertiesActivity.this);
|
||||
view.setText(text);
|
||||
return view;
|
||||
}
|
||||
|
||||
private int tenDp = (int) getResources().getDimension(R.dimen.attr_margin);
|
||||
|
||||
@Override
|
||||
public View getInfoWindow(@NonNull Marker marker) {
|
||||
CustomMarker customMarker = (CustomMarker) marker;
|
||||
LinearLayout view = new LinearLayout(QueryRenderedFeaturesPropertiesActivity.this);
|
||||
view.setOrientation(LinearLayout.VERTICAL);
|
||||
view.setBackgroundColor(Color.WHITE);
|
||||
|
||||
if (customMarker.features.size() > 0) {
|
||||
view.addView(row(String.format("Found %s features", customMarker.features.size())));
|
||||
Feature feature = customMarker.features.get(0);
|
||||
for (Map.Entry<String, JsonElement> prop : feature.getProperties().entrySet()) {
|
||||
view.addView(row(String.format("%s: %s", prop.getKey(), prop.getValue())));
|
||||
}
|
||||
} else {
|
||||
view.addView(row("No features here"));
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public MapboxMap getMapboxMap() {
|
||||
return mapboxMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mapView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mapView.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupActionBar() {
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private static class CustomMarker extends Marker {
|
||||
|
||||
private final List<Feature> features;
|
||||
|
||||
public CustomMarker(BaseMarkerOptions baseMarkerOptions, List<Feature> features) {
|
||||
super(baseMarkerOptions);
|
||||
this.features = features;
|
||||
}
|
||||
}
|
||||
|
||||
private static class CustomMarkerOptions extends BaseMarkerOptions<CustomMarker, CustomMarkerOptions> {
|
||||
|
||||
|
||||
private List<Feature> features;
|
||||
|
||||
public CustomMarkerOptions features(List<Feature> features) {
|
||||
this.features = features;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CustomMarkerOptions() {
|
||||
}
|
||||
|
||||
private CustomMarkerOptions(Parcel in) {
|
||||
//Should implement this
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomMarkerOptions getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomMarker getMarker() {
|
||||
return new CustomMarker(this, features);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<CustomMarkerOptions> CREATOR
|
||||
= new Parcelable.Creator<CustomMarkerOptions>() {
|
||||
public CustomMarkerOptions createFromParcel(Parcel in) {
|
||||
return new CustomMarkerOptions(in);
|
||||
}
|
||||
|
||||
public CustomMarkerOptions[] newArray(int size) {
|
||||
return new CustomMarkerOptions[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
//Should implement this
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="@color/primary"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@+id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@id/toolbar" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/selection_box"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="150dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:alpha="0.3"
|
||||
android:background="#1d72da" />
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="@color/primary"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@+id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@id/toolbar"/>
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -57,6 +57,9 @@
|
||||
<string name="activity_geojson_clustering">GeoJson Clustering</string>
|
||||
<string name="activity_print">Print a map</string>
|
||||
<string name="activity_surfaceview_overlay">SurfaceView MediaOverlay</string>
|
||||
<string name="activity_query_rendered_feature_properties">Query feature properties</string>
|
||||
<string name="activity_query_rendered_features_box_count">Count features in box</string>
|
||||
<string name="activity_query_rendered_features_box_highlight">Highlight features in box</string>
|
||||
<string name="title_activity_navigation_drawer">Android SDK View integration</string>
|
||||
|
||||
<!-- Description -->
|
||||
@@ -100,6 +103,9 @@
|
||||
<string name="description_print">Shows how to print a map</string>
|
||||
<string name="description_navigation_drawer">Test animation of Android SDK View components</string>
|
||||
<string name="description_surfaceview_mediacontrols">Test overlaying SurfaceView</string>
|
||||
<string name="description_query_rendered_feature_properties_point">Query rendered feature properties on click</string>
|
||||
<string name="description_query_rendered_features_box_count">Count all rendered features in box</string>
|
||||
<string name="description_query_rendered_features_box_highlight">Hightligh buildings in box</string>
|
||||
|
||||
<string name="menuitem_title_concurrent_infowindow">Concurrent Open InfoWindows</string>
|
||||
<string name="menuitem_title_deselect_markers_on_tap">Deselect Markers On Tap</string>
|
||||
@@ -121,6 +127,7 @@
|
||||
<string name="category_userlocation">User Location</string>
|
||||
<string name="category_navigation">Navigation</string>
|
||||
<string name="category_style">Styling</string>
|
||||
<string name="category_features">Features</string>
|
||||
|
||||
<string name="action_visible_bounds_explanation">Center map around 2 markers</string>
|
||||
<string name="action_remove_polylines">Remove polylines</string>
|
||||
|
||||
Reference in New Issue
Block a user