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

Commit

Permalink
[android] - fix reset behavior for setLatLngBoundsForCameraTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Jun 10, 2019
1 parent 0bab912 commit 899df59
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void easeTo(@NonNull LatLng center, double zoom, double bearing, double pitch, l

LatLng getLatLng();

void setLatLngBounds(@NonNull LatLngBounds latLngBounds);
void setLatLngBounds(@Nullable LatLngBounds latLngBounds);

void setVisibleCoordinateBounds(@NonNull LatLng[] coordinates, @NonNull RectF padding,
double direction, long duration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand Down Expand Up @@ -76,25 +77,30 @@ public boolean onOptionsItemSelected(MenuItem item) {
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 1 addition & 1 deletion platform/android/src/native_map_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 899df59

Please sign in to comment.