summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera
diff options
context:
space:
mode:
authorTobrun <tobrun@mapbox.com>2016-01-11 11:32:00 +0100
committerTobrun <tobrun@mapbox.com>2016-01-29 13:15:58 +0100
commit8ed1dc9f7412d61a66bae576346f2674e6ab3926 (patch)
treecdd6ee3b83dcdb3733a80cb46797318b6598dda7 /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera
parent710398b780cc05e961a9c58c18176af46bbd34be (diff)
downloadqtlocation-mapboxgl-8ed1dc9f7412d61a66bae576346f2674e6ab3926.tar.gz
[android] #3145 - MapboxMap
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java122
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java53
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java214
3 files changed, 312 insertions, 77 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 7b98a0df37..6b059ed475 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
@@ -1,9 +1,17 @@
package com.mapbox.mapboxsdk.camera;
+import android.content.res.TypedArray;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.FloatRange;
+
+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.utils.MathUtils;
public final class CameraPosition implements Parcelable {
@@ -44,35 +52,22 @@ public final class CameraPosition implements Parcelable {
public final float zoom;
/**
- *
* Constructs a CameraPosition.
- * @param target The target location to align with the center of the screen.
- * @param zoom Zoom level at target. See zoom(float) for details of restrictions.
- * @param tilt The camera angle, in degrees, from the nadir (directly down). See tilt(float) for details of restrictions.
+ *
+ * @param target The target location to align with the center of the screen.
+ * @param zoom Zoom level at target. See zoom(float) for details of restrictions.
+ * @param tilt The camera angle, in degrees, from the nadir (directly down). See tilt(float) for details of restrictions.
* @param bearing Direction that the camera is pointing in, in degrees clockwise from north. This value will be normalized to be within 0 degrees inclusive and 360 degrees exclusive.
- * @throws NullPointerException if target is null
+ * @throws NullPointerException if target is null
* @throws IllegalArgumentException if tilt is outside the range of 0 to 90 degrees inclusive.
*/
- public CameraPosition (LatLng target, float zoom, float tilt, float bearing) throws NullPointerException, IllegalArgumentException{
- super();
- if (target == null) {
- throw new NullPointerException("target is NULL");
- }
+ CameraPosition(LatLng target, float zoom, float tilt, float bearing) {
this.target = target;
-
- // Allow for default value of -1
- if (tilt != -1) {
- if (tilt < 0.0f || tilt > 90.0f) {
- throw new IllegalArgumentException("tilt is outside of 0 to 90 degrees range");
- }
- }
- this.tilt = tilt;
-
this.bearing = bearing;
+ this.tilt = tilt;
this.zoom = zoom;
}
-
@Override
public int describeContents() {
return 0;
@@ -86,6 +81,36 @@ public final class CameraPosition implements Parcelable {
out.writeFloat(zoom);
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ CameraPosition cameraPosition = (CameraPosition) o;
+ if (!target.equals(cameraPosition.target)) {
+ return false;
+ } else if (zoom != cameraPosition.zoom) {
+ return false;
+ } else if (tilt != cameraPosition.tilt) {
+ return false;
+ } else if (bearing != cameraPosition.bearing) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 1;
+ result = 31 * result + (target != null ? target.hashCode() : 0);
+ return result;
+ }
+
/**
* Builds camera position.
*/
@@ -105,6 +130,7 @@ public final class CameraPosition implements Parcelable {
/**
* Create Builder with an existing CameraPosition data.
+ *
* @param previous Existing CameraPosition values to use
*/
public Builder(CameraPosition previous) {
@@ -118,17 +144,64 @@ public final class CameraPosition implements Parcelable {
}
/**
+ * Create Builder with an existing CameraPosition data.
+ *
+ * @param typedArray TypedArray containgin attribute values
+ */
+ public Builder(TypedArray typedArray){
+ super();
+ if(typedArray!=null) {
+ this.bearing = typedArray.getFloat(R.styleable.MapView_direction, 0.0f);
+ double lat = typedArray.getFloat(R.styleable.MapView_center_latitude, 0.0f);
+ double lng = typedArray.getFloat(R.styleable.MapView_center_longitude, 0.0f);
+ this.target= new LatLng(lat, lng);
+ this.tilt = typedArray.getFloat(R.styleable.MapView_tilt, 0.0f);
+ this.zoom = typedArray.getFloat(R.styleable.MapView_zoom, 0.0f);
+ }
+ }
+
+ /**
+ * Create Builder from an existing PositionCameraUpdate update.
+ *
+ * @param update Update containing camera options
+ */
+ public Builder(CameraUpdateFactory.PositionCameraUpdate update) {
+ super();
+ if (update != null) {
+ this.bearing = update.getBearing();
+ this.target = update.getTarget();
+ this.tilt = update.getTilt();
+ this.zoom = update.getZoom();
+ }
+ }
+
+
+ /**
+ * Create Builder from an existing PositionCameraUpdate update.
+ *
+ * @param update Update containing camera options
+ */
+ public Builder(CameraUpdateFactory.ZoomUpdate update){
+ super();
+ if(update!=null){
+ this.zoom = update.getZoom();
+ }
+ }
+
+ /**
* Sets the direction that the camera is pointing in, in degrees clockwise from north.
+ *
* @param bearing Bearing
* @return Builder
*/
- public Builder bearing (float bearing) {
- this.bearing = bearing;
+ public Builder bearing(float bearing) {
+ this.bearing = (float) (-bearing * MathConstants.DEG2RAD);
return this;
}
/**
* Builds a CameraPosition.
+ *
* @return CameraPosition
*/
public CameraPosition build() {
@@ -137,6 +210,7 @@ public final class CameraPosition implements Parcelable {
/**
* Sets the location that the camera is pointing at.
+ *
* @param location Location
* @return Builder
*/
@@ -147,17 +221,19 @@ public final class CameraPosition implements Parcelable {
/**
* Set the tilt
+ *
* @param tilt Tilt value
* @return Builder
*/
@FloatRange(from = 0.0, to = 60.0)
public Builder tilt(float tilt) {
- this.tilt = tilt;
+ this.tilt = (float) (MathUtils.clamp(tilt, MapboxConstants.MINIMUM_TILT, MapboxConstants.MAXIMUM_TILT) * MathConstants.DEG2RAD);
return this;
}
/**
* Set the zoom
+ *
* @param zoom Zoom value
* @return Builder
*/
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
index 33f551550b..61f3a2ecfa 100644
--- 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
@@ -1,56 +1,5 @@
package com.mapbox.mapboxsdk.camera;
-import com.mapbox.mapboxsdk.geometry.LatLng;
+public interface CameraUpdate {
-public final class CameraUpdate {
-
- /**
- * Direction that the camera is pointing in, in degrees clockwise from north.
- */
- private final float bearing;
-
- /**
- * The location that the camera is pointing at.
- */
- private final LatLng target;
-
- /**
- * The angle, in degrees, of the camera angle from the nadir (directly facing the Earth). See tilt(float) for details of restrictions on the range of values.
- */
- private final float tilt;
-
- /**
- * Zoom level near the center of the screen. See zoom(float) for the definition of the camera's zoom level.
- */
- private final float zoom;
-
- /**
- * Package Private Constructor to only be used CameraUpdateFactory
- * @param bearing Final Bearing
- * @param target Final Target
- * @param tilt Final Tilt
- * @param zoom Final Zoom
- */
- CameraUpdate(float bearing, LatLng target, float tilt, float zoom) {
- this.bearing = bearing;
- this.target = target;
- this.tilt = tilt;
- this.zoom = zoom;
- }
-
- public float getBearing() {
- return bearing;
- }
-
- public LatLng getTarget() {
- return target;
- }
-
- public float getTilt() {
- return tilt;
- }
-
- public float getZoom() {
- return zoom;
- }
}
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
index 3ba2090bd2..6f39f8b7cc 100644
--- 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
@@ -1,15 +1,225 @@
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 CameraUpdate(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom);
+ 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(ZoomUpdate.ZOOM_TO_POINT, 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;
+ }
}
}