Skip to content

Commit ef71a4d

Browse files
committed
feat (annotations): Support CircleAnnotation
1 parent 82e5710 commit ef71a4d

22 files changed

+767
-76
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,6 @@ ASALocalRun/
404404
# Local History for Visual Studio
405405
.localhistory/
406406

407-
tools/
407+
tools/Addins
408408

409409
*.dev.cs

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ b/ iOS's `info.plist`
100100
| 10 | [BuildingExtrusionsExample](./mapboxqs/BuildingExtrusionsExample.m) | OK |
101101
| 11 | [CameraAnimationExample](./mapboxqs/CameraAnimationExample.m) | |
102102
| 12 | [CameraAnimatorsExample](./mapboxqs/CameraAnimatorsExample.m) | |
103-
| 13 | [CircleAnnotationExample](./mapboxqs/CircleAnnotationExample.m) | |
103+
| 13 | [CircleAnnotationExample](./mapboxqs/CircleAnnotationExample.m) | x |
104104
| 14 | [ColorExpressionExample](./mapboxqs/ColorExpressionExample.m) | |
105105
| 15 | [Custom2DPuckExample](./mapboxqs/Custom2DPuckExample.m) | |
106106
| 16 | [Custom3DPuckExample](./mapboxqs/Custom3DPuckExample.m) | |
@@ -128,7 +128,7 @@ b/ iOS's `info.plist`
128128
| 38 | [LocalizationExample](./mapboxqs/LocalizationExample.m) | |
129129
| 39 | [MultipleGeometriesExample](./mapboxqs/MultipleGeometriesExample.m) | |
130130
| 40 | [NavigationSimulatorExample](./mapboxqs/NavigationSimulatorExample.m) | |
131-
| 41 | [OfflineManagerExample](./mapboxqs/OfflineManagerExample.m) | |
131+
| 41 | [OfflineManagerExample](./mapboxqs/OfflineManagerExample.m) | x |
132132
| 42 | [OfflineRegionManagerExample](./mapboxqs/OfflineRegionManagerExample.m) | |
133133
| 43 | [PitchAndDistanceExample](./mapboxqs/PitchAndDistanceExample.m) | |
134134
| 44 | [PointAnnotationClusteringExample](./mapboxqs/PointAnnotationClusteringExample.m) | |

build.cake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class {name}ExampleInfo : IExampleInfo
3939

