diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature')
5 files changed, 0 insertions, 807 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxCountActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxCountActivity.java deleted file mode 100644 index 96038f3725..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxCountActivity.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.activity.feature; - -import android.graphics.PointF; -import android.graphics.RectF; -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.view.MenuItem; -import android.view.View; -import android.widget.Toast; -import com.google.gson.JsonElement; -import com.mapbox.geojson.Feature; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.maps.Style; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.utils.NavUtils; -import timber.log.Timber; - -import java.util.List; -import java.util.Map; - -/** - * Test activity showcasing using the query rendered features API to count features in a rectangle. - */ -public class QueryRenderedFeaturesBoxCountActivity extends AppCompatActivity { - - public MapView mapView; - private MapboxMap mapboxMap; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_query_features_box); - - final View selectionBox = findViewById(R.id.selection_box); - - // Initialize map as normal - mapView = (MapView) findViewById(R.id.mapView); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(mapboxMap -> { - QueryRenderedFeaturesBoxCountActivity.this.mapboxMap = mapboxMap; - - mapboxMap.setStyle(new Style.Builder().fromUri(Style.MAPBOX_STREETS)); - - selectionBox.setOnClickListener(view -> { - // 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()); - Timber.i("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); - }); - }); - } - - private void debugOutput(List<Feature> features) { - Timber.i("Got %s features", features.size()); - for (Feature feature : features) { - if (feature != null) { - Timber.i("Got feature %s with %s properties and Geometry %s", - feature.id(), - feature.properties() != null ? feature.properties().entrySet().size() : "<null>", - feature.geometry() != null ? feature.geometry().getClass().getSimpleName() : "<null>" - ); - if (feature.properties() != null) { - for (Map.Entry<String, JsonElement> entry : feature.properties().entrySet()) { - Timber.i("Prop %s - %s", entry.getKey(), entry.getValue()); - } - } - } else { - Timber.i("Got 0 features"); - } - } - } - - public MapboxMap getMapboxMap() { - return mapboxMap; - } - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - - if (mapboxMap != null) { - // Regression test for #14394 - mapboxMap.queryRenderedFeatures(new PointF(0, 0)); - } - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @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: - // activity uses singleInstance for testing purposes - // code below provides a default navigation when using the app - onBackPressed(); - return true; - } - return super.onOptionsItemSelected(item); - } - - @Override - public void onBackPressed() { - // activity uses singleInstance for testing purposes - // code below provides a default navigation when using the app - NavUtils.navigateHome(this); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxHighlightActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxHighlightActivity.java deleted file mode 100644 index 4d13432792..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxHighlightActivity.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.activity.feature; - -import android.graphics.Color; -import android.graphics.RectF; -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.view.View; -import android.widget.Toast; - -import com.mapbox.geojson.Feature; -import com.mapbox.geojson.FeatureCollection; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.maps.Style; -import com.mapbox.mapboxsdk.style.expressions.Expression; -import com.mapbox.mapboxsdk.style.layers.FillLayer; -import com.mapbox.mapboxsdk.style.layers.Layer; -import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; -import com.mapbox.mapboxsdk.testapp.R; - -import java.util.List; - -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.expressions.Expression.get; -import static com.mapbox.mapboxsdk.style.expressions.Expression.literal; -import static com.mapbox.mapboxsdk.style.expressions.Expression.lt; -import static com.mapbox.mapboxsdk.style.expressions.Expression.toNumber; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillColor; - -/** - * Demo's query rendered features - */ -public class QueryRenderedFeaturesBoxHighlightActivity extends AppCompatActivity { - - public MapView mapView; - private MapboxMap mapboxMap; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_query_features_box); - - final View selectionBox = findViewById(R.id.selection_box); - - // Initialize map as normal - mapView = (MapView) findViewById(R.id.mapView); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(mapboxMap -> { - QueryRenderedFeaturesBoxHighlightActivity.this.mapboxMap = mapboxMap; - - // Add layer / source - final GeoJsonSource source = new GeoJsonSource("highlighted-shapes-source"); - final Layer layer = new FillLayer("highlighted-shapes-layer", "highlighted-shapes-source") - .withProperties(fillColor(Color.RED)); - - selectionBox.setOnClickListener(view -> { - // 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()); - Timber.i("Querying box %s for buildings", box); - - Expression filter = lt(toNumber(get("height")), literal(10)); - List<Feature> features = mapboxMap.queryRenderedFeatures(box, filter, "building"); - - // Show count - Toast.makeText( - QueryRenderedFeaturesBoxHighlightActivity.this, - String.format("%s features in box", features.size()), - Toast.LENGTH_SHORT).show(); - - // Update source data - source.setGeoJson(FeatureCollection.fromFeatures(features)); - }); - - mapboxMap.setStyle(new Style.Builder() - .fromUri(Style.MAPBOX_STREETS) - .withSource(source) - .withLayer(layer) - ); - }); - } - - public MapboxMap getMapboxMap() { - return mapboxMap; - } - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @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(); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxSymbolCountActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxSymbolCountActivity.java deleted file mode 100644 index 22daf262d8..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxSymbolCountActivity.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.activity.feature; - -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.RectF; -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.view.View; -import android.widget.Toast; - -import com.mapbox.geojson.Feature; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.maps.Style; -import com.mapbox.mapboxsdk.style.layers.BackgroundLayer; -import com.mapbox.mapboxsdk.style.layers.SymbolLayer; -import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; -import com.mapbox.mapboxsdk.testapp.R; -import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils; - -import java.io.IOException; -import java.util.List; - -import timber.log.Timber; - -import static com.mapbox.mapboxsdk.style.expressions.Expression.rgb; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundColor; -import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage; - -/** - * Test activity showcasing using the query rendered features API to count Symbols in a rectangle. - */ -public class QueryRenderedFeaturesBoxSymbolCountActivity extends AppCompatActivity { - - public MapView mapView; - private MapboxMap mapboxMap; - - private Toast toast; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_query_features_box); - - final View selectionBox = findViewById(R.id.selection_box); - - // Initialize map as normal - mapView = (MapView) findViewById(R.id.mapView); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(mapboxMap -> { - QueryRenderedFeaturesBoxSymbolCountActivity.this.mapboxMap = mapboxMap; - - try { - String testPoints = ResourceUtils.readRawResource(mapView.getContext(), R.raw.test_points_utrecht); - Bitmap markerImage = BitmapFactory.decodeResource(getResources(), R.drawable.mapbox_marker_icon_default); - - mapboxMap.setStyle(new Style.Builder() - .withLayer( - new BackgroundLayer("bg") - .withProperties( - backgroundColor(rgb(120, 161, 226)) - ) - ) - .withLayer( - new SymbolLayer("symbols-layer", "symbols-source") - .withProperties( - iconImage("test-icon") - ) - ) - .withSource( - new GeoJsonSource("symbols-source", testPoints) - ) - .withImage("test-icon", markerImage) - ); - } catch (IOException exception) { - exception.printStackTrace(); - } - - selectionBox.setOnClickListener(view -> { - // 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()); - Timber.i("Querying box %s", box); - List<Feature> features = mapboxMap.queryRenderedFeatures(box, "symbols-layer"); - - // Show count - if (toast != null) { - toast.cancel(); - } - toast = Toast.makeText( - QueryRenderedFeaturesBoxSymbolCountActivity.this, - String.format("%s features in box", features.size()), - Toast.LENGTH_SHORT); - toast.show(); - }); - }); - } - - public MapboxMap getMapboxMap() { - return mapboxMap; - } - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @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(); - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesPropertiesActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesPropertiesActivity.java deleted file mode 100644 index f2f22bae9e..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesPropertiesActivity.java +++ /dev/null @@ -1,244 +0,0 @@ -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.AppCompatActivity; -import android.view.View; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.google.gson.JsonElement; -import com.mapbox.geojson.Feature; -import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; -import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.maps.Style; -import com.mapbox.mapboxsdk.testapp.R; - - -import java.util.List; -import java.util.Map; - -import timber.log.Timber; - -/** - * Test activity showcasing using the query rendered features API to query feature properties on Map click. - */ -public class QueryRenderedFeaturesPropertiesActivity extends AppCompatActivity { - - public MapView mapView; - private MapboxMap mapboxMap; - private Marker marker; - - private MapboxMap.OnMapClickListener mapClickListener = new MapboxMap.OnMapClickListener() { - @Override - public boolean onMapClick(@NonNull LatLng point) { - final float density = getResources().getDisplayMetrics().density; - final PointF pixel = mapboxMap.getProjection().toScreenLocation(point); - Timber.i( - "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); - return true; - } - }; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_query_features_point); - - // Initialize map as normal - mapView = (MapView) findViewById(R.id.mapView); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(mapboxMap -> { - mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> { - QueryRenderedFeaturesPropertiesActivity.this.mapboxMap = mapboxMap; - - // Add custom window adapter - addCustomInfoWindowAdapter(mapboxMap); - - // Add a click listener - mapboxMap.addOnMapClickListener(mapClickListener); - }); - }); - } - - private void debugOutput(List<Feature> features) { - Timber.i("Got %s features", features.size()); - for (Feature feature : features) { - if (feature != null) { - Timber.i("Got feature %s with %s properties and Geometry %s", - feature.id(), - feature.properties() != null ? feature.properties().entrySet().size() : "<null>", - feature.geometry() != null ? feature.geometry().getClass().getSimpleName() : "<null>" - ); - if (feature.properties() != null) { - for (Map.Entry<String, JsonElement> entry : feature.properties().entrySet()) { - Timber.i("Prop %s - %s", entry.getKey(), entry.getValue()); - } - } - } else { - Timber.i("Got NULL feature"); - } - } - } - - 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; - } - - @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.properties().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 - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - mapView.onSaveInstanceState(outState); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - if (mapboxMap != null) { - mapboxMap.removeOnMapClickListener(mapClickListener); - } - mapView.onDestroy(); - } - - @Override - public void onLowMemory() { - super.onLowMemory(); - mapView.onLowMemory(); - } - - private static class CustomMarker extends Marker { - - private final List<Feature> features; - - 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; - } - - 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 - } - } -} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QuerySourceFeaturesActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QuerySourceFeaturesActivity.java deleted file mode 100644 index f7d5a39e4a..0000000000 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QuerySourceFeaturesActivity.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.mapbox.mapboxsdk.testapp.activity.feature; - -import android.os.Bundle; -import android.support.design.widget.FloatingActionButton; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AppCompatActivity; -import android.widget.Toast; -import com.google.gson.JsonObject; -import com.mapbox.geojson.Feature; -import com.mapbox.geojson.FeatureCollection; -import com.mapbox.geojson.Point; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.maps.Style; -import com.mapbox.mapboxsdk.style.expressions.Expression; -import com.mapbox.mapboxsdk.style.layers.CircleLayer; -import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; -import com.mapbox.mapboxsdk.testapp.R; - -import java.util.List; - -import static com.mapbox.mapboxsdk.style.expressions.Expression.eq; -import static com.mapbox.mapboxsdk.style.expressions.Expression.get; -import static com.mapbox.mapboxsdk.style.expressions.Expression.literal; -import static com.mapbox.mapboxsdk.style.expressions.Expression.neq; - -/** - * Test activity showcasing using the query source features API to query feature counts - */ -public class QuerySourceFeaturesActivity extends AppCompatActivity { - - public MapView mapView; - private MapboxMap mapboxMap; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_query_source_features); - - // Initialize map as normal - mapView = (MapView) findViewById(R.id.mapView); - mapView.onCreate(savedInstanceState); - mapView.getMapAsync(map -> { - this.mapboxMap = map; - mapboxMap.getStyle(this::initStyle); - mapboxMap.setStyle(Style.MAPBOX_STREETS); - }); - } - - private void initStyle(Style style) { - JsonObject properties = new JsonObject(); - properties.addProperty("key1", "value1"); - final GeoJsonSource source = new GeoJsonSource("test-source", - FeatureCollection.fromFeatures(new Feature[] { - Feature.fromGeometry(Point.fromLngLat(17.1, 51), properties), - Feature.fromGeometry(Point.fromLngLat(17.2, 51), properties), - Feature.fromGeometry(Point.fromLngLat(17.3, 51), properties), - Feature.fromGeometry(Point.fromLngLat(17.4, 51), properties), - })); - style.addSource(source); - - Expression visible = eq(get("key1"), literal("value1")); - Expression invisible = neq(get("key1"), literal("value1")); - - CircleLayer layer = new CircleLayer("test-layer", source.getId()) - .withFilter(visible); - style.addLayer(layer); - - // Add a click listener - mapboxMap.addOnMapClickListener(point -> { - // Query - List<Feature> features = source.querySourceFeatures(eq(get("key1"), literal("value1"))); - Toast.makeText(QuerySourceFeaturesActivity.this, String.format("Found %s features", - features.size()), Toast.LENGTH_SHORT).show(); - - return false; - }); - - FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); - fab.setColorFilter(ContextCompat.getColor(this, R.color.primary)); - fab.setOnClickListener(view -> { - Expression visibility = layer.getFilter(); - if (visibility != null && visibility.equals(visible)) { - layer.setFilter(invisible); - fab.setImageResource(R.drawable.ic_layers_clear); - } else { - layer.setFilter(visible); - fab.setImageResource(R.drawable.ic_layers); - } - }); - } - - @Override - protected void onStart() { - super.onStart(); - mapView.onStart(); - } - - @Override - protected void onResume() { - super.onResume(); - mapView.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mapView.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - mapView.onStop(); - } - - @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(); - } -} |