From 899df59035c440d5cc61e7ffd52cd993a1ac02f8 Mon Sep 17 00:00:00 2001 From: tobrun Date: Mon, 10 Jun 2019 12:54:38 +0200 Subject: [android] - fix reset behavior for setLatLngBoundsForCameraTarget --- .../java/com/mapbox/mapboxsdk/maps/NativeMap.java | 2 +- .../maplayout/LatLngBoundsForCameraActivity.java | 26 +++++++++++++--------- .../src/main/res/menu/menu_bounds.xml | 4 ++++ .../src/main/res/values/actions.xml | 1 + platform/android/src/native_map_view.cpp | 2 +- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java index 7692c1a9f2..da70013713 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java @@ -63,7 +63,7 @@ interface NativeMap { LatLng getLatLng(); - void setLatLngBounds(@NonNull LatLngBounds latLngBounds); + void setLatLngBounds(@Nullable LatLngBounds latLngBounds); void setVisibleCoordinateBounds(@NonNull LatLng[] coordinates, @NonNull RectF padding, double direction, long duration); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LatLngBoundsForCameraActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LatLngBoundsForCameraActivity.java index 1a9d3d300b..2493aa00e5 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LatLngBoundsForCameraActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LatLngBoundsForCameraActivity.java @@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.testapp.activity.maplayout; import android.graphics.Color; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.view.Gravity; import android.view.Menu; @@ -76,25 +77,30 @@ public class LatLngBoundsForCameraActivity extends AppCompatActivity implements case R.id.menu_action_cross_idl: setupBounds(CROSS_IDL_BOUNDS); return true; + case R.id.menu_action_reset: + setupBounds(null); + return true; } return super.onOptionsItemSelected(item); } - private void setupBounds(LatLngBounds bounds) { + private void setupBounds(@Nullable LatLngBounds bounds) { mapboxMap.setLatLngBoundsForCameraTarget(bounds); showBoundsArea(bounds); } - private void showBoundsArea(LatLngBounds bounds) { + private void showBoundsArea(@Nullable LatLngBounds bounds) { mapboxMap.clear(); - PolygonOptions boundsArea = new PolygonOptions() - .add(bounds.getNorthWest()) - .add(bounds.getNorthEast()) - .add(bounds.getSouthEast()) - .add(bounds.getSouthWest()); - boundsArea.alpha(0.25f); - boundsArea.fillColor(Color.RED); - mapboxMap.addPolygon(boundsArea); + if (bounds != null) { + PolygonOptions boundsArea = new PolygonOptions() + .add(bounds.getNorthWest()) + .add(bounds.getNorthEast()) + .add(bounds.getSouthEast()) + .add(bounds.getSouthWest()); + boundsArea.alpha(0.25f); + boundsArea.fillColor(Color.RED); + mapboxMap.addPolygon(boundsArea); + } } private void showCrosshair() { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_bounds.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_bounds.xml index db7aad6d1f..4b39a392a0 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_bounds.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_bounds.xml @@ -9,4 +9,8 @@ android:id="@+id/menu_action_cross_idl" android:title="@string/restrict_across_idl" app:showAsAction="never"/> + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/actions.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/actions.xml index 7513baaa36..d36c741c50 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/actions.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/actions.xml @@ -90,4 +90,5 @@ Zoom to 4 Restrict almost worldview Restrict across IDL + Reset bounds \ No newline at end of file diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 8493110d75..48b65c4c02 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -314,7 +314,7 @@ void NativeMapView::setLatLngBounds(jni::JNIEnv& env, const jni::ObjectsetBounds(bounds); } -- cgit v1.2.1