[android] - fix reset behavior for setLatLngBoundsForCameraTarget

This commit is contained in:
tobrun
2019-06-10 12:54:38 +02:00
committed by Tobrun
parent 6262b83cc6
commit df062afe6d
5 changed files with 23 additions and 12 deletions

View File

@@ -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);

View File

@@ -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() {

View File

@@ -9,4 +9,8 @@
android:id="@+id/menu_action_cross_idl"
android:title="@string/restrict_across_idl"
app:showAsAction="never"/>
<item
android:id="@+id/menu_action_reset"
android:title="@string/restrict_reset"
app:showAsAction="never"/>
</menu>

View File

@@ -90,4 +90,5 @@
<string name="zoom_to_4">Zoom to 4</string>
<string name="restrict_almost_worldview">Restrict almost worldview</string>
<string name="restrict_across_idl">Restrict across IDL</string>
<string name="restrict_reset">Reset bounds</string>
</resources>

View File

@@ -314,7 +314,7 @@ void NativeMapView::setLatLngBounds(jni::JNIEnv& env, const jni::Object<mbgl::an
if (jBounds) {
bounds.withLatLngBounds(mbgl::android::LatLngBounds::getLatLngBounds(env, jBounds));
} else {
bounds.withLatLngBounds(mbgl::LatLngBounds::world());
bounds.withLatLngBounds(mbgl::LatLngBounds::unbounded());
}
map->setBounds(bounds);
}