Subject: tileRegionLoadOptions, Downloading offline maps
Previous to SDK v10, offline regions were rectangular in nature: we would specify simply the coordinates of the North-East point and the coordinates of the South-West point and that was it. Now, on V10, Mapbox introduced the concept of region geometries, so it seems that an offline region can be defined various shapes, not just rectangles. The question is: how to define a rectangle on the new API? There are no examples and in the documentation Mapbox include one very specific case of a single point, as it seems:
Android:
val tileRegionLoadOptions = TileRegionLoadOptions.Builder()
.geometry(TOKYO)
.descriptors(listOf(tilesetDescriptor))
.metadata(Value(TILE_REGION_METADATA))
iOS:
let tileRegionLoadOptions = TileRegionLoadOptions(geometry: Geometry(coordinate: tokyoCoord), descriptors: [], metadata: metadata, : true)
For example consider that we want to specify an offline region as a rectangle defined by:
(long/lat)
-8.226762635, 41.95699448
-8.244230531, 41.92861862
-8.244230531, 41.95699448
-8.226762635, 41.92861862
How can we code this on the new geometry property?
On Android, you can do this with:
Polygon.fromLngLats(listOf(points))
Or with any other class which implements Geometry
, you can find such classes by searching for Implementing classes
in Android Studio:
More complete example:
private fun getDownloadOptions(points: List<Point>) = TileRegionLoadOptions.Builder()
.geometry(Polygon.fromLngLats(listOf(points)))
.build()