From 5be1eeeedd909fdb6e6cd5acde6e86601a6105b1 Mon Sep 17 00:00:00 2001 From: Artak Kalantarian Date: Wed, 22 Feb 2023 00:52:40 -0800 Subject: [PATCH] =?UTF-8?q?[android]=20Fixed=20an=20issue=20with=20native?= =?UTF-8?q?=20code=20throwing=20an=20exception=20expecting=20bound?= =?UTF-8?q?=E2=80=A6=20(#830)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bart Louwers --- platform/android/CHANGELOG.md | 9 ++- .../mapbox/mapboxsdk/style/sources/TileSet.kt | 65 +++++++++++++++++-- .../style/sources/RasterSourceTest.kt | 22 +++++++ 3 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/sources/RasterSourceTest.kt diff --git a/platform/android/CHANGELOG.md b/platform/android/CHANGELOG.md index 6135a51cc..74d814619 100644 --- a/platform/android/CHANGELOG.md +++ b/platform/android/CHANGELOG.md @@ -4,7 +4,14 @@ MapLibre welcomes participation and contributions from everyone. Please read [`C ## main -* Add your pull request... +### ✨ Features and improvements + +### 🐞 Bug fixes + +* Fixed regression with `RasterSource` native code throwing an exception expecting bound after switching to `FloatArray`. [#830](https://github.com/maplibre/maplibre-gl-native/pull/830) + +### ⛵ Dependencies + ## 10.0.0 - February 15, 2023 diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/TileSet.kt b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/TileSet.kt index 1221a1585..8c4f24c5d 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/TileSet.kt +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/TileSet.kt @@ -2,6 +2,8 @@ package com.mapbox.mapboxsdk.style.sources import androidx.annotation.Size import com.mapbox.mapboxsdk.geometry.LatLng +import com.mapbox.mapboxsdk.geometry.LatLngBounds + /** * Tile set, allows using TileJson specification as source. * Note that `encoding` is only relevant to `raster-dem` sources, and is not supported in the TileJson spec. @@ -86,9 +88,9 @@ class TileSet(val tilejson: String, vararg tiles: String) { @JvmField var maxZoom: Float? = null - var bounds: FloatArray? = null + var bounds: Array? = null private set - var center: FloatArray? = null + var center: Array? = null private set /** @@ -128,6 +130,7 @@ class TileSet(val tilejson: String, vararg tiles: String) { * * @param grids the grids to set */ + @Suppress("unused") fun setGrids(vararg grids: String) { this.grids = arrayOf(*grids) } @@ -186,26 +189,74 @@ class TileSet(val tilejson: String, vararg tiles: String) { * @param bounds the Float array to set */ fun setBounds(@Size(value = 4) vararg bounds: Float) { + this.bounds = bounds.toTypedArray() + } + + /** + * Default: [-180, -90, 180, 90]. The maximum extent of available map tiles. Bounds MUST define an area + * covered by all zoom levels. The bounds are represented in WGS:84 + * latitude and longitude values, in the order left, bottom, right, top. + * Values are floating point numbers. + * + * @param left the Float left bound + * @param bottom the Float bottom bound + * @param right the Float right bound + * @param top the Float top bound + */ + fun setBounds(left: Float, bottom: Float, right: Float, top: Float) { + setBounds(left, bottom, right, top) + } + + /** + * Default: [-180, -90, 180, 90]. The maximum extent of available map tiles. Bounds MUST define an area + * covered by all zoom levels. The bounds are represented in WGS:84 + * latitude and longitude values, as a Float array of exactly four elements in the order + * left, bottom, right, top. They are all floating point numbers. + * + * @param bounds The Array of floats containing bounds in the order left, bottom, right, top + */ + @Deprecated("Not strongly typed", ReplaceWith("setBounds(bounds: LatLngBounds")) + fun setBounds(@Size(value = 4) bounds: Array) { this.bounds = bounds } + /** + * Default: [-180, -90, 180, 90]. The maximum extent of available map tiles. Bounds MUST define an area + * covered by all zoom levels. The bounds are represented in WGS:84 + * + * @param bounds The LatLngBounds instance containing bounds + */ + fun setBounds(bounds: LatLngBounds) { + setBounds(bounds.longitudeWest.toFloat(), bounds.latitudeSouth.toFloat(), bounds.longitudeEast.toFloat(), bounds.latitudeNorth.toFloat()) + } + /** * The first value is the longitude, the second is latitude (both in - * WGS:84 values), the third value is the zoom level as an integer. + * WGS:84 values), * Longitude and latitude MUST be within the specified bounds. - * The zoom level MUST be between minzoom and maxzoom. * Implementations can use this value to set the default location. If the * value is null, implementations may use their own algorithm for * determining a default location. * - * @param center the Float array to set + * @param center the Float array to set as lattitude, longitude */ + @Deprecated("This function is not type safe", ReplaceWith("setCenter(center:LatLng)")) fun setCenter(@Size(value = 2) vararg center: Float) { - this.center = center + val latLng = LatLng(center[1].toDouble(), center[0].toDouble()) + setCenter(latLng) } + /** + * Set the center. + * Longitude and latitude MUST be within the specified bounds. + * Implementations can use this value to set the default location. If the + * value is null, implementations may use their own algorithm for + * determining a default location. + * + * @param center the LatLng value to use a the center + */ fun setCenter(center: LatLng) { - this.center = floatArrayOf(center.longitude.toFloat(), center.latitude.toFloat()) + this.center = arrayOf(center.longitude.toFloat(), center.latitude.toFloat()) } fun toValueObject(): Map { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/sources/RasterSourceTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/sources/RasterSourceTest.kt new file mode 100644 index 000000000..c7a0ea6d2 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/style/sources/RasterSourceTest.kt @@ -0,0 +1,22 @@ +package com.mapbox.mapboxsdk.style.sources + +import androidx.test.annotation.UiThreadTest +import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4ClassRunner::class) +@UiThreadTest +class RasterSourceTest { + @Test + fun rasterSource_constructor() { + val tiles = arrayOf("https://example.com") + val tileSet = TileSet("2.1.0", *tiles) + + // set bounds on tile set + val bounds = floatArrayOf(-180.0f, -85.05113f, 180.0f, 85.05113f) + tileSet.setBounds(*bounds) + // create RasterSource + RasterSource("source_id", tileSet) + } +}