Skip to content

Commit c8bd89f

Browse files
authored
fix: QueryRenderedFeaturesWith dp for android (11.5.1-alpha09) (#41)
* - always use DP for Android (convert to DP from pixel when retreiveing from native and convert back when passing from cross platform value to native) * 11.5.1-alpha09
1 parent b9cfada commit c8bd89f

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

src/libs/Mapbox.Maui/Mapbox.Maui.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<RepositoryUrl>https://github.com/tuyen-vuduc/mapbox-maui</RepositoryUrl>
6262
<PackageProjectUrl>https://mapbox.tuyen-vuduc.tech</PackageProjectUrl>
6363
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
64-
<PackageVersion>11.5.1-alpha08</PackageVersion>
64+
<PackageVersion>11.5.1-alpha09</PackageVersion>
6565
<PackageReadmeFile>README.md</PackageReadmeFile>
6666
<PackageLicenseFile>LICENSE</PackageLicenseFile>
6767
<PackageIcon>tv-mapbox.png</PackageIcon>

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

+12-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using Com.Mapbox.Maps.Plugins.Animation;
1717
using Com.Mapbox.Functions;
1818
using Com.Mapbox.Maps.Plugins;
19-
using Android.Content.PM;
2019

2120
static class AdditionalExtensions
2221
{
@@ -60,7 +59,15 @@ internal static double PixelToPoint(this double pixel)
6059

6160
return pixel / Metrics.Density;
6261
}
63-
62+
63+
internal static double PointToPixel(this double point)
64+
{
65+
Metrics ??= Resources.System?.DisplayMetrics;
66+
if (Metrics == null) return 0;
67+
68+
return point * Metrics.Density;
69+
}
70+
6471
internal static Java.Lang.Boolean ToPlatform(this bool xvalue)
6572
{
6673
return new Java.Lang.Boolean(xvalue);
@@ -366,7 +373,9 @@ public static CameraOptions ToX(this CameraState cameraOptions)
366373
Zoom = (float?)cameraOptions.Zoom,
367374
};
368375
public static ScreenPosition ToX(this ScreenCoordinate screenCoordinate)
369-
=> new(screenCoordinate.GetX(), screenCoordinate.GetY());
376+
=> new(
377+
screenCoordinate.GetX().PixelToPoint(),
378+
screenCoordinate.GetY().PixelToPoint());
370379

371380
public static MapboxMapsCameraOptions ToNative(this CameraOptions cameraOptions)
372381
{

src/libs/Mapbox.Maui/Platforms/Android/GeometryExtensions.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ internal static Com.Mapbox.Geojson.Point ToNative(this Point xvalue)
9494
return Com.Mapbox.Geojson.Point.FromLngLat(xvalue.Y, xvalue.X);
9595
}
9696

97-
internal static Com.Mapbox.Maps.ScreenCoordinate ToScreenCoordinate(this Point xvalue)
98-
{
99-
return new Com.Mapbox.Maps.ScreenCoordinate(xvalue.Y, xvalue.X);
100-
}
97+
internal static Com.Mapbox.Maps.ScreenCoordinate ToScreenCoordinate(this ScreenPosition xvalue)
98+
=> new Com.Mapbox.Maps.ScreenCoordinate(
99+
xvalue.X.PointToPixel(),
100+
xvalue.Y.PointToPixel());
101101

102102
internal static GeoJSON.Text.Feature.Feature ToX(this Com.Mapbox.Geojson.Feature src)
103103
=> new GeoJSON.Text.Feature.Feature(

src/libs/Mapbox.Maui/Platforms/Android/MapboxViewHandler.Query.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ public Task<IEnumerable<XQueriedFeature>> QueryRenderedFeaturesWith(ScreenPositi
1414
Array.Empty<XQueriedFeature>() as IEnumerable<XQueriedFeature>
1515
);
1616

17+
var x = point.X.PointToPixel();
18+
var y = point.Y.PointToPixel();
19+
1720
var tcs = new TaskCompletionSource<IEnumerable<XQueriedFeature>>();
1821
_ = mapView.MapboxMap.QueryRenderedFeatures(
1922
new RenderedQueryGeometry(
2023
new ScreenBox(
21-
new ScreenCoordinate(point.X - 25.0, point.Y - 25.0),
22-
new ScreenCoordinate(point.X + 25.0, point.Y + 25.0)
24+
new ScreenCoordinate(x - 25.0, y - 25.0),
25+
new ScreenCoordinate(x + 25.0, y + 25.0)
2326
)
2427
),
2528
options.ToPlatform(),

0 commit comments

Comments
 (0)