From 6a9706adafe993cec3f6990315bda9b0ecd1108f Mon Sep 17 00:00:00 2001 From: osana Date: Thu, 29 Nov 2018 13:39:09 -0500 Subject: native should be called only with LatLngUnwrappedBounds --- .../mapboxsdk/camera/CameraUpdateFactory.java | 3 +- .../mapboxsdk/geometry/LatLngUnwrappedBounds.java | 247 +++++++++++++++++++++ .../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 26 ++- .../com/mapbox/mapboxsdk/maps/NativeMapView.java | 11 +- .../OfflineTilePyramidRegionDefinition.java | 24 +- .../mapboxsdk/snapshotter/MapSnapshotter.java | 11 +- .../style/sources/CustomGeometrySource.java | 5 +- .../mapboxsdk/testapp/camera/CameraForTest.java | 12 +- .../snapshot/MapSnapshotterReuseActivity.java | 6 +- platform/android/src/geometry/lat_lng_bounds.cpp | 5 +- platform/android/src/geometry/lat_lng_bounds.hpp | 5 +- platform/android/src/native_map_view.cpp | 5 +- .../src/offline/offline_region_definition.cpp | 2 +- .../android/src/snapshotter/map_snapshotter.cpp | 4 +- .../src/style/sources/custom_geometry_source.cpp | 2 +- 15 files changed, 324 insertions(+), 44 deletions(-) create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngUnwrappedBounds.java 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 54788caa40..34ca230090 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 @@ -8,6 +8,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.geometry.LatLngUnwrappedBounds; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.Projection; import com.mapbox.mapboxsdk.maps.UiSettings; @@ -289,7 +290,7 @@ public final class CameraUpdateFactory { @Override public CameraPosition getCameraPosition(@NonNull MapboxMap mapboxMap) { - return mapboxMap.getCameraForLatLngBounds(bounds, padding); + return mapboxMap.getCameraForLatLngBounds(LatLngUnwrappedBounds.from(bounds), padding); } @Override diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngUnwrappedBounds.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngUnwrappedBounds.java new file mode 100644 index 0000000000..d279da0211 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngUnwrappedBounds.java @@ -0,0 +1,247 @@ +package com.mapbox.mapboxsdk.geometry; + +import android.os.Parcel; +import android.os.Parcelable; +import android.support.annotation.FloatRange; +import android.support.annotation.Keep; +import android.support.annotation.NonNull; + +import com.mapbox.mapboxsdk.constants.GeometryConstants; + +public class LatLngUnwrappedBounds implements Parcelable { + + @Keep + private final double latitudeNorth; + @Keep + private final double latitudeSouth; + @Keep + private final double longitudeEast; + @Keep + private final double longitudeWest; + + /** + * Constructs a LatLngUnwrappedBounds from doubles representing a LatLng pair. + *

+ * This values of latNorth and latSouth should be in the range of [-90, 90], + * see {@link GeometryConstants#MIN_LATITUDE} and {@link GeometryConstants#MAX_LATITUDE}, + * otherwise IllegalArgumentException will be thrown. + * latNorth should be greater or equal latSouth, otherwise IllegalArgumentException will be thrown. + * lonEast should be greater or equal lonWest, otherwise IllegalArgumentException will be thrown. + *

+ * This method doesn't recalculate most east or most west boundaries. + * Note that lonEast and lonWest will NOT be wrapped to be in the range of [-180, 180]. + */ + public static LatLngUnwrappedBounds from( + @FloatRange(from = GeometryConstants.MIN_LATITUDE, to = GeometryConstants.MAX_LATITUDE) double latNorth, + double lonEast, + @FloatRange(from = GeometryConstants.MIN_LATITUDE, to = GeometryConstants.MAX_LATITUDE) double latSouth, + double lonWest) { + + checkParams(latNorth, lonEast, latSouth, lonWest); + + return new LatLngUnwrappedBounds(latNorth, lonEast, latSouth, lonWest); + } + + public static LatLngUnwrappedBounds from(LatLngBounds latLngBounds) { + + if (latLngBounds == null) { + return null; + } + + if (latLngBounds.getLonEast() < latLngBounds.getLonWest()) { + return new LatLngUnwrappedBounds(latLngBounds.getLatNorth(), + latLngBounds.getLonEast(), + latLngBounds.getLatSouth(), + latLngBounds.getLonWest() - GeometryConstants.LONGITUDE_SPAN); + } + + return new LatLngUnwrappedBounds(latLngBounds.getLatNorth(), + latLngBounds.getLonEast(), + latLngBounds.getLatSouth(), + latLngBounds.getLonWest()); + } + + private static void checkParams( + @FloatRange(from = GeometryConstants.MIN_LATITUDE, to = GeometryConstants.MAX_LATITUDE) double latNorth, + double lonEast, + @FloatRange(from = GeometryConstants.MIN_LATITUDE, to = GeometryConstants.MAX_LATITUDE) double latSouth, + double lonWest) { + + if (Double.isNaN(latNorth) || Double.isNaN(latSouth)) { + throw new IllegalArgumentException("latitude must not be NaN"); + } + + if (Double.isNaN(lonEast) || Double.isNaN(lonWest)) { + throw new IllegalArgumentException("longitude must not be NaN"); + } + + if (latNorth > GeometryConstants.MAX_LATITUDE || latNorth < GeometryConstants.MIN_LATITUDE + || latSouth > GeometryConstants.MAX_LATITUDE || latSouth < GeometryConstants.MIN_LATITUDE) { + throw new IllegalArgumentException("latitude must be between -90 and 90"); + } + + if (latNorth < latSouth) { + throw new IllegalArgumentException("latNorth cannot be less than latSouth"); + } + + if (lonEast < lonWest) { + throw new IllegalArgumentException("lonEast cannot be less than lonWest"); + } + } + + /** + * Construct a new LatLngUnwrappedBounds based on its corners, given in NESW + * order. + * + * @param northLatitude Northern Latitude + * @param eastLongitude Eastern Longitude + * @param southLatitude Southern Latitude + * @param westLongitude Western Longitude + */ + @Keep + LatLngUnwrappedBounds(final double northLatitude, final double eastLongitude, + final double southLatitude, final double westLongitude) { + this.latitudeNorth = northLatitude; + this.longitudeEast = eastLongitude; + this.latitudeSouth = southLatitude; + this.longitudeWest = westLongitude; + } + + /** + * Get the north latitude value of this bounds. + * + * @return double latitude value for north + */ + public double getLatNorth() { + return this.latitudeNorth; + } + + /** + * Get the south latitude value of this bounds. + * + * @return double latitude value for south + */ + public double getLatSouth() { + return this.latitudeSouth; + } + + /** + * Get the east longitude value of this bounds. + * + * @return double longitude value for east + */ + public double getLonEast() { + return this.longitudeEast; + } + + /** + * Get the west longitude value of this bounds. + * + * @return double longitude value for west + */ + public double getLonWest() { + return this.longitudeWest; + } + + /** + * Get the latitude-longitude pair of the south west corner of this bounds. + * + * @return LatLng of the south west corner + */ + @NonNull + public LatLng getSouthWest() { + return new LatLng(latitudeSouth, longitudeWest); + } + + /** + * Get the latitude-longitude paur if the north east corner of this bounds. + * + * @return LatLng of the north east corner + */ + @NonNull + public LatLng getNorthEast() { + return new LatLng(latitudeNorth, longitudeEast); + } + + /** + * Get the latitude-longitude pair of the south east corner of this bounds. + * + * @return LatLng of the south east corner + */ + @NonNull + public LatLng getSouthEast() { + return new LatLng(latitudeSouth, longitudeEast); + } + + /** + * Get the latitude-longitude pair of the north west corner of this bounds. + * + * @return LatLng of the north west corner + */ + @NonNull + public LatLng getNorthWest() { + return new LatLng(latitudeNorth, longitudeWest); + } + + /** + * Inner class responsible for recreating Parcels into objects. + */ + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + @Override + public LatLngUnwrappedBounds createFromParcel(@NonNull final Parcel in) { + return readFromParcel(in); + } + + @Override + public LatLngUnwrappedBounds[] newArray(final int size) { + return new LatLngUnwrappedBounds[size]; + } + }; + + /** + * Returns a hash code value for the object. + * + * @return the hash code + */ + @Override + public int hashCode() { + return (int) ((latitudeNorth + 90) + + ((latitudeSouth + 90) * 1000) + + ((longitudeEast + 180) * 1000000) + + ((longitudeWest + 180) * 1000000000)); + } + + /** + * Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. + * + * @return a bitmask indicating the set of special object types marshaled by this Parcelable object instance. + */ + @Override + public int describeContents() { + return 0; + } + + /** + * Flatten this object in to a Parcel. + * + * @param out The Parcel in which the object should be written. + * @param flags Additional flags about how the object should be written + */ + @Override + public void writeToParcel(@NonNull final Parcel out, final int flags) { + out.writeDouble(this.latitudeNorth); + out.writeDouble(this.longitudeEast); + out.writeDouble(this.latitudeSouth); + out.writeDouble(this.longitudeWest); + } + + private static LatLngUnwrappedBounds readFromParcel(final Parcel in) { + final double northLat = in.readDouble(); + final double eastLon = in.readDouble(); + final double southLat = in.readDouble(); + final double westLon = in.readDouble(); + return new LatLngUnwrappedBounds(northLat, eastLon, southLat, westLon); + } + +} 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 3b4db2e62a..eaee270109 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 @@ -36,6 +36,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.geometry.LatLngUnwrappedBounds; import com.mapbox.mapboxsdk.location.LocationComponent; import com.mapbox.mapboxsdk.log.Logger; import com.mapbox.mapboxsdk.offline.OfflineRegionDefinition; @@ -1244,66 +1245,67 @@ public final class MapboxMap { /** * Get a camera position that fits a provided bounds and the current camera tilt and bearing. * - * @param latLngBounds the bounds to set the map with + * @param latLngUnwrappedBounds the bounds to set the map with * @return the camera position that fits the bounds */ @NonNull - public CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds latLngBounds) { + public CameraPosition getCameraForLatLngBounds(@NonNull LatLngUnwrappedBounds latLngUnwrappedBounds) { // we use current camera tilt value to provide expected transformations as #11993 - return getCameraForLatLngBounds(latLngBounds, new int[] {0, 0, 0, 0}); + return getCameraForLatLngBounds(latLngUnwrappedBounds, new int[] {0, 0, 0, 0}); } /** * Get a camera position that fits a provided bounds and padding and the current camera tilt and bearing. * - * @param latLngBounds the bounds to set the map with + * @param latLngUnwrappedBounds the bounds to set the map with * @param padding the padding to apply to the bounds * @return the camera position that fits the bounds and padding */ @NonNull - public CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds latLngBounds, + public CameraPosition getCameraForLatLngBounds(@NonNull LatLngUnwrappedBounds latLngUnwrappedBounds, @NonNull @Size(value = 4) int[] padding) { // we use current camera tilt/bearing value to provide expected transformations as #11993 - return getCameraForLatLngBounds(latLngBounds, padding, transform.getRawBearing(), transform.getTilt()); + return getCameraForLatLngBounds(latLngUnwrappedBounds, + padding, transform.getRawBearing(), transform.getTilt()); } /** * Get a camera position that fits a provided bounds, bearing and tilt. * - * @param latLngBounds the bounds to set the map with + * @param latLngUnwrappedBounds the bounds to set the map with * @param bearing the bearing to transform the camera position with * @param tilt to transform the camera position with * @return the camera position that fits the bounds and given bearing and tilt */ @NonNull - public CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds latLngBounds, + public CameraPosition getCameraForLatLngBounds(@NonNull LatLngUnwrappedBounds latLngUnwrappedBounds, @FloatRange(from = MapboxConstants.MINIMUM_DIRECTION, to = MapboxConstants.MAXIMUM_DIRECTION) double bearing, @FloatRange(from = MapboxConstants.MINIMUM_TILT, to = MapboxConstants.MAXIMUM_TILT) double tilt) { - return getCameraForLatLngBounds(latLngBounds, new int[] {0, 0, 0, 0}, bearing, tilt); + return getCameraForLatLngBounds(latLngUnwrappedBounds, new int[] {0, 0, 0, 0}, bearing, tilt); } /** * Get a camera position that fits a provided bounds, padding, bearing and tilt. * - * @param latLngBounds the bounds to set the map with + * @param latLngUnwrappedBounds the bounds to set the map with * @param padding the padding to apply to the bounds * @param bearing the bearing to transform the camera position with * @param tilt to transform the camera position with * @return the camera position that fits the bounds, bearing and tilt */ @NonNull - public CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds latLngBounds, + public CameraPosition getCameraForLatLngBounds(@NonNull LatLngUnwrappedBounds latLngUnwrappedBounds, @NonNull @Size(value = 4) int[] padding, @FloatRange(from = MapboxConstants.MINIMUM_DIRECTION, to = MapboxConstants.MAXIMUM_DIRECTION) double bearing, @FloatRange(from = MapboxConstants.MINIMUM_TILT, to = MapboxConstants.MAXIMUM_TILT) double tilt) { - return nativeMapView.getCameraForLatLngBounds(latLngBounds, padding, bearing, tilt); + return nativeMapView.getCameraForLatLngBounds(latLngUnwrappedBounds, padding, bearing, tilt); } /** 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 8c929fee63..925d590890 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 @@ -25,6 +25,7 @@ import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.exceptions.CalledFromWorkerThreadException; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.geometry.LatLngUnwrappedBounds; import com.mapbox.mapboxsdk.geometry.ProjectedMeters; import com.mapbox.mapboxsdk.log.Logger; import com.mapbox.mapboxsdk.maps.renderer.MapRenderer; @@ -214,7 +215,7 @@ final class NativeMapView { if (checkState("setLatLngBounds")) { return; } - nativeSetLatLngBounds(latLngBounds); + nativeSetLatLngBounds(LatLngUnwrappedBounds.from(latLngBounds)); } public void cancelTransitions() { @@ -267,7 +268,8 @@ final class NativeMapView { return nativeGetLatLng().wrap(); } - public CameraPosition getCameraForLatLngBounds(LatLngBounds bounds, int[] padding, double bearing, double tilt) { + public CameraPosition getCameraForLatLngBounds(LatLngUnwrappedBounds bounds, + int[] padding, double bearing, double tilt) { if (checkState("getCameraForLatLngBounds")) { return null; } @@ -1024,7 +1026,7 @@ final class NativeMapView { private native String nativeGetStyleJson(); @Keep - private native void nativeSetLatLngBounds(LatLngBounds latLngBounds); + private native void nativeSetLatLngBounds(LatLngUnwrappedBounds latLngUnwrappedBounds); @Keep private native void nativeCancelTransitions(); @@ -1045,7 +1047,8 @@ final class NativeMapView { @NonNull @Keep private native CameraPosition nativeGetCameraForLatLngBounds( - LatLngBounds latLngBounds, double top, double left, double bottom, double right, double bearing, double tilt); + LatLngUnwrappedBounds latLngUnwrappedBounds, + double top, double left, double bottom, double right, double bearing, double tilt); @NonNull @Keep diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineTilePyramidRegionDefinition.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineTilePyramidRegionDefinition.java index 8649c70acb..8ee3da5118 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineTilePyramidRegionDefinition.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineTilePyramidRegionDefinition.java @@ -7,6 +7,7 @@ import android.support.annotation.Keep; import android.support.annotation.NonNull; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.geometry.LatLngUnwrappedBounds; /** * An offline region defined by a style URL, geographic bounding box, zoom range, and @@ -44,7 +45,7 @@ public class OfflineTilePyramidRegionDefinition implements OfflineRegionDefiniti @Keep public OfflineTilePyramidRegionDefinition( String styleURL, LatLngBounds bounds, double minZoom, double maxZoom, float pixelRatio) { - // Note: Also used in JNI + this.styleURL = styleURL; this.bounds = bounds; this.minZoom = minZoom; @@ -52,6 +53,27 @@ public class OfflineTilePyramidRegionDefinition implements OfflineRegionDefiniti this.pixelRatio = pixelRatio; } + /** + * Constructor to create an OfflineTilePyramidDefinition from parameters. + * + * @param styleURL the style + * @param unwrappedBounds the unwrapped bounds + * @param minZoom min zoom + * @param maxZoom max zoom + * @param pixelRatio pixel ratio of the device + */ + @Keep + public OfflineTilePyramidRegionDefinition( + String styleURL, LatLngUnwrappedBounds unwrappedBounds, + double minZoom, double maxZoom, float pixelRatio) { + + // Note: Also used in JNI + this(styleURL, + LatLngBounds.from(unwrappedBounds.getLatNorth(), unwrappedBounds.getLonEast(), + unwrappedBounds.getLatSouth(), unwrappedBounds.getLonWest()), + minZoom, maxZoom, pixelRatio); + } + /** * Constructor to create an OfflineTilePyramidDefinition from a Parcel. * diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java index a1d84f1fd4..5362f3ba86 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java @@ -27,6 +27,7 @@ import com.mapbox.mapboxsdk.attribution.AttributionParser; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.maps.Style; import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.geometry.LatLngUnwrappedBounds; import com.mapbox.mapboxsdk.log.Logger; import com.mapbox.mapboxsdk.maps.TelemetryDefinition; import com.mapbox.mapboxsdk.storage.FileSource; @@ -288,7 +289,8 @@ public class MapSnapshotter { String programCacheDir = FileSource.getInternalCachePath(context); nativeInitialize(this, fileSource, options.pixelRatio, options.width, - options.height, options.styleUrl, options.styleJson, options.region, options.cameraPosition, + options.height, options.styleUrl, options.styleJson, + LatLngUnwrappedBounds.from(options.region), options.cameraPosition, options.showLogo, programCacheDir, options.localIdeographFontFamily); } @@ -339,10 +341,10 @@ public class MapSnapshotter { /** * Updates the snapshotter with a new {@link LatLngBounds} * - * @param region the region + * @param unwrappedRegion the region */ @Keep - public native void setRegion(LatLngBounds region); + public native void setRegion(LatLngUnwrappedBounds unwrappedRegion); /** * Updates the snapshotter with a new style url @@ -570,7 +572,8 @@ public class MapSnapshotter { protected native void nativeInitialize(MapSnapshotter mapSnapshotter, FileSource fileSource, float pixelRatio, int width, int height, String styleUrl, String styleJson, - LatLngBounds region, CameraPosition position, + LatLngUnwrappedBounds unwrappedRegion, + CameraPosition position, boolean showLogo, String programCacheDir, String localIdeographFontFamily); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java index b75ccf5a9c..ba68ee694a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java @@ -9,6 +9,7 @@ import android.support.annotation.WorkerThread; import com.mapbox.geojson.Feature; import com.mapbox.geojson.FeatureCollection; import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.geometry.LatLngUnwrappedBounds; import com.mapbox.mapboxsdk.style.expressions.Expression; import java.lang.ref.WeakReference; @@ -84,7 +85,7 @@ public class CustomGeometrySource extends Source { * @param bounds The region in which features should be invalidated at all zoom levels */ public void invalidateRegion(LatLngBounds bounds) { - nativeInvalidateBounds(bounds); + nativeInvalidateBounds(LatLngUnwrappedBounds.from(bounds)); } /** @@ -140,7 +141,7 @@ public class CustomGeometrySource extends Source { private native void nativeInvalidateTile(int z, int x, int y); @Keep - private native void nativeInvalidateBounds(LatLngBounds bounds); + private native void nativeInvalidateBounds(LatLngUnwrappedBounds bounds); @Override @Keep diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraForTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraForTest.java index 39b2c8d763..47d6ef8518 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraForTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/camera/CameraForTest.java @@ -5,7 +5,7 @@ import com.mapbox.geojson.Point; import com.mapbox.geojson.Polygon; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.geometry.LatLngUnwrappedBounds; import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; import com.mapbox.mapboxsdk.testapp.activity.espresso.DeviceIndependentTestActivity; import org.junit.Test; @@ -22,7 +22,7 @@ public class CameraForTest extends BaseActivityTest { validateTestSetup(); onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( - LatLngBounds.from(10, 10, -10, -10)); + LatLngUnwrappedBounds.from(10, 10, -10, -10)); CameraPosition expectedPosition = new CameraPosition.Builder() .target(new LatLng()).zoom(4.16).tilt(0).bearing(0).build(); assertEquals("Latitude should match", @@ -40,7 +40,7 @@ public class CameraForTest extends BaseActivityTest { validateTestSetup(); onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( - LatLngBounds.from(10, 10, -10, -10), new int[] {5, 5, 5, 5}); + LatLngUnwrappedBounds.from(10, 10, -10, -10), new int[] {5, 5, 5, 5}); CameraPosition expectedPosition = new CameraPosition.Builder() .target(new LatLng()).zoom(4.13).tilt(0).bearing(0).build(); assertEquals("Latitude should match", @@ -61,7 +61,7 @@ public class CameraForTest extends BaseActivityTest { validateTestSetup(); onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( - LatLngBounds.from(10, 10, -10, -10), 45, 0); + LatLngUnwrappedBounds.from(10, 10, -10, -10), 45, 0); CameraPosition expectedPosition = new CameraPosition.Builder() .target(new LatLng()).zoom(3.66).tilt(0).bearing(45).build(); assertEquals("Latitude should match", @@ -82,7 +82,7 @@ public class CameraForTest extends BaseActivityTest { validateTestSetup(); onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( - LatLngBounds.from(10, 10, -10, -10), 0, 45); + LatLngUnwrappedBounds.from(10, 10, -10, -10), 0, 45); CameraPosition expectedPosition = new CameraPosition.Builder() .target(new LatLng(-0.264576975267, 0)).zoom(4.13).tilt(45).bearing(0).build(); assertEquals("Latitude should match", @@ -103,7 +103,7 @@ public class CameraForTest extends BaseActivityTest { validateTestSetup(); onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> { CameraPosition actualPosition = mapboxMap.getCameraForLatLngBounds( - LatLngBounds.from(10, 10, -10, -10), new int[] {5, 5, 5, 5}, 45, 45); + LatLngUnwrappedBounds.from(10, 10, -10, -10), new int[] {5, 5, 5, 5}, 45, 45); CameraPosition expectedPosition = new CameraPosition.Builder() .target(new LatLng(-0.3732134634, -0.3713191053)).zoom(3.63).tilt(45).bearing(45).build(); assertEquals("Latitude should match", diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterReuseActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterReuseActivity.java index 901f364c88..e08cd4f698 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterReuseActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterReuseActivity.java @@ -8,7 +8,7 @@ import android.widget.ImageView; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.maps.Style; import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.geometry.LatLngBounds; +import com.mapbox.mapboxsdk.geometry.LatLngUnwrappedBounds; import com.mapbox.mapboxsdk.snapshotter.MapSnapshot; import com.mapbox.mapboxsdk.snapshotter.MapSnapshotter; import com.mapbox.mapboxsdk.testapp.R; @@ -63,8 +63,8 @@ public class MapSnapshotterReuseActivity extends AppCompatActivity implements Ma imageView.setImageBitmap(snapshot.getBitmap()); } - private LatLngBounds getRandomBounds() { - return LatLngBounds.from( + private LatLngUnwrappedBounds getRandomBounds() { + return LatLngUnwrappedBounds.from( randomInRange(5, 10), randomInRange(-5, 5), randomInRange(-5, 5), diff --git a/platform/android/src/geometry/lat_lng_bounds.cpp b/platform/android/src/geometry/lat_lng_bounds.cpp index d76ff5b365..c7d139bf58 100644 --- a/platform/android/src/geometry/lat_lng_bounds.cpp +++ b/platform/android/src/geometry/lat_lng_bounds.cpp @@ -9,7 +9,8 @@ jni::Local> LatLngBounds::New(jni::JNIEnv& env, mbgl:: return javaClass.New(env, constructor, bounds.north(), bounds.east(), bounds.south(), bounds.west()); } -mbgl::LatLngBounds LatLngBounds::getLatLngBounds(jni::JNIEnv& env, const jni::Object& bounds) { +mbgl::LatLngBounds LatLngBounds::getLatLngUnwrappedBounds(jni::JNIEnv &env, + const jni::Object &bounds) { static auto& javaClass = jni::Class::Singleton(env); static auto swLatField = javaClass.GetField(env, "latitudeSouth"); static auto swLonField = javaClass.GetField(env, "longitudeWest"); @@ -19,8 +20,6 @@ mbgl::LatLngBounds LatLngBounds::getLatLngBounds(jni::JNIEnv& env, const jni::Ob mbgl::LatLng sw = { bounds.Get(env, swLatField), bounds.Get(env, swLonField) }; mbgl::LatLng ne = { bounds.Get(env, neLatField), bounds.Get(env, neLonField) }; - sw.unwrapForShortestPath(ne); - return mbgl::LatLngBounds::hull(sw, ne); } diff --git a/platform/android/src/geometry/lat_lng_bounds.hpp b/platform/android/src/geometry/lat_lng_bounds.hpp index d51026711d..819d0ca847 100644 --- a/platform/android/src/geometry/lat_lng_bounds.hpp +++ b/platform/android/src/geometry/lat_lng_bounds.hpp @@ -12,11 +12,12 @@ namespace android { class LatLngBounds : private mbgl::util::noncopyable { public: - static constexpr auto Name() { return "com/mapbox/mapboxsdk/geometry/LatLngBounds"; }; + static constexpr auto Name() { return "com/mapbox/mapboxsdk/geometry/LatLngUnwrappedBounds"; }; static jni::Local> New(jni::JNIEnv&, mbgl::LatLngBounds); - static mbgl::LatLngBounds getLatLngBounds(jni::JNIEnv&, const jni::Object&); + static mbgl::LatLngBounds getLatLngUnwrappedBounds(jni::JNIEnv &, + const jni::Object &); static void registerNative(jni::JNIEnv&); }; diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index d908b14d36..58bc105c81 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -231,7 +231,7 @@ void NativeMapView::setStyleJson(jni::JNIEnv& env, const jni::String& json) { void NativeMapView::setLatLngBounds(jni::JNIEnv& env, const jni::Object& jBounds) { if (jBounds) { - map->setLatLngBounds(mbgl::android::LatLngBounds::getLatLngBounds(env, jBounds)); + map->setLatLngBounds(mbgl::android::LatLngBounds::getLatLngUnwrappedBounds(env, jBounds)); } else { map->setLatLngBounds(mbgl::LatLngBounds::world()); } @@ -324,7 +324,8 @@ void NativeMapView::setLatLng(jni::JNIEnv&, jni::jdouble latitude, jni::jdouble jni::Local> NativeMapView::getCameraForLatLngBounds(jni::JNIEnv& env, const jni::Object& jBounds, double top, double left, double bottom, double right, double bearing, double tilt) { mbgl::EdgeInsets padding = {top, left, bottom, right}; - return CameraPosition::New(env, map->cameraForLatLngBounds(mbgl::android::LatLngBounds::getLatLngBounds(env, jBounds), padding, bearing, tilt)); + return CameraPosition::New(env, map->cameraForLatLngBounds( + mbgl::android::LatLngBounds::getLatLngUnwrappedBounds(env, jBounds), padding, bearing, tilt)); } jni::Local> NativeMapView::getCameraForGeometry(jni::JNIEnv& env, const jni::Object& jGeometry, double top, double left, double bottom, double right, double bearing, double tilt) { diff --git a/platform/android/src/offline/offline_region_definition.cpp b/platform/android/src/offline/offline_region_definition.cpp index 23e5b7466b..fbb2396adb 100644 --- a/platform/android/src/offline/offline_region_definition.cpp +++ b/platform/android/src/offline/offline_region_definition.cpp @@ -50,7 +50,7 @@ mbgl::OfflineTilePyramidRegionDefinition OfflineTilePyramidRegionDefinition::get return mbgl::OfflineTilePyramidRegionDefinition( jni::Make(env, jDefinition.Get(env, styleURLF)), - LatLngBounds::getLatLngBounds(env, jDefinition.Get(env, boundsF)), + LatLngBounds::getLatLngUnwrappedBounds(env, jDefinition.Get(env, boundsF)), jDefinition.Get(env, minZoomF), jDefinition.Get(env, maxZoomF), jDefinition.Get(env, pixelRatioF) diff --git a/platform/android/src/snapshotter/map_snapshotter.cpp b/platform/android/src/snapshotter/map_snapshotter.cpp index a5f44a1d4c..3da5245f42 100644 --- a/platform/android/src/snapshotter/map_snapshotter.cpp +++ b/platform/android/src/snapshotter/map_snapshotter.cpp @@ -47,7 +47,7 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env, optional bounds; if (region) { - bounds = LatLngBounds::getLatLngBounds(_env, region); + bounds = LatLngBounds::getLatLngUnwrappedBounds(_env, region); } std::pair style; @@ -130,7 +130,7 @@ void MapSnapshotter::setCameraPosition(JNIEnv& env, const jni::Object& region) { - snapshotter->setRegion(LatLngBounds::getLatLngBounds(env, region)); + snapshotter->setRegion(LatLngBounds::getLatLngUnwrappedBounds(env, region)); } diff --git a/platform/android/src/style/sources/custom_geometry_source.cpp b/platform/android/src/style/sources/custom_geometry_source.cpp index 057f5c99ba..0c3b582e3e 100644 --- a/platform/android/src/style/sources/custom_geometry_source.cpp +++ b/platform/android/src/style/sources/custom_geometry_source.cpp @@ -142,7 +142,7 @@ namespace android { } void CustomGeometrySource::invalidateBounds(jni::JNIEnv& env, const jni::Object& jBounds) { - auto bounds = LatLngBounds::getLatLngBounds(env, jBounds); + auto bounds = LatLngBounds::getLatLngUnwrappedBounds(env, jBounds); source.as()->CustomGeometrySource::invalidateRegion(bounds); } -- cgit v1.2.1