diff --git a/platform/android/CHANGELOG.md b/platform/android/CHANGELOG.md index d8338347c22..ec0a5f15865 100644 --- a/platform/android/CHANGELOG.md +++ b/platform/android/CHANGELOG.md @@ -2,6 +2,16 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to do so please see the [`Contributing Guide`](https://github.com/mapbox/mapbox-gl-native/blob/master/CONTRIBUTING.md) first to get started. +## 5.1.0 - TBA + +5.1.0 builds further on 5.0.1 and adds: + +* LatLngBounds includes with another bounds [#8517](https://github.com/mapbox/mapbox-gl-native/pull/8517) +* LatLngBounds includes takes in account LatLng on the edges (cfr. core) [#8517](https://github.com/mapbox/mapbox-gl-native/pull/8517) +* LatLngBounds facility getters/setters for LatLnbg on the edges of the bounds [#8517](https://github.com/mapbox/mapbox-gl-native/pull/8517) +* Expose world bounds in LatLngBounds [#8517](https://github.com/mapbox/mapbox-gl-native/pull/8517) +* OfflineRegion are validated if the bounds is found in the world bounds, else onError will be invoked [#8517](https://github.com/mapbox/mapbox-gl-native/pull/8517) + ## 5.0.0 - March 17th, 2017 5.0.0 final release contains: 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 3b92f0f0f57..4a4e2a30aac 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 @@ -5,12 +5,16 @@ import android.support.annotation.NonNull; import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException; +import com.mapbox.services.android.telemetry.constants.GeoConstants; import java.util.ArrayList; import java.util.List; /** * A geographical area representing a latitude/longitude aligned rectangle. + *

+ * This class does not wrap values to the world bounds. + *

*/ public class LatLngBounds implements Parcelable { @@ -36,6 +40,18 @@ public class LatLngBounds implements Parcelable { this.mLonWest = westLongitude; } + /** + * Returns the world bounds. + * + * @return the bounds representing the world + */ + public static LatLngBounds world() { + return new LatLngBounds.Builder() + .include(new LatLng(GeoConstants.MAX_LATITUDE, GeoConstants.MAX_LONGITUDE)) + .include(new LatLng(GeoConstants.MIN_LATITUDE, GeoConstants.MIN_LONGITUDE)) + .build(); + } + /** * Calculates the centerpoint of this LatLngBounds by simple interpolation and returns * it as a point. This is a non-geodesic calculation which is not the geographic center. @@ -47,22 +63,78 @@ public LatLng getCenter() { (this.mLonEast + this.mLonWest) / 2); } + /** + * Get the north latitude value of this bounds. + * + * @return double latitude value for north + */ public double getLatNorth() { return this.mLatNorth; } + /** + * Get the south latitude value of this bounds. + * + * @return double latitude value for south + */ public double getLatSouth() { return this.mLatSouth; } + /** + * Get the east longitude value of this bounds. + * + * @return double longitude value for east + */ public double getLonEast() { return this.mLonEast; } + /** + * Get the west longitude value of this bounds. + * + * @return double longitude value for west + */ public double getLonWest() { return this.mLonWest; } + /** + * Get the latitude-longitude pair of the south west corner of this bounds. + * + * @return LatLng of the south west corner + */ + public LatLng getSouthWest() { + return new LatLng(mLatSouth, mLonWest); + } + + /** + * Get the latitude-longitude paur if the north east corner of this bounds. + * + * @return LatLng of the north east corner + */ + public LatLng getNorthEast() { + return new LatLng(mLatNorth, mLonEast); + } + + /** + * Get the latitude-longitude pair of the south east corner of this bounds. + * + * @return LatLng of the south east corner + */ + public LatLng getSouthEast() { + return new LatLng(mLatSouth, mLonEast); + } + + /** + * Get the latitude-longitude pair of the north west corner of this bounds. + * + * @return LatLng of the north west corner + */ + public LatLng getNorthWest() { + return new LatLng(mLatNorth, mLonWest); + } + /** * Get the area spanned by this LatLngBounds * @@ -133,8 +205,27 @@ static LatLngBounds fromLatLngs(final List latLngs) { return new LatLngBounds(maxLat, maxLon, minLat, minLon); } + /** + * Return an array of LatLng objects resembling this bounds. + * + * @return an array of 2 LatLng objects. + */ public LatLng[] toLatLngs() { - return new LatLng[] {new LatLng(mLatNorth, mLonEast), new LatLng(mLatSouth, mLonWest)}; + return new LatLng[] {getNorthEast(), getSouthWest()}; + } + + /** + * Constructs a LatLngBounds from current bounds with an additional latitude-longitude pair. + * + * @param latLng the latitude lognitude pair to include in the bounds. + * @return the newly constructed bounds + */ + public LatLngBounds include(LatLng latLng) { + return new LatLngBounds.Builder() + .include(getNorthEast()) + .include(getSouthWest()) + .include(latLng) + .build(); } /** @@ -159,19 +250,28 @@ public boolean equals(final Object o) { } /** - * Determines whether this LatLngBounds contains a point and the point - * does not touch its boundary. + * Determines whether this LatLngBounds contains a point. * * @param latLng the point which may be contained - * @return true, if the point is contained within the box. + * @return true, if the point is contained within the bounds */ public boolean contains(final ILatLng latLng) { final double latitude = latLng.getLatitude(); final double longitude = latLng.getLongitude(); - return ((latitude < this.mLatNorth) - && (latitude > this.mLatSouth)) - && ((longitude < this.mLonEast) - && (longitude > this.mLonWest)); + return ((latitude <= this.mLatNorth) + && (latitude >= this.mLatSouth)) + && ((longitude <= this.mLonEast) + && (longitude >= this.mLonWest)); + } + + /** + * Determines whether this LatLngBounds contains another bounds. + * + * @param other the bounds which may be contained + * @return true, if the bounds is contained within the bounds + */ + public boolean contains(final LatLngBounds other) { + return contains(other.getNorthEast()) && contains(other.getSouthWest()); } /** diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java index 8bf19c4065b..225278b17d9 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java @@ -5,6 +5,8 @@ import android.os.Looper; import android.support.annotation.NonNull; +import com.mapbox.mapboxsdk.R; +import com.mapbox.mapboxsdk.geometry.LatLngBounds; import com.mapbox.mapboxsdk.net.ConnectivityReceiver; import com.mapbox.mapboxsdk.storage.FileSource; @@ -26,7 +28,6 @@ public class OfflineManager { System.loadLibrary("mapbox-gl"); } - // Native peer pointer private long nativePtr; @@ -139,7 +140,8 @@ private Handler getHandler() { * * @param callback the callback to be invoked */ - public void listOfflineRegions(@NonNull final ListOfflineRegionsCallback callback) { + public void listOfflineRegions(@NonNull + final ListOfflineRegionsCallback callback) { listOfflineRegions(fileSource, new ListOfflineRegionsCallback() { @Override @@ -180,10 +182,15 @@ public void run() { * @param metadata the metadata in bytes * @param callback the callback to be invoked */ - public void createOfflineRegion( - @NonNull OfflineRegionDefinition definition, - @NonNull byte[] metadata, - @NonNull final CreateOfflineRegionCallback callback) { + public void createOfflineRegion(@NonNull OfflineRegionDefinition definition, @NonNull byte[] metadata, + final CreateOfflineRegionCallback callback) { + if (!isValidOfflineRegionDefinition(definition)) { + callback.onError( + String.format(context.getString(R.string.mapbox_offline_error_region_definition_invalid), + definition.getBounds()) + ); + return; + } ConnectivityReceiver.instance(context).activate(); createOfflineRegion(fileSource, definition, metadata, new CreateOfflineRegionCallback() { @@ -212,6 +219,16 @@ public void run() { }); } + /** + * Validates if the offline region definition bounds is valid for an offline region download. + * + * @param definition the offline region definition + * @return true if the region fits the world bounds. + */ + private boolean isValidOfflineRegionDefinition(OfflineRegionDefinition definition) { + return LatLngBounds.world().contains(definition.getBounds()); + } + /* * Changing or bypassing this limit without permission from Mapbox is prohibited * by the Mapbox Terms of Service. diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionDefinition.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionDefinition.java index a21ff0a443b..18d662a2861 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionDefinition.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionDefinition.java @@ -1,9 +1,14 @@ package com.mapbox.mapboxsdk.offline; +import com.mapbox.mapboxsdk.geometry.LatLngBounds; + /** * This is the interface that all Offline Region definitions have to implement. *

* For the present, a tile pyramid is the only type of offline region. */ public interface OfflineRegionDefinition { + + LatLngBounds getBounds(); + } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml index 7283aced5f0..b544a257a51 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml @@ -89,6 +89,9 @@ + + + diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml index 0d8e9bdc490..d4a9b2f58b7 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml @@ -13,6 +13,7 @@ Title Description Address + Provided OfflineRegionDefinition doesn\'t fit the world bounds: %s