4040
Information($"\n>> Generate >> {name}ExamplePage.cs");
4141
FileWriteText($"{exampleFolderPath}/{name}Example.cs", $@"{"using"} System;
42-
{"using"} Mapbox.Maui;
42+
{"using"} MapboxMaui;
4343
{"using"} iOSPage = Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page;
4444
namespace MapboxMauiQs;
4545

src/libs/Mapbox.Maui/IMapboxView.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ partial interface IMapboxView {
4040
public interface IAnnotationController
4141
{
4242
public IPolygonAnnotationManager CreatePolygonAnnotationManager(string id, LayerPosition layerPosition);
43-
//public IAnnotationManager<Annotations.PolygonAnnotation> CircleAnnotationManager(string id);
44-
//public IAnnotationManager<Annotations.PolygonAnnotation> PointAnnotationManager(string id);
45-
//public IAnnotationManager<Annotations.PolygonAnnotation> PolylineAnnotationManager(string id);
43+
public ICircleAnnotationManager CreateCircleAnnotationManager(string id, LayerPosition layerPosition);
44+
//public IPointAnnotationManager CreatePointAnnotationManager(string id, LayerPosition layerPosition);
45+
//public IPolylineAnnotationManager CreatePolylineAnnotationManager(string, LayerPosition layerPosition);
4646
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
1313
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
1414
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
15+
<RootNamespace>MapboxMaui</RootNamespace>
1516
</PropertyGroup>
1617

1718
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-ios|AnyCPU'">
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
namespace MapboxMaui.Annotations;
2+
3+
using GeoJSON.Net.Geometry;
4+
5+
public class CircleAnnotation : Annotation<Point>
6+
{
7+
public CircleAnnotation(Point geometry, string id = null)
8+
: base(geometry, id)
9+
{
10+
}
11+
12+
/// Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key.
13+
public double? CircleSortKey
14+
{
15+
get
16+
{
17+
return GetProperty<double?>("circle-sort-key", default);
18+
}
19+
set
20+
{
21+
SetProperty("circle-sort-key", value);
22+
}
23+
}
24+
25+
/// Amount to blur the circle. 1 blurs the circle such that only the centerpoint is full opacity.
26+
public double? CircleBlur
27+
{
28+
get
29+
{
30+
return GetProperty<double?>("circle-blur", default);
31+
}
32+
set
33+
{
34+
SetProperty("circle-blur", value);
35+
}
36+
}
37+
38+
/// The fill color of the circle.
39+
public Color CircleColor
40+
{
41+
get
42+
{
43+
return GetProperty<Color>("circle-color", default);
44+
}
45+
set
46+
{
47+
SetProperty("circle-color", value);
48+
}
49+
}
50+
51+
/// The opacity at which the circle will be drawn.
52+
public double? CircleOpacity
53+
{
54+
get
55+
{
56+
return GetProperty<double?>("circle-opacity", default);
57+
}
58+
set
59+
{
60+
SetProperty("circle-opacity", value);
61+
}
62+
}
63+
64+
/// Circle radius.
65+
public double? CircleRadius
66+
{
67+
get
68+
{
69+
return GetProperty<double?>("circle-radius", default);
70+
}
71+
set
72+
{
73+
SetProperty("circle-radius", value);
74+
}
75+
}
76+
77+
/// The stroke color of the circle.
78+
public Color CircleStrokeColor
79+
{
80+
get
81+
{
82+
return GetProperty<Color>("circle-stroke-color", default);
83+
}
84+
set
85+
{
86+
SetProperty("circle-stroke-color", value);
87+
}
88+
}
89+
90+
/// The opacity of the circle's stroke.
91+
public double? CircleStrokeOpacity
92+
{
93+
get
94+
{
95+
return GetProperty<double?>("circle-stroke-opacity", default);
96+
}
97+
set
98+
{
99+
SetProperty("circle-stroke-opacity", value);
100+
}
101+
}
102+
103+
/// The width of the circle's stroke. Strokes are placed outside of the `circle-radius`.
104+
public double? CircleStrokeWidth
105+
{
106+
get
107+
{
108+
return GetProperty<double?>("circle-stroke-width", default);
109+
}
110+
set
111+
{
112+
SetProperty("circle-stroke-width", value);
113+
}
114+
}
115+
}
116+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace MapboxMaui.Annotations;
2+
3+
public interface ICircleAnnotationManager : IAnnotationManager<CircleAnnotation>
4+
{
5+
CirclePitchAlignment? CirclePitchAlignment { get; set; }
6+
CirclePitchScale? CirclePitchScale { get; set; }
7+
double[] CircleTranslate { get; set; }
8+
CircleTranslateAnchor? CircleTranslateAnchor { get; set; }
9+
}
10+
11+
public partial class CircleAnnotationManager
12+
{
13+
}

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

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace MapboxMaui;
22
using MapboxMapsCameraOptions = Com.Mapbox.Maps.CameraOptions;
33
using PlatformValue = Com.Mapbox.Bindgen.Value;
4-
using PlatformPolygonAnnotationOptions = Com.Mapbox.Maps.Plugin.Annotation.Generated.PolygonAnnotationOptions;
54
using MapboxTerrain = Com.Mapbox.Maps.Extension.Style.Terrain.Generated.Terrain;
65
using StyleTransitionBuilder = Com.Mapbox.Maps.Extension.Style.Types.StyleTransition.Builder;
76
using PlatformStyleTransition = Com.Mapbox.Maps.Extension.Style.Types.StyleTransition;
@@ -135,38 +134,6 @@ internal static PlatformValue ToPlatformValue(this BaseKVContainer xvalue, bool
135134
return result;
136135
}
137136

138-
internal static PlatformPolygonAnnotationOptions ToPlatformValue(this Annotations.PolygonAnnotation annotation)
139-
{
140-
var points = annotation
141-
.GeometryValue
142-
.Coordinates
143-
.Select(
144-
x => new Android.Runtime.JavaList<Com.Mapbox.Geojson.Point>(
145-
x.Coordinates.Select(
146-
y => Com.Mapbox.Geojson.Point.FromLngLat(y.Longitude, y.Latitude)
147-
)) as IList<Com.Mapbox.Geojson.Point>
148-
)
149-
.ToList();
150-
151-
var result = new PlatformPolygonAnnotationOptions
152-
{
153-
FillColor = annotation.FillColor?.ToRgbaString(),
154-
FillOpacity = annotation.FillOpacity.HasValue
155-
? new Java.Lang.Double(annotation.FillOpacity.Value)
156-
: null,
157-
158-
FillOutlineColor = annotation.FillOutlineColor?.ToRgbaString(),
159-
FillPattern = annotation.FillPattern,
160-
FillSortKey = annotation.FillSortKey.HasValue
161-
? new Java.Lang.Double(annotation.FillSortKey.Value)
162-
: null
163-
}
164-
.WithDraggable(annotation.IsDraggable)
165-
.WithPoints(points);
166-
167-
return result;
168-
}
169-
170137
internal static Com.Mapbox.Maps.LayerPosition ToPlatformValue(this Styles.LayerPosition xvalue)
171138
{
172139
return xvalue.Enum switch
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
namespace MapboxMaui.Annotations;
2+
3+
using PlatformPolygonAnnotationOptions = Com.Mapbox.Maps.Plugin.Annotation.Generated.PolygonAnnotationOptions;
4+
using PlatformCircleAnnotationOptions = Com.Mapbox.Maps.Plugin.Annotation.Generated.CircleAnnotationOptions;
5+
6+
public static class AnnotationExtensions
7+
{
8+
internal static PlatformCircleAnnotationOptions ToPlatformValue(this CircleAnnotation annotation)
9+
{
10+
var result = new PlatformCircleAnnotationOptions
11+
{
12+
CircleBlur = annotation.CircleBlur?.AsDouble(),
13+
CircleColor = annotation.CircleColor?.ToRgbaString(),
14+
CircleOpacity = annotation.CircleOpacity?.AsDouble(),
15+
CircleRadius = annotation.CircleRadius?.AsDouble(),
16+
CircleSortKey = annotation.CircleSortKey?.AsDouble(),
17+
CircleStrokeColor = annotation.CircleStrokeColor?.ToRgbaString(),
18+
CircleStrokeOpacity = annotation.CircleStrokeOpacity?.AsDouble(),
19+
CircleStrokeWidth = annotation.CircleStrokeWidth?.AsDouble(),
20+
}
21+
.WithDraggable(annotation.IsDraggable)
22+
.WithPoint((Com.Mapbox.Geojson.Point)annotation.GeometryValue.ToNative());
23+
24+
return result;
25+
}
26+
27+
internal static Java.Lang.Double AsDouble(this double value)
28+
{
29+
return new Java.Lang.Double(value);
30+
}
31+
32+
internal static PlatformPolygonAnnotationOptions ToPlatformValue(this PolygonAnnotation annotation)
33+
{
34+
var points = annotation
35+
.GeometryValue
36+
.Coordinates
37+
.Select(
38+
x => new Android.Runtime.JavaList<Com.Mapbox.Geojson.Point>(
39+
x.Coordinates.Select(
40+
y => Com.Mapbox.Geojson.Point.FromLngLat(y.Longitude, y.Latitude)
41+
)) as IList<Com.Mapbox.Geojson.Point>
42+
)
43+
.ToList();
44+
45+
var result = new PlatformPolygonAnnotationOptions
46+
{
47+
FillColor = annotation.FillColor?.ToRgbaString(),
48+
FillOpacity = annotation.FillOpacity?.AsDouble(),
49+
FillOutlineColor = annotation.FillOutlineColor?.ToRgbaString(),
50+
FillPattern = annotation.FillPattern,
51+
FillSortKey = annotation.FillSortKey?.AsDouble()
52+
}
53+
.WithDraggable(annotation.IsDraggable)
54+
.WithPoints(points);
55+
56+
return result;
57+
}
58+
}
59+
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
namespace MapboxMaui.Annotations;
2+
3+
using PlatformCircleAnnotationManager = Com.Mapbox.Maps.Plugin.Annotation.Generated.CircleAnnotationManager;
4+
5+
public partial class CircleAnnotationManager
6+
: AnnotationManager<PlatformCircleAnnotationManager, CircleAnnotation>
7+
, ICircleAnnotationManager
8+
{
9+
private readonly PlatformCircleAnnotationManager nativeManager;
10+
11+
public CircleAnnotationManager(
12+
string id,
13+
PlatformCircleAnnotationManager nativeManager)
14+
: base(id, nativeManager)
15+
{
16+
this.nativeManager = nativeManager;
17+
}
18+
19+
public CirclePitchAlignment? CirclePitchAlignment
20+
{
21+
get => nativeManager.CirclePitchAlignment?.GetValue();
22+
set => nativeManager.CirclePitchAlignment = value != null
23+
? Com.Mapbox.Maps.Extension.Style.Layers.Properties.Generated.CirclePitchAlignment.ValueOf(
24+
value.Value)
25+
: null;
26+
}
27+
public CirclePitchScale? CirclePitchScale
28+
{
29+
get => nativeManager.CirclePitchScale?.GetValue();
30+
set => nativeManager.CirclePitchScale = value != null
31+
? Com.Mapbox.Maps.Extension.Style.Layers.Properties.Generated.CirclePitchScale.ValueOf(
32+
value.Value)
33+
: null;
34+
}
35+
public double[] CircleTranslate
36+
{
37+
get => nativeManager.CircleTranslate?
38+
.Select(x => x.DoubleValue())
39+
.ToArray();
40+
set => nativeManager.CircleTranslate = value?
41+
.Select(x => new Java.Lang.Double(x))
42+
.ToList();
43+
}
44+
public CircleTranslateAnchor? CircleTranslateAnchor
45+
{
46+
get => nativeManager.CircleTranslateAnchor?.GetValue();
47+
set => nativeManager.CircleTranslateAnchor = value != null
48+
? Com.Mapbox.Maps.Extension.Style.Layers.Properties.Generated.CircleTranslateAnchor.ValueOf(
49+
value.Value)
50+
: null;
51+
}
52+
53+
54+
public override void AddAnnotations(params CircleAnnotation[] xitems)
55+
{
56+
var items = xitems
57+
.Select(x => x.ToPlatformValue())
58+
.ToList();
59+
60+
var platformAnnotations = nativeManager.Create(items);
61+
62+
for (int i = 0; i < platformAnnotations.Count; i++)
63+
{
64+
var item = platformAnnotations[i] as Com.Mapbox.Maps.Plugin.Annotation.Generated.CircleAnnotation;
65+
xitems[i].Id = item.Id.ToString();
66+
}
67+
}
68+
69+
public override void RemoveAllAnnotations()
70+
{
71+
nativeManager.Annotations.Clear();
72+
}
73+
74+
public override void RemoveAnnotations(params string[] annotationIDs)
75+
{
76+
foreach (var xid in annotationIDs)
77+
{
78+
if (!long.TryParse(xid, out var id)) continue;
79+
80+
var item = nativeManager
81+
.Annotations
82+
.Cast<Com.Mapbox.Maps.Plugin.Annotation.Generated.CircleAnnotation>()
83+
.FirstOrDefault(x => x.Id == id);
84+
85+
if (item == null) continue;
86+
87+
nativeManager.Annotations.Remove(item);
88+
}
89+
}
90+
}
91+

0 commit comments

Comments
 (0)