[android] - move calculation of LatLngBounds to core (#8765)
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.camera;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdate;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
@@ -11,14 +13,8 @@ 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.maps.UiSettings;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
/**
|
||||
* Test activity showcasing using the LatLngBounds camera API.
|
||||
* <p>
|
||||
@@ -31,6 +27,9 @@ public class LatLngBoundsActivity extends AppCompatActivity implements OnMapRead
|
||||
private static final LatLng LOS_ANGELES = new LatLng(34.053940, -118.242622);
|
||||
private static final LatLng NEW_YORK = new LatLng(40.712730, -74.005953);
|
||||
|
||||
private final LatLng CHINA_BOTTOM_LEFT = new LatLng(15.68169, 73.499857);
|
||||
private final LatLng CHINA_TOP_RIGHT = new LatLng(53.560711, 134.77281);
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
|
||||
@@ -46,41 +45,31 @@ public class LatLngBoundsActivity extends AppCompatActivity implements OnMapRead
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(MapboxMap map) {
|
||||
public void onMapReady(final MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
UiSettings uiSettings = mapboxMap.getUiSettings();
|
||||
uiSettings.setAllGesturesEnabled(false);
|
||||
moveToBounds(new LatLngBounds.Builder().include(NEW_YORK).include(LOS_ANGELES).build(), new int[] {0, 0, 0, 0});
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
moveToBounds(new LatLngBounds.Builder().include(CHINA_BOTTOM_LEFT).include(CHINA_TOP_RIGHT).build(),
|
||||
new int[] {100, 100, 100, 100 });
|
||||
}
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
mapboxMap.addMarker(new MarkerOptions()
|
||||
.title("Los Angeles")
|
||||
.snippet("City Hall")
|
||||
.position(LOS_ANGELES));
|
||||
|
||||
mapboxMap.addMarker(new MarkerOptions()
|
||||
.title("New York")
|
||||
.snippet("City Hall")
|
||||
.position(NEW_YORK));
|
||||
|
||||
List<LatLng> points = new ArrayList<>();
|
||||
points.add(NEW_YORK);
|
||||
points.add(LOS_ANGELES);
|
||||
|
||||
// Create Bounds
|
||||
final LatLngBounds bounds = new LatLngBounds.Builder()
|
||||
.includes(points)
|
||||
.build();
|
||||
|
||||
// Add map padding
|
||||
int mapPadding = (int) getResources().getDimension(R.dimen.fab_margin);
|
||||
mapboxMap.setPadding(mapPadding, mapPadding, mapPadding, mapPadding);
|
||||
|
||||
// Move camera to the bounds with added padding
|
||||
int padding = (int) getResources().getDimension(R.dimen.coordinatebounds_margin);
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding), 1500);
|
||||
|
||||
// Log data
|
||||
Timber.e("Move to bounds: " + bounds.toString());
|
||||
Timber.e("Resulting bounds:" + mapboxMap.getProjection().getVisibleRegion().latLngBounds.toString());
|
||||
private void moveToBounds(LatLngBounds latLngBounds, int[] padding) {
|
||||
mapboxMap.clear();
|
||||
mapboxMap.addMarker(new MarkerOptions().position(latLngBounds.getNorthEast()));
|
||||
mapboxMap.addMarker(new MarkerOptions().position(latLngBounds.getSouthEast()));
|
||||
mapboxMap.addMarker(new MarkerOptions().position(latLngBounds.getSouthWest()));
|
||||
mapboxMap.addMarker(new MarkerOptions().position(latLngBounds.getNorthWest()));
|
||||
CameraUpdate update =
|
||||
CameraUpdateFactory.newLatLngBounds(latLngBounds,
|
||||
padding[0],
|
||||
padding[1],
|
||||
padding[2],
|
||||
padding[3]);
|
||||
mapboxMap.moveCamera(update);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -60,22 +60,6 @@ public class CameraPositionTest {
|
||||
assertEquals("zoom should match", zoom, cameraPosition.zoom, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJniBuilder() {
|
||||
double bearing = 180;
|
||||
double zoom = 12;
|
||||
double latitude = 10;
|
||||
double longitude = 11;
|
||||
double tilt = 44;
|
||||
|
||||
double[] cameraVars = new double[]{latitude, longitude, bearing, tilt, zoom};
|
||||
CameraPosition cameraPosition = new CameraPosition.Builder(cameraVars).build();
|
||||
assertEquals("bearing should match", bearing, cameraPosition.bearing, DELTA);
|
||||
assertEquals("latlng should match", new LatLng(latitude, longitude), cameraPosition.target);
|
||||
assertEquals("tilt should match", tilt, cameraPosition.tilt, DELTA);
|
||||
assertEquals("zoom should match", zoom, cameraPosition.zoom, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
LatLng latLng = new LatLng(1, 2);
|
||||
|
||||
Reference in New Issue
Block a user