Skip to content

Commit a000026

Browse files
committed
- LineAnnotationExample: OK
1 parent 0cc6f0d commit a000026

20 files changed

+711
-161
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ b/ iOS's `info.plist`
122122
| 32 | [IconSizeChangeExample](./mapboxqs/IconSizeChangeExample.m) | |
123123
| 33 | [LargeGeoJSONPerformanceExample](./mapboxqs/LargeGeoJSONPerformanceExample.m) | |
124124
| 34 | [LayerPositionExample](./mapboxqs/LayerPositionExample.m) | |
125-
| 35 | [LineAnnotationExample](./mapboxqs/LineAnnotationExample.m) | |
125+
| 35 | [LineAnnotationExample](./mapboxqs/LineAnnotationExample.m) | OK |
126126
| 36 | [LineGradientExample](./mapboxqs/LineGradientExample.m) | |
127127
| 37 | [LiveDataExample](./mapboxqs/LiveDataExample.m) | |
128128
| 38 | [LocalizationExample](./mapboxqs/LocalizationExample.m) | |

build.cake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,15 @@ public class {name}Example : ContentPage, IExamplePage, IQueryAttributable
6464
6565
private void Map_MapReady(object sender, EventArgs e)
6666
{{
67-
// Setup Map here
67+
var centerLocation = new Point(21.0278, 105.8342);
68+
var cameraOptions = new CameraOptions
69+
{{
70+
Center = centerLocation,
71+
Zoom = 14,
72+
}};
73+
74+
map.CameraOptions = cameraOptions;
75+
map.MapboxStyle = MapboxStyle.MAPBOX_STREETS;
6876
}}
6977
7078
private void Map_MapLoaded(object sender, EventArgs e)

