Skip to content

Commit 8de6056

Browse files
committed
- cleanup SetProperty usages
1 parent 73eb5de commit 8de6056

File tree

18 files changed

+270
-97
lines changed

18 files changed

+270
-97
lines changed

src/libs/Mapbox.Maui/IMapboxView.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace Mapbox.Maui;
22

33
using System.Windows.Input;
4+
using Mapbox.Maui.Annotations;
45
using Mapbox.Maui.Styles;
56

67
public partial interface IMapboxView : IView
@@ -21,6 +22,9 @@ public partial interface IMapboxView : IView
2122
Light Light { get; set; }
2223

2324
IEnumerable<MapboxLayer> Layers { get; set; }
25+
26+
IEnumerable<IAnnotation> Annotations { get; set; }
27+
2428
}
2529

2630
partial interface IMapboxView {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<ItemGroup>
4747
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
4848
<PackageReference Include="Xamarin.Build.Download" Version="0.11.4" />
49+
<PackageReference Include="GeoJSON.Net" Version="1.3.6-rc" />
4950
</ItemGroup>
5051

5152
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0-android'">
@@ -64,12 +65,14 @@
6465
<None Remove="Models\Styles\Sources\" />
6566
<None Remove="Models\Expressions\" />
6667
<None Remove="Models\Styles\Layers\" />
68+
<None Remove="Models\Annotations\" />
6769
</ItemGroup>
6870
<ItemGroup>
6971
<Folder Include="Models\Styles\" />
7072
<Folder Include="Models\Styles\Sources\" />
7173
<Folder Include="Models\Expressions\" />
7274
<Folder Include="Models\Styles\Layers\" />
75+
<Folder Include="Models\Annotations\" />
7376
</ItemGroup>
7477
<ProjectExtensions>
7578
<MonoDevelop>

src/libs/Mapbox.Maui/MapboxView.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
using Mapbox.Maui.Styles;
2-
namespace Mapbox.Maui;
1+
namespace Mapbox.Maui;
2+
3+
using Mapbox.Maui.Annotations;
4+
using Mapbox.Maui.Styles;
35

46
public partial class MapboxView : View, IMapboxView
57
{
8+
public static readonly BindableProperty AnnotationsProperty = BindableProperty.Create(
9+
nameof(Annotations),
10+
typeof(IEnumerable<IAnnotation>),
11+
typeof(MapboxView)
12+
);
13+
public IEnumerable<IAnnotation> Annotations
14+
{
15+
get => (IEnumerable<IAnnotation>)GetValue(AnnotationsProperty);
16+
set => SetValue(AnnotationsProperty, value);
17+
}
18+
619
public static readonly BindableProperty LayersProperty = BindableProperty.Create(
720
nameof(Layers),
821
typeof(IEnumerable<MapboxLayer>),

src/libs/Mapbox.Maui/MapboxViewHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static IPropertyMapper<IMapboxView, MapboxViewHandler> PropertyMapper
2525
[nameof(MapboxView.Terrain)] = HandleTerrainChanged,
2626
[nameof(MapboxView.Layers)] = HandleLayersChanged,
2727
[nameof(MapboxView.Light)] = HandleLightChanged,
28+
[nameof(MapboxView.Annotations)] = HandleAnnotationsChanged,
2829
};
2930

3031
public MapboxViewHandler() : base(PropertyMapper)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
namespace Mapbox.Maui.Annotations;
2+
3+
using GeoJSON.Net.Geometry;
4+
5+
public interface IAnnotation
6+
{
7+
/// The unique identifier of the annotation.
8+
public string Id { get; }
9+
10+
/// The geometry that is backing this annotation.
11+
public IGeometryObject Geometry { get; }
12+
13+
/// Properties associated with the annotation.
14+
public IReadOnlyDictionary<string, object> UserInfo { get; set; }
15+
}
16+
17+
public abstract class Annotation<T>
18+
: BaseKVContainer
19+
, IAnnotation where T : IGeometryObject
20+
{
21+
public string Id { get; }
22+
23+
public IGeometryObject Geometry { get; }
24+
25+
public T GeometryValue => (T)Geometry;
26+
27+
public IReadOnlyDictionary<string, object> UserInfo { get; set; }
28+
29+
/// Toggles the annotation's selection state.
30+
/// If the annotation is deselected, it becomes selected.
31+
/// If the annotation is selected, it becomes deselected.
32+
public bool IsSelected { get; set; }
33+
34+
/// Property to determine whether annotation can be manually moved around map
35+
public bool IsDraggable { get; set; }
36+
37+
protected Annotation(T geometry, string id = null)
38+
{
39+
Id = id ?? Guid.NewGuid().ToString();
40+
Geometry = geometry;
41+
}
42+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
namespace Mapbox.Maui.Annotations;
2+
3+
using GeoJSON.Net.Geometry;
4+
5+
public class PolygonAnnotation : Annotation<Polygon>
6+
{
7+
public PolygonAnnotation(Polygon 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 FillSortKey
14+
{
15+
get => GetProperty<double>("fill-sort-key", default);
16+
set => SetProperty("fill-sort-key", value);
17+
}
18+
19+
/// The color of the filled part of this layer. This color can be specified as `rgba` with an alpha component and the color's opacity will not affect the opacity of the 1px stroke, if it is used.
20+
public Color FillColor
21+
{
22+
get => GetProperty<Color>("fill-color", default);
23+
set => SetProperty("fill-color", value);
24+
}
25+
26+
/// The opacity of the entire fill layer. In contrast to the `fill-color`, this value will also affect the 1px stroke around the fill, if the stroke is used.
27+
public double FillOpacity
28+
{
29+
get => GetProperty<double>("fill-opacity", default);
30+
set => SetProperty("fill-opacity", value);
31+
}
32+
33+
/// The outline color of the fill. Matches the value of `fill-color` if unspecified.
34+
public Color FillOutlineColor
35+
{
36+
get => GetProperty<Color>("fill-outline-color", default);
37+
set => SetProperty("fill-outline-color", value);
38+
}
39+
40+
/// Name of image in sprite to use for drawing image fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). Note that zoom-dependent expressions will be evaluated only at integer zoom levels.
41+
public string FillPattern
42+
{
43+
get => GetProperty<string>("fill-pattern", default);
44+
set => SetProperty("fill-pattern", value);
45+
}
46+
}

src/libs/Mapbox.Maui/Models/Styles/Layers/FillExtrusionLayer.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public class FillExtrusionLayer : MapboxLayer
55
public FillExtrusionLayer(string id) : base(id)
66
{
77
Type = LayerType.fillExtrusion;
8-
Visibility = new PropertyValue<Mapbox.Maui.Visibility>(Mapbox.Maui.Visibility.visible);
8+
Visibility = new PropertyValue<Visibility>(Maui.Visibility.visible);
99
}
1010

1111
public static class FillExtrusionLayerKey
@@ -37,7 +37,7 @@ public PropertyValue<double> FillExtrusionAmbientOcclusionIntensity
3737
default,
3838
MapboxLayerKey.paint
3939
);
40-
set => SetProperty<PropertyValue<double>>(
40+
set => SetProperty(
4141
FillExtrusionLayerKey.fillExtrusionAmbientOcclusionIntensity,
4242
value,
4343
MapboxLayerKey.paint
@@ -52,7 +52,7 @@ public PropertyValue<StyleTransition> FillExtrusionAmbientOcclusionIntensityTran
5252
default,
5353
MapboxLayerKey.paint
5454
);
55-
set => SetProperty<PropertyValue<StyleTransition>>(
55+
set => SetProperty(
5656
FillExtrusionLayerKey.fillExtrusionAmbientOcclusionIntensityTransition,
5757
value,
5858
MapboxLayerKey.paint
@@ -67,7 +67,7 @@ public PropertyValue<double> FillExtrusionAmbientOcclusionRadius
6767
default,
6868
MapboxLayerKey.paint
6969
);
70-
set => SetProperty<PropertyValue<double>>(
70+
set => SetProperty(
7171
FillExtrusionLayerKey.fillExtrusionAmbientOcclusionRadius,
7272
value,
7373
MapboxLayerKey.paint
@@ -82,7 +82,7 @@ public PropertyValue<StyleTransition> FillExtrusionAmbientOcclusionRadiusTransit
8282
default,
8383
MapboxLayerKey.paint
8484
);
85-
set => SetProperty<PropertyValue<StyleTransition>>(
85+
set => SetProperty(
8686
FillExtrusionLayerKey.fillExtrusionAmbientOcclusionRadiusTransition,
8787
value,
8888
MapboxLayerKey.paint
@@ -97,7 +97,7 @@ public PropertyValue<double> FillExtrusionBase
9797
default,
9898
MapboxLayerKey.paint
9999
);
100-
set => SetProperty<PropertyValue<double>>(
100+
set => SetProperty(
101101
FillExtrusionLayerKey.fillExtrusionBase,
102102
value,
103103
MapboxLayerKey.paint
@@ -112,7 +112,7 @@ public PropertyValue<StyleTransition> FillExtrusionBaseTransition
112112
default,
113113
MapboxLayerKey.paint
114114
);
115-
set => SetProperty<PropertyValue<StyleTransition>>(
115+
set => SetProperty(
116116
FillExtrusionLayerKey.fillExtrusionBaseTransition,
117117
value,
118118
MapboxLayerKey.paint
@@ -127,7 +127,7 @@ public PropertyValue<Color> FillExtrusionColor
127127
default,
128128
MapboxLayerKey.paint
129129
);
130-
set => SetProperty<PropertyValue<Color>>(
130+
set => SetProperty(
131131
FillExtrusionLayerKey.fillExtrusionColor,
132132
value,
133133
MapboxLayerKey.paint
@@ -142,7 +142,7 @@ public PropertyValue<StyleTransition> FillExtrusionColorTransition
142142
default,
143143
MapboxLayerKey.paint
144144
);
145-
set => SetProperty<PropertyValue<StyleTransition>>(
145+
set => SetProperty(
146146
FillExtrusionLayerKey.fillExtrusionColorTransition,
147147
value,
148148
MapboxLayerKey.paint
@@ -157,7 +157,7 @@ public PropertyValue<double> FillExtrusionHeight
157157
default,
158158
MapboxLayerKey.paint
159159
);
160-
set => SetProperty<PropertyValue<double>>(
160+
set => SetProperty(
161161
FillExtrusionLayerKey.fillExtrusionHeight,
162162
value,
163163
MapboxLayerKey.paint
@@ -172,7 +172,7 @@ public PropertyValue<StyleTransition> FillExtrusionHeightTransition
172172
default,
173173
MapboxLayerKey.paint
174174
);
175-
set => SetProperty<PropertyValue<StyleTransition>>(
175+
set => SetProperty(
176176
FillExtrusionLayerKey.fillExtrusionHeightTransition,
177177
value,
178178
MapboxLayerKey.paint
@@ -187,7 +187,7 @@ public PropertyValue<double> FillExtrusionOpacity
187187
default,
188188
MapboxLayerKey.paint
189189
);
190-
set => SetProperty<PropertyValue<double>>(
190+
set => SetProperty(
191191
FillExtrusionLayerKey.fillExtrusionOpacity,
192192
value,
193193
MapboxLayerKey.paint
@@ -202,7 +202,7 @@ public PropertyValue<StyleTransition> FillExtrusionOpacityTransition
202202
default,
203203
MapboxLayerKey.paint
204204
);
205-
set => SetProperty<PropertyValue<StyleTransition>>(
205+
set => SetProperty(
206206
FillExtrusionLayerKey.fillExtrusionOpacityTransition,
207207
value,
208208
MapboxLayerKey.paint
@@ -217,7 +217,7 @@ public PropertyValue<string> FillExtrusionPattern
217217
default,
218218
MapboxLayerKey.paint
219219
);
220-
set => SetProperty<PropertyValue<string>>(
220+
set => SetProperty(
221221
FillExtrusionLayerKey.fillExtrusionPattern,
222222
value,
223223
MapboxLayerKey.paint
@@ -232,7 +232,7 @@ public PropertyValue<double[]> FillExtrusionTranslate
232232
default,
233233
MapboxLayerKey.paint
234234
);
235-
set => SetProperty<PropertyValue<double[]>>(
235+
set => SetProperty(
236236
FillExtrusionLayerKey.fillExtrusionTranslate,
237237
value,
238238
MapboxLayerKey.paint
@@ -247,7 +247,7 @@ public PropertyValue<StyleTransition> FillExtrusionTranslateTransition
247247
default,
248248
MapboxLayerKey.paint
249249
);
250-
set => SetProperty<PropertyValue<StyleTransition>>(
250+
set => SetProperty(
251251
FillExtrusionLayerKey.fillExtrusionTranslateTransition,
252252
value,
253253
MapboxLayerKey.paint
@@ -262,7 +262,7 @@ public PropertyValue<FillExtrusionTranslateAnchor> FillExtrusionTranslateAnchor
262262
default,
263263
MapboxLayerKey.paint
264264
);
265-
set => SetProperty<PropertyValue<FillExtrusionTranslateAnchor>>(
265+
set => SetProperty(
266266
FillExtrusionLayerKey.fillExtrusionTranslateAnchor,
267267
value,
268268
MapboxLayerKey.paint
@@ -277,7 +277,7 @@ public PropertyValue<bool> FillExtrusionVerticalGradient
277277
default,
278278
MapboxLayerKey.paint
279279
);
280-
set => SetProperty<PropertyValue<bool>>(
280+
set => SetProperty(
281281
FillExtrusionLayerKey.fillExtrusionVerticalGradient,
282282
value,
283283
MapboxLayerKey.paint

0 commit comments

Comments
 (0)