summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun <tobrun@mapbox.com>2016-02-02 11:21:47 +0100
committerTobrun <tobrun@mapbox.com>2016-02-02 17:25:46 +0100
commit6dff169f2b2085f1de2b6c568f61b3d506b9374b (patch)
tree246bc43212c7bda0719454df0df5e1c42d562ba4
parenta699690c1689222f518b5d7adc0dfd059884ac49 (diff)
downloadqtlocation-mapboxgl-6dff169f2b2085f1de2b6c568f61b3d506b9374b.tar.gz
[android] #3754 - newLatLngBounds: unit tests for LatLng and LatLngBounds, builder pattern + refactoring.
[android] #3754 - Working version using the underlying VisibleCoorindateBounds [android] #3754 - refactor Camera api inside maps package, correctly use factory pattern, LatLngBounds hooks into camera API [android] #3754 - cleanup old API
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java9
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java5
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java225
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidLatLngBoundsException.java8
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateBounds.java93
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateRegion.java64
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java90
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraUpdate.java12
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraUpdateFactory.java362
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java6
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java87
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java113
-rwxr-xr-xplatform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java1
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java6
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UserLocationView.java1
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MathUtils.java11
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/BulkMarkerActivity.java2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CoordinateChangeActivity.java3
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DirectionsActivity.java2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ManualZoomActivity.java2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapFragmentActivity.java2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapboxMapActivity.java2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MaxMinZoomActivity.java2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MyLocationTrackingModeActivity.java2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/SupportMapFragmentActivity.java2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/VisibleCoordinateBoundsActivity.java27
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java160
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngTest.java (renamed from platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/LatLngTest.java)35
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateBoundsTest.java60
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateRegionTest.java56
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java2
34 files changed, 690 insertions, 768 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java
index 6b059ed475..1b7bcba32e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java
@@ -9,8 +9,7 @@ import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.MathConstants;
import com.mapbox.mapboxsdk.geometry.LatLng;
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.CameraUpdateFactory;
import com.mapbox.mapboxsdk.utils.MathUtils;
public final class CameraPosition implements Parcelable {
@@ -161,11 +160,11 @@ public final class CameraPosition implements Parcelable {
}
/**
- * Create Builder from an existing PositionCameraUpdate update.
+ * Create Builder from an existing CameraPositionUpdate update.
*
* @param update Update containing camera options
*/
- public Builder(CameraUpdateFactory.PositionCameraUpdate update) {
+ public Builder(CameraUpdateFactory.CameraPositionUpdate update) {
super();
if (update != null) {
this.bearing = update.getBearing();
@@ -177,7 +176,7 @@ public final class CameraPosition implements Parcelable {
/**
- * Create Builder from an existing PositionCameraUpdate update.
+ * Create Builder from an existing CameraPositionUpdate update.
*
* @param update Update containing camera options
*/
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java
deleted file mode 100644
index 61f3a2ecfa..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.mapbox.mapboxsdk.camera;
-
-public interface CameraUpdate {
-
-}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java
deleted file mode 100644
index 73986c8971..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java
+++ /dev/null
@@ -1,225 +0,0 @@
-package com.mapbox.mapboxsdk.camera;
-
-import android.graphics.Point;
-import android.support.annotation.IntDef;
-import android.support.annotation.NonNull;
-
-import com.mapbox.mapboxsdk.geometry.LatLng;
-import com.mapbox.mapboxsdk.geometry.LatLngBounds;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-public class CameraUpdateFactory {
-
- /**
- * Returns a CameraUpdate that moves the camera to a specified CameraPosition.
- *
- * @param cameraPosition Camera Position to change to
- * @return CameraUpdate Final Camera Position data
- */
- public static CameraUpdate newCameraPosition(@NonNull CameraPosition cameraPosition) {
- return new PositionCameraUpdate(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom);
- }
-
- /**
- * Returns a CameraUpdate that moves the center of the screen to a latitude and longitude
- * specified by a LatLng object. This centers the camera on the LatLng object.
- *
- * @param latLng
- * @return
- */
- public static CameraUpdate newLatLng(@NonNull LatLng latLng) {
- return new PositionCameraUpdate(-1, latLng, -1, -1);
- }
-
- /**
- * Returns a CameraUpdate that transforms the camera such that the specified latitude/longitude
- * bounds are centered on screen at the greatest possible zoom level.
- * You can specify padding, in order to inset the bounding box from the map view's edges.
- * The returned CameraUpdate has a bearing of 0 and a tilt of 0.
- *
- * @param bounds
- * @param padding
- * @return
- */
- public static CameraUpdate newLatLngBounds(@NonNull LatLngBounds bounds, int padding) {
- throw new UnsupportedOperationException("Not implemented yet");
- }
-
- /**
- * Returns a CameraUpdate that transforms the camera such that the specified latitude/longitude
- * bounds are centered on screen within a bounding box of specified dimensions at the greatest
- * possible zoom level. You can specify additional padding, to further restrict the size of
- * the bounding box. The returned CameraUpdate has a bearing of 0 and a tilt of 0.
- *
- * @param bounds
- * @param width
- * @param height
- * @param padding
- * @return
- */
- public static CameraUpdate newLatLngBounds(@NonNull LatLngBounds bounds, int width, int height, int padding) {
- throw new UnsupportedOperationException("Not implemented yet");
- }
-
- /**
- * Returns a CameraUpdate that moves the center of the screen to a latitude and longitude specified by a LatLng object, and moves to the given zoom level.
- *
- * @param latLng
- * @param zoom
- * @return
- */
- public static CameraUpdate newLatLngZoom(@NonNull LatLng latLng, float zoom) {
- return new PositionCameraUpdate(-1, latLng, -1, zoom);
- }
-
- /**
- * Returns a CameraUpdate that scrolls the camera over the map, shifting the center of view by the specified number of pixels in the x and y directions.
- *
- * @param xPixel
- * @param yPixel
- * @return
- */
- public static CameraUpdate scrollBy(float xPixel, float yPixel) {
- throw new UnsupportedOperationException("Not implemented yet");
- }
-
- /**
- * Returns a CameraUpdate that shifts the zoom level of the current camera viewpoint.
- *
- * @param amount
- * @param focus
- * @return
- */
- public static CameraUpdate zoomBy(float amount, Point focus) {
- return new ZoomUpdate(amount, focus.x, focus.y);
- }
-
- /**
- * Returns a CameraUpdate that shifts the zoom level of the current camera viewpoint.
- *
- * @param amount
- * @return
- */
- public static CameraUpdate zoomBy(float amount) {
- return new ZoomUpdate(ZoomUpdate.ZOOM_BY, amount);
- }
-
- /**
- * Returns a CameraUpdate that zooms in on the map by moving the viewpoint's height closer to the Earth's surface. The zoom increment is 1.0.
- *
- * @return
- */
- public static CameraUpdate zoomIn() {
- return new ZoomUpdate(ZoomUpdate.ZOOM_IN);
- }
-
- /**
- * Returns a CameraUpdate that zooms out on the map by moving the viewpoint's height farther away from the Earth's surface. The zoom increment is -1.0.
- *
- * @return
- */
- public static CameraUpdate zoomOut() {
- return new ZoomUpdate(ZoomUpdate.ZOOM_OUT);
- }
-
- /**
- * Returns a CameraUpdate that moves the camera viewpoint to a particular zoom level.
- *
- * @param zoom
- * @return
- */
- public static CameraUpdate zoomTo(float zoom) {
- return new ZoomUpdate(ZoomUpdate.ZOOM_TO, zoom);
- }
-
- //
- // CameraUpdate types
- //
-
- public static class PositionCameraUpdate implements CameraUpdate {
-
- private final float bearing;
- private final LatLng target;
- private final float tilt;
- private final float zoom;
-
- PositionCameraUpdate(float bearing, LatLng target, float tilt, float zoom) {
- this.bearing = bearing;
- this.target = target;
- this.tilt = tilt;
- this.zoom = zoom;
- }
-
- public LatLng getTarget() {
- return target;
- }
-
- public float getBearing() {
- return bearing;
- }
-
- public float getTilt() {
- return tilt;
- }
-
- public float getZoom() {
- return zoom;
- }
- }
-
- public static class ZoomUpdate implements CameraUpdate {
-
- @IntDef({ZOOM_IN, ZOOM_OUT, ZOOM_BY, ZOOM_TO, ZOOM_TO_POINT})
- @Retention(RetentionPolicy.SOURCE)
- public @interface Type {
- }
-
- public static final int ZOOM_IN = 0;
- public static final int ZOOM_OUT = 1;
- public static final int ZOOM_BY = 2;
- public static final int ZOOM_TO = 3;
- public static final int ZOOM_TO_POINT = 4;
-
- @Type
- private final int type;
- private final float zoom;
- private float x;
- private float y;
-
- ZoomUpdate(@Type int type) {
- this.type = type;
- this.zoom = 0;
- }
-
- ZoomUpdate(@Type int type, float zoom) {
- this.type = type;
- this.zoom = zoom;
- }
-
- ZoomUpdate(float zoom, float x, float y) {
- this.type = ZOOM_TO_POINT;
- this.zoom = zoom;
- this.x = x;
- this.y = y;
- }
-
- public float getZoom() {
- return zoom;
- }
-
- @Type
- public int getType() {
- return type;
- }
-
- public float getX() {
- return x;
- }
-
- public float getY() {
- return y;
- }
- }
-}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidLatLngBoundsException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidLatLngBoundsException.java
new file mode 100644
index 0000000000..cf30d6ff26
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidLatLngBoundsException.java
@@ -0,0 +1,8 @@
+package com.mapbox.mapboxsdk.exceptions;
+
+public class InvalidLatLngBoundsException extends RuntimeException {
+
+ public InvalidLatLngBoundsException(int latLngsListSize) {
+ super("Cannot create a LatLngBounds from " + latLngsListSize +" items");
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateBounds.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateBounds.java
deleted file mode 100644
index fefc2502d3..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateBounds.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package com.mapbox.mapboxsdk.geometry;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.support.annotation.NonNull;
-
-/**
- * A rectangular geograpical region defined by a south west {@link LatLng} and a north east {@link LatLng}.
- */
-public class CoordinateBounds implements Parcelable {
-
- private LatLng mSouthWest;
- private LatLng mNorthEast;
-
- public CoordinateBounds(@NonNull Parcel in) {
- mSouthWest = in.readParcelable(LatLng.class.getClassLoader());
- mNorthEast = in.readParcelable(LatLng.class.getClassLoader());
- }
-
- public CoordinateBounds(@NonNull LatLng southWest, @NonNull LatLng northEast) {
- mSouthWest = southWest;
- mNorthEast = northEast;
- }
-
- @NonNull
- public LatLng getSouthWest() {
- return mSouthWest;
- }
-
- public void setSouthWest(@NonNull LatLng mSouthWest) {
- this.mSouthWest = mSouthWest;
- }
-
- @NonNull
- public LatLng getNorthEast() {
- return mNorthEast;
- }
-
- public void setNorthEast(@NonNull LatLng mNorthEast) {
- this.mNorthEast = mNorthEast;
- }
-
- @Override
- public int hashCode() {
- int result;
- long temp;
- temp = mSouthWest.hashCode();
- result = (int) (temp ^ (temp >>> 32));
- temp = mNorthEast.hashCode();
- result = 31 * result + (int) (temp ^ (temp >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o instanceof CoordinateBounds) {
- CoordinateBounds other = (CoordinateBounds) o;
- return getNorthEast().equals(other.getNorthEast())
- && getSouthWest().equals(other.getSouthWest());
- }
- return false;
- }
-
- @Override
- public String toString() {
- return "CoordinateBounds [mNorthEast[" + getNorthEast() + "], mSouthWest[]" + getSouthWest() + "]";
- }
-
- public static final Parcelable.Creator<CoordinateBounds> CREATOR =
- new Parcelable.Creator<CoordinateBounds>() {
- @Override
- public CoordinateBounds createFromParcel(Parcel in) {
- return new CoordinateBounds(in);
- }
-
- @Override
- public CoordinateBounds[] newArray(int size) {
- return new CoordinateBounds[size];
- }
- };
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel out, int arg1) {
- out.writeParcelable(mSouthWest, arg1);
- out.writeParcelable(mNorthEast, arg1);
- }
-}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateRegion.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateRegion.java
deleted file mode 100644
index c7c0aa1c49..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/CoordinateRegion.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package com.mapbox.mapboxsdk.geometry;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.support.annotation.NonNull;
-
-/**
- * A geographical region defined by a {@link LatLng} and a {@link CoordinateSpan}.
- */
-public class CoordinateRegion implements Parcelable{
-
- private LatLng mCenter;
- private CoordinateSpan mSpan;
-
- public CoordinateRegion(@NonNull Parcel in){
- mCenter = in.readParcelable(LatLng.class.getClassLoader());
- mSpan = in.readParcelable(CoordinateSpan.class.getClassLoader());
- }
-
- public CoordinateRegion(@NonNull LatLng center, @NonNull CoordinateSpan span) {
- mCenter = center;
- mSpan = span;
- }
-
- public LatLng getCenter() {
- return mCenter;
- }
-
- public void setCenter(@NonNull LatLng center) {
- mCenter = center;
- }
-
- public CoordinateSpan getSpan() {
- return mSpan;
- }
-
- public void setSpan(@NonNull CoordinateSpan span) {
- this.mSpan = span;
- }
-
- public static final Parcelable.Creator<CoordinateRegion> CREATOR =
- new Parcelable.Creator<CoordinateRegion>() {
- @Override
- public CoordinateRegion createFromParcel(Parcel in) {
- return new CoordinateRegion(in);
- }
-
- @Override
- public CoordinateRegion[] newArray(int size) {
- return new CoordinateRegion[size];
- }
- };
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void writeToParcel(Parcel out, int arg1) {
- out.writeParcelable(mCenter, arg1);
- out.writeParcelable(mSpan, arg1);
- }
-}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
index 9cfa5997c4..17816a0776 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
@@ -2,7 +2,14 @@ package com.mapbox.mapboxsdk.geometry;
import android.os.Parcel;
import android.os.Parcelable;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import com.mapbox.mapboxsdk.annotations.Icon;
+import com.mapbox.mapboxsdk.annotations.Marker;
+import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException;
+
+import java.util.ArrayList;
import java.util.List;
/**
@@ -15,46 +22,20 @@ public class LatLngBounds implements Parcelable {
private final double mLonEast;
private final double mLonWest;
- private final boolean mIsValid;
-
/**
* Construct a new LatLngBounds based on its corners, given in NESW
* order.
*
* @param northLatitude Northern Latitude
- * @param eastLongitude Eastern Longitude
+ * @param eastLongitude Eastern Longitude
* @param southLatitude Southern Latitude
- * @param westLongitude Western Longitude
+ * @param westLongitude Western Longitude
*/
- public LatLngBounds(final double northLatitude, final double eastLongitude, final double southLatitude, final double westLongitude) {
+ LatLngBounds(final double northLatitude, final double eastLongitude, final double southLatitude, final double westLongitude) {
this.mLatNorth = northLatitude;
this.mLonEast = eastLongitude;
this.mLatSouth = southLatitude;
this.mLonWest = westLongitude;
- this.mIsValid = ((this.mLonWest < this.mLonEast) && (this.mLatNorth > this.mLatSouth));
- }
-
- /**
- * Construct a new LatLngBounds based on its corners, given in NESW order.
- *
- * @param northEast Coordinate
- * @param southWest Coordinate
- */
- public LatLngBounds(final LatLng northEast, final LatLng southWest) {
- this(northEast.getLatitude(), northEast.getLongitude(), southWest.getLatitude(), southWest.getLongitude());
- }
-
- /**
- * Create a LatLngBounds box from another LatLngBounds
- *
- * @param other the other LatLngBounds
- */
- public LatLngBounds(final LatLngBounds other) {
- this.mLatNorth = other.getLatNorth();
- this.mLonEast = other.getLonEast();
- this.mLatSouth = other.getLatSouth();
- this.mLonWest = other.getLonWest();
- this.mIsValid = other.isValid();
}
/**
@@ -84,10 +65,6 @@ public class LatLngBounds implements Parcelable {
return this.mLonWest;
}
- public boolean isValid() {
- return this.mIsValid;
- }
-
/**
* Get the area spanned by this LatLngBounds
*
@@ -123,7 +100,7 @@ public class LatLngBounds implements Parcelable {
*
* @return boolean indicating if span is empty
*/
- public boolean isEmpty() {
+ public boolean isEmptySpan() {
return getLongitudeSpan() == 0.0 || getLatitudeSpan() == 0.0;
}
@@ -139,7 +116,7 @@ public class LatLngBounds implements Parcelable {
* @param latLngs List of LatLng objects
* @return LatLngBounds
*/
- public static LatLngBounds fromLatLngs(final List<? extends ILatLng> latLngs) {
+ static LatLngBounds fromLatLngs(final List<? extends ILatLng> latLngs) {
double minLat = 90,
minLon = 180,
maxLat = -90,
@@ -158,6 +135,10 @@ public class LatLngBounds implements Parcelable {
return new LatLngBounds(maxLat, maxLon, minLat, minLon);
}
+ public LatLng[] toLatLngs(){
+ return new LatLng[]{new LatLng(mLatNorth,mLonEast),new LatLng(mLatSouth,mLonWest)};
+ }
+
/**
* Determines whether this LatLngBounds matches another one via LatLng.
*
@@ -167,8 +148,8 @@ public class LatLngBounds implements Parcelable {
@Override
public boolean equals(final Object o) {
if (this == o) return true;
- if (o instanceof BoundingBox) {
- BoundingBox other = (BoundingBox) o;
+ if (o instanceof LatLngBounds) {
+ LatLngBounds other = (LatLngBounds) o;
return mLatNorth == other.getLatNorth()
&& mLatSouth == other.getLatSouth()
&& mLonEast == other.getLonEast()
@@ -184,7 +165,7 @@ public class LatLngBounds implements Parcelable {
* @param latLng the point which may be contained
* @return true, if the point is contained within the box.
*/
- public boolean contains(final ILatLng latLng) {
+ public boolean including(final ILatLng latLng) {
final double latitude = latLng.getLatitude();
final double longitude = latLng.getLongitude();
return ((latitude < this.mLatNorth)
@@ -242,14 +223,14 @@ public class LatLngBounds implements Parcelable {
/**
* Returns a new LatLngBounds that is the intersection of this with another LatLngBounds
*
- * @param northLongitude Northern Longitude
- * @param eastLatitude Eastern Latitude
- * @param southLongitude Southern Longitude
- * @param westLatitude Western Latitude
+ * @param northLatitude Northern Longitude
+ * @param eastLongitude Eastern Latitude
+ * @param southLatitude Southern Longitude
+ * @param westLongitude Western Latitude
* @return LatLngBounds
*/
- public LatLngBounds intersect(double northLongitude, double eastLatitude, double southLongitude, double westLatitude) {
- return intersect(new LatLngBounds(northLongitude, eastLatitude, southLongitude, westLatitude));
+ public LatLngBounds intersect(double northLatitude, double eastLongitude, double southLatitude, double westLongitude) {
+ return intersect(new LatLngBounds(northLatitude, eastLongitude, southLatitude, westLongitude));
}
public static final Parcelable.Creator<LatLngBounds> CREATOR =
@@ -293,4 +274,25 @@ public class LatLngBounds implements Parcelable {
final double latWest = in.readDouble();
return new LatLngBounds(lonNorth, latEast, lonSouth, latWest);
}
+
+ public static final class Builder {
+
+ private List<LatLng> mLatLngList;
+
+ public Builder() {
+ mLatLngList = new ArrayList<>();
+ }
+
+ public LatLngBounds build() {
+ if (mLatLngList.size() < 2) {
+ throw new InvalidLatLngBoundsException(mLatLngList.size());
+ }
+ return LatLngBounds.fromLatLngs(mLatLngList);
+ }
+
+ public Builder include(@NonNull LatLng latLng) {
+ mLatLngList.add(latLng);
+ return this;
+ }
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraUpdate.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraUpdate.java
new file mode 100644
index 0000000000..0f3e710134
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraUpdate.java
@@ -0,0 +1,12 @@
+package com.mapbox.mapboxsdk.maps;
+
+import android.support.annotation.NonNull;
+
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+
+public interface CameraUpdate {
+
+ CameraPosition getCameraPosition(@NonNull MapboxMap mapboxMap);
+
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraUpdateFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraUpdateFactory.java
new file mode 100644
index 0000000000..38b340908a
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraUpdateFactory.java
@@ -0,0 +1,362 @@
+package com.mapbox.mapboxsdk.maps;
+
+import android.graphics.Point;
+import android.graphics.PointF;
+import android.graphics.RectF;
+import android.support.annotation.IntDef;
+import android.support.annotation.NonNull;
+
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.geometry.LatLngBounds;
+import com.mapbox.mapboxsdk.utils.MathUtils;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+public class CameraUpdateFactory {
+
+ /**
+ * Returns a CameraUpdate that moves the camera to a specified CameraPosition.
+ *
+ * @param cameraPosition Camera Position to change to
+ * @return CameraUpdate Final Camera Position data
+ */
+ public static CameraUpdate newCameraPosition(@NonNull CameraPosition cameraPosition) {
+ return new CameraPositionUpdate(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom);
+ }
+
+ /**
+ * Returns a CameraUpdate that moves the center of the screen to a latitude and longitude
+ * specified by a LatLng object. This centers the camera on the LatLng object.
+ *
+ * @param latLng
+ * @return
+ */
+ public static CameraUpdate newLatLng(@NonNull LatLng latLng) {
+ return new CameraPositionUpdate(-1, latLng, -1, -1);
+ }
+
+ /**
+ * Returns a CameraUpdate that transforms the camera such that the specified latitude/longitude
+ * bounds are centered on screen at the greatest possible zoom level.
+ * You can specify padding, in order to inset the bounding box from the map view's edges.
+ * The returned CameraUpdate has a bearing of 0 and a tilt of 0.
+ *
+ * @param bounds
+ * @param padding
+ * @return
+ */
+ public static CameraUpdate newLatLngBounds(@NonNull LatLngBounds bounds, int padding) {
+ return newLatLngBounds(bounds, padding, padding, padding, padding);
+ }
+
+
+ /**
+ * Returns a CameraUpdate that transforms the camera such that the specified latitude/longitude
+ * bounds are centered on screen at the greatest possible zoom level.
+ * You can specify padding, in order to inset the bounding box from the map view's edges.
+ * The returned CameraUpdate has a bearing of 0 and a tilt of 0.
+ *
+ * @param bounds
+ * @param paddingLeft
+ * @param paddingTop
+ * @param paddingRight
+ * @param paddingBottom
+ * @return
+ */
+ public static CameraUpdate newLatLngBounds(@NonNull LatLngBounds bounds, int paddingLeft, int paddingTop, int paddingRight, int paddingBottom) {
+ return new CameraBoundsUpdate(bounds, paddingLeft, paddingTop, paddingRight, paddingBottom);
+ }
+
+// /**
+// * Returns a CameraUpdate that transforms the camera such that the specified latitude/longitude
+// * bounds are centered on screen within a bounding box of specified dimensions at the greatest
+// * possible zoom level. You can specify additional padding, to further restrict the size of
+// * the bounding box. The returned CameraUpdate has a bearing of 0 and a tilt of 0.
+// *
+// * @param bounds
+// * @param width
+// * @param height
+// * @param padding
+// * @return
+// */
+// public static CameraUpdate newLatLngBounds(@NonNull LatLngBounds bounds, int width, int height, int padding) {
+// throw new UnsupportedOperationException("Not implemented yet");
+// }
+
+ /**
+ * Returns a CameraUpdate that moves the center of the screen to a latitude and longitude specified by a LatLng object, and moves to the given zoom level.
+ *
+ * @param latLng
+ * @param zoom
+ * @return
+ */
+ public static CameraUpdate newLatLngZoom(@NonNull LatLng latLng, float zoom) {
+ return new CameraPositionUpdate(-1, latLng, -1, zoom);
+ }
+
+// /**
+// * Returns a CameraUpdate that scrolls the camera over the map, shifting the center of view by the specified number of pixels in the x and y directions.
+// *
+// * @param xPixel
+// * @param yPixel
+// * @return
+// */
+// public static CameraUpdate scrollBy(float xPixel, float yPixel) {
+// throw new UnsupportedOperationException("Not implemented yet");
+// }
+
+ /**
+ * Returns a CameraUpdate that shifts the zoom level of the current camera viewpoint.
+ *
+ * @param amount
+ * @param focus
+ * @return
+ */
+ public static CameraUpdate zoomBy(float amount, Point focus) {
+ return new ZoomUpdate(amount, focus.x, focus.y);
+ }
+
+ /**
+ * Returns a CameraUpdate that shifts the zoom level of the current camera viewpoint.
+ *
+ * @param amount
+ * @return
+ */
+ public static CameraUpdate zoomBy(float amount) {
+ return new ZoomUpdate(ZoomUpdate.ZOOM_BY, amount);
+ }
+
+ /**
+ * Returns a CameraUpdate that zooms in on the map by moving the viewpoint's height closer to the Earth's surface. The zoom increment is 1.0.
+ *
+ * @return
+ */
+ public static CameraUpdate zoomIn() {
+ return new ZoomUpdate(ZoomUpdate.ZOOM_IN);
+ }
+
+ /**
+ * Returns a CameraUpdate that zooms out on the map by moving the viewpoint's height farther away from the Earth's surface. The zoom increment is -1.0.
+ *
+ * @return
+ */
+ public static CameraUpdate zoomOut() {
+ return new ZoomUpdate(ZoomUpdate.ZOOM_OUT);
+ }
+
+ /**
+ * Returns a CameraUpdate that moves the camera viewpoint to a particular zoom level.
+ *
+ * @param zoom
+ * @return
+ */
+ public static CameraUpdate zoomTo(float zoom) {
+ return new ZoomUpdate(ZoomUpdate.ZOOM_TO, zoom);
+ }
+
+ //
+ // CameraUpdate types
+ //
+
+ public static class CameraPositionUpdate implements CameraUpdate {
+
+ private final float bearing;
+ private final LatLng target;
+ private final float tilt;
+ private final float zoom;
+
+ CameraPositionUpdate(float bearing, LatLng target, float tilt, float zoom) {
+ this.bearing = bearing;
+ this.target = target;
+ this.tilt = tilt;
+ this.zoom = zoom;
+ }
+
+ public LatLng getTarget() {
+ return target;
+ }
+
+ public float getBearing() {
+ return bearing;
+ }
+
+ public float getTilt() {
+ return tilt;
+ }
+
+ public float getZoom() {
+ return zoom;
+ }
+
+ @Override
+ public CameraPosition getCameraPosition(@NonNull MapboxMap mapboxMap) {
+ return new CameraPosition.Builder(this).build();
+ }
+ }
+
+ public static class CameraBoundsUpdate implements CameraUpdate {
+
+ private LatLngBounds bounds;
+ private RectF padding;
+
+ public CameraBoundsUpdate(LatLngBounds bounds, RectF padding) {
+ this.bounds = bounds;
+ this.padding = padding;
+ }
+
+ public CameraBoundsUpdate(LatLngBounds bounds, int[] padding) {
+ this(bounds, new RectF(padding[0], padding[1], padding[2], padding[3]));
+ }
+
+ public CameraBoundsUpdate(LatLngBounds bounds, int paddingLeft, int paddingTop, int paddingRight, int paddingBottom) {
+ this(bounds, new int[]{paddingLeft, paddingTop, paddingRight, paddingBottom});
+ }
+
+ public LatLngBounds getBounds() {
+ return bounds;
+ }
+
+ public RectF getPadding() {
+ return padding;
+ }
+
+ @Override
+ public CameraPosition getCameraPosition(@NonNull MapboxMap mapboxMap) {
+ MapView mapView = mapboxMap.getMapView();
+ RectF padding = getPadding();
+
+ // Calculate the bounds of the possibly rotated shape with respect to the viewport.
+ PointF nePixel = new PointF(-10000, -10000);
+ PointF swPixel = new PointF(1000, 10000);
+ float viewportHeight = mapView.getHeight();
+ for (LatLng latLng : getBounds().toLatLngs()) {
+ PointF pixel = mapView.toScreenLocation(latLng);
+ swPixel.x = Math.min(swPixel.x, pixel.x);
+ nePixel.x = Math.max(nePixel.x, pixel.x);
+ swPixel.y = Math.min(swPixel.y, viewportHeight - pixel.y);
+ nePixel.y = Math.max(nePixel.y, viewportHeight - pixel.y);
+ }
+
+ float width = nePixel.x - swPixel.x;
+ float height = nePixel.y - swPixel.y;
+
+ // Calculate the zoom level.
+ float scaleX = (mapView.getWidth() - padding.left - padding.right) / width;
+ float scaleY = (mapView.getHeight() - padding.top - padding.bottom) / height;
+ float minScale = scaleX < scaleY ? scaleX : scaleY;
+ double zoom = Math.log(mapView.getScale() * minScale) / Math.log(2);
+ zoom = MathUtils.clamp(zoom, (float) mapView.getMinZoom(), (float) mapView.getMaxZoom());
+
+ // Calculate the center point of a virtual bounds that is extended in all directions by padding.
+ PointF paddedNEPixel = new PointF(nePixel.x + padding.right / minScale, nePixel.y + padding.top / minScale);
+ PointF paddedSWPixel = new PointF(swPixel.x - padding.left / minScale, swPixel.y - padding.bottom / minScale);
+ PointF centerPixel = new PointF((paddedNEPixel.x + paddedSWPixel.x) / 2, (paddedNEPixel.y + paddedSWPixel.y) / 2);
+
+ centerPixel.y = viewportHeight - centerPixel.y;
+
+ LatLng center = mapboxMap.fromScreenLocation(centerPixel);
+
+ return new CameraPosition.Builder()
+ .target(center)
+ .zoom((float) zoom)
+ .tilt(0)
+ .bearing(0)
+ .build();
+ }
+ }
+
+ public static class ZoomUpdate implements CameraUpdate {
+
+ @IntDef({ZOOM_IN, ZOOM_OUT, ZOOM_BY, ZOOM_TO, ZOOM_TO_POINT})
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface Type {
+ }
+
+ public static final int ZOOM_IN = 0;
+ public static final int ZOOM_OUT = 1;
+ public static final int ZOOM_BY = 2;
+ public static final int ZOOM_TO = 3;
+ public static final int ZOOM_TO_POINT = 4;
+
+ @Type
+ private final int type;
+ private final float zoom;
+ private float x;
+ private float y;
+
+ ZoomUpdate(@Type int type) {
+ this.type = type;
+ this.zoom = 0;
+ }
+
+ ZoomUpdate(@Type int type, float zoom) {
+ this.type = type;
+ this.zoom = zoom;
+ }
+
+ ZoomUpdate(float zoom, float x, float y) {
+ this.type = ZOOM_TO_POINT;
+ this.zoom = zoom;
+ this.x = x;
+ this.y = y;
+ }
+
+ public float getZoom() {
+ return zoom;
+ }
+
+ @Type
+ public int getType() {
+ return type;
+ }
+
+ public float getX() {
+ return x;
+ }
+
+ public float getY() {
+ return y;
+ }
+
+ public float transformZoom(float currentZoom) {
+ switch (getType()) {
+ case CameraUpdateFactory.ZoomUpdate.ZOOM_IN:
+ currentZoom++;
+ break;
+ case CameraUpdateFactory.ZoomUpdate.ZOOM_OUT:
+ currentZoom--;
+ if (currentZoom < 0) {
+ currentZoom = 0;
+ }
+ break;
+ case CameraUpdateFactory.ZoomUpdate.ZOOM_TO:
+ currentZoom = getZoom();
+ break;
+ case CameraUpdateFactory.ZoomUpdate.ZOOM_BY:
+ currentZoom = currentZoom + getZoom();
+ break;
+ case CameraUpdateFactory.ZoomUpdate.ZOOM_TO_POINT:
+ currentZoom = currentZoom + getZoom();
+ break;
+ }
+ return currentZoom;
+ }
+
+ @Override
+ public CameraPosition getCameraPosition(@NonNull MapboxMap mapboxMap) {
+ CameraPosition cameraPosition = mapboxMap.getCameraPosition();
+ if (getType() != CameraUpdateFactory.ZoomUpdate.ZOOM_TO_POINT) {
+ return new CameraPosition.Builder(cameraPosition)
+ .zoom(transformZoom(cameraPosition.zoom))
+ .build();
+ } else {
+ return new CameraPosition.Builder(cameraPosition)
+ .zoom(transformZoom(cameraPosition.zoom))
+ .target(mapboxMap.fromScreenLocation(new PointF(getX(), getY())))
+ .build();
+ }
+ }
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java
index 51834adb51..2789e85ed8 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java
@@ -28,7 +28,6 @@ import com.mapbox.mapboxsdk.utils.ApiAccess;
public class MapFragment extends Fragment {
private MapView mMap;
- private OnMapReadyCallback mMapReadyCallback;
public static MapFragment newInstance(){
return new MapFragment();
@@ -61,9 +60,6 @@ public class MapFragment extends Fragment {
public void onResume() {
super.onResume();
mMap.onResume();
- if(mMapReadyCallback!=null){
- mMapReadyCallback.onMapReady(mMap.getMapboxMap());
- }
}
@Override
@@ -99,6 +95,6 @@ public class MapFragment extends Fragment {
@NonNull
public void getMapAsync(@NonNull OnMapReadyCallback onMapReadyCallback){
- mMapReadyCallback = onMapReadyCallback;
+ mMap.getMapAsync(onMapReadyCallback);
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
index fc8ad0c255..a9fe3a7994 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
@@ -67,7 +67,6 @@ import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.camera.CameraPosition;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
@@ -75,7 +74,6 @@ import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.exceptions.IconBitmapChangedException;
import com.mapbox.mapboxsdk.exceptions.InvalidAccessTokenException;
import com.mapbox.mapboxsdk.geometry.BoundingBox;
-import com.mapbox.mapboxsdk.geometry.CoordinateBounds;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.layers.CustomLayer;
import com.mapbox.mapboxsdk.utils.ApiAccess;
@@ -1305,7 +1303,7 @@ public class MapView extends FrameLayout {
* not included in `options`.
*
* @param bearing Bearing in Radians
- * @param center Center Coordinate
+ * @param center Center LatLng
* @param pitch Pitch in Radians
* @param zoom Zoom Level
*/
@@ -1324,7 +1322,7 @@ public class MapView extends FrameLayout {
* not included in `options`.
*
* @param bearing Bearing in Radians
- * @param center Center Coordinate
+ * @param center Center LatLng
* @param duration Animation time in Nanoseconds
* @param pitch Pitch in Radians
* @param zoom Zoom Level
@@ -1358,7 +1356,7 @@ public class MapView extends FrameLayout {
* Flying animation to a specified location/zoom/bearing with automatic curve.
*
* @param bearing Bearing in Radians
- * @param center Center Coordinate
+ * @param center Center LatLng
* @param duration Animation time in Nanoseconds
* @param pitch Pitch in Radians
* @param zoom Zoom Level
@@ -1388,70 +1386,6 @@ public class MapView extends FrameLayout {
mNativeMapView.flyTo(bearing, center, duration, pitch, zoom);
}
- /**
- * Changes the map's viewport to fit the given coordinate bounds.
- *
- * @param bounds The bounds that the viewport will show in its entirety.
- */
- @UiThread
- void setVisibleCoordinateBounds(@NonNull CoordinateBounds bounds) {
- setVisibleCoordinateBounds(bounds, false);
- }
-
- /**
- * Changes the map's viewing area to fit the given coordinate bounds, optionally animating the change.
- *
- * @param bounds The bounds that the viewport will show in its entirety.
- * @param animated If true, animates the change. If false, immediately changes the map.
- */
- @UiThread
- void setVisibleCoordinateBounds(@NonNull CoordinateBounds bounds, boolean animated) {
- setVisibleCoordinateBounds(bounds, new RectF(), animated);
- }
-
- /**
- * Changes the map’s viewport to fit the given coordinate bounds with additional padding at the
- * edge of the map, optionally animating the change.
- *
- * @param bounds The bounds that the viewport will show in its entirety.
- * @param padding The minimum padding (in pixels) that will be visible around the given coordinate bounds.
- * @param animated If true, animates the change. If false, immediately changes the map.
- */
- @UiThread
- void setVisibleCoordinateBounds(@NonNull CoordinateBounds bounds, @NonNull RectF padding, boolean animated) {
- LatLng[] coordinates = {
- new LatLng(bounds.getNorthEast().getLatitude(), bounds.getSouthWest().getLongitude()),
- bounds.getSouthWest(),
- new LatLng(bounds.getSouthWest().getLatitude(), bounds.getNorthEast().getLongitude()),
- bounds.getNorthEast()
-
- };
- setVisibleCoordinateBounds(coordinates, padding, animated);
- }
-
- /**
- * Changes the map’s viewport to fit the given coordinates, optionally some additional padding on each side
- * and animating the change.
- *
- * @param coordinates The coordinates that the viewport will show.
- * @param padding The minimum padding (in pixels) that will be visible around the given coordinate bounds.
- * @param animated If true, animates the change. If false, immediately changes the map.
- */
- @UiThread
- void setVisibleCoordinateBounds(@NonNull LatLng[] coordinates, @NonNull RectF padding, boolean animated) {
- setVisibleCoordinateBounds(coordinates, padding, getDirection(), animated);
- }
-
- private void setVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, double direction, boolean animated) {
- setVisibleCoordinateBounds(coordinates, padding, direction, animated ? MapboxConstants.ANIMATION_DURATION : 0l);
- }
-
- void setVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, double direction, long duration) {
- mNativeMapView.setVisibleCoordinateBounds(coordinates, new RectF(padding.left / mScreenDensity,
- padding.top / mScreenDensity, padding.right / mScreenDensity, padding.bottom / mScreenDensity),
- direction, duration);
- }
-
private void adjustTopOffsetPixels() {
int count = mAnnotations.size();
for (int i = 0; i < count; i++) {
@@ -1513,6 +1447,10 @@ public class MapView extends FrameLayout {
}
}
+ double getScale() {
+ return mNativeMapView.getScale();
+ }
+
// This class handles TextureView callbacks
private class SurfaceTextureListener implements TextureView.SurfaceTextureListener {
@@ -2826,8 +2764,15 @@ public class MapView extends FrameLayout {
* @param callback The callback object that will be triggered when the map is ready to be used.
*/
@UiThread
- public void getMapAsync(@NonNull OnMapReadyCallback callback) {
- callback.onMapReady(mMapboxMap);
+ public void getMapAsync(@NonNull final OnMapReadyCallback callback) {
+
+ // We need to put our callback on the message queue
+ post(new Runnable() {
+ @Override
+ public void run() {
+ callback.onMapReady(mMapboxMap);
+ }
+ });
}
MapboxMap getMapboxMap() {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
index 1a9780b92b..54b81229c6 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
@@ -12,7 +12,6 @@ import android.support.annotation.RequiresPermission;
import android.support.annotation.UiThread;
import android.text.TextUtils;
import android.util.Log;
-import android.view.Gravity;
import android.view.View;
import com.mapbox.mapboxsdk.annotations.Annotation;
@@ -24,8 +23,6 @@ import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition;
-import com.mapbox.mapboxsdk.camera.CameraUpdate;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
@@ -42,7 +39,7 @@ public class MapboxMap {
private MapView mMapView;
private UiSettings mUiSettings;
- private CameraPosition mCurrentCameraPosition;
+ private CameraPosition mCameraPosition;
private String mStyleUrl;
private List<Marker> mSelectedMarkers;
private List<InfoWindow> mInfoWindows;
@@ -92,7 +89,7 @@ public class MapboxMap {
* @return The current position of the Camera.
*/
public final CameraPosition getCameraPosition() {
- return mCurrentCameraPosition;
+ return mCameraPosition;
}
/**
@@ -115,52 +112,8 @@ public class MapboxMap {
*/
@UiThread
public final void moveCamera(CameraUpdate update) {
- CameraPosition cameraPosition;
- if (update instanceof CameraUpdateFactory.PositionCameraUpdate) {
- CameraUpdateFactory.PositionCameraUpdate positionCameraUpdate = (CameraUpdateFactory.PositionCameraUpdate) update;
- cameraPosition = new CameraPosition.Builder(positionCameraUpdate).build();
- } else if (update instanceof CameraUpdateFactory.ZoomUpdate) {
- CameraUpdateFactory.ZoomUpdate zoomUpdate = (CameraUpdateFactory.ZoomUpdate) update;
- if(zoomUpdate.getType()!= CameraUpdateFactory.ZoomUpdate.ZOOM_TO_POINT){
- cameraPosition = new CameraPosition.Builder(mCurrentCameraPosition)
- .zoom(getZoom(zoomUpdate, mCurrentCameraPosition.zoom))
- .build();
- }else{
- cameraPosition = new CameraPosition.Builder(mCurrentCameraPosition)
- .zoom(getZoom(zoomUpdate, mCurrentCameraPosition.zoom))
- .target(fromScreenLocation(new PointF(zoomUpdate.getX(),zoomUpdate.getY())))
- .build();
- }
- } else {
- Log.e(MapboxConstants.TAG, "Unsupported CameraUpdate");
- return;
- }
- mCurrentCameraPosition = cameraPosition;
- mMapView.jumpTo(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom);
- }
-
- private float getZoom(CameraUpdateFactory.ZoomUpdate update, float currentZoom) {
- switch (update.getType()) {
- case CameraUpdateFactory.ZoomUpdate.ZOOM_IN:
- currentZoom++;
- break;
- case CameraUpdateFactory.ZoomUpdate.ZOOM_OUT:
- currentZoom--;
- if (currentZoom < 0) {
- currentZoom = 0;
- }
- break;
- case CameraUpdateFactory.ZoomUpdate.ZOOM_TO:
- currentZoom = update.getZoom();
- break;
- case CameraUpdateFactory.ZoomUpdate.ZOOM_BY:
- currentZoom = currentZoom + update.getZoom();
- break;
- case CameraUpdateFactory.ZoomUpdate.ZOOM_TO_POINT:
- currentZoom = currentZoom + update.getZoom();
- break;
- }
- return currentZoom;
+ mCameraPosition = update.getCameraPosition(this);
+ mMapView.jumpTo(mCameraPosition.bearing, mCameraPosition.target, mCameraPosition.tilt, mCameraPosition.zoom);
}
/**
@@ -185,28 +138,8 @@ public class MapboxMap {
*/
@UiThread
public final void easeCamera(CameraUpdate update, int durationMs, final MapboxMap.CancelableCallback callback) {
- CameraPosition cameraPosition;
- if (update instanceof CameraUpdateFactory.PositionCameraUpdate) {
- CameraUpdateFactory.PositionCameraUpdate positionCameraUpdate = (CameraUpdateFactory.PositionCameraUpdate) update;
- cameraPosition = new CameraPosition.Builder(positionCameraUpdate).build();
- } else if (update instanceof CameraUpdateFactory.ZoomUpdate) {
- CameraUpdateFactory.ZoomUpdate zoomUpdate = (CameraUpdateFactory.ZoomUpdate) update;
- if(zoomUpdate.getType()!= CameraUpdateFactory.ZoomUpdate.ZOOM_TO_POINT){
- cameraPosition = new CameraPosition.Builder(mCurrentCameraPosition)
- .zoom(getZoom(zoomUpdate, mCurrentCameraPosition.zoom))
- .build();
- }else{
- cameraPosition = new CameraPosition.Builder(mCurrentCameraPosition)
- .zoom(getZoom(zoomUpdate, mCurrentCameraPosition.zoom))
- .target(fromScreenLocation(new PointF(zoomUpdate.getX(),zoomUpdate.getY())))
- .build();
- }
- } else {
- Log.e(MapboxConstants.TAG, "Unsupported CameraUpdate");
- return;
- }
- mCurrentCameraPosition = cameraPosition;
- mMapView.easeTo(cameraPosition.bearing, cameraPosition.target, getDurationNano(durationMs), cameraPosition.tilt, cameraPosition.zoom, callback);
+ mCameraPosition = update.getCameraPosition(this);
+ mMapView.easeTo(mCameraPosition.bearing, mCameraPosition.target, getDurationNano(durationMs), mCameraPosition.tilt, mCameraPosition.zoom, callback);
}
/**
@@ -257,28 +190,8 @@ public class MapboxMap {
*/
@UiThread
public final void animateCamera(CameraUpdate update, int durationMs, final MapboxMap.CancelableCallback callback) {
- CameraPosition cameraPosition;
- if (update instanceof CameraUpdateFactory.PositionCameraUpdate) {
- CameraUpdateFactory.PositionCameraUpdate positionCameraUpdate = (CameraUpdateFactory.PositionCameraUpdate) update;
- cameraPosition = new CameraPosition.Builder(positionCameraUpdate).build();
- } else if (update instanceof CameraUpdateFactory.ZoomUpdate) {
- CameraUpdateFactory.ZoomUpdate zoomUpdate = (CameraUpdateFactory.ZoomUpdate) update;
- if(zoomUpdate.getType()!= CameraUpdateFactory.ZoomUpdate.ZOOM_TO_POINT){
- cameraPosition = new CameraPosition.Builder(mCurrentCameraPosition)
- .zoom(getZoom(zoomUpdate, mCurrentCameraPosition.zoom))
- .build();
- }else {
- cameraPosition = new CameraPosition.Builder(mCurrentCameraPosition)
- .zoom(getZoom(zoomUpdate, mCurrentCameraPosition.zoom))
- .target(fromScreenLocation(new PointF(zoomUpdate.getX(), zoomUpdate.getY())))
- .build();
- }
- } else {
- Log.e(MapboxConstants.TAG, "Unsupported CameraUpdate");
- return;
- }
- mCurrentCameraPosition = cameraPosition;
- mMapView.flyTo(cameraPosition.bearing, cameraPosition.target, getDurationNano(durationMs), cameraPosition.tilt, cameraPosition.zoom, callback);
+ mCameraPosition = update.getCameraPosition(this);
+ mMapView.flyTo(mCameraPosition.bearing, mCameraPosition.target, getDurationNano(durationMs), mCameraPosition.tilt, mCameraPosition.zoom, callback);
}
// internal time layer conversion
@@ -1123,9 +1036,13 @@ public class MapboxMap {
mMapView.invalidateCustomLayers();
}
- //
- // Interfaces
- //
+ MapView getMapView(){
+ return mMapView;
+ }
+
+//
+// Interfaces
+//
/**
* Interface definition for a callback to be invoked when the map is flinged.
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
index 2671bfcfcc..1c44e62627 100755
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
@@ -15,7 +15,6 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
import com.mapbox.mapboxsdk.layers.CustomLayer;
-import java.lang.ref.WeakReference;
import java.util.List;
// Class that wraps the native methods for convenience
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java
index 2b268777a0..147cd31b5a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java
@@ -28,7 +28,6 @@ import com.mapbox.mapboxsdk.utils.ApiAccess;
public class SupportMapFragment extends Fragment {
private MapView mMap;
- private OnMapReadyCallback mMapReadyCallback;
public static SupportMapFragment newInstance(){
return new SupportMapFragment();
@@ -61,9 +60,6 @@ public class SupportMapFragment extends Fragment {
public void onResume() {
super.onResume();
mMap.onResume();
- if(mMapReadyCallback!=null){
- mMapReadyCallback.onMapReady(mMap.getMapboxMap());
- }
}
@Override
@@ -99,6 +95,6 @@ public class SupportMapFragment extends Fragment {
@NonNull
public void getMapAsync(@NonNull OnMapReadyCallback onMapReadyCallback){
- mMapReadyCallback = onMapReadyCallback;
+ mMap.getMapAsync(onMapReadyCallback);
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UserLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UserLocationView.java
index a826ffdfe9..9f8261a0a7 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UserLocationView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UserLocationView.java
@@ -27,7 +27,6 @@ import android.view.ViewGroup;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.camera.CameraPosition;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.geometry.LatLng;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MathUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MathUtils.java
index 4169577bd5..ff1b56422b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MathUtils.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MathUtils.java
@@ -13,4 +13,15 @@ public class MathUtils {
return Math.max(min, Math.min(max, value));
}
+ /**
+ * Test a value in specified range, returning minimum if it's below, and maximum if it's above
+ * @param value Value to test
+ * @param min Minimum value of range
+ * @param max Maximum value of range
+ * @return value if it's between min and max, min if it's below, max if it's above
+ */
+ public static float clamp(float value, float min, float max) {
+ return Math.max(min, Math.min(max, value));
+ }
+
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/BulkMarkerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/BulkMarkerActivity.java
index 895db44896..3c5e53a0ad 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/BulkMarkerActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/BulkMarkerActivity.java
@@ -17,7 +17,7 @@ import android.widget.Spinner;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.maps.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java
index 040e6d26c2..9ccbc34c3d 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CameraActivity.java
@@ -12,7 +12,7 @@ import android.widget.Toast;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.camera.CameraPosition;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.maps.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CoordinateChangeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CoordinateChangeActivity.java
index b9db578564..25c3896be2 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CoordinateChangeActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/CoordinateChangeActivity.java
@@ -10,8 +10,7 @@ import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
-import com.mapbox.mapboxsdk.camera.CameraPosition;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.maps.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DirectionsActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DirectionsActivity.java
index 6045eeadfd..7c37fc9540 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DirectionsActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DirectionsActivity.java
@@ -17,7 +17,7 @@ import com.mapbox.directions.service.models.Waypoint;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.maps.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java
index 3a3b170a86..9bf168ee75 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/DoubleMapActivity.java
@@ -12,7 +12,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.maps.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.maps.MapView;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ManualZoomActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ManualZoomActivity.java
index 1f74d1e7f8..83f50f7e61 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ManualZoomActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/ManualZoomActivity.java
@@ -10,7 +10,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.maps.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapFragmentActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapFragmentActivity.java
index 4615d35e33..e8750b66d7 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapFragmentActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapFragmentActivity.java
@@ -9,7 +9,7 @@ import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import com.mapbox.mapboxsdk.camera.CameraPosition;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.maps.CameraUpdateFactory;
import com.mapbox.mapboxsdk.maps.MapFragment;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapboxMapActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapboxMapActivity.java
index 16160a2fc6..89ae1150ea 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapboxMapActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapboxMapActivity.java
@@ -9,7 +9,7 @@ import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import com.mapbox.mapboxsdk.camera.CameraPosition;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.maps.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MaxMinZoomActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MaxMinZoomActivity.java
index 4068bb3585..3ace776e02 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MaxMinZoomActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MaxMinZoomActivity.java
@@ -9,7 +9,7 @@ import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.maps.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MyLocationTrackingModeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MyLocationTrackingModeActivity.java
index 50c2dd83e8..411ca36316 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MyLocationTrackingModeActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MyLocationTrackingModeActivity.java
@@ -15,7 +15,7 @@ import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.maps.CameraUpdateFactory;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/SupportMapFragmentActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/SupportMapFragmentActivity.java
index bf690b7943..67d329d0d6 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/SupportMapFragmentActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/SupportMapFragmentActivity.java
@@ -9,7 +9,7 @@ import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import com.mapbox.mapboxsdk.camera.CameraPosition;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.maps.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java
index 1713673129..75c1eae191 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java
@@ -8,7 +8,7 @@ import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import com.mapbox.mapboxsdk.camera.CameraPosition;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.maps.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/VisibleCoordinateBoundsActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/VisibleCoordinateBoundsActivity.java
index 894b5805cc..5dbb033581 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/VisibleCoordinateBoundsActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/VisibleCoordinateBoundsActivity.java
@@ -1,19 +1,15 @@
package com.mapbox.mapboxsdk.testapp;
-import android.graphics.RectF;
import android.os.Bundle;
import android.support.annotation.NonNull;
-import android.support.design.widget.Snackbar;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
-import android.view.View;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.maps.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
-import com.mapbox.mapboxsdk.geometry.CoordinateBounds;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.maps.MapboxMap;
@@ -63,16 +59,17 @@ public class VisibleCoordinateBoundsActivity extends AppCompatActivity {
.snippet("City Hall")
.position(NEW_YORK));
- Snackbar.make(findViewById(android.R.id.content), R.string.action_visible_bounds_explanation, Snackbar.LENGTH_INDEFINITE)
- .setAction(android.R.string.ok, new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // Reposition coordinate bounds
- LatLngBounds bounds = new LatLngBounds(NEW_YORK, LOS_ANGELES);
- int padding = (int) getResources().getDimension(R.dimen.coordinatebounds_margin);
- mapboxMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding));
- }
- }).show();
+ // Create Bounds
+ final LatLngBounds bounds = new LatLngBounds.Builder()
+ .include(NEW_YORK)
+ .include(LOS_ANGELES)
+ .build();
+
+ // And padding
+ int padding = (int) getResources().getDimension(R.dimen.coordinatebounds_margin);
+
+ // Animate camera
+ mapboxMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding));
}
});
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java
new file mode 100644
index 0000000000..69c2d4935b
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java
@@ -0,0 +1,160 @@
+package com.mapbox.mapboxsdk.geometry;
+
+import com.mapbox.mapboxsdk.annotations.Marker;
+import com.mapbox.mapboxsdk.annotations.MarkerOptions;
+import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+public class LatLngBoundsTest {
+
+ private static final double DELTA = 1e-15;
+
+ private LatLngBounds mLatLngBounds;
+ private static final LatLng LAT_LNG_NULL_ISLAND = new LatLng(0, 0);
+ private static final LatLng LAT_LNG_NOT_NULL_ISLAND = new LatLng(2, 2);
+
+ @Before
+ public void beforeTest() {
+ mLatLngBounds = new LatLngBounds.Builder()
+ .include(LAT_LNG_NULL_ISLAND)
+ .include(LAT_LNG_NOT_NULL_ISLAND)
+ .build();
+ }
+
+ @Test
+ public void testSanity() {
+ LatLngBounds.Builder latLngBoundsBuilder = new LatLngBounds.Builder();
+ latLngBoundsBuilder.include(LAT_LNG_NULL_ISLAND).include(LAT_LNG_NOT_NULL_ISLAND);
+ assertNotNull("latLng should not be null", latLngBoundsBuilder.build());
+ }
+
+ @Test(expected = InvalidLatLngBoundsException.class)
+ public void testNoLatLngs() {
+ new LatLngBounds.Builder().build();
+ }
+
+ @Test(expected = InvalidLatLngBoundsException.class)
+ public void testOneLatLngs() {
+ new LatLngBounds.Builder().include(LAT_LNG_NULL_ISLAND).build();
+ }
+
+ @Test
+ public void testLatitiudeSpan() {
+ assertEquals("Span should be the same", 2, mLatLngBounds.getLatitudeSpan(), DELTA);
+ }
+
+ @Test
+ public void testLongitudeSpan() {
+ assertEquals("Span should be the same", 2, mLatLngBounds.getLongitudeSpan(), DELTA);
+ }
+
+ @Test
+ public void testCoordinateSpan() {
+ CoordinateSpan coordinateSpan = mLatLngBounds.getSpan();
+ assertEquals("CoordinateSpan should be the same", new CoordinateSpan(2, 2), coordinateSpan);
+ }
+
+ @Test
+ public void testCenter() {
+ LatLng center = mLatLngBounds.getCenter();
+ assertEquals("Center should match", new LatLng(1, 1), center);
+ }
+
+ @Test
+ public void testEmptySpan() {
+ mLatLngBounds = new LatLngBounds.Builder()
+ .include(LAT_LNG_NOT_NULL_ISLAND)
+ .include(LAT_LNG_NOT_NULL_ISLAND)
+ .build();
+ assertTrue("Should be empty", mLatLngBounds.isEmptySpan());
+ }
+
+ @Test
+ public void testNotEmptySpan() {
+ mLatLngBounds = new LatLngBounds.Builder()
+ .include(LAT_LNG_NOT_NULL_ISLAND)
+ .include(LAT_LNG_NULL_ISLAND)
+ .build();
+ assertFalse("Should not be empty", mLatLngBounds.isEmptySpan());
+ }
+
+ @Test
+ public void testIncluding() {
+ assertTrue("LatLng should be included", mLatLngBounds.including(new LatLng(1, 1)));
+ }
+
+ @Test
+ public void testNoIncluding() {
+ assertFalse("LatLng should not be included", mLatLngBounds.including(new LatLng(3, 1)));
+ }
+
+ @Test
+ public void testHashCode() {
+ assertEquals(2147483647, mLatLngBounds.hashCode(), -1946419200);
+ }
+
+ @Test
+ public void testEquality() {
+ LatLngBounds latLngBounds = new LatLngBounds.Builder()
+ .include(LAT_LNG_NULL_ISLAND)
+ .include(LAT_LNG_NOT_NULL_ISLAND)
+ .build();
+ assertEquals("equality should match", mLatLngBounds, latLngBounds);
+ }
+
+ @Test
+ public void testToString() {
+ assertEquals(mLatLngBounds.toString(), "N:2.0; E:2.0; S:0.0; W:0.0");
+ }
+
+ @Test
+ public void testIntersect() {
+ LatLngBounds latLngBounds = new LatLngBounds.Builder()
+ .include(new LatLng(1, 1))
+ .include(LAT_LNG_NULL_ISLAND)
+ .build();
+ assertEquals("intersect should match", latLngBounds, latLngBounds.intersect(mLatLngBounds.getLatNorth(), mLatLngBounds.getLonEast(), mLatLngBounds.getLatSouth(), mLatLngBounds.getLonWest()));
+ }
+
+ @Test
+ public void testNoIntersect() {
+ LatLngBounds latLngBounds = new LatLngBounds.Builder()
+ .include(new LatLng(10, 10))
+ .include(new LatLng(9, 8))
+ .build();
+ assertNull(latLngBounds.intersect(mLatLngBounds));
+ }
+
+ @Test
+ public void testInnerUnion() {
+ LatLngBounds latLngBounds = new LatLngBounds.Builder()
+ .include(new LatLng(1, 1))
+ .include(LAT_LNG_NULL_ISLAND)
+ .build();
+ assertEquals("union should match", latLngBounds, latLngBounds.intersect(mLatLngBounds));
+ }
+
+ @Test
+ public void testOuterUnion() {
+ LatLngBounds latLngBounds = new LatLngBounds.Builder()
+ .include(new LatLng(10, 10))
+ .include(new LatLng(9, 8))
+ .build();
+ assertEquals("outer union should match",
+ latLngBounds.union(mLatLngBounds),
+ new LatLngBounds.Builder()
+ .include(new LatLng(10, 10))
+ .include(LAT_LNG_NULL_ISLAND)
+ .build());
+ }
+
+
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/LatLngTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngTest.java
index 71994ef64b..99516d079d 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/LatLngTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngTest.java
@@ -1,6 +1,7 @@
-package com.mapbox.mapboxsdk.maps;
+package com.mapbox.mapboxsdk.geometry;
import android.location.Location;
+import android.os.Parcel;
import com.mapbox.mapboxsdk.geometry.LatLng;
@@ -47,6 +48,34 @@ public class LatLngTest {
}
@Test
+ public void testLatitudeSetter() {
+ LatLng latLng = new LatLng(1.2, 3.4);
+ latLng.setLatitude(3);
+ assertEquals("latitude should match", 3, latLng.getLatitude(), DELTA);
+ }
+
+ @Test
+ public void testLongitudeSetter() {
+ LatLng latLng = new LatLng(1.2, 3.4);
+ latLng.setLongitude(3);
+ assertEquals("longitude should match", 3, latLng.getLongitude(), DELTA);
+ }
+
+ @Test
+ public void testAltitudeSetter() {
+ LatLng latLng = new LatLng(1.2, 3.4);
+ latLng.setAltitude(3);
+ assertEquals("altitude should match", 3, latLng.getAltitude(), DELTA);
+ }
+
+ @Test
+ public void testLatLngConstructor() {
+ LatLng latLng1 = new LatLng(1.2, 3.4);
+ LatLng latLng2 = new LatLng(latLng1);
+ assertEquals("latLng should match", latLng1, latLng2);
+ }
+
+ @Test
public void testDistanceTo() {
LatLng latLng1 = new LatLng(0.0, 0.0);
LatLng latLng2 = new LatLng(1.0, 1.0);
@@ -63,10 +92,6 @@ public class LatLngTest {
assertEquals("distance should match", 0.0, distance, DELTA);
}
- /*
- * A sample test where Mockito is necessary
- */
-
@Test
public void testLocationProvider() {
double latitude = 1.2;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateBoundsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateBoundsTest.java
deleted file mode 100644
index cf8ba3dc4d..0000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateBoundsTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package com.mapbox.mapboxsdk.maps;
-
-import com.mapbox.mapboxsdk.geometry.CoordinateBounds;
-import com.mapbox.mapboxsdk.geometry.LatLng;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-public class CoordinateBoundsTest {
-
- @Test
- public void testSanity() {
- CoordinateBounds coordinateBounds = new CoordinateBounds(null, null);
- assertNotNull("coordinateBounds should not be null", coordinateBounds);
- }
-
- @Test
- public void testSouthWestConstructor() {
- LatLng southWest = new LatLng(12, 12);
- CoordinateBounds coordinateBounds = new CoordinateBounds(southWest, null);
- assertEquals("southWest should match", southWest, coordinateBounds.getSouthWest());
- }
-
- @Test
- public void testNorthEastConstructor() {
- LatLng northEast = new LatLng(12, 12);
- CoordinateBounds coordinateBounds = new CoordinateBounds(null, northEast);
- assertEquals("northEast should match", northEast, coordinateBounds.getNorthEast());
- }
-
- @Test
- public void testHashCode() {
- LatLng northEast = new LatLng(60, 60);
- LatLng southWest = new LatLng(43, 26);
- CoordinateBounds coordinateBounds = new CoordinateBounds(northEast, southWest);
- assertEquals("hash code should match", coordinateBounds.hashCode(), -1515487232);
- }
-
- @Test
- public void testToString() {
- LatLng northEast = new LatLng(60, 60);
- LatLng southWest = new LatLng(43, 26);
- CoordinateBounds coordinateBounds = new CoordinateBounds(northEast, southWest);
- assertEquals("string should match",
- coordinateBounds.toString(),
- "CoordinateBounds [mNorthEast[" + coordinateBounds.getNorthEast() + "], mSouthWest[]" + coordinateBounds.getSouthWest() + "]");
- }
-
- @Test
- public void testEquals() {
- LatLng northEast = new LatLng(60, 60);
- LatLng southWest = new LatLng(43, 26);
- CoordinateBounds firstBounds = new CoordinateBounds(northEast, southWest);
- CoordinateBounds sameBounds = new CoordinateBounds(northEast, southWest);
- assertTrue(firstBounds.equals(sameBounds));
- }
-}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateRegionTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateRegionTest.java
deleted file mode 100644
index c37f48bf7c..0000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/CoordinateRegionTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package com.mapbox.mapboxsdk.maps;
-
-import com.mapbox.mapboxsdk.geometry.CoordinateRegion;
-import com.mapbox.mapboxsdk.geometry.CoordinateSpan;
-import com.mapbox.mapboxsdk.geometry.LatLng;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-public class CoordinateRegionTest {
-
- @Test
- public void testSanity() {
- LatLng center = new LatLng(1.2, 3.4, 5.6);
- CoordinateSpan span = new CoordinateSpan(9.8, 7.6);
- CoordinateRegion coordinateRegion = new CoordinateRegion(center, span);
- assertNotNull("coordinateRegion should not be null", coordinateRegion);
- }
-
- @Test
- public void testCenterConstructor() {
- LatLng center = new LatLng(1.2, 3.4, 5.6);
- CoordinateSpan span = new CoordinateSpan(9.8, 7.6);
- CoordinateRegion coordinateRegion = new CoordinateRegion(center, span);
- assertEquals("center should match", coordinateRegion.getCenter(), center);
- }
-
- @Test
- public void testSpanConstructor() {
- LatLng center = new LatLng(1.2, 3.4, 5.6);
- CoordinateSpan span = new CoordinateSpan(9.8, 7.6);
- CoordinateRegion coordinateRegion = new CoordinateRegion(center, span);
- assertEquals("span should match", coordinateRegion.getSpan(), span);
- }
-
- @Test
- public void testCenterMethod() {
- LatLng center = new LatLng(1.2, 3.4, 5.6);
- CoordinateSpan span = new CoordinateSpan(9.8, 7.6);
- CoordinateRegion coordinateRegion = new CoordinateRegion(null, span);
- coordinateRegion.setCenter(center);
- assertEquals("center should match", coordinateRegion.getCenter(), center);
- }
-
- @Test
- public void testSpanMethod() {
- LatLng center = new LatLng(1.2, 3.4, 5.6);
- CoordinateSpan span = new CoordinateSpan(9.8, 7.6);
- CoordinateRegion coordinateRegion = new CoordinateRegion(center, null);
- coordinateRegion.setSpan(span);
- assertEquals("span should match", coordinateRegion.getSpan(), span);
- }
-
-}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
index b9677af002..bbfd0c3e33 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
@@ -6,7 +6,6 @@ import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
@@ -359,7 +358,6 @@ public class MapboxMapTest {
assertTrue("Zoomlevel should be same", 12 == mMapboxMap.getCameraPosition().zoom);
}
-
//
// OnMarkerClick interface
//