Skip to content

Commit ed5bd9c

Browse files
authored
fix: wrong converting coordinate bound on iOS (#47)
The iOS implementation of the `GetCoordinateBoundsForCamera` method returns south east instead of south west, resulting in incorrect coordinate bounds for the area. This commit changes fixes the issue.
1 parent 29ff66d commit ed5bd9c

File tree

1 file changed

+151
-151
lines changed

1 file changed

+151
-151
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,152 +1,152 @@
11
using Foundation;
2-
using MapboxMapsObjC;
3-
using Microsoft.Maui.Platform;
4-
5-
namespace MapboxMaui;
6-
7-
partial class MapboxViewHandler : IMapboxController
8-
{
9-
public CoordinateBounds GetCoordinateBoundsForCamera(CameraOptions cameraOptions)
10-
{
11-
var mapView = PlatformView.MapView;
12-
13-
if (mapView == null) return null;
14-
15-
var xcameraOptions = cameraOptions.ToNative();
16-
var xbounds = mapView.MapboxMap().CoordinateBoundsForCameraBounds(xcameraOptions);
17-
18-
return new CoordinateBounds(
19-
xbounds.Southeast.ToMapPosition(),
20-
xbounds.Northeast.ToMapPosition(),
21-
xbounds.InfiniteBounds
22-
);
23-
}
24-
25-
public IPosition GetMapPosition(ScreenPosition position)
26-
{
27-
var mapView = PlatformView.MapView;
28-
29-
if (mapView == null) return null;
30-
31-
var coords = mapView.MapboxMap().CoordinateFor(
32-
position.ToNative()
33-
);
34-
35-
return coords.ToMapPosition();
36-
}
37-
38-
public ScreenPosition GetScreenPosition(IPosition position)
39-
{
40-
var mapView = PlatformView.MapView;
41-
42-
if (mapView == null) return default;
43-
44-
var coords = mapView.MapboxMap().PointFor(position.ToCoords());
45-
return coords.ToPoint();
46-
}
47-
48-
public CameraOptions? CameraForCoordinates(
49-
IEnumerable<IPosition> coordinates,
50-
CameraOptions? cameraOptions = null,
51-
Thickness? coordinatesPadding = null,
52-
double? maxZoom = null,
53-
ScreenPosition? offset = null)
54-
{
55-
var mapView = PlatformView.MapView;
56-
57-
if (mapView == null) return default;
58-
59-
TMBCameraOptions? xresult = null;
60-
mapView.MapboxMap().CameraFor(
61-
coordinates?.Select(x => x.ToNSValue()).ToArray(),
62-
(cameraOptions?? new()).ToNative(),
63-
coordinatesPadding?.ToNSValue(),
64-
maxZoom?.ToNSNumber(),
65-
offset?.ToNSValue(),
66-
(result, _) =>
67-
{
68-
xresult = result;
69-
});
70-
return xresult?.ToX();
71-
}
72-
73-
public void CameraForCoordinates(
74-
IEnumerable<IPosition> coordinates,
75-
Action<CameraOptions?> completion,
76-
CameraOptions? cameraOptions = null,
77-
Thickness? coordinatesPadding = null,
78-
double? maxZoom = null,
79-
ScreenPosition? offset = null)
80-
{
81-
82-
var mapView = PlatformView.MapView;
83-
84-
if (mapView == null)
85-
{
86-
completion?.Invoke(null);
87-
return;
88-
}
89-
90-
mapView.MapboxMap().CameraFor(
91-
coordinates?.Select(x => x.ToNSValue()).ToArray(),
92-
(cameraOptions?? new()).ToNative(),
93-
coordinatesPadding?.ToNSValue(),
94-
maxZoom?.ToNSNumber(),
95-
offset?.ToNSValue(),
96-
(result, _) =>
97-
{
98-
completion?.Invoke(result?.ToX());
99-
});
100-
}
101-
102-
public void SetSourcePropertyFor<T>(
103-
string sourceId, string propertyName,
104-
T value, Action<Exception> completion = null)
105-
{
106-
var mapView = PlatformView.MapView;
107-
108-
if (mapView == null)
109-
{
110-
completion?.Invoke(null);
111-
return;
112-
}
113-
114-
mapView.MapboxMap().SetSourcePropertyFor(
115-
sourceId,
116-
propertyName,
117-
value.Wrap(),
118-
(error) =>
119-
{
120-
var exception = error is not null
121-
? new NSErrorException(error)
122-
: null;
123-
completion?.Invoke(exception);
124-
});
125-
}
126-
127-
128-
public void SetLayerPropertyFor<T>(
129-
string layerId, string propertyName,
130-
T value, Action<Exception> completion = null)
131-
{
132-
var mapView = PlatformView.MapView;
133-
134-
if (mapView == null)
135-
{
136-
completion?.Invoke(null);
137-
return;
138-
}
139-
140-
mapView.MapboxMap().SetLayerPropertyFor(
141-
layerId,
142-
propertyName,
143-
value.Wrap(),
144-
(error) =>
145-
{
146-
var exception = error is not null
147-
? new NSErrorException(error)
148-
: null;
149-
completion?.Invoke(exception);
150-
});
151-
}
152-
}
2+
using MapboxMapsObjC;
3+
using Microsoft.Maui.Platform;
4+
5+
namespace MapboxMaui;
6+
7+
partial class MapboxViewHandler : IMapboxController
8+
{
9+
public CoordinateBounds GetCoordinateBoundsForCamera(CameraOptions cameraOptions)
10+
{
11+
var mapView = PlatformView.MapView;
12+
13+
if (mapView == null) return null;
14+
15+
var xcameraOptions = cameraOptions.ToNative();
16+
var xbounds = mapView.MapboxMap().CoordinateBoundsForCameraBounds(xcameraOptions);
17+
18+
return new CoordinateBounds(
19+
xbounds.Southwest.ToMapPosition(),
20+
xbounds.Northeast.ToMapPosition(),
21+
xbounds.InfiniteBounds
22+
);
23+
}
24+
25+
public IPosition GetMapPosition(ScreenPosition position)
26+
{
27+
var mapView = PlatformView.MapView;
28+
29+
if (mapView == null) return null;
30+
31+
var coords = mapView.MapboxMap().CoordinateFor(
32+
position.ToNative()
33+
);
34+
35+
return coords.ToMapPosition();
36+
}
37+
38+
public ScreenPosition GetScreenPosition(IPosition position)
39+
{
40+
var mapView = PlatformView.MapView;
41+
42+
if (mapView == null) return default;
43+
44+
var coords = mapView.MapboxMap().PointFor(position.ToCoords());
45+
return coords.ToPoint();
46+
}
47+
48+
public CameraOptions? CameraForCoordinates(
49+
IEnumerable<IPosition> coordinates,
50+
CameraOptions? cameraOptions = null,
51+
Thickness? coordinatesPadding = null,
52+
double? maxZoom = null,
53+
ScreenPosition? offset = null)
54+
{
55+
var mapView = PlatformView.MapView;
56+
57+
if (mapView == null) return default;
58+
59+
TMBCameraOptions? xresult = null;
60+
mapView.MapboxMap().CameraFor(
61+
coordinates?.Select(x => x.ToNSValue()).ToArray(),
62+
(cameraOptions?? new()).ToNative(),
63+
coordinatesPadding?.ToNSValue(),
64+
maxZoom?.ToNSNumber(),
65+
offset?.ToNSValue(),
66+
(result, _) =>
67+
{
68+
xresult = result;
69+
});
70+
return xresult?.ToX();
71+
}
72+
73+
public void CameraForCoordinates(
74+
IEnumerable<IPosition> coordinates,
75+
Action<CameraOptions?> completion,
76+
CameraOptions? cameraOptions = null,
77+
Thickness? coordinatesPadding = null,
78+
double? maxZoom = null,
79+
ScreenPosition? offset = null)
80+
{
81+
82+
var mapView = PlatformView.MapView;
83+
84+
if (mapView == null)
85+
{
86+
completion?.Invoke(null);
87+
return;
88+
}
89+
90+
mapView.MapboxMap().CameraFor(
91+
coordinates?.Select(x => x.ToNSValue()).ToArray(),
92+
(cameraOptions?? new()).ToNative(),
93+
coordinatesPadding?.ToNSValue(),
94+
maxZoom?.ToNSNumber(),
95+
offset?.ToNSValue(),
96+
(result, _) =>
97+
{
98+
completion?.Invoke(result?.ToX());
99+
});
100+
}
101+
102+
public void SetSourcePropertyFor<T>(
103+
string sourceId, string propertyName,
104+
T value, Action<Exception> completion = null)
105+
{
106+
var mapView = PlatformView.MapView;
107+
108+
if (mapView == null)
109+
{
110+
completion?.Invoke(null);
111+
return;
112+
}
113+
114+
mapView.MapboxMap().SetSourcePropertyFor(
115+
sourceId,
116+
propertyName,
117+
value.Wrap(),
118+
(error) =>
119+
{
120+
var exception = error is not null
121+
? new NSErrorException(error)
122+
: null;
123+
completion?.Invoke(exception);
124+
});
125+
}
126+
127+
128+
public void SetLayerPropertyFor<T>(
129+
string layerId, string propertyName,
130+
T value, Action<Exception> completion = null)
131+
{
132+
var mapView = PlatformView.MapView;
133+
134+
if (mapView == null)
135+
{
136+
completion?.Invoke(null);
137+
return;
138+
}
139+
140+
mapView.MapboxMap().SetLayerPropertyFor(
141+
layerId,
142+
propertyName,
143+
value.Wrap(),
144+
(error) =>
145+
{
146+
var exception = error is not null
147+
? new NSErrorException(error)
148+
: null;
149+
completion?.Invoke(exception);
150+
});
151+
}
152+
}

0 commit comments

Comments
 (0)