Skip to content

Commit 4af74b8

Browse files
authored
feat!: a couple of planned API changes for v0.3.0 (#341)
Implements some part of #218 - [x] remove `*Sync()` methods, turn async methods sync - [x] rename MapCompass.rotationDuration to MapCompass.nativeRotationDuration - [x] make queryLayers(), featuresAtPoint(), featuresInRect() synchronous
1 parent 1fc4e78 commit 4af74b8

File tree

14 files changed

+117
-264
lines changed

14 files changed

+117
-264
lines changed

example/integration_test/controller_test.dart

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,27 @@ void main() {
5555
final ctrl = await ctrlCompleter.future;
5656
final size = tester.getSize(find.byType(MapLibreMap));
5757

58-
final region = await ctrl.getVisibleRegion();
58+
final region = ctrl.getVisibleRegion();
5959

60-
var offset = await ctrl.toScreenLocation(
60+
var offset = ctrl.toScreenLocation(
6161
Position(region.longitudeWest, region.latitudeNorth),
6262
);
6363
expect(offset.dx, closeTo(0, 1));
6464
expect(offset.dy, closeTo(0, 1));
6565

66-
offset = await ctrl.toScreenLocation(
66+
offset = ctrl.toScreenLocation(
6767
Position(region.longitudeEast, region.latitudeNorth),
6868
);
6969
expect(offset.dx, closeTo(size.width, 1));
7070
expect(offset.dy, closeTo(0, 1));
7171

72-
offset = await ctrl.toScreenLocation(
72+
offset = ctrl.toScreenLocation(
7373
Position(region.longitudeWest, region.latitudeSouth),
7474
);
7575
expect(offset.dx, closeTo(0, 1));
7676
expect(offset.dy, closeTo(size.height, 1));
7777

78-
offset = await ctrl.toScreenLocation(
78+
offset = ctrl.toScreenLocation(
7979
Position(region.longitudeEast, region.latitudeSouth),
8080
);
8181
expect(offset.dx, closeTo(size.width, 1));
@@ -91,14 +91,14 @@ void main() {
9191
await tester.pumpWidget(app);
9292
final ctrl = await ctrlCompleter.future;
9393
final size = tester.getSize(find.byType(MapLibreMap));
94-
final region = await ctrl.getVisibleRegion();
94+
final region = ctrl.getVisibleRegion();
9595
final positions = [
9696
Position(region.longitudeWest, region.latitudeNorth),
9797
Position(region.longitudeEast, region.latitudeNorth),
9898
Position(region.longitudeWest, region.latitudeSouth),
9999
Position(region.longitudeEast, region.latitudeSouth),
100100
];
101-
final offsets = await ctrl.toScreenLocations(positions);
101+
final offsets = ctrl.toScreenLocations(positions);
102102

103103
expect(offsets[0].dx, closeTo(0, 1));
104104
expect(offsets[0].dy, closeTo(0, 1));
@@ -122,21 +122,21 @@ void main() {
122122
await tester.pumpWidget(app);
123123
final ctrl = await ctrlCompleter.future;
124124
final size = tester.getSize(find.byType(MapLibreMap));
125-
final region = await ctrl.getVisibleRegion();
125+
final region = ctrl.getVisibleRegion();
126126

127-
var lngLat = await ctrl.toLngLat(Offset.zero);
127+
var lngLat = ctrl.toLngLat(Offset.zero);
128128
expect(lngLat.lng, closeTo(region.longitudeWest, 0.00001));
129129
expect(lngLat.lat, closeTo(region.latitudeNorth, 0.00001));
130130

131-
lngLat = await ctrl.toLngLat(Offset(size.width, 0));
131+
lngLat = ctrl.toLngLat(Offset(size.width, 0));
132132
expect(lngLat.lng, closeTo(region.longitudeEast, 0.00001));
133133
expect(lngLat.lat, closeTo(region.latitudeNorth, 0.00001));
134134

135-
lngLat = await ctrl.toLngLat(Offset(0, size.height));
135+
lngLat = ctrl.toLngLat(Offset(0, size.height));
136136
expect(lngLat.lng, closeTo(region.longitudeWest, 0.00001));
137137
expect(lngLat.lat, closeTo(region.latitudeSouth, 0.00001));
138138

139-
lngLat = await ctrl.toLngLat(Offset(size.width, size.height));
139+
lngLat = ctrl.toLngLat(Offset(size.width, size.height));
140140
expect(lngLat.lng, closeTo(region.longitudeEast, 0.00001));
141141
expect(lngLat.lat, closeTo(region.latitudeSouth, 0.00001));
142142
});
@@ -150,14 +150,14 @@ void main() {
150150
await tester.pumpWidget(app);
151151
final ctrl = await ctrlCompleter.future;
152152
final size = tester.getSize(find.byType(MapLibreMap));
153-
final region = await ctrl.getVisibleRegion();
153+
final region = ctrl.getVisibleRegion();
154154
final offsets = [
155155
Offset.zero,
156156
Offset(size.width, 0),
157157
Offset(0, size.height),
158158
Offset(size.width, size.height),
159159
];
160-
final lngLats = await ctrl.toLngLats(offsets);
160+
final lngLats = ctrl.toLngLats(offsets);
161161

162162
expect(lngLats[0].lng, closeTo(region.longitudeWest, 0.00001));
163163
expect(lngLats[0].lat, closeTo(region.latitudeNorth, 0.00001));
@@ -184,9 +184,9 @@ void main() {
184184
await tester.pumpWidget(app);
185185
final ctrl = await ctrlCompleter.future;
186186
final size = tester.getSize(find.byType(MapLibreMap));
187-
final pos0 = await ctrl.toLngLat(Offset(0, size.height / 4));
188-
final pos1 = await ctrl.toLngLat(Offset(100, size.height / 4));
189-
final meters = await ctrl.getMetersPerPixelAtLatitude(
187+
final pos0 = ctrl.toLngLat(Offset(0, size.height / 4));
188+
final pos1 = ctrl.toLngLat(Offset(100, size.height / 4));
189+
final meters = ctrl.getMetersPerPixelAtLatitude(
190190
pos0.lat.toDouble(),
191191
);
192192
final actual =
@@ -206,7 +206,7 @@ void main() {
206206
);
207207
await tester.pumpWidget(app);
208208
final ctrl = await ctrlCompleter.future;
209-
final region = await ctrl.getVisibleRegion();
209+
final region = ctrl.getVisibleRegion();
210210
// testing devices have different screen sizes
211211
expect(region.longitudeWest, lessThan(0));
212212
expect(region.longitudeEast, greaterThan(0));
@@ -326,10 +326,10 @@ void main() {
326326
final size = tester.getSize(find.byType(MapLibreMap));
327327
final centerScreen = Offset(size.width / 2, size.height / 2);
328328

329-
var layers = await ctrl.queryLayers(Offset.zero);
329+
var layers = ctrl.queryLayers(Offset.zero);
330330
expect(layers, isEmpty);
331331

332-
layers = await ctrl.queryLayers(centerScreen);
332+
layers = ctrl.queryLayers(centerScreen);
333333
expect(layers, hasLength(1));
334334
expect(layers.first, expectedPoint);
335335

@@ -375,7 +375,7 @@ void main() {
375375

376376
await tester.pumpAndSettle(const Duration(seconds: 2));
377377

378-
layers = await ctrl.queryLayers(centerScreen);
378+
layers = ctrl.queryLayers(centerScreen);
379379
expect(layers, hasLength(2));
380380
expect(layers, containsAll([expectedPoint, expectedPolygon]));
381381
});
@@ -403,7 +403,7 @@ void main() {
403403
sourceId: 'maptiler_planet',
404404
sourceLayer: 'water',
405405
);
406-
final layers = await ctrl.queryLayers(Offset.zero);
406+
final layers = ctrl.queryLayers(Offset.zero);
407407
expect(layers, hasLength(1));
408408
expect(layers.first, oceanExpected);
409409
});
@@ -486,9 +486,9 @@ void main() {
486486
await tester.pump(const Duration(seconds: 1));
487487
final size = tester.getSize(find.byType(MapLibreMap));
488488
final centerScreen = Offset(size.width / 2, size.height / 2);
489-
var features = await ctrl.featuresAtPoint(Offset.zero);
489+
var features = ctrl.featuresAtPoint(Offset.zero);
490490
expect(features, isEmpty);
491-
features = await ctrl.featuresAtPoint(centerScreen);
491+
features = ctrl.featuresAtPoint(centerScreen);
492492
expect(features, hasLength(2));
493493
final pointFeature = features.firstWhere(
494494
(f) => f.id == 1 || f.id == '1',
@@ -500,14 +500,14 @@ void main() {
500500
);
501501
expect(polygonFeature.properties['poly'], 'gon');
502502

503-
features = await ctrl.featuresAtPoint(
503+
features = ctrl.featuresAtPoint(
504504
centerScreen,
505505
layerIds: [pointLayerId],
506506
);
507507
expect(features, hasLength(1));
508508
expect(features.first.id, isIn([1, '1']));
509509
expect(features.first.properties['foo'], 'bar');
510-
features = await ctrl.featuresAtPoint(
510+
features = ctrl.featuresAtPoint(
511511
centerScreen,
512512
layerIds: [polygonLayerId],
513513
);
@@ -523,14 +523,14 @@ void main() {
523523
),
524524
);
525525
await tester.pump(const Duration(seconds: 1));
526-
features = await ctrl.featuresAtPoint(centerScreen);
526+
features = ctrl.featuresAtPoint(centerScreen);
527527
expect(features, hasLength(3));
528-
features = await ctrl.featuresAtPoint(
528+
features = ctrl.featuresAtPoint(
529529
centerScreen,
530530
layerIds: [pointLayerId, pointLayer2Id],
531531
);
532532
expect(features, hasLength(2));
533-
features = await ctrl.featuresAtPoint(
533+
features = ctrl.featuresAtPoint(
534534
centerScreen,
535535
layerIds: [],
536536
);
@@ -644,12 +644,12 @@ void main() {
644644
);
645645
await tester.pump(const Duration(seconds: 1));
646646
final size = tester.getSize(find.byType(MapLibreMap));
647-
var features = await ctrl.featuresInRect(
647+
var features = ctrl.featuresInRect(
648648
const Rect.fromLTWH(0, 0, 10, 10),
649649
);
650650
expect(features, isEmpty);
651651
final pointScreen = Offset(size.width / 2, size.height / 2);
652-
features = await ctrl.featuresInRect(
652+
features = ctrl.featuresInRect(
653653
Rect.fromCenter(center: pointScreen, width: 2, height: 2),
654654
);
655655
expect(features, hasLength(2));
@@ -661,19 +661,19 @@ void main() {
661661
(f) => f.id == 3 || f.id == '3',
662662
);
663663
expect(polygonFeature.properties['poly'], 'gon');
664-
final lineStartScreen = await ctrl.toScreenLocation(
664+
final lineStartScreen = ctrl.toScreenLocation(
665665
Position(0.09, 0.11),
666666
);
667-
final lineEndScreen = await ctrl.toScreenLocation(Position(0.11, 0.11));
668-
features = await ctrl.featuresInRect(
667+
final lineEndScreen = ctrl.toScreenLocation(Position(0.11, 0.11));
668+
features = ctrl.featuresInRect(
669669
Rect.fromPoints(lineStartScreen, lineEndScreen),
670670
);
671671
// FIXME: blocked on https://github.com/josxha/flutter-maplibre/issues/317
672672
// expect(
673673
// features.firstWhere((f) => f.id == 2 || f.id == '2').properties['line'],
674674
// 'string',
675675
// );
676-
features = await ctrl.featuresInRect(
676+
features = ctrl.featuresInRect(
677677
Rect.fromLTWH(0, 0, size.width, size.height),
678678
);
679679
expect(features, hasLength(3));
@@ -693,7 +693,7 @@ void main() {
693693
);
694694
expect(polygonFeature2.properties['poly'], 'gon');
695695

696-
features = await ctrl.featuresInRect(
696+
features = ctrl.featuresInRect(
697697
Rect.fromLTWH(0, 0, size.width, size.height),
698698
layerIds: [pointLayerId, lineLayerId],
699699
);
@@ -708,7 +708,7 @@ void main() {
708708
(f) => f.id == 2 || f.id == '2',
709709
);
710710
expect(lineFeature2.properties['line'], 'string');
711-
features = await ctrl.featuresInRect(
711+
features = ctrl.featuresInRect(
712712
Rect.fromLTWH(0, 0, size.width, size.height),
713713
layerIds: [],
714714
);

example/integration_test/map_scalebar_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ void main() {
4848
closeTo(scaleBarPainter.width, 0.01),
4949
);
5050
final scalebarCenter = tester.getCenter(customPaintFinder);
51-
final scalebarLat = ctrl.toLngLatSync(scalebarCenter).lat.toDouble();
52-
final metersPerPixel = ctrl.getMetersPerPixelAtLatitudeSync(
51+
final scalebarLat = ctrl.toLngLat(scalebarCenter).lat.toDouble();
52+
final metersPerPixel = ctrl.getMetersPerPixelAtLatitude(
5353
scalebarLat,
5454
);
5555
final expected = scaleBarPainter.meters / metersPerPixel;

example/lib/controller_page.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ pitch: ${camera.pitch}'''),
126126
onPressed: () async {
127127
final camera = _controller.getCamera();
128128
final lat = camera.center.lat.toDouble();
129-
final meters = await _controller
130-
.getMetersPerPixelAtLatitude(lat);
129+
final meters = _controller.getMetersPerPixelAtLatitude(lat);
131130
debugPrint('latitude: $lat: $meters m/px');
132131
if (context.mounted) {
133132
ScaffoldMessenger.of(context)
@@ -146,7 +145,7 @@ pitch: ${camera.pitch}'''),
146145
),
147146
OutlinedButton(
148147
onPressed: () async {
149-
final region = await _controller.getVisibleRegion();
148+
final region = _controller.getVisibleRegion();
150149
if (context.mounted) {
151150
ScaffoldMessenger.of(context)
152151
..hideCurrentSnackBar()
@@ -162,7 +161,7 @@ pitch: ${camera.pitch}'''),
162161
),
163162
OutlinedButton(
164163
onPressed: () async {
165-
final lngLat = await _controller.toLngLat(Offset.zero);
164+
final lngLat = _controller.toLngLat(Offset.zero);
166165
if (context.mounted) {
167166
ScaffoldMessenger.of(context)
168167
..hideCurrentSnackBar()
@@ -182,7 +181,7 @@ pitch: ${camera.pitch}'''),
182181
),
183182
OutlinedButton(
184183
onPressed: () async {
185-
final offset = await _controller.toScreenLocation(
184+
final offset = _controller.toScreenLocation(
186185
Position(0, 0),
187186
);
188187
if (context.mounted) {

example/lib/features_query_page.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ class _FeaturesQueryPageState extends State<FeaturesQueryPage> {
2828
onStyleLoaded: _onStyleLoaded,
2929
onEvent: (event) async {
3030
if (event is MapEventClick) {
31-
final screenPoint = await _controller.toScreenLocation(event.point);
32-
final features = await _controller.featuresAtPoint(
31+
final screenPoint = _controller.toScreenLocation(event.point);
32+
final features = _controller.featuresAtPoint(
3333
screenPoint,
3434
);
3535
if (context.mounted) {
3636
_showFeatures(features);
3737
}
3838
} else if (event is MapEventLongClick) {
39-
final screenPoint = await _controller.toScreenLocation(event.point);
40-
final features = await _controller.featuresInRect(
39+
final screenPoint = _controller.toScreenLocation(event.point);
40+
final features = _controller.featuresInRect(
4141
Rect.fromCircle(
4242
center: screenPoint,
4343
radius: 20,

example/lib/style_layers_fill_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class _StyleLayersFillPageState extends State<StyleLayersFillPage> {
2525
onStyleLoaded: _onStyleLoaded,
2626
onEvent: (event) async {
2727
if (event case MapEventClick()) {
28-
final screenPoint = await _controller.toScreenLocation(event.point);
29-
final features = await _controller.queryLayers(screenPoint);
28+
final screenPoint = _controller.toScreenLocation(event.point);
29+
final features = _controller.queryLayers(screenPoint);
3030
debugPrint(
3131
'${features.length} layers clicked\n'
3232
'${features.join('\n')}',

0 commit comments

Comments
 (0)