Skip to content

Commit 53f7cd6

Browse files
committed
fix: allows to change geometry value of an annotation (v11.5.1-alpha04)
1 parent 79b7551 commit 53f7cd6

File tree

10 files changed

+132
-4
lines changed

10 files changed

+132
-4
lines changed

kill-jd.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
taskkill -F -im java.exe
2+
taskkill -F -im dotnet.exe

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-alpha03</PackageVersion>
64+
<PackageVersion>11.5.1-alpha04</PackageVersion>
6565
<PackageReadmeFile>README.md</PackageReadmeFile>
6666
<PackageLicenseFile>LICENSE</PackageLicenseFile>
6767
<PackageIcon>tv-mapbox.png</PackageIcon>

src/libs/Mapbox.Maui/Models/Annotations/IAnnotation.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ public abstract class Annotation<T>
2020
{
2121
public string Id { get; set; }
2222

23-
public IGeometryObject Geometry { get; }
23+
public IGeometryObject Geometry { get; private set; }
2424

25-
public T GeometryValue => (T)Geometry;
25+
public T GeometryValue {
26+
get => (T)Geometry;
27+
set => Geometry = value;
28+
}
2629

2730
public IReadOnlyDictionary<string, object> UserInfo { get; set; }
2831

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void UpdateAnnotations(params TAnnotation[] annotations)
4545
if (annotations.Length == 0) return;
4646

4747
var xannotations = annotations
48-
.Select(ToPlatformAnnotationOption)
48+
.Select(ToPlatformAnnotation)
4949
.ToList();
5050

5151
NativeManager.Update(xannotations);
@@ -60,5 +60,6 @@ public void RemoveAnnotations(params string[] annotationIDs)
6060
}
6161

6262
protected abstract IAnnotationOptions ToPlatformAnnotationOption(TAnnotation annotation);
63+
protected abstract Annotation ToPlatformAnnotation(TAnnotation annotation);
6364
protected abstract IList GetNativeAnnotations(params string[] annotationIDs);
6465
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace MapboxMaui.Annotations;
22

3+
using Android.Graphics;
34
using Com.Mapbox.Maps.Plugins.Annotations;
45
using System.Collections;
56
using PlatformCircleAnnotationManager = Com.Mapbox.Maps.Plugins.Annotations.Generated.CircleAnnotationManager;
@@ -61,5 +62,7 @@ protected override IList GetNativeAnnotations(params string[] annotationIDs)
6162
}
6263
return itemsToDelete;
6364
}
65+
protected override Annotation ToPlatformAnnotation(CircleAnnotation annotation)
66+
=> (Annotation)annotation.ToPlatformValue().Build(annotation.Id, nativeManager);
6467
}
6568

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

+2
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,7 @@ protected override IList GetNativeAnnotations(params string[] annotationIDs)
175175
}
176176
return itemsToDelete;
177177
}
178+
protected override Annotation ToPlatformAnnotation(PointAnnotation annotation)
179+
=> (Annotation)annotation.ToPlatformValue().Build(annotation.Id, nativeManager);
178180
}
179181

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

+2
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,6 @@ protected override IList GetNativeAnnotations(params string[] annotationIDs)
5656
}
5757
return itemsToDelete;
5858
}
59+
protected override Annotation ToPlatformAnnotation(PolygonAnnotation annotation)
60+
=> (Annotation)annotation.ToPlatformValue().Build(annotation.Id, nativeManager);
5961
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,6 @@ protected override IList GetNativeAnnotations(params string[] annotationIDs)
7272
}
7373
return itemsToDelete;
7474
}
75+
protected override Annotation ToPlatformAnnotation(PolylineAnnotation annotation)
76+
=> (Annotation)annotation.ToPlatformValue().Build(annotation.Id, nativeManager);
7577
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
namespace MapboxMauiQs;
2+
3+
public class MovingCarExample : ContentPage, IExamplePage, IQueryAttributable
4+
{
5+
MapboxView map;
6+
IExampleInfo info;
7+
IPosition lastPosition;
8+
9+
public MovingCarExample()
10+
{
11+
iOSPage.SetUseSafeArea(this, false);
12+
Content = new Grid
13+
{
14+
Children = {
15+
(map = new MapboxView()),
16+
new HorizontalStackLayout
17+
{
18+
VerticalOptions = LayoutOptions.End,
19+
HorizontalOptions = LayoutOptions.Center,
20+
Margin = new Thickness(16),
21+
Spacing = 16,
22+
Children =
23+
{
24+
new Button
25+
{
26+
Text = "Move",
27+
Command = new Command(Move),
28+
},
29+
new Button
30+
{
31+
Text = "Center",
32+
Command = new Command(Centralize),
33+
},
34+
},
35+
},
36+
}
37+
};
38+
39+
map.MapReady += Map_MapReady;
40+
map.MapLoaded += Map_MapLoaded;
41+
}
42+
43+
private void Centralize(object obj)
44+
{
45+
if (carAnnotation is null) return;
46+
47+
map.CameraController.EaseTo(new CameraOptions()
48+
{
49+
Center = carAnnotation.GeometryValue.Coordinates,
50+
});
51+
}
52+
53+
private void Move(object obj)
54+
{
55+
if (carAnnotation is null) return;
56+
57+
var currentPosition = carAnnotation.GeometryValue;
58+
carAnnotation.GeometryValue = new GeoJSON.Text.Geometry.Point(
59+
new MapPosition(
60+
currentPosition.Latitude() + 0.001,
61+
currentPosition.Longitude() + 0.0001
62+
)
63+
);
64+
pointAnnotationManager.UpdateAnnotations(carAnnotation);
65+
}
66+
67+
public void ApplyQueryAttributes(IDictionary<string, object> query)
68+
{
69+
info = query["example"] as IExampleInfo;
70+
71+
Title = info?.Title;
72+
}
73+
74+
private void Map_MapReady(object sender, EventArgs e)
75+
{
76+
var centerLocation = lastPosition = new MapPosition(21.0278, 105.8342);
77+
var cameraOptions = new CameraOptions
78+
{
79+
Center = centerLocation,
80+
Zoom = 14,
81+
};
82+
83+
map.CameraOptions = cameraOptions;
84+
map.MapboxStyle = MapboxStyle.MAPBOX_STREETS;
85+
}
86+
87+
IPointAnnotationManager pointAnnotationManager;
88+
PointAnnotation carAnnotation;
89+
private void Map_MapLoaded(object sender, EventArgs e)
90+
{
91+
map.Images = [
92+
new ResolvedImage("CAR", "ic_car_top"),
93+
];
94+
95+
pointAnnotationManager = map.AnnotationController.CreatePointAnnotationManager("CARS", LayerPosition.Unknown());
96+
97+
carAnnotation = new PointAnnotation(new GeoJSON.Text.Geometry.Point(lastPosition))
98+
{
99+
IconImage = "CAR",
100+
};
101+
pointAnnotationManager.AddAnnotations(carAnnotation);
102+
}
103+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace MapboxMauiQs;
2+
3+
class MovingCarExampleInfo : IExampleInfo
4+
{
5+
public string Group => "Lab";
6+
public string Title => "Display a car moving on map";
7+
public string Subtitle => "Demo how to show a car moving on the map";
8+
public string PageRoute => typeof(MovingCarExample).FullName;
9+
public int Index => 71;
10+
}

0 commit comments

Comments
 (0)