Skip to content

Commit 0cc6f0d

Browse files
committed
- CustomPointAnnotationExample: OK
1 parent 20a1871 commit 0cc6f0d

File tree

5 files changed

+103
-37
lines changed

5 files changed

+103
-37
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ b/ iOS's `info.plist`
106106
| 16 | [Custom3DPuckExample](./mapboxqs/Custom3DPuckExample.m) | |
107107
| 17 | [CustomLayerExample](./mapboxqs/CustomLayerExample.m) | |
108108
| 18 | [CustomLocationProviderExample](./mapboxqs/CustomLocationProviderExample.m) | |
109-
| 19 | [CustomPointAnnotationExample](./mapboxqs/CustomPointAnnotationExample.m) | |
109+
| 19 | [CustomPointAnnotationExample](./mapboxqs/CustomPointAnnotationExample.m) | OK |
110110
| 20 | [CustomStyleURLExample](./mapboxqs/CustomStyleURLExample.m) | OK |
111111
| 21 | [DataDrivenSymbolsExample](./mapboxqs/DataDrivenSymbolsExample.m) | |
112112
| 22 | [DataJoinExample](./mapboxqs/DataJoinExample.m) | |
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using MapboxMaui.Annotations;
2+
using Color = Android.Graphics.Color;
3+
using Microsoft.Maui.Platform;
4+
5+
namespace MapboxMaui;
6+
7+
public static class ClusterOptionsExtensions
8+
{
9+
public static new Com.Mapbox.Maps.Plugin.Annotation.ClusterOptions ToPlatform(this ClusterOptions clusterOptions)
10+
=> clusterOptions == null
11+
? null
12+
: new Com.Mapbox.Maps.Plugin.Annotation.ClusterOptions(
13+
true,
14+
(long)clusterOptions.ClusterRadius,
15+
clusterOptions.CircleRadius?.Expression?.ToPlatformValue(),
16+
clusterOptions.CircleRadius?.GetConstant(18.0) ?? 18.0,
17+
clusterOptions.TextColor?.Expression?.ToPlatformValue(),
18+
clusterOptions.TextColor?.GetConstant(Color.White.ToColor())?.ToPlatform() ?? Color.White,
19+
clusterOptions.TextSize?.Expression?.ToPlatformValue(),
20+
clusterOptions.TextSize?.GetConstant(12.0) ?? 12.0,
21+
clusterOptions.TextField?.Expression?.ToPlatformValue(),
22+
(long)clusterOptions.ClusterMaxZoom,
23+
new List<Kotlin.Pair> {
24+
new Kotlin.Pair(new Java.Lang.Integer(250), new Java.Lang.Integer(Color.LightPink)),
25+
new Kotlin.Pair(new Java.Lang.Integer(150), new Java.Lang.Integer(Color.Orange)),
26+
new Kotlin.Pair(new Java.Lang.Integer(100), new Java.Lang.Integer(Color.Red)),
27+
new Kotlin.Pair(new Java.Lang.Integer(50), new Java.Lang.Integer(Color.Cyan)),
28+
new Kotlin.Pair(new Java.Lang.Integer(10), new Java.Lang.Integer(Color.Green)),
29+
new Kotlin.Pair(new Java.Lang.Integer(0), new Java.Lang.Integer(Color.Yellow)),
30+
},
31+
new Dictionary<string, Java.Lang.Object>(
32+
clusterOptions.ClusterProperties?
33+
.Select(
34+
x => new KeyValuePair<string, Java.Lang.Object>(
35+
x.Key,
36+
x.Value.Wrap()
37+
)
38+
)
39+
)
40+
);
41+
}
42+

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

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -283,38 +283,14 @@ public IPointAnnotationManager CreatePointAnnotationManager(
283283

284284
if (mapView == null) return null;
285285

286-
var xclusterOptions = new Com.Mapbox.Maps.Plugin.Annotation.ClusterOptions(
287-
true,
288-
(long)clusterOptions.ClusterRadius,
289-
clusterOptions.CircleRadius?.Expression?.ToPlatformValue(),
290-
clusterOptions.CircleRadius?.GetConstant(18.0) ?? 18.0,
291-
clusterOptions.TextColor?.Expression?.ToPlatformValue(),
292-
clusterOptions.TextColor?.GetConstant(Color.White.ToColor())?.ToPlatform() ?? Color.White,
293-
clusterOptions.TextSize?.Expression?.ToPlatformValue(),
294-
clusterOptions.TextSize?.GetConstant(12.0) ?? 12.0,
295-
clusterOptions.TextField?.Expression?.ToPlatformValue(),
296-
(long)clusterOptions.ClusterMaxZoom,
297-
new List<Kotlin.Pair> {
298-
new Kotlin.Pair(new Java.Lang.Integer(250), new Java.Lang.Integer(Color.LightPink)),
299-
new Kotlin.Pair(new Java.Lang.Integer(150), new Java.Lang.Integer(Color.Orange)),
300-
new Kotlin.Pair(new Java.Lang.Integer(100), new Java.Lang.Integer(Color.Red)),
301-
new Kotlin.Pair(new Java.Lang.Integer(50), new Java.Lang.Integer(Color.Cyan)),
302-
new Kotlin.Pair(new Java.Lang.Integer(10), new Java.Lang.Integer(Color.Green)),
303-
new Kotlin.Pair(new Java.Lang.Integer(0), new Java.Lang.Integer(Color.Yellow)),
304-
},
305-
new Dictionary<string, Java.Lang.Object>(
306-
clusterOptions.ClusterProperties?
307-
.Select(
308-
x => new KeyValuePair<string, Java.Lang.Object>(
309-
x.Key,
310-
x.Value.Wrap()
311-
)
312-
)
313-
)
314-
);
286+
var xclusterOptions = clusterOptions.ToPlatform();
287+
var clusterMaxZoom = clusterOptions != null
288+
? new Java.Lang.Long((long)clusterOptions.ClusterMaxZoom)
289+
: null;
315290
var options = new AnnotationSourceOptions(
316-
new Java.Lang.Long((long)clusterOptions.ClusterMaxZoom),
317-
null, null, null, xclusterOptions);
291+
clusterMaxZoom,
292+
null, null, null,
293+
xclusterOptions);
318294
var nativeManager = AnnotationPluginImplKt
319295
.GetAnnotations(mapView)
320296
.CreateAnnotationManager(

src/qs/MapboxMauiQs/Examples/19.CustomPointAnnotation/CustomPointAnnotationExample.cs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,49 @@ public class CustomPointAnnotationExample : ContentPage, IExamplePage, IQueryAtt
55
MapboxView map;
66
IExampleInfo info;
77

8-
public CustomPointAnnotationExample()
9-
{
10-
iOSPage.SetUseSafeArea(this, false);
11-
Content = map = new MapboxView();
8+
public CustomPointAnnotationExample()
9+
{
10+
iOSPage.SetUseSafeArea(this, false);
11+
Content = map = new MapboxView();
1212

1313
map.MapReady += Map_MapReady;
14-
}
14+
map.MapLoaded += Map_MapLoaded;
15+
}
16+
17+
private void Map_MapLoaded(object sender, EventArgs e)
18+
{
19+
var image = new ResolvedImage("my-custom-image-name", "star");
20+
map.Images = new[] { image };
21+
22+
// We want to display the annotation at the center of the map's current viewport
23+
var centerCoordinate = map.CameraOptions.Center;
24+
25+
// Make a `PointAnnotationManager` which will be responsible for managing
26+
// a collection of `PointAnnotion`s.
27+
// Annotation managers are kept alive by `AnnotationOrchestrator`
28+
// (`mapView.annotations`) until you explicitly destroy them
29+
// by calling `mapView.annotations.removeAnnotationManager(withId:)`
30+
var pointAnnotationManager = map.AnnotationController.CreatePointAnnotationManager(
31+
"pointAnnotationManager",
32+
LayerPosition.Unknown()
33+
);
34+
35+
// Initialize a point annotation with a geometry ("coordinate" in this case)
36+
// and configure it with a custom image (sourced from the asset catalogue)
37+
var customPointAnnotation = new PointAnnotation(
38+
new GeoJSON.Text.Geometry.Point(
39+
new Position(centerCoordinate.Value.X, centerCoordinate.Value.Y)
40+
)
41+
)
42+
{
43+
IsDraggable = true,
44+
IconImage = "my-custom-image-name"
45+
};
46+
//customPointAnnotation.Image = .init(image: customImage, name: "my-custom-image-name")
47+
48+
// Add the annotation to the manager in order to render it on the map.
49+
pointAnnotationManager.AddAnnotations(customPointAnnotation);
50+
}
1551

1652
private void Map_MapReady(object sender, EventArgs e)
1753
{
Lines changed: 12 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)