Skip to content

Commit b1367b2

Browse files
committed
- iOS impl
1 parent 4a0e03e commit b1367b2

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

src/libs/Mapbox.Maui/Platforms/iOS/AdditionalExtensions.cs

+5
Original file line numberDiff line numberDiff line change
@@ -369,5 +369,10 @@ internal static NSValue ToNSValue(this ScreenPosition screenPosition)
369369
{
370370
return NSValue.FromCGPoint(screenPosition.ToNative());
371371
}
372+
373+
internal static NSNumber ToNSNumber(this double value)
374+
{
375+
return NSNumber.FromDouble(value);
376+
}
372377
}
373378

src/libs/Mapbox.Maui/Platforms/iOS/MapboxViewHandler.Controller.cs

+81
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,85 @@ public ScreenPosition GetScreenPosition(IPosition position)
4242
var coords = mapView.MapboxMap().PointFor(position.ToCoords());
4343
return coords.ToPoint();
4444
}
45+
46+
/**
47+
* Convenience method that returns the [CameraOptions] object for given parameters.
48+
*
49+
* Note: if the render thread did not yet calculate the size of the map (due to initialization or map resizing) - empty [CameraOptions] will be returned.
50+
* Emptiness could be checked with [CameraOptions.isEmpty]. Consider using asynchronous overloaded method.
51+
*
52+
* @param coordinates The `coordinates` representing the bounds of the camera.
53+
* @param camera The [CameraOptions] which will be applied before calculating the camera for the coordinates. If any of the fields in [CameraOptions] are not provided then the current value from the map for that field will be used.
54+
* @param coordinatesPadding The amount of padding in pixels to add to the given `coordinates`.
55+
* Note: This padding is not applied to the map but to the coordinates provided. If you want to apply padding to the map use param `camera`.
56+
* @param maxZoom The maximum zoom level allowed in the returned camera options.
57+
* @param offset The center of the given bounds relative to map center in pixels.
58+
*
59+
* @return The [CameraOptions] object representing the provided parameters if the map size was calculated and empty [CameraOptions] otherwise, see [CameraOptions.isEmpty].
60+
* Also empty [CameraOptions] are returned in case of an internal error.
61+
*/
62+
public CameraOptions? CameraForCoordinates(
63+
IEnumerable<MapPosition> coordinates,
64+
CameraOptions? cameraOptions = null,
65+
Thickness? coordinatesPadding = null,
66+
double? maxZoom = null,
67+
ScreenPosition? offset = null)
68+
{
69+
var mapView = PlatformView.MapView;
70+
71+
if (mapView == null) return default;
72+
73+
TMBCameraOptions? xresult = null;
74+
mapView.MapboxMap().CameraFor(
75+
coordinates?.Select(x => x.ToNSValue()).ToArray(),
76+
cameraOptions?.ToNative(),
77+
coordinatesPadding?.ToNSValue(),
78+
maxZoom?.ToNSNumber(),
79+
offset?.ToNSValue(),
80+
(result, _) =>
81+
{
82+
xresult = result;
83+
});
84+
return xresult?.ToX();
85+
}
86+
87+
/**
88+
* Convenience method that returns the [CameraOptions] object for given parameters.
89+
*
90+
* @param coordinates The `coordinates` representing the bounds of the camera.
91+
* @param camera The [CameraOptions] which will be applied before calculating the camera for the coordinates. If any of the fields in [CameraOptions] are not provided then the current value from the map for that field will be used.
92+
* @param coordinatesPadding The amount of padding in pixels to add to the given `coordinates`.
93+
* Note: This padding is not applied to the map but to the coordinates provided. If you want to apply padding to the map use param `camera`.
94+
* @param maxZoom The maximum zoom level allowed in the returned camera options.
95+
* @param offset The center of the given bounds relative to map center in pixels.
96+
* @param completion Callback returning the [CameraOptions] object representing the provided parameters. Those [CameraOptions] always take into account actual MapView size and may return empty ([CameraOptions.isEmpty]) options only if an internal error has occurred.
97+
*/
98+
public void CameraForCoordinates(
99+
IEnumerable<MapPosition> coordinates,
100+
Action<CameraOptions?> completion,
101+
CameraOptions? cameraOptions = null,
102+
Thickness? coordinatesPadding = null,
103+
double? maxZoom = null,
104+
ScreenPosition? offset = null)
105+
{
106+
107+
var mapView = PlatformView.MapView;
108+
109+
if (mapView == null)
110+
{
111+
completion(null);
112+
return;
113+
}
114+
115+
mapView.MapboxMap().CameraFor(
116+
coordinates?.Select(x => x.ToNSValue()).ToArray(),
117+
cameraOptions?.ToNative(),
118+
coordinatesPadding?.ToNSValue(),
119+
maxZoom?.ToNSNumber(),
120+
offset?.ToNSValue(),
121+
(result, _) =>
122+
{
123+
completion(result?.ToX());
124+
});
125+
}
45126
}

0 commit comments

Comments
 (0)