summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java1
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java27
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java23
3 files changed, 41 insertions, 10 deletions
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 31f13cbcff..39b937210c 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
@@ -20,3 +20,4 @@ public interface CameraUpdate {
CameraPosition getCameraPosition(@NonNull MapboxMap mapboxMap);
}
+
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 aba1b13ecd..daf5ef415d 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
@@ -93,7 +93,9 @@ public final class CameraUpdateFactory {
* @param xPixel Amount of pixels to scroll to in x direction
* @param yPixel Amount of pixels to scroll to in y direction
* @return CameraUpdate Final Camera Position
+ * @deprecated use {@link MapboxMap#scrollBy(float, float)} for more precise displacements when using a padded map.
*/
+ @Deprecated
public static CameraUpdate scrollBy(float xPixel, float yPixel) {
return new CameraMoveUpdate(xPixel, yPixel);
}
@@ -336,22 +338,27 @@ public final class CameraUpdateFactory {
public CameraPosition getCameraPosition(@NonNull MapboxMap mapboxMap) {
UiSettings uiSettings = mapboxMap.getUiSettings();
Projection projection = mapboxMap.getProjection();
-
// Calculate the new center point
float viewPortWidth = uiSettings.getWidth();
float viewPortHeight = uiSettings.getHeight();
- PointF targetPoint = new PointF(viewPortWidth / 2 + x, viewPortHeight / 2 + y);
+ int[] padding = mapboxMap.getPadding();
- // Convert point to LatLng
- LatLng latLng = projection.fromScreenLocation(targetPoint);
+ // we inverse the map padding, is reapplied when using moveTo/easeTo or animateTo
+ PointF targetPoint = new PointF(
+ (viewPortWidth - padding[0] + padding[1]) / 2 + x,
+ (viewPortHeight + padding[1] - padding[3]) / 2 + y
+ );
+ LatLng latLng = projection.fromScreenLocation(targetPoint);
CameraPosition previousPosition = mapboxMap.getCameraPosition();
- return new CameraPosition.Builder()
- .target(latLng != null ? latLng : previousPosition.target)
- .zoom(previousPosition.zoom)
- .tilt(previousPosition.tilt)
- .bearing(previousPosition.bearing)
- .build();
+ CameraPosition position =
+ new CameraPosition.Builder()
+ .target(latLng)
+ .zoom(previousPosition.zoom)
+ .tilt(previousPosition.tilt)
+ .bearing(previousPosition.bearing)
+ .build();
+ return position;
}
@Override
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 7b9484d309..7172a6a52a 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
@@ -866,6 +866,29 @@ public final class MapboxMap {
}
}
+ /**
+ * Scrolls the camera over the map, shifting the center of view by the specified number of pixels in the x and y
+ * directions.
+ *
+ * @param x Amount of pixels to scroll to in x direction
+ * @param y Amount of pixels to scroll to in y direction
+ */
+ public void scrollBy(float x, float y) {
+ nativeMapView.moveBy(x, y);
+ }
+
+ /**
+ * Scrolls the camera over the map, shifting the center of view by the specified number of pixels in the x and y
+ * directions.
+ *
+ * @param x Amount of pixels to scroll to in x direction
+ * @param y Amount of pixels to scroll to in y direction
+ * @param duration Amount of time the scrolling should take
+ */
+ public void scrollBy(float x, float y, long duration) {
+ nativeMapView.moveBy(x, y, duration);
+ }
+
//
// Reset North
//