Skip to content

Commit

Permalink
Prepare 2.2.1 release (#672)
Browse files Browse the repository at this point in the history
* [offline] add default pixelRatio for TilesetDescriptorOptions (#640)

* [offline] add default pixelRatio for TilesetDescriptorOptions
* Automatically set MapboxMapsOptions.tileStore

* fixes build for flutter 3.24.1 #668 (#671)

* fixes build for flutter 3.24.1 (#668)

* Bump lifecycle and annotation Android dependencies versions

* Add changelog entry

---------

Co-authored-by: LEE <[email protected]>

* Bump version to 2.2.1

---------

Co-authored-by: Mai Mai <[email protected]>
Co-authored-by: LEE <[email protected]>
  • Loading branch information
3 people authored Aug 28, 2024
1 parent 2a65332 commit 1aa4f5c
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 79 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 2.2.1

* Fix build errors when using Flutter SDK 3.24.

### 2.2.0

* Bump Maps SDK to 11.6.0
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Mapbox Maps SDK Flutter SDK

The Mapbox Maps SDK Flutter SDK is an officially developed solution from Mapbox that enables use of our latest Maps SDK product (v11.6.0-rc.1). The SDK allows developers to embed highly customized maps using a Flutter widget on Android and iOS.
The Mapbox Maps SDK Flutter SDK is an officially developed solution from Mapbox that enables use of our latest Maps SDK product (v11.6.0). The SDK allows developers to embed highly customized maps using a Flutter widget on Android and iOS.

Web and desktop are not supported.

Expand Down Expand Up @@ -111,7 +111,7 @@ To use the Maps Flutter SDK add the git dependency to the pubspec.yaml:

```
dependencies:
mapbox_maps_flutter: ^2.2.0
mapbox_maps_flutter: ^2.2.1
```

### Configure permissions
Expand Down
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ if (file("$rootDir/gradle/ktlint.gradle").exists() && file("$rootDir/gradle/lint
dependencies {
implementation "com.mapbox.maps:android:11.6.0"

implementation "androidx.annotation:annotation:1.7.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.0"
implementation "androidx.annotation:annotation:1.8.2"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.8.4"
}
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,12 @@ fun com.mapbox.maps.StylePackLoadProgress.toFLTStylePackLoadProgress(): StylePac
)
}

fun TilesetDescriptorOptions.toTilesetDescriptorOptions(): com.mapbox.maps.TilesetDescriptorOptions {
fun TilesetDescriptorOptions.toTilesetDescriptorOptions(context: Context): com.mapbox.maps.TilesetDescriptorOptions {
val builder = com.mapbox.maps.TilesetDescriptorOptions.Builder()
.styleURI(styleURI)
.minZoom(minZoom.toByte())
.maxZoom(maxZoom.toByte())
pixelRatio?.let { builder.pixelRatio(it.toFloat()) }
.pixelRatio(pixelRatio?.toFloat() ?: context.resources.displayMetrics.density)
tilesets?.let { builder.tilesets(it) }
stylePackOptions?.let { builder.stylePackOptions(it.toStylePackLoadOptions()) }
extraOptions?.let { builder.extraOptions(it.toValue()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import androidx.lifecycle.ViewTreeLifecycleOwner
import androidx.lifecycle.setViewTreeLifecycleOwner
import com.mapbox.bindgen.Value
import com.mapbox.common.SettingsServiceFactory
import com.mapbox.common.SettingsServiceStorageType
Expand Down Expand Up @@ -81,9 +81,8 @@ class MapboxMapController(
parentLifecycle.addObserver(this)
}

override fun getLifecycle(): Lifecycle {
return lifecycleRegistry
}
override val lifecycle: Lifecycle
get() = lifecycleRegistry

override fun onCreate(owner: LifecycleOwner) {
lifecycleRegistry.currentState = Lifecycle.State.CREATED
Expand Down Expand Up @@ -173,14 +172,14 @@ class MapboxMapController(
}
lifecycleHelper = LifecycleHelper(lifecycleProvider.getLifecycle()!!, shouldDestroyOnDestroy)

mapView?.let { ViewTreeLifecycleOwner.set(it, lifecycleHelper) }
mapView?.setViewTreeLifecycleOwner(lifecycleHelper)
}

override fun onFlutterViewDetached() {
super.onFlutterViewDetached()
lifecycleHelper?.dispose()
lifecycleHelper = null
ViewTreeLifecycleOwner.set(mapView!!, null)
mapView!!.setViewTreeLifecycleOwner(null)
}

override fun dispose() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.mapbox.maps.mapbox_maps.offline

import android.content.Context
import com.mapbox.common.TileStore
import com.mapbox.maps.MapboxMapsOptions
import com.mapbox.maps.mapbox_maps.ProxyBinaryMessenger
import com.mapbox.maps.mapbox_maps.pigeons.*
import io.flutter.plugin.common.BinaryMessenger
Expand All @@ -27,6 +28,7 @@ class OfflineMapInstanceManager(
override fun setupTileStore(channelSuffix: String, filePath: String?) {
val proxy = ProxyBinaryMessenger(messenger, channelSuffix)
val tileStore = filePath?.let { TileStore.create(it) } ?: TileStore.create()
MapboxMapsOptions.tileStore = tileStore
val tileStoreController = TileStoreController(context, messenger, tileStore)
_TileStore.setUp(proxy, tileStoreController)
proxies["tilestore/$channelSuffix"] = proxy
Expand All @@ -35,5 +37,6 @@ class OfflineMapInstanceManager(
override fun tearDownTileStore(channelSuffix: String) {
val proxy = proxies["tilestore/$channelSuffix"] ?: return
_TileStore.setUp(proxy, null)
MapboxMapsOptions.tileStore = null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TileStoreController(
callback: (Result<TileRegion>) -> Unit
) {
tileStore.loadTileRegion(
id, offlineManager.tileRegionLoadOptions(loadOptions),
id, offlineManager.tileRegionLoadOptions(loadOptions, context),
{ progress ->
mainHandler.post {
tileRegionLoadProgressHandlers[id]?.success(progress.toFLTTileRegionLoadProgress().toList())
Expand Down Expand Up @@ -75,7 +75,7 @@ class TileStoreController(
) {
tileStore.estimateTileRegion(
id,
offlineManager.tileRegionLoadOptions(loadOptions),
offlineManager.tileRegionLoadOptions(loadOptions, context),
estimateOptions?.toTileRegionEstimateOptions() ?: com.mapbox.common.TileRegionEstimateOptions(null),
{ progress ->
mainHandler.post {
Expand Down Expand Up @@ -116,7 +116,7 @@ class TileStoreController(
}

override fun tileRegionContainsDescriptor(id: String, options: List<TilesetDescriptorOptions>, callback: (Result<Boolean>) -> Unit) {
val descriptors = options.map { offlineManager.createTilesetDescriptor(it.toTilesetDescriptorOptions()) }
val descriptors = options.map { offlineManager.createTilesetDescriptor(it.toTilesetDescriptorOptions(context)) }
tileStore.tileRegionContainsDescriptors(id, descriptors) { expected ->
mainHandler.post {
callback(expected.toResult { it })
Expand Down Expand Up @@ -152,7 +152,7 @@ class TileStoreController(
}
}

private fun OfflineManager.tileRegionLoadOptions(fltValue: TileRegionLoadOptions): com.mapbox.common.TileRegionLoadOptions {
private fun OfflineManager.tileRegionLoadOptions(fltValue: TileRegionLoadOptions, context: Context): com.mapbox.common.TileRegionLoadOptions {
val builder = com.mapbox.common.TileRegionLoadOptions.Builder()
.geometry(fltValue.geometry?.toGeometry())
.metadata(fltValue.metadata?.toValue())
Expand All @@ -165,7 +165,7 @@ private fun OfflineManager.tileRegionLoadOptions(fltValue: TileRegionLoadOptions
fltValue.descriptorsOptions?.let { options ->
val descriptors: List<TilesetDescriptorOptions> = options.filterNotNull()
builder.descriptors(
descriptors.map { createTilesetDescriptor(it.toTilesetDescriptorOptions()) }
descriptors.map { createTilesetDescriptor(it.toTilesetDescriptorOptions(context)) }
)
}

Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PODS:
- Flutter (1.0.0)
- integration_test (0.0.1):
- Flutter
- mapbox_maps_flutter (2.2.0):
- mapbox_maps_flutter (2.2.1):
- Flutter
- MapboxMaps (~> 11.6.0)
- Turf (= 2.8.0)
Expand Down Expand Up @@ -49,7 +49,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
integration_test: 13825b8a9334a850581300559b8839134b124670
mapbox_maps_flutter: d853261834ff2a87f716e5c4beb150bca3f4cb65
mapbox_maps_flutter: 943324063065b4ef15e146be95ed87f5bae1a6ba
MapboxCommon: 6008e74b1312a093dec291497a036fc8b47f344f
MapboxCoreMaps: bd097795c5ae4f002181769e7151474a33ce878a
MapboxMaps: fc1b2ab98563d0157ba01f6e4a2fd8a8af556d92
Expand Down
54 changes: 36 additions & 18 deletions example/lib/offline_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,14 @@ class OfflineMapWidgetState extends State<OfflineMapWidget> {
final StreamController<double> _tileRegionLoadProgress =
StreamController.broadcast();

_onMapCreated(MapboxMap mapboxMap) async {
this.mapboxMap = mapboxMap;
await _downloadStylePack();
await _downloadTileRegion();
}

_downloadStylePack() async {
final offlineManager = await OfflineManager.create();
final stylePackLoadOptions = StylePackLoadOptions(
glyphsRasterizationMode:
GlyphsRasterizationMode.IDEOGRAPHS_RASTERIZED_LOCALLY,
metadata: {"tag": "test"},
acceptExpired: false);
offlineManager.loadStylePack(MapboxStyles.OUTDOORS, stylePackLoadOptions,
offlineManager.loadStylePack(MapboxStyles.SATELLITE_STREETS, stylePackLoadOptions,
(progress) {
final percentage =
progress.completedResourceCount / progress.requiredResourceCount;
Expand All @@ -59,13 +53,15 @@ class OfflineMapWidgetState extends State<OfflineMapWidget> {
}

_downloadTileRegion() async {
final tmpDir = await getTemporaryDirectory();
final tileStore = await TileStore.createAt(await tmpDir.uri);
final path = await getTemporaryDirectory();
final tileStore = await TileStore.createAt(path.uri);
final tileRegionLoadOptions = TileRegionLoadOptions(
geometry: Point(coordinates: Position(-80.1263, 25.7845)).toJson(),
geometry: City.helsinki.toJson(),
descriptorsOptions: [
// If you are using a raster tileset you may need to set a different pixelRatio.
// The default is UIScreen.main.scale on iOS and displayMetrics's density on Android.
TilesetDescriptorOptions(
styleURI: MapboxStyles.OUTDOORS, minZoom: 0, maxZoom: 16)
styleURI: MapboxStyles.SATELLITE_STREETS, minZoom: 0, maxZoom: 16)
],
acceptExpired: true,
networkRestriction: NetworkRestriction.NONE);
Expand All @@ -85,18 +81,40 @@ class OfflineMapWidgetState extends State<OfflineMapWidget> {

@override
Widget build(BuildContext context) {
final mapWidget = MapWidget(
key: ValueKey("mapWidget"),
styleUri: MapboxStyles.OUTDOORS,
cameraOptions: CameraOptions(center: City.helsinki, zoom: 2.0),
onMapCreated: _onMapCreated,
);
String downloadButtonText = "Download Map";
final mapIsDownloaded = Future
.wait([_tileRegionLoadProgress.sink.done, _stylePackProgress.sink.done])
.whenComplete(() async {
await OfflineSwitch.shared.setMapboxStackConnected(false);
});

return new Column(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: mapWidget,
child: FutureBuilder(future: mapIsDownloaded, builder: (context, snapshot) {
if (snapshot.hasData) {
return MapWidget(
key: ValueKey("mapWidget"),
styleUri: MapboxStyles.SATELLITE_STREETS,
cameraOptions: CameraOptions(center: City.helsinki, zoom: 12.0),
);
} else {
return TextButton(
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all<Color>(Colors.blue),
),
onPressed: () async {
setState(() {
downloadButtonText = "Downloading";
});
await _downloadStylePack();
await _downloadTileRegion();
},
child: Text(downloadButtonText),
);
}
}),
),
SizedBox(
height: 100,
Expand Down
28 changes: 14 additions & 14 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -166,33 +166,33 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
url: "https://pub.dev"
source: hosted
version: "10.0.4"
version: "10.0.0"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
url: "https://pub.dev"
source: hosted
version: "3.0.3"
version: "2.0.1"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
url: "https://pub.dev"
source: hosted
version: "3.0.1"
version: "2.0.1"
mapbox_maps_flutter:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "2.2.0-rc.1"
version: "2.2.1"
matcher:
dependency: transitive
description:
Expand All @@ -213,10 +213,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev"
source: hosted
version: "1.12.0"
version: "1.11.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -410,10 +410,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.7.0"
version: "0.6.1"
turf:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -458,10 +458,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.dev"
source: hosted
version: "14.2.1"
version: "13.0.0"
webdriver:
dependency: transitive
description:
Expand All @@ -488,4 +488,4 @@ packages:
version: "1.0.4"
sdks:
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
flutter: ">=3.16.6"
Loading

0 comments on commit 1aa4f5c

Please sign in to comment.