Skip to content

Commit 7be4507

Browse files
committed
feat: Sample AnimatePointAnnotation (not done) (#15)
* - only pack the MAUI lib * - Change to IPosition instead of GeoJSON.Point for MapTappedLocation - Change MapTappedPosition to a record - Add CoordinateBounds * - Add empty example AnimatePointAnnotation * - fix issue of converting MapboxGeoJSON Point to GeoJSON.NET.Position * bumb new version
1 parent 1ef495e commit 7be4507

40 files changed

+331
-142
lines changed

build.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ dotnet nuget locals -c all
44
dotnet build -t:Clean,Rebuild src/qs/MapboxMauiQs/MapboxMauiQs.csproj \
55
-property:MAPBOX_DOWNLOADS_TOKEN=$MAPBOX_DOWNLOADS_TOKEN
66

7-
dotnet pack -c Release -t:Clean,Rebuild mapbox-maui.sln --output $PWD/nugets
7+
dotnet pack -c Release -t:Clean,Rebuild src/libs/Mapbox.Maui/Mapbox.Maui.csproj \
8+
--output $PWD/nugets

src/libs/Mapbox.Maui/IMapboxView.cs

+6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ public interface IMapFeatureQueryable
6161
Task<IEnumerable<QueriedRenderedFeature>> QueryRenderedFeaturesWith(ScreenPosition point, RenderedQueryOptions options);
6262
}
6363

64+
public interface IMapboxController
65+
{
66+
IPosition GetMapPosition(ScreenPosition position);
67+
CoordinateBounds GetCoordinateBoundsForCamera(CameraOptions cameraOptions);
68+
}
69+
6470
public class MapTappedEventArgs : EventArgs
6571
{
6672
public MapTappedPosition Position { get; }

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<RepositoryUrl>https://github.com/tuyen-vuduc/mapbox-maui</RepositoryUrl>
5454
<PackageProjectUrl>https://mapbox.tuyen-vuduc.tech</PackageProjectUrl>
5555
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
56-
<PackageVersion>11.3.0-alpha02</PackageVersion>
56+
<PackageVersion>11.3.0-alpha03</PackageVersion>
5757
<PackageReadmeFile>README.md</PackageReadmeFile>
5858
<PackageLicenseFile>LICENSE</PackageLicenseFile>
5959
<PackageIcon>tv-mapbox.png</PackageIcon>

src/libs/Mapbox.Maui/MapboxView.Events.cs

+1-9
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,4 @@ public ICommand MapLoadedCommand
116116
get => (ICommand)GetValue(MapLoadedCommandProperty);
117117
set => SetValue(MapLoadedCommandProperty, value);
118118
}
119-
}
120-
121-
public class MapTappedPosition
122-
{
123-
public ScreenPosition ScreenPosition { get; set; }
124-
125-
public GeoJSON.Text.Geometry.Point Point { get; set; }
126-
}
127-
119+
}

src/libs/Mapbox.Maui/MapboxView.cs

+1
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,5 @@ public MapboxStyle MapboxStyle
221221

222222
public IAnnotationController AnnotationController { get; internal set; }
223223
public IMapFeatureQueryable QueryManager { get; internal set; }
224+
public IMapboxController MapboxController { get; internal set; }
224225
}

src/libs/Mapbox.Maui/Models/BaseKVContainer.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System.Collections.ObjectModel;
2-
using System.Collections.Specialized;
3-
4-
namespace MapboxMaui;
1+
namespace MapboxMaui;
52

63
public abstract class BaseKVContainer : INotifyCollectionChanged
74
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace MapboxMaui;
2+
3+
public record CoordinateBounds (
4+
IPosition Southwest,
5+
IPosition Northeast,
6+
bool InfiniteBounds = false);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace MapboxMaui;
2+
3+
public record MapTappedPosition(
4+
ScreenPosition ScreenPosition,
5+
IPosition MapPosition);

src/libs/Mapbox.Maui/Platforms/Android/Annotations/PointAnnotationManager.cs

