Skip to content

Commit 1aa4f5c

Browse files
evil159maiosCoderXXLee
authored
Prepare 2.2.1 release (#672)
* [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 <11565796+CoderXXLee@users.noreply.github.com> * Bump version to 2.2.1 --------- Co-authored-by: Mai Mai <mai.mai@mapbox.com> Co-authored-by: LEE <11565796+CoderXXLee@users.noreply.github.com>
1 parent 2a65332 commit 1aa4f5c

16 files changed

+112
-79
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 2.2.1
2+
3+
* Fix build errors when using Flutter SDK 3.24.
4+
15
### 2.2.0
26

37
* Bump Maps SDK to 11.6.0

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Mapbox Maps SDK Flutter SDK
22

3-
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.
3+
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.
44

55
Web and desktop are not supported.
66

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

112112
```
113113
dependencies:
114-
mapbox_maps_flutter: ^2.2.0
114+
mapbox_maps_flutter: ^2.2.1
115115
```
116116

117117
### Configure permissions

android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,6 @@ if (file("$rootDir/gradle/ktlint.gradle").exists() && file("$rootDir/gradle/lint
8080
dependencies {
8181
implementation "com.mapbox.maps:android:11.6.0"
8282

83-
implementation "androidx.annotation:annotation:1.7.1"
84-
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.0"
83+
implementation "androidx.annotation:annotation:1.8.2"
84+
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.8.4"
8585
}

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/Extentions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,12 +611,12 @@ fun com.mapbox.maps.StylePackLoadProgress.toFLTStylePackLoadProgress(): StylePac
611611
)
612612
}
613613

614-
fun TilesetDescriptorOptions.toTilesetDescriptorOptions(): com.mapbox.maps.TilesetDescriptorOptions {
614+
fun TilesetDescriptorOptions.toTilesetDescriptorOptions(context: Context): com.mapbox.maps.TilesetDescriptorOptions {
615615
val builder = com.mapbox.maps.TilesetDescriptorOptions.Builder()
616616
.styleURI(styleURI)
617617
.minZoom(minZoom.toByte())
618618
.maxZoom(maxZoom.toByte())
619-
pixelRatio?.let { builder.pixelRatio(it.toFloat()) }
619+
.pixelRatio(pixelRatio?.toFloat() ?: context.resources.displayMetrics.density)
620620
tilesets?.let { builder.tilesets(it) }
621621
stylePackOptions?.let { builder.stylePackOptions(it.toStylePackLoadOptions()) }
622622
extraOptions?.let { builder.extraOptions(it.toValue()) }

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/MapboxMapController.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import androidx.lifecycle.DefaultLifecycleObserver
77
import androidx.lifecycle.Lifecycle
88
import androidx.lifecycle.LifecycleOwner
99
import androidx.lifecycle.LifecycleRegistry
10-
import androidx.lifecycle.ViewTreeLifecycleOwner
10+
import androidx.lifecycle.setViewTreeLifecycleOwner
1111
import com.mapbox.bindgen.Value
1212
import com.mapbox.common.SettingsServiceFactory
1313
import com.mapbox.common.SettingsServiceStorageType
@@ -81,9 +81,8 @@ class MapboxMapController(
8181
parentLifecycle.addObserver(this)
8282
}
8383

84-
override fun getLifecycle(): Lifecycle {
85-
return lifecycleRegistry
86-
}
84+
override val lifecycle: Lifecycle
85+
get() = lifecycleRegistry
8786

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

176-
mapView?.let { ViewTreeLifecycleOwner.set(it, lifecycleHelper) }
175+
mapView?.setViewTreeLifecycleOwner(lifecycleHelper)
177176
}
178177

179178
override fun onFlutterViewDetached() {
180179
super.onFlutterViewDetached()
181180
lifecycleHelper?.dispose()
182181
lifecycleHelper = null
183-
ViewTreeLifecycleOwner.set(mapView!!, null)
182+
mapView!!.setViewTreeLifecycleOwner(null)
184183
}
185184

186185
override fun dispose() {

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/offline/OfflineMapInstanceManager.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.mapbox.maps.mapbox_maps.offline
22

33
import android.content.Context
44
import com.mapbox.common.TileStore
5+
import com.mapbox.maps.MapboxMapsOptions
56
import com.mapbox.maps.mapbox_maps.ProxyBinaryMessenger
67
import com.mapbox.maps.mapbox_maps.pigeons.*
78
import io.flutter.plugin.common.BinaryMessenger
@@ -27,6 +28,7 @@ class OfflineMapInstanceManager(
2728
override fun setupTileStore(channelSuffix: String, filePath: String?) {
2829
val proxy = ProxyBinaryMessenger(messenger, channelSuffix)
2930
val tileStore = filePath?.let { TileStore.create(it) } ?: TileStore.create()
31+
MapboxMapsOptions.tileStore = tileStore
3032
val tileStoreController = TileStoreController(context, messenger, tileStore)
3133
_TileStore.setUp(proxy, tileStoreController)
3234
proxies["tilestore/$channelSuffix"] = proxy
@@ -35,5 +37,6 @@ class OfflineMapInstanceManager(
3537
override fun tearDownTileStore(channelSuffix: String) {
3638
val proxy = proxies["tilestore/$channelSuffix"] ?: return
3739
_TileStore.setUp(proxy, null)
40+
MapboxMapsOptions.tileStore = null
3841
}
3942
}

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/offline/TileStoreController.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class TileStoreController(
3838
callback: (Result<TileRegion>) -> Unit
3939
) {
4040
tileStore.loadTileRegion(
41-
id, offlineManager.tileRegionLoadOptions(loadOptions),
41+
id, offlineManager.tileRegionLoadOptions(loadOptions, context),
4242
{ progress ->
4343
mainHandler.post {
4444
tileRegionLoadProgressHandlers[id]?.success(progress.toFLTTileRegionLoadProgress().toList())
@@ -75,7 +75,7 @@ class TileStoreController(
7575
) {
7676
tileStore.estimateTileRegion(
7777
id,
78-
offlineManager.tileRegionLoadOptions(loadOptions),
78+
offlineManager.tileRegionLoadOptions(loadOptions, context),
7979
estimateOptions?.toTileRegionEstimateOptions() ?: com.mapbox.common.TileRegionEstimateOptions(null),
8080
{ progress ->
8181
mainHandler.post {
@@ -116,7 +116,7 @@ class TileStoreController(
116116
}
117117

118118
override fun tileRegionContainsDescriptor(id: String, options: List<TilesetDescriptorOptions>, callback: (Result<Boolean>) -> Unit) {
119-
val descriptors = options.map { offlineManager.createTilesetDescriptor(it.toTilesetDescriptorOptions()) }
119+
val descriptors = options.map { offlineManager.createTilesetDescriptor(it.toTilesetDescriptorOptions(context)) }
120120
tileStore.tileRegionContainsDescriptors(id, descriptors) { expected ->
121121
mainHandler.post {
122122
callback(expected.toResult { it })
@@ -152,7 +152,7 @@ class TileStoreController(
152152
}
153153
}
154154

155-
private fun OfflineManager.tileRegionLoadOptions(fltValue: TileRegionLoadOptions): com.mapbox.common.TileRegionLoadOptions {
155+
private fun OfflineManager.tileRegionLoadOptions(fltValue: TileRegionLoadOptions, context: Context): com.mapbox.common.TileRegionLoadOptions {
156156
val builder = com.mapbox.common.TileRegionLoadOptions.Builder()
157157
.geometry(fltValue.geometry?.toGeometry())
158158
.metadata(fltValue.metadata?.toValue())
@@ -165,7 +165,7 @@ private fun OfflineManager.tileRegionLoadOptions(fltValue: TileRegionLoadOptions
165165
fltValue.descriptorsOptions?.let { options ->
166166
val descriptors: List<TilesetDescriptorOptions> = options.filterNotNull()
167167
builder.descriptors(
168-
descriptors.map { createTilesetDescriptor(it.toTilesetDescriptorOptions()) }
168+
descriptors.map { createTilesetDescriptor(it.toTilesetDescriptorOptions(context)) }
169169
)
170170
}
171171

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PODS:
22
- Flutter (1.0.0)
33
- integration_test (0.0.1):
44
- Flutter
5-
- mapbox_maps_flutter (2.2.0):
5+
- mapbox_maps_flutter (2.2.1):
66
- Flutter
77
- MapboxMaps (~> 11.6.0)
88
- Turf (= 2.8.0)
@@ -49,7 +49,7 @@ EXTERNAL SOURCES:
4949
SPEC CHECKSUMS:
5050
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
5151
integration_test: 13825b8a9334a850581300559b8839134b124670
52-
mapbox_maps_flutter: d853261834ff2a87f716e5c4beb150bca3f4cb65
52+
mapbox_maps_flutter: 943324063065b4ef15e146be95ed87f5bae1a6ba
5353
MapboxCommon: 6008e74b1312a093dec291497a036fc8b47f344f
5454
MapboxCoreMaps: bd097795c5ae4f002181769e7151474a33ce878a
5555
MapboxMaps: fc1b2ab98563d0157ba01f6e4a2fd8a8af556d92

example/lib/offline_map.dart

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,14 @@ class OfflineMapWidgetState extends State<OfflineMapWidget> {
3232
final StreamController<double> _tileRegionLoadProgress =
3333
StreamController.broadcast();
3434

35-
_onMapCreated(MapboxMap mapboxMap) async {
36-
this.mapboxMap = mapboxMap;
37-
await _downloadStylePack();
38-
await _downloadTileRegion();
39-
}
40-
4135
_downloadStylePack() async {
4236
final offlineManager = await OfflineManager.create();
4337
final stylePackLoadOptions = StylePackLoadOptions(
4438
glyphsRasterizationMode:
4539
GlyphsRasterizationMode.IDEOGRAPHS_RASTERIZED_LOCALLY,
4640
metadata: {"tag": "test"},
4741
acceptExpired: false);
48-
offlineManager.loadStylePack(MapboxStyles.OUTDOORS, stylePackLoadOptions,
42+
offlineManager.loadStylePack(MapboxStyles.SATELLITE_STREETS, stylePackLoadOptions,
4943
(progress) {
5044
final percentage =
5145
progress.completedResourceCount / progress.requiredResourceCount;
@@ -59,13 +53,15 @@ class OfflineMapWidgetState extends State<OfflineMapWidget> {
5953
}
6054

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

8682
@override
8783
Widget build(BuildContext context) {
88-
final mapWidget = MapWidget(
89-
key: ValueKey("mapWidget"),
90-
styleUri: MapboxStyles.OUTDOORS,
91-
cameraOptions: CameraOptions(center: City.helsinki, zoom: 2.0),
92-
onMapCreated: _onMapCreated,
93-
);
84+
String downloadButtonText = "Download Map";
85+
final mapIsDownloaded = Future
86+
.wait([_tileRegionLoadProgress.sink.done, _stylePackProgress.sink.done])
87+
.whenComplete(() async {
88+
await OfflineSwitch.shared.setMapboxStackConnected(false);
89+
});
9490

9591
return new Column(
9692
mainAxisSize: MainAxisSize.min,
9793
children: [
9894
Expanded(
99-
child: mapWidget,
95+
child: FutureBuilder(future: mapIsDownloaded, builder: (context, snapshot) {
96+
if (snapshot.hasData) {
97+
return MapWidget(
98+
key: ValueKey("mapWidget"),
99+
styleUri: MapboxStyles.SATELLITE_STREETS,
100+
cameraOptions: CameraOptions(center: City.helsinki, zoom: 12.0),
101+
);
102+
} else {
103+
return TextButton(
104+
style: ButtonStyle(
105+
foregroundColor: MaterialStateProperty.all<Color>(Colors.blue),
106+
),
107+
onPressed: () async {
108+
setState(() {
109+
downloadButtonText = "Downloading";
110+
});
111+
await _downloadStylePack();
112+
await _downloadTileRegion();
113+
},
114+
child: Text(downloadButtonText),
115+
);
116+
}
117+
}),
100118
),
101119
SizedBox(
102120
height: 100,

example/pubspec.lock

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -166,33 +166,33 @@ packages:
166166
dependency: transitive
167167
description:
168168
name: leak_tracker
169-
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
169+
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
170170
url: "https://pub.dev"
171171
source: hosted
172-
version: "10.0.4"
172+
version: "10.0.0"
173173
leak_tracker_flutter_testing:
174174
dependency: transitive
175175
description:
176176
name: leak_tracker_flutter_testing
177-
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
177+
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
178178
url: "https://pub.dev"
179179
source: hosted
180-
version: "3.0.3"
180+
version: "2.0.1"
181181
leak_tracker_testing:
182182
dependency: transitive
183183
description:
184184
name: leak_tracker_testing
185-
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
185+
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
186186
url: "https://pub.dev"
187187
source: hosted
188-
version: "3.0.1"
188+
version: "2.0.1"
189189
mapbox_maps_flutter:
190190
dependency: "direct main"
191191
description:
192192
path: ".."
193193
relative: true
194194
source: path
195-
version: "2.2.0-rc.1"
195+
version: "2.2.1"
196196
matcher:
197197
dependency: transitive
198198
description:
@@ -213,10 +213,10 @@ packages:
213213
dependency: transitive
214214
description:
215215
name: meta
216-
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
216+
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
217217
url: "https://pub.dev"
218218
source: hosted
219-
version: "1.12.0"
219+
version: "1.11.0"
220220
path:
221221
dependency: transitive
222222
description:
@@ -410,10 +410,10 @@ packages:
410410
dependency: transitive
411411
description:
412412
name: test_api
413-
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
413+
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
414414
url: "https://pub.dev"
415415
source: hosted
416-
version: "0.7.0"
416+
version: "0.6.1"
417417
turf:
418418
dependency: "direct dev"
419419
description:
@@ -458,10 +458,10 @@ packages:
458458
dependency: transitive
459459
description:
460460
name: vm_service
461-
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
461+
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
462462
url: "https://pub.dev"
463463
source: hosted
464-
version: "14.2.1"
464+
version: "13.0.0"
465465
webdriver:
466466
dependency: transitive
467467
description:
@@ -488,4 +488,4 @@ packages:
488488
version: "1.0.4"
489489
sdks:
490490
dart: ">=3.3.0 <4.0.0"
491-
flutter: ">=3.18.0-18.0.pre.54"
491+
flutter: ">=3.16.6"

0 commit comments

Comments
 (0)