Skip to content

Commit 2f902a8

Browse files
markszentejosxha
andauthored
fix: add padding to fitBounds on ios (#426)
This PR adds missing support for setting padding in `fitBounds` on iOS. --------- Co-authored-by: Joscha <[email protected]>
1 parent 0b59aea commit 2f902a8

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

example/lib/controller_page.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class _ControllerPageState extends State<ControllerPage> {
7878
latitudeSouth: 45.806154,
7979
latitudeNorth: 47.902069,
8080
),
81+
padding: const EdgeInsets.all(50),
8182
);
8283
debugPrint('fitBounds end');
8384
} on PlatformException catch (error) {

maplibre/lib/src/platform/ios/extensions.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ extension LngLatBoundsExt on LngLatBounds {
7171
}
7272
}
7373

74+
/// Internal extensions on [EdgeInsets].
75+
extension EdgeInsetsExt on EdgeInsets {
76+
/// Convert an [EdgeInsets] to a [UIEdgeInsets].
77+
UIEdgeInsets toUIEdgeInsets() {
78+
final insets = Struct.create<UIEdgeInsets>()
79+
..top = top
80+
..left = left
81+
..bottom = bottom
82+
..right = right;
83+
return insets;
84+
}
85+
}
86+
7487
/// Internal extensions on [MLNCoordinateBounds].
7588
extension MLNCoordinateBoundsExt on MLNCoordinateBounds {
7689
/// Convert a [MLNCoordinateBounds] to a [LngLatBounds].

maplibre/lib/src/platform/ios/map_state.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,12 @@ final class MapLibreMapStateIos extends MapLibreMapStateNative
101101
EdgeInsets padding = EdgeInsets.zero,
102102
}) async {
103103
final ffiBounds = bounds.toMLNCoordinateBounds();
104-
// TODO support padding with Struct UIEdgeInsets
105-
_mapView.setVisibleCoordinateBounds(ffiBounds, animated: true);
104+
final ffiPadding = padding.toUIEdgeInsets();
105+
_mapView.setVisibleCoordinateBounds$1(
106+
ffiBounds,
107+
edgePadding: ffiPadding,
108+
animated: true,
109+
);
106110
}
107111

108112
@override

0 commit comments

Comments
 (0)