-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMapboxViewHandler.Query.cs
52 lines (44 loc) · 1.77 KB
/
MapboxViewHandler.Query.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
namespace MapboxMaui;
using Com.Mapbox.Bindgen;
using Com.Mapbox.Maps;
using XQueriedFeature = Query.QueriedRenderedFeature;
using XRenderedQueryOptions = Query.RenderedQueryOptions;
partial class MapboxViewHandler : IMapFeatureQueryable
{
public Task<IEnumerable<XQueriedFeature>> QueryRenderedFeaturesWith(ScreenPosition point, XRenderedQueryOptions options)
{
var mapView = PlatformView.GetMapView();
if (mapView == null) return Task.FromResult(
Array.Empty<XQueriedFeature>() as IEnumerable<XQueriedFeature>
);
var tcs = new TaskCompletionSource<IEnumerable<XQueriedFeature>>();
_ = mapView.MapboxMap.QueryRenderedFeatures(
new RenderedQueryGeometry(
new ScreenBox(
new ScreenCoordinate(point.X - 25.0, point.Y - 25.0),
new ScreenCoordinate(point.X + 25.0, point.Y + 25.0)
)
),
options.ToPlatform(),
new QueryRenderedFeaturesWithPointCallback(tcs)
);
return tcs.Task;
}
class QueryRenderedFeaturesWithPointCallback : Java.Lang.Object, IQueryRenderedFeaturesCallback
{
private readonly TaskCompletionSource<IEnumerable<XQueriedFeature>> tcs;
public QueryRenderedFeaturesWithPointCallback(TaskCompletionSource<IEnumerable<XQueriedFeature>> tcs)
{
this.tcs = tcs;
}
public void Run(Expected p0)
{
if (p0.Error != null) {
tcs.TrySetException(new Exception(p0.Error.ToString()));
return;
}
var xfeatures = (p0.Value as Java.Util.IList)?.ToArray().Cast<QueriedRenderedFeature>();
tcs.TrySetResult(xfeatures.Select(x => x.ToX()).ToArray());
}
}
}