Skip to content

Commit c6b1ad4

Browse files
committed
- PointAnnotationClusteringExample OK
1 parent 7020e01 commit c6b1ad4

File tree

6 files changed

+74
-34
lines changed

6 files changed

+74
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ b/ iOS's `info.plist`
131131
| 41 | [OfflineManagerExample](./mapboxqs/OfflineManagerExample.m) | OK |
132132
| 42 | [OfflineRegionManagerExample](./mapboxqs/OfflineRegionManagerExample.m) | |
133133
| 43 | [PitchAndDistanceExample](./mapboxqs/PitchAndDistanceExample.m) | |
134-
| 44 | [PointAnnotationClusteringExample](./mapboxqs/PointAnnotationClusteringExample.m) | |
134+
| 44 | [PointAnnotationClusteringExample](./mapboxqs/PointAnnotationClusteringExample.m) | OK |
135135
| 45 | [PointClusteringExample](./mapboxqs/PointClusteringExample.m) | |
136136
| 46 | [PolygonAnnotationExample](./mapboxqs/PolygonAnnotationExample.m) | OK |
137137
| 47 | [RasterTileSourceExample](./mapboxqs/RasterTileSourceExample.m) | |

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public PropertyValue(DslExpression expression)
3131
Constant = default;
3232
}
3333

34+
public T GetConstant(T defaultValue) => Expression == null ? Constant : defaultValue;
35+
3436
public static implicit operator PropertyValue<T>(T value) => new(value);
3537
public static explicit operator PropertyValue<T>(DslExpression value) => new(value);
3638
}

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

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,61 @@
22

33
using PlatformPolygonAnnotationOptions = Com.Mapbox.Maps.Plugin.Annotation.Generated.PolygonAnnotationOptions;
44
using PlatformCircleAnnotationOptions = Com.Mapbox.Maps.Plugin.Annotation.Generated.CircleAnnotationOptions;
5+
using PlatformPointAnnotationOptions = Com.Mapbox.Maps.Plugin.Annotation.Generated.PointAnnotationOptions;
56

