diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/main')
3 files changed, 60 insertions, 10 deletions
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 5e6e828856..1a9d3d300b 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 @@ -5,9 +5,10 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; import android.view.Gravity; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.widget.FrameLayout; - import com.mapbox.mapboxsdk.annotations.PolygonOptions; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngBounds; @@ -18,7 +19,7 @@ import com.mapbox.mapboxsdk.maps.Style; import com.mapbox.mapboxsdk.testapp.R; /** - * Test activity showcasing restricting user gestures to a bounds around Iceland. + * Test activity showcasing restricting user gestures to a bounds around Iceland, almost worldview and IDL. */ public class LatLngBoundsForCameraActivity extends AppCompatActivity implements OnMapReadyCallback { @@ -27,6 +28,16 @@ public class LatLngBoundsForCameraActivity extends AppCompatActivity implements .include(new LatLng(62.985661, -12.626277)) .build(); + private static final LatLngBounds ALMOST_WORLD_BOUNDS = new LatLngBounds.Builder() + .include(new LatLng(20.0, 170.0)) + .include(new LatLng(-20, -170.0)) + .build(); + + private static final LatLngBounds CROSS_IDL_BOUNDS = new LatLngBounds.Builder() + .include(new LatLng(20.0, 170.0)) + .include(new LatLng(-20, 190.0)) + .build(); + private MapView mapView; private MapboxMap mapboxMap; @@ -35,7 +46,7 @@ public class LatLngBoundsForCameraActivity extends AppCompatActivity implements super.onCreate(savedInstanceState); setContentView(R.layout.activity_restricted_bounds); - mapView = (MapView) findViewById(R.id.mapView); + mapView = findViewById(R.id.mapView); mapView.onCreate(savedInstanceState); mapView.getMapAsync(this); } @@ -44,18 +55,43 @@ public class LatLngBoundsForCameraActivity extends AppCompatActivity implements public void onMapReady(@NonNull MapboxMap mapboxMap) { this.mapboxMap = mapboxMap; mapboxMap.setStyle(Style.SATELLITE_STREETS); - mapboxMap.setLatLngBoundsForCameraTarget(ICELAND_BOUNDS); mapboxMap.setMinZoomPreference(2); - showBoundsArea(); + mapboxMap.getUiSettings().setFlingVelocityAnimationEnabled(false); showCrosshair(); + setupBounds(ICELAND_BOUNDS); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu_bounds, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_action_allmost_world_bounds: + setupBounds(ALMOST_WORLD_BOUNDS); + return true; + case R.id.menu_action_cross_idl: + setupBounds(CROSS_IDL_BOUNDS); + return true; + } + return super.onOptionsItemSelected(item); + } + + private void setupBounds(LatLngBounds bounds) { + mapboxMap.setLatLngBoundsForCameraTarget(bounds); + showBoundsArea(bounds); } - private void showBoundsArea() { + private void showBoundsArea(LatLngBounds bounds) { + mapboxMap.clear(); PolygonOptions boundsArea = new PolygonOptions() - .add(ICELAND_BOUNDS.getNorthWest()) - .add(ICELAND_BOUNDS.getNorthEast()) - .add(ICELAND_BOUNDS.getSouthEast()) - .add(ICELAND_BOUNDS.getSouthWest()); + .add(bounds.getNorthWest()) + .add(bounds.getNorthEast()) + .add(bounds.getSouthEast()) + .add(bounds.getSouthWest()); boundsArea.alpha(0.25f); boundsArea.fillColor(Color.RED); mapboxMap.addPolygon(boundsArea); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_bounds.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_bounds.xml new file mode 100644 index 0000000000..db7aad6d1f --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_bounds.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<menu xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto"> + <item + android:id="@+id/menu_action_allmost_world_bounds" + android:title="@string/restrict_almost_worldview" + app:showAsAction="never"/> + <item + android:id="@+id/menu_action_cross_idl" + android:title="@string/restrict_across_idl" + app:showAsAction="never"/> +</menu> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/actions.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/actions.xml index e3cdc06dc1..7513baaa36 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/actions.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/actions.xml @@ -88,4 +88,6 @@ <string name="zoom_by_2">Zoom by 2</string> <string name="zoom_to_point">Zoom to point</string> <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> </resources>
\ No newline at end of file |