[android] - add binding integration for Map::setLatLngbounds, add example (#8622)

This commit is contained in:
Tobrun
2017-04-13 16:06:09 +02:00
committed by GitHub
parent 0810192163
commit 21f54cc506
10 changed files with 206 additions and 3 deletions

View File

@@ -19,6 +19,7 @@ import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource;
@@ -107,6 +108,25 @@ public class MapboxMapTest {
}));
}
//
// CameraForLatLngBounds
//
@Test
public void testCameraForLatLngBounds() {
ViewUtils.checkViewIsDisplayed(R.id.mapView);
final MapboxMap mapboxMap = activity.getMapboxMap();
onView(withId(R.id.mapView)).perform(new MapboxMapAction(new InvokeViewAction() {
@Override
public void onViewAction(UiController uiController, View view) {
// set
mapboxMap.setLatLngBoundsForCameraTarget(
new LatLngBounds.Builder().include(new LatLng()).include(new LatLng(1, 1)).build());
// reset
mapboxMap.setLatLngBoundsForCameraTarget(null);
}
}));
}
//
// MinZoomLevel
//

View File

@@ -592,6 +592,17 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity"/>
</activity>
<activity
android:name=".activity.maplayout.LatLngBoundsForCameraActivity"
android:description="@string/description_restricted_bounds"
android:label="@string/activity_restricted_bounds">
<meta-data
android:name="@string/category"
android:value="@string/category_maplayout"/>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity"/>
</activity>
<!-- Storage -->
<activity
@@ -611,9 +622,11 @@
<activity
android:name=".activity.style.RuntimeStyleTestActivity"
android:screenOrientation="portrait"/>
<activity android:name=".activity.style.RuntimeStyleTimingTestActivity"
<activity
android:name=".activity.style.RuntimeStyleTimingTestActivity"
android:screenOrientation="portrait"/>
<activity android:name=".activity.espresso.EspressoTestActivity"
<activity
android:name=".activity.espresso.EspressoTestActivity"
android:screenOrientation="portrait"/>
<!-- Configuration Settings -->

View File

@@ -0,0 +1,109 @@
package com.mapbox.mapboxsdk.testapp.activity.maplayout;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
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;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.testapp.R;
/**
* Test Activity showcasing restricting user gestures to a bounds around Iceland.
*/
public class LatLngBoundsForCameraActivity extends AppCompatActivity implements OnMapReadyCallback {
private static final LatLngBounds ICELAND_BOUNDS = new LatLngBounds.Builder()
.include(new LatLng(66.852863, -25.985652))
.include(new LatLng(62.985661, -12.626277))
.build();
private MapView mapView;
private MapboxMap mapboxMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_restricted_bounds);
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
}
@Override
public void onMapReady(MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
mapboxMap.setLatLngBoundsForCameraTarget(ICELAND_BOUNDS);
mapboxMap.setMinZoomPreference(2);
showBoundsArea();
showCrosshair();
}
private void showBoundsArea() {
PolygonOptions boundsArea = new PolygonOptions()
.add(ICELAND_BOUNDS.getNorthWest())
.add(ICELAND_BOUNDS.getNorthEast())
.add(ICELAND_BOUNDS.getSouthEast())
.add(ICELAND_BOUNDS.getSouthWest());
boundsArea.alpha(0.25f);
boundsArea.fillColor(Color.RED);
mapboxMap.addPolygon(boundsArea);
}
private void showCrosshair() {
View crosshair = new View(this);
crosshair.setLayoutParams(new FrameLayout.LayoutParams(10, 10, Gravity.CENTER));
crosshair.setBackgroundColor(Color.BLUE);
mapView.addView(crosshair);
}
@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();
}
}

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.mapbox.mapboxsdk.maps.MapView
android:id="@id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:mapbox_cameraTargetLat="64.840048"
app:mapbox_cameraTargetLng="-18.910457"
app:mapbox_cameraZoom="4"
app:mapbox_styleUrl="@string/mapbox_style_satellite_streets"/>
</android.support.design.widget.CoordinatorLayout>

View File

@@ -55,6 +55,7 @@
<string name="activity_map_in_dialog">Dialog with map</string>
<string name="activity_marker_view_rectangle">Marker views in rectangle</string>
<string name="activity_url_transform">Url transform</string>
<string name="activity_restricted_bounds">Restrict camera to a bounds</string>
<!--Description-->
<string name="description_user_location_tracking">Tracks the location of the user</string>
@@ -109,6 +110,7 @@
<string name="description_marker_view_rectangle">Marker Views within a rectangle</string>
<string name="description_circle_layer">Show bus stops and route in Singapore</string>
<string name="description_url_transform">Transform urls on the fly</string>
<string name="description_restricted_bounds">Limit viewport to Iceland</string>
<!--Categories-->
<string name="category">category</string>