-16
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,6 @@ public IconRotationAlignment? IconRotationAlignment
5050
get => nativeManager.IconRotationAlignment?.GetValue();
5151
set => nativeManager.IconRotationAlignment = value?.ToPlatform();
5252
}
53-
public IconTextFit? IconTextFit
54-
{
55-
get => nativeManager.IconTextFit?.GetValue();
56-
set => nativeManager.IconTextFit = value?.ToPlatform();
57-
}
58-
public double[] IconTextFitPadding
59-
{
60-
get => nativeManager.IconTextFitPadding.GetValue();
61-
set => nativeManager.IconTextFitPadding = value?.ToPlatform();
62-
}
6353
public bool? SymbolAvoidEdges
6454
{
6555
get => nativeManager.SymbolAvoidEdges?.BooleanValue();
@@ -163,12 +153,6 @@ public TextTranslateAnchor? TextTranslateAnchor
163153
get => nativeManager.TextTranslateAnchor?.GetValue();
164154
set => nativeManager.TextTranslateAnchor = value?.ToPlatform();
165155
}
166-
public double? TextLineHeight
167-
{
168-
get => nativeManager.TextLineHeight?.DoubleValue();
169-
set => nativeManager.TextLineHeight = value?.ToPlatform();
170-
}
171-
172156
public override void AddAnnotations(params PointAnnotation[] xitems)
173157
{
174158
var items = xitems

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

+28-13
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,35 @@ public static class GeometryExtensions
88
{
99
internal static Com.Mapbox.Geojson.Point ToGeoPoint(this GeoJSON.Text.Geometry.IPosition xvalue)
1010
{
11-
return Com.Mapbox.Geojson.Point.FromLngLat(
11+
return xvalue.Altitude is not null
12+
? Com.Mapbox.Geojson.Point.FromLngLat(
13+
xvalue.Longitude,
14+
xvalue.Latitude,
15+
xvalue.Altitude.Value)
16+
: Com.Mapbox.Geojson.Point.FromLngLat(
1217
xvalue.Longitude,
1318
xvalue.Latitude);
1419
}
15-
20+
21+
public static IPosition ToMapPosition(this Com.Mapbox.Geojson.Point point)
22+
{
23+
return new MapPosition(
24+
point.Latitude(),
25+
point.Longitude(),
26+
point.Altitude());
27+
}
28+
1629
internal static MapTappedPosition ToMapTappedPosition(this Com.Mapbox.Geojson.Point point, ScreenCoordinate screenCoordinate)
1730
{
18-
return new MapTappedPosition
19-
{
20-
ScreenPosition = new ScreenPosition(
31+
return new MapTappedPosition(
32+
new ScreenPosition(
2133
screenCoordinate.GetX().PixelToPoint(),
2234
screenCoordinate.GetY().PixelToPoint()),
23-
Point = new GeoJSON.Text.Geometry.Point(
24-
new Position(
25-
screenCoordinate.GetX().PixelToPoint(),
26-
screenCoordinate.GetY().PixelToPoint(),
27-
point.HasAltitude ? point.Altitude() : null)
28-
)
29-
};
35+
new MapPosition(
36+
point.Latitude(),
37+
point.Longitude(),
38+
point.HasAltitude ? point.Altitude() : null)
39+
);
3040
}
3141

3242
internal static Com.Mapbox.Geojson.IGeometry ToNative(this GeoJSON.Text.Geometry.IGeometryObject xvalue)
@@ -84,6 +94,11 @@ internal static Com.Mapbox.Geojson.Point ToNative(this Point xvalue)
8494
return Com.Mapbox.Geojson.Point.FromLngLat(xvalue.Y, xvalue.X);
8595
}
8696

97+
internal static Com.Mapbox.Maps.ScreenCoordinate ToScreenCoordinate(this Point xvalue)
98+
{
99+
return new Com.Mapbox.Maps.ScreenCoordinate(xvalue.Y, xvalue.X);
100+
}
101+
87102
internal static GeoJSON.Text.Feature.Feature ToX(this Com.Mapbox.Geojson.Feature src)
88103
=> new GeoJSON.Text.Feature.Feature(
89104
src.Geometry().ToX(),
@@ -96,7 +111,7 @@ internal static IGeometryObject ToX(this Com.Mapbox.Geojson.IGeometry src)
96111
{
97112
case Com.Mapbox.Geojson.Point point:
98113
return new GeoJSON.Text.Geometry.Point(
99-
new Position(
114+
new MapPosition(
100115
point.Latitude(), point.Longitude(),
101116
point.HasAltitude ? point.Altitude() : null
102117
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+

2+
namespace MapboxMaui;
3+
4+
partial class MapboxViewHandler : IMapboxController
5+
{
6+
public CoordinateBounds GetCoordinateBoundsForCamera(CameraOptions cameraOptions)
7+
{
8+
var mapView = mapboxFragment?.MapView;
9+
10+
if (mapView == null) return null;
11+
12+
var xcameraOptions = cameraOptions.ToNative();
13+
var xbounds = mapView.MapboxMap.CoordinateBoundsForCamera(xcameraOptions);
14+
15+
return new CoordinateBounds(
16+
xbounds.Southwest.ToMapPosition(),
17+
xbounds.Northeast.ToMapPosition(),
18+
xbounds.InfiniteBounds
19+
);
20+
}
21+
22+
public IPosition GetMapPosition(ScreenPosition position)
23+
{
24+
var mapView = mapboxFragment?.MapView;
25+
26+
if (mapView == null) return null;
27+
28+
var coords = mapView.MapboxMap.CoordinateForPixel(position.ToScreenCoordinate());
29+
return coords.ToMapPosition();
30+
}
31+
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ protected override void ConnectHandler(PlatformView platformView)
229229
{
230230
mapboxView.AnnotationController = this;
231231
mapboxView.QueryManager = this;
232+
mapboxView.MapboxController = this;
232233
}
233234
}
234235

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

+22-11
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,15 @@ public static class GeometryExtensions
1010
{
1111
internal static MapTappedPosition ToMapTappedPosition(this CLLocationCoordinate2D coords, CGPoint screenCoordinate)
1212
{
13-
return new MapTappedPosition
14-
{
15-
ScreenPosition = new ScreenPosition(
13+
return new MapTappedPosition(
14+
new ScreenPosition(
1615
screenCoordinate.X,
1716
screenCoordinate.Y
1817
),
19-
Point = new GeoJSON.Text.Geometry.Point(
20-
new Position(
21-
coords.Latitude,
22-
coords.Longitude
23-
)
24-
),
25-
};
18+
new MapPosition(
19+
coords.Latitude,
20+
coords.Longitude
21+
));
2622
}
2723

2824
internal static MBXGeometry ToNative(this IGeometryObject xobj)
@@ -97,6 +93,21 @@ internal static CGPoint ToCGPoint(this IPosition xobj)
9793
);
9894
}
9995

96+
internal static CGPoint ToCGPoint(this ScreenPosition xobj)
97+
{
98+
return new CGPoint(
99+
xobj.X,
100+
xobj.Y
101+
);
102+
}
103+
104+
public static IPosition ToMapPosition(this CLLocationCoordinate2D point)
105+
{
106+
return new MapPosition(
107+
point.Latitude,
108+
point.Longitude);
109+
}
110+
100111
internal static NSValue ToNSValue(this IPosition xobj)
101112
{
102113
return NSValue.FromCGPoint(
@@ -105,7 +116,7 @@ internal static NSValue ToNSValue(this IPosition xobj)
105116
}
106117

107118
internal static IPosition ToPosition(this NSValue src)
108-
=> new Position(
119+
=> new MapPosition(
109120
src.CoordinateValue.Latitude,
110121
src.CoordinateValue.Longitude
111122
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using MapboxMapsObjC;
2+
3+
namespace MapboxMaui;
4+
5+
partial class MapboxViewHandler : IMapboxController
6+
{
7+
public CoordinateBounds GetCoordinateBoundsForCamera(CameraOptions cameraOptions)
8+
{
9+
var mapView = PlatformView.MapView;
10+
11+
if (mapView == null) return null;
12+
13+
var xcameraOptions = cameraOptions.ToNative();
14+
var xbounds = mapView.MapboxMap().CoordinateBoundsForCameraBounds(xcameraOptions);
15+
16+
return new CoordinateBounds(
17+
xbounds.Southeast.ToMapPosition(),
18+
xbounds.Northeast.ToMapPosition(),
19+
xbounds.InfiniteBounds
20+
);
21+
}
22+
public IPosition GetMapPosition(ScreenPosition position)
23+
{
24+
var mapView = PlatformView.MapView;
25+
26+
if (mapView == null) return null;
27+
28+
var coords = mapView.MapboxMap().CoordinateFor(
29+
position.ToCGPoint()
30+
);
31+
32+
return coords.ToMapPosition();
33+
}
34+
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public partial class MapboxViewHandler
1414
UITapGestureRecognizer mapTapGestureRecognizer;
1515
UILongPressGestureRecognizer mapLongPressGestureRecognizer;
1616

17-
1817
private static void HandleLightChanged(MapboxViewHandler handler, IMapboxView view)
1918
{
2019
var mapView = handler.PlatformView.MapView;
@@ -287,6 +286,7 @@ protected override void DisconnectHandler(PlatformView platformView)
287286
{
288287
mapboxView.AnnotationController = null;
289288
mapboxView.QueryManager = null;
289+
mapboxView.MapboxController = null;
290290
}
291291

292292
var mapView = platformView.MapView;
@@ -312,6 +312,7 @@ protected override void ConnectHandler(PlatformView platformView)
312312
mapboxView.InvokeMapReady();
313313
mapboxView.AnnotationController = this;
314314
mapboxView.QueryManager = this;
315+
mapboxView.MapboxController = this;
315316
}
316317

317318
var mapView = platformView.MapView;

src/libs/Mapbox.Maui/usings.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
global using System.Text.Json;
2+
global using System.Collections.ObjectModel;
3+
global using System.Collections.Specialized;
24
global using GeoJSON.Text;
35
global using GeoJSON.Text.Feature;
46
global using GeoJSON.Text.Geometry;
@@ -8,4 +10,5 @@
810
global using MapboxMaui.Offline;
911
global using MapboxMaui.Annotations;
1012
global using iOSPage = Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page;
11-
global using ScreenPosition = Microsoft.Maui.Graphics.Point;
13+
global using ScreenPosition = Microsoft.Maui.Graphics.Point;
14+
global using MapPosition = GeoJSON.Text.Geometry.Position;

src/qs/MapboxMauiQs/Examples/01.AddMarkersSymbol/AddMarkersSymbolExample.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void ApplyQueryAttributes(IDictionary<string, object> query)
3434

3535
private void Map_MapReady(object sender, EventArgs e)
3636
{
37-
var centerLocation = new Position(55.70651, 12.554729);
37+
var centerLocation = new MapPosition(55.70651, 12.554729);
3838
var cameraOptions = new CameraOptions
3939
{
4040
Center = centerLocation,
@@ -56,7 +56,7 @@ private void Map_MapLoaded(object sender, EventArgs e)
5656

5757
var feature = new Feature(
5858
new GeoJSON.Text.Geometry.Point(
59-
new GeoJSON.Text.Geometry.Position(latitude: 55.608166, longitude: 12.65147)
59+
new MapPosition(latitude: 55.608166, longitude: 12.65147)
6060
),
6161
new Dictionary<string, object> {
6262
{ Constants.ICON_KEY, Constants.BLUE_MARKER_PROPERTY }
@@ -66,7 +66,7 @@ private void Map_MapLoaded(object sender, EventArgs e)
6666

6767
var feature1 = new Feature(
6868
new GeoJSON.Text.Geometry.Point(
69-
new GeoJSON.Text.Geometry.Position(latitude: 55.70651, longitude: 12.554729)
69+
new MapPosition(latitude: 55.70651, longitude: 12.554729)
7070
),
7171
new Dictionary<string, object> {
7272
{ Constants.ICON_KEY, Constants.RED_MARKER_PROPERTY }

src/qs/MapboxMauiQs/Examples/02.AddOneMarkerSymbol/AddOneMarkerSymbolExample.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private void Map_StyleLoaded(object sender, EventArgs e)
2626
var source = new GeoJSONSource(sourceId)
2727
{
2828
Data = new GeoJSON.Text.Geometry.Point(
29-
new Position(55.665957, 12.550343))
29+
new MapPosition(55.665957, 12.550343))
3030
};
3131

3232
map.Sources = new[] { source };
@@ -43,7 +43,7 @@ private void Map_StyleLoaded(object sender, EventArgs e)
4343
private void Map_MapReady(object sender, EventArgs e)
4444
{
4545
// Do any additional setup after loading the view.
46-
var center = new Position(55.665957, 12.550343);
46+
var center = new MapPosition(55.665957, 12.550343);
4747
var cameraOptions = new CameraOptions {
4848
Center = center,
4949
Zoom = 8,

0 commit comments

Comments
 (0)