src/libs/Mapbox.Maui/IMapboxView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ public interface IAnnotationController
4444
IPolygonAnnotationManager CreatePolygonAnnotationManager(string id, LayerPosition layerPosition);
4545
ICircleAnnotationManager CreateCircleAnnotationManager(string id, LayerPosition layerPosition);
4646
IPointAnnotationManager CreatePointAnnotationManager(string id, LayerPosition layerPosition, ClusterOptions clusterOptions = null);
47-
//public IPolylineAnnotationManager CreatePolylineAnnotationManager(string, LayerPosition layerPosition);
47+
public IPolylineAnnotationManager CreatePolylineAnnotationManager(string id, LayerPosition layerPosition);
4848
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace MapboxMaui.Annotations;
2+
3+
public interface IPolylineAnnotationManager : IAnnotationManager<PolylineAnnotation>
4+
{
5+
LineCap? LineCap { get; set; }
6+
double? LineMiterLimit { get; set; }
7+
double? LineRoundLimit { get; set; }
8+
double[] LineDasharray { get; set; }
9+
double[] LineTranslate { get; set; }
10+
LineTranslateAnchor? LineTranslateAnchor { get; set; }
11+
double[] LineTrimOffset { get; set; }
12+
}
13+
14+
public partial class PolylineAnnotationManager
15+
{
16+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
using GeoJSON.Text.Geometry;
2+
3+
namespace MapboxMaui.Annotations;
4+
5+
public class PolylineAnnotation : Annotation<LineString>
6+
{
7+
public PolylineAnnotation(LineString geometry, string id = null)
8+
: base(geometry, id)
9+
{
10+
}
11+
12+
/// The display of lines when joining.
13+
public LineJoin? LineJoin
14+
{
15+
get
16+
{
17+
return GetProperty<LineJoin?>("line-join", default);
18+
}
19+
set
20+
{
21+
SetProperty("line-join", value);
22+
}
23+
}
24+
25+
/// Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key.
26+
public double? LineSortKey
27+
{
28+
get
29+
{
30+
return GetProperty<double?>("line-sort-key", default);
31+
}
32+
set
33+
{
34+
SetProperty("line-sort-key", value);
35+
}
36+
}
37+
38+
/// Blur applied to the line, in pixels.
39+
public double? LineBlur
40+
{
41+
get
42+
{
43+
return GetProperty<double?>("line-blur", default);
44+
}
45+
set
46+
{
47+
SetProperty("line-blur", value);
48+
}
49+
}
50+
51+
/// The color with which the line will be drawn.
52+
public Color LineColor
53+
{
54+
get
55+
{
56+
return GetProperty<Color>("line-color", default);
57+
}
58+
set
59+
{
60+
SetProperty("line-color", value);
61+
}
62+
}
63+
64+
/// Draws a line casing outside of a line's actual path. Value indicates the width of the inner gap.
65+
public double? LineGapWidth
66+
{
67+
get
68+
{
69+
return GetProperty<double?>("line-gap-width", default);
70+
}
71+
set
72+
{
73+
SetProperty("line-gap-width", value);
74+
}
75+
}
76+
77+
/// The line's offset. For linear features, a positive value offsets the line to the right, relative to the direction of the line, and a negative value to the left. For polygon features, a positive value results in an inset, and a negative value results in an outset.
78+
public double? LineOffset
79+
{
80+
get
81+
{
82+
return GetProperty<double?>("line-offset", default);
83+
}
84+
set
85+
{
86+
SetProperty("line-offset", value);
87+
}
88+
}
89+
90+
/// The opacity at which the line will be drawn.
91+
public double? LineOpacity
92+
{
93+
get
94+
{
95+
return GetProperty<double?>("line-opacity", default);
96+
}
97+
set
98+
{
99+
SetProperty("line-opacity", value);
100+
}
101+
}
102+
103+
/// Name of image in sprite to use for drawing image lines. For seamless patterns, image width must be a factor of two (2, 4, 8, ..., 512). Note that zoom-dependent expressions will be evaluated only at integer zoom levels.
104+
public string LinePattern
105+
{
106+
get
107+
{
108+
return GetProperty<string>("line-pattern", default);
109+
}
110+
set
111+
{
112+
SetProperty("line-pattern", value);
113+
}
114+
}
115+
116+
/// Stroke thickness.
117+
public double? LineWidth
118+
{
119+
get
120+
{
121+
return GetProperty<double?>("line-width", default);
122+
}
123+
set
124+
{
125+
SetProperty("line-width", value);
126+
}
127+
}
128+
}
129+

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using PlatformPolygonAnnotationOptions = Com.Mapbox.Maps.Plugin.Annotation.Generated.PolygonAnnotationOptions;
44
using PlatformCircleAnnotationOptions = Com.Mapbox.Maps.Plugin.Annotation.Generated.CircleAnnotationOptions;
55
using PlatformPointAnnotationOptions = Com.Mapbox.Maps.Plugin.Annotation.Generated.PointAnnotationOptions;
6+
using PlatformPolylineAnnotationOptions = Com.Mapbox.Maps.Plugin.Annotation.Generated.PolylineAnnotationOptions;
67

78
public static class AnnotationExtensions
89
{
@@ -94,5 +95,33 @@ internal static PlatformPolygonAnnotationOptions ToPlatformValue(this PolygonAnn
9495

9596
return result;
9697
}
98+
99+
internal static PlatformPolylineAnnotationOptions ToPlatformValue(this PolylineAnnotation annotation)
100+
{
101+
var points = annotation
102+
.GeometryValue
103+
.Coordinates
104+
.Select(
105+
y => Com.Mapbox.Geojson.Point.FromLngLat(y.Longitude, y.Latitude)
106+
)
107+
.ToList();
108+
109+
var result = new PlatformPolylineAnnotationOptions
110+
{
111+
LineBlur = annotation.LineBlur?.ToPlatform(),
112+
LineColor = annotation.LineColor?.ToRgbaString(),
113+
LineGapWidth = annotation.LineGapWidth?.ToPlatform(),
114+
LineJoin = annotation.LineJoin?.ToPlatform(),
115+
LineOffset = annotation.LineOffset?.ToPlatform(),
116+
LineOpacity = annotation.LineOpacity?.ToPlatform(),
117+
LinePattern = annotation.LinePattern,
118+
LineSortKey = annotation.LineSortKey?.ToPlatform(),
119+
LineWidth = annotation.LineWidth?.ToPlatform(),
120+
}
121+
.WithDraggable(annotation.IsDraggable)
122+
.WithPoints(points);
123+
124+
return result;
125+
}
97126
}
98127

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,12 @@ public PolygonAnnotationManager(
1919
public bool? FillAntialias
2020
{
2121
get => nativeManager.FillAntialias?.BooleanValue();
22-
set => nativeManager.FillAntialias = value.HasValue
23-
? new Java.Lang.Boolean(value.Value)
24-
: null;
22+
set => nativeManager.FillAntialias = value?.ToPlatform();
2523
}
2624
public double[] FillTranslate
2725
{
28-
get => nativeManager.FillTranslate
29-
.Select(x => x.DoubleValue())
30-
.ToArray();
31-
set => nativeManager.FillTranslate = value?
32-
.Select(x => new Java.Lang.Double(x))
33-
.ToList();
26+
get => nativeManager.FillTranslate.GetValue();
27+
set => nativeManager.FillTranslate = value.ToPlatform();
3428
}
3529
public FillTranslateAnchor? FillTranslateAnchor
3630
{
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 PlatformPolylineAnnotationManager = Com.Mapbox.Maps.Plugin.Annotation.Generated.PolylineAnnotationManager;
4+
5+
partial class PolylineAnnotationManager
6+
: AnnotationManager<PlatformPolylineAnnotationManager, PolylineAnnotation>
7+
, IPolylineAnnotationManager
8+
{
9+
private readonly PlatformPolylineAnnotationManager nativeManager;
10+
11+
public PolylineAnnotationManager(
12+
string id,
13+
PlatformPolylineAnnotationManager nativeManager)
14+
: base(id, nativeManager)
15+
{
16+
this.nativeManager = nativeManager;
17+
}
18+
19+
public LineCap? LineCap
20+
{
21+
get => nativeManager.LineCap?.GetValue();
22+
set => nativeManager.LineCap = value?.ToPlatform();
23+
}
24+
public double? LineMiterLimit
25+
{
26+
get => nativeManager.LineMiterLimit?.DoubleValue();
27+
set => nativeManager.LineMiterLimit = value?.ToPlatform();
28+
}
29+
public double? LineRoundLimit
30+
{
31+
get => nativeManager.LineRoundLimit?.DoubleValue();
32+
set => nativeManager.LineRoundLimit = value?.ToPlatform();
33+
}
34+
public double[] LineDasharray
35+
{
36+
get => nativeManager.LineDasharray?.GetValue();
37+
set => nativeManager.LineDasharray = value?.ToPlatform();
38+
}
39+
public double[] LineTranslate
40+
{
41+
get => nativeManager.LineTranslate?.GetValue();
42+
set => nativeManager.LineTranslate = value?.ToPlatform();
43+
}
44+
public LineTranslateAnchor? LineTranslateAnchor
45+
{
46+
get => nativeManager.LineTranslateAnchor?.GetValue();
47+
set => nativeManager.LineTranslateAnchor = value?.ToPlatform();
48+
}
49+
public double[] LineTrimOffset
50+
{
51+
get => nativeManager.LineTrimOffset?.GetValue();
52+
set => nativeManager.LineTrimOffset = value?.ToPlatform();
53+
}
54+
55+
public override void AddAnnotations(params PolylineAnnotation[] xitems)
56+
{
57+
var items = xitems
58+
.Select(x => x.ToPlatformValue())
59+
.ToList();
60+
61+
var platformAnnotations = nativeManager.Create(items);
62+
63+
for (int i = 0; i < platformAnnotations.Count; i++)
64+
{
65+
var item = platformAnnotations[i] as Com.Mapbox.Maps.Plugin.Annotation.Generated.PolylineAnnotation;
66+
xitems[i].Id = item.Id.ToString();
67+
}
68+
}
69+
70+
public override void RemoveAllAnnotations()
71+
{
72+
nativeManager.Annotations.Clear();
73+
}
74+
75+
public override void RemoveAnnotations(params string[] annotationIDs)
76+
{
77+
foreach (var xid in annotationIDs)
78+
{
79+
if (!long.TryParse(xid, out var id)) continue;
80+
81+
var item = nativeManager
82+
.Annotations
83+
.Cast<Com.Mapbox.Maps.Plugin.Annotation.Generated.PolylineAnnotation>()
84+
.FirstOrDefault(x => x.Id == id);
85+
86+
if (item == null) continue;
87+
88+
nativeManager.Annotations.Remove(item);
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)