67
public static class AnnotationExtensions
78
{
9+
internal static PlatformPointAnnotationOptions ToPlatformValue(this PointAnnotation annotation)
10+
{
11+
var result = new PlatformPointAnnotationOptions
12+
{
13+
IconAnchor = annotation.IconAnchor?.ToPlatform(),
14+
IconImage = annotation.IconImage,
15+
IconOffset = annotation.IconOffset?.ToPlatform(),
16+
IconRotate = annotation.IconRotate?.AsDouble(),
17+
IconSize = annotation.IconSize?.AsDouble(),
18+
SymbolSortKey = annotation.SymbolSortKey?.AsDouble(),
19+
TextAnchor = annotation.TextAnchor?.ToPlatform(),
20+
TextField = annotation.TextField,
21+
TextJustify = annotation.TextJustify?.ToPlatform(),
22+
TextLetterSpacing = annotation.TextLetterSpacing?.AsDouble(),
23+
TextLineHeight = annotation.TextLineHeight?.AsDouble(),
24+
TextMaxWidth = annotation.TextMaxWidth?.AsDouble(),
25+
TextOffset = annotation.TextOffset?.ToPlatform(),
26+
TextRadialOffset = annotation.TextRadialOffset?.AsDouble(),
27+
TextRotate = annotation.TextRotate?.AsDouble(),
28+
TextSize = annotation.TextSize?.AsDouble(),
29+
TextTransform = annotation.TextTransform?.ToPlatform(),
30+
IconColor = annotation.IconColor?.ToRgbaString(),
31+
IconHaloBlur = annotation.IconHaloBlur?.AsDouble(),
32+
IconHaloColor = annotation.IconHaloColor?.ToRgbaString(),
33+
IconHaloWidth = annotation.IconHaloWidth?.AsDouble(),
34+
IconOpacity = annotation.IconOpacity?.AsDouble(),
35+
TextColor = annotation.TextColor?.ToRgbaString(),
36+
TextHaloBlur = annotation.TextHaloBlur?.AsDouble(),
37+
TextHaloColor = annotation.TextHaloColor?.ToRgbaString(),
38+
TextHaloWidth = annotation.TextHaloWidth?.AsDouble(),
39+
TextOpacity = annotation.TextOpacity?.AsDouble(),
40+
}
41+
.WithDraggable(annotation.IsDraggable)
42+
.WithPoint((Com.Mapbox.Geojson.Point)annotation.GeometryValue.ToNative());
43+
44+
return result;
45+
}
46+
847
internal static PlatformCircleAnnotationOptions ToPlatformValue(this CircleAnnotation annotation)
948
{
1049
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-
}
50+
{
51+
CircleBlur = annotation.CircleBlur?.AsDouble(),
52+
CircleColor = annotation.CircleColor?.ToRgbaString(),
53+
CircleOpacity = annotation.CircleOpacity?.AsDouble(),
54+
CircleRadius = annotation.CircleRadius?.AsDouble(),
55+
CircleSortKey = annotation.CircleSortKey?.AsDouble(),
56+
CircleStrokeColor = annotation.CircleStrokeColor?.ToRgbaString(),
57+
CircleStrokeOpacity = annotation.CircleStrokeOpacity?.AsDouble(),
58+
CircleStrokeWidth = annotation.CircleStrokeWidth?.AsDouble(),
59+
}
2160
.WithDraggable(annotation.IsDraggable)
2261
.WithPoint((Com.Mapbox.Geojson.Point)annotation.GeometryValue.ToNative());
2362

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ internal static Expression ToPlatformValue(
1111
this DslExpression xvalue
1212
)
1313
{
14-
var @operator = string.IsNullOrWhiteSpace(xvalue.Operator.Value)
15-
? xvalue.Operator.Value
16-
: xvalue.First();
17-
18-
var expressionBuilder = new Expression.ExpressionBuilder(@operator);
14+
var expressionBuilder = new Expression.ExpressionBuilder(xvalue.Operator.Value);
1915

2016
foreach (var argument in xvalue)
2117
{

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

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

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

286-
var options = new AnnotationSourceOptions(
287-
null, null, null, null,
288-
new Com.Mapbox.Maps.Plugin.Annotation.ClusterOptions(
286+
var xclusterOptions = new Com.Mapbox.Maps.Plugin.Annotation.ClusterOptions(
289287
true,
290288
(long)clusterOptions.ClusterRadius,
291-
clusterOptions.CircleRadius?.Wrap(),
292-
18.0,
293-
clusterOptions.TextColor?.Wrap(),
294-
Color.White,
295-
clusterOptions.TextSize?.Wrap(),
296-
12.0,
297-
clusterOptions.TextField?.Wrap(),
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(),
298296
(long)clusterOptions.ClusterMaxZoom,
299297
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)),
300300
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.Blue)),
302-
new Kotlin.Pair(new Java.Lang.Integer(0), new Java.Lang.Integer(Color.Green)),
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)),
303304
},
304305
new Dictionary<string, Java.Lang.Object>(
305306
clusterOptions.ClusterProperties?
306307
.Select(
307308
x => new KeyValuePair<string, Java.Lang.Object>(
308309
x.Key,
309-
x.Value.ToPlatformValue()
310+
x.Value.Wrap()
310311
)
311312
)
312313
)
313-
));
314+
);
315+
var options = new AnnotationSourceOptions(
316+
new Java.Lang.Long((long)clusterOptions.ClusterMaxZoom),
317+
null, null, null, xclusterOptions);
314318
var nativeManager = AnnotationPluginImplKt
315319
.GetAnnotations(mapView)
316320
.CreateAnnotationManager(

src/qs/MapboxMauiQs/Examples/44.PointAnnotationClustering/PointAnnotationClusteringExample.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,9 @@ void CreateClusters(PointAnnotation[] annotations)
166166

167167
pointAnnotationManager.AddAnnotations(annotations);
168168

169-
var layerIdPrefix = DeviceInfo.Current.Platform == DevicePlatform.Android
170-
? "mapbox-android-cluster-text-layer-"
171-
: "mapbox-iOS-cluster-circle-layer-manager-";
172-
var layerId = layerIdPrefix + clusterLayerID;
169+
var layerId = DeviceInfo.Current.Platform == DevicePlatform.Android
170+
? clusterLayerID
171+
: $"mapbox-iOS-cluster-circle-layer-manager-{clusterLayerID}";
173172
var circleLayer = new CircleLayer(layerId)
174173
{
175174
CircleStrokeColor = Colors.Black,

0 commit comments

Comments
 (0)