[android] - add binding integration for Map::setLatLngbounds, add example (#8622)
This commit is contained in:
@@ -6,6 +6,7 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to
|
||||
|
||||
5.1.0 builds further on 5.0.1 and adds:
|
||||
|
||||
* Limit Viewport [#8622](https://github.com/mapbox/mapbox-gl-native/pull/8622)
|
||||
* Transition Properties for Layer attributes [#8509](https://github.com/mapbox/mapbox-gl-native/pull/8509)
|
||||
* Style wide transition duration and transition offset in milliseconds [#8576](https://github.com/mapbox/mapbox-gl-native/pull/8576)
|
||||
* Transifex integration, Catalan & Dutch translations [#8556](https://github.com/mapbox/mapbox-gl-native/pull/8556)
|
||||
|
||||
@@ -36,6 +36,7 @@ import com.mapbox.mapboxsdk.constants.MyBearingTracking;
|
||||
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
|
||||
import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
|
||||
import com.mapbox.mapboxsdk.style.layers.Filter;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
@@ -1504,6 +1505,22 @@ public final class MapboxMap {
|
||||
return annotationManager.getInfoWindowManager().isAllowConcurrentMultipleOpenInfoWindows();
|
||||
}
|
||||
|
||||
//
|
||||
// LatLngBounds
|
||||
//
|
||||
|
||||
/**
|
||||
* Sets a LatLngBounds that constraints map transformations to this bounds.
|
||||
* <p>
|
||||
* Set to null to clear current bounds, newly set bounds will override previously set bounds.
|
||||
* </p>
|
||||
*
|
||||
* @param latLngBounds the bounds to constrain the map with
|
||||
*/
|
||||
public void setLatLngBoundsForCameraTarget(@Nullable LatLngBounds latLngBounds) {
|
||||
nativeMapView.setLatLngBounds(latLngBounds);
|
||||
}
|
||||
|
||||
//
|
||||
// Padding
|
||||
//
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.mapbox.mapboxsdk.annotations.Polygon;
|
||||
import com.mapbox.mapboxsdk.annotations.Polyline;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
|
||||
import com.mapbox.mapboxsdk.storage.FileSource;
|
||||
import com.mapbox.mapboxsdk.style.layers.CannotAddLayerException;
|
||||
@@ -259,6 +260,13 @@ final class NativeMapView {
|
||||
return nativeGetStyleJson();
|
||||
}
|
||||
|
||||
public void setLatLngBounds(LatLngBounds latLngBounds) {
|
||||
if (isDestroyedOn("setLatLngBounds")) {
|
||||
return;
|
||||
}
|
||||
nativeSetLatLngBounds(latLngBounds);
|
||||
}
|
||||
|
||||
public void cancelTransitions() {
|
||||
if (isDestroyedOn("cancelTransitions")) {
|
||||
return;
|
||||
@@ -999,6 +1007,8 @@ final class NativeMapView {
|
||||
|
||||
private native String nativeGetStyleJson();
|
||||
|
||||
private native void nativeSetLatLngBounds(LatLngBounds latLngBounds);
|
||||
|
||||
private native void nativeCancelTransitions();
|
||||
|
||||
private native void nativeSetGestureInProgress(boolean inProgress);
|
||||
|
||||
@@ -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
|
||||
//
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include "bitmap.hpp"
|
||||
#include "run_loop_impl.hpp"
|
||||
#include "java/util.hpp"
|
||||
#include "geometry/lat_lng_bounds.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
@@ -354,6 +355,14 @@ void NativeMapView::setStyleJson(jni::JNIEnv& env, jni::String json) {
|
||||
map->setStyleJSON(jni::Make<std::string>(env, json));
|
||||
}
|
||||
|
||||
void NativeMapView::setLatLngBounds(jni::JNIEnv& env, jni::Object<mbgl::android::LatLngBounds> jBounds) {
|
||||
if (jBounds) {
|
||||
map->setLatLngBounds(mbgl::android::LatLngBounds::getLatLngBounds(env, jBounds));
|
||||
} else {
|
||||
map->setLatLngBounds(mbgl::LatLngBounds::world());
|
||||
}
|
||||
}
|
||||
|
||||
void NativeMapView::cancelTransitions(jni::JNIEnv&) {
|
||||
map->cancelTransitions();
|
||||
}
|
||||
@@ -1560,7 +1569,8 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
|
||||
METHOD(&NativeMapView::removeSourceById, "nativeRemoveSourceById"),
|
||||
METHOD(&NativeMapView::removeSource, "nativeRemoveSource"),
|
||||
METHOD(&NativeMapView::addImage, "nativeAddImage"),
|
||||
METHOD(&NativeMapView::removeImage, "nativeRemoveImage")
|
||||
METHOD(&NativeMapView::removeImage, "nativeRemoveImage"),
|
||||
METHOD(&NativeMapView::setLatLngBounds, "nativeSetLatLngBounds")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "geometry/projected_meters.hpp"
|
||||
#include "style/layers/layers.hpp"
|
||||
#include "style/sources/sources.hpp"
|
||||
#include "geometry/lat_lng_bounds.hpp"
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
@@ -110,6 +111,8 @@ public:
|
||||
|
||||
void setStyleJson(jni::JNIEnv&, jni::String);
|
||||
|
||||
void setLatLngBounds(jni::JNIEnv&, jni::Object<mbgl::android::LatLngBounds>);
|
||||
|
||||
void cancelTransitions(jni::JNIEnv&);
|
||||
|
||||
void setGestureInProgress(jni::JNIEnv&, jni::jboolean);
|
||||
|
||||
Reference in New Issue
Block a user