Skip to content

Commit 6bed053

Browse files
committed
- AddMarkersSymbolExample: OK
1 parent c6b1ad4 commit 6bed053

File tree

6 files changed

+171
-26
lines changed

6 files changed

+171
-26
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ b/ iOS's `info.plist`
8888

8989
| # | Example | Ported |
9090
| - | - | - |
91-
| 1 | [AddMarkersSymbolExample](./mapboxqs/AddMarkersSymbolExample.m) | |
91+
| 1 | [AddMarkersSymbolExample](./mapboxqs/AddMarkersSymbolExample.m) | OK |
9292
| 2 | [AddOneMarkerSymbolExample](./mapboxqs/AddOneMarkerSymbolExample.m) | OK |
9393
| 3 | [AdvancedViewportGesturesExample](./mapboxqs/AdvancedViewportGesturesExample.m) | |
9494
| 4 | [AnimateGeoJSONLineExample](./mapboxqs/AnimateGeoJSONLineExample.m) | |

src/libs/Mapbox.Maui/Platforms/iOS/GeometryExtensions.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using CoreGraphics;
22
using Foundation;
3+
using GeoJSON.Text.Feature;
34
using GeoJSON.Text.Geometry;
45
using MapboxCommon;
56
using MapboxMapsObjC;
@@ -69,20 +70,20 @@ internal static MBXGeometry ToNative(this IGeometryObject xobj)
6970
.ToArray()));
7071

7172
//case FeatureCollection featureCollection:
72-
// return GeometryHelper.CreateMultiPolygon(
73-
// NSArray.FromNSObjects(
74-
// multiPolygon.Coordinates
75-
// .Select(
76-
// x => NSArray.FromNSObjects(
77-
// x.Coordinates
78-
// .Select(
79-
// y => NSArray.FromNSObjects(
80-
// y.Coordinates
81-
// .Select(
82-
// z => z.ToNSValue())
83-
// .ToArray()))
84-
// .ToArray()))
85-
// .ToArray()));
73+
//return GeometryHelper.CreateMultiPolygon(
74+
// NSArray.FromNSObjects(
75+
// multiPolygon.Coordinates
76+
// .Select(
77+
// x => NSArray.FromNSObjects(
78+
// x.Coordinates
79+
// .Select(
80+
// y => NSArray.FromNSObjects(
81+
// y.Coordinates
82+
// .Select(
83+
// z => z.ToNSValue())
84+
// .ToArray()))
85+
// .ToArray()))
86+
// .ToArray()));
8687
}
8788

8889
return null;
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
using System.Text.Json;
2+
using GeoJSON.Text.Feature;
3+
using MapboxMaui;
4+
using MapboxMaui.Expressions;
5+
using MapboxMaui.Styles;
6+
using iOSPage = Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page;
7+
namespace MapboxMauiQs;
8+
9+
public class AddMarkersSymbolExample : ContentPage, IExamplePage, IQueryAttributable
10+
{
11+
private static class Constants
12+
{
13+
public const string ICON_KEY = "icon_key";
14+
public const string BLUE_MARKER_PROPERTY = "icon_blue_property";
15+
public const string RED_MARKER_PROPERTY = "icon_red_property";
16+
public const string BLUE_ICON_ID = "blue";
17+
public const string RED_ICON_ID = "red";
18+
public const string SOURCE_ID = "source_id";
19+
public const string LAYER_ID = "layer_id";
20+
}
21+
22+
MapboxView map;
23+
IExampleInfo info;
24+
25+
public AddMarkersSymbolExample()
26+
{
27+
iOSPage.SetUseSafeArea(this, false);
28+
Content = map = new MapboxView();
29+
30+
map.MapReady += Map_MapReady;
31+
map.MapLoaded += Map_MapLoaded;
32+
}
33+
34+
public void ApplyQueryAttributes(IDictionary<string, object> query)
35+
{
36+
info = query["example"] as IExampleInfo;
37+
38+
Title = info?.Title;
39+
}
40+
41+
private void Map_MapReady(object sender, EventArgs e)
42+
{
43+
var centerLocation = new Point(55.70651, 12.554729);
44+
var cameraOptions = new CameraOptions
45+
{
46+
Center = centerLocation,
47+
Zoom = 8,
48+
};
49+
50+
map.CameraOptions = cameraOptions;
51+
map.MapboxStyle = MapboxStyle.MAPBOX_STREETS;
52+
}
53+
54+
private void Map_MapLoaded(object sender, EventArgs e)
55+
{
56+
map.Images = new[] {
57+
new ResolvedImage(Constants.BLUE_ICON_ID, "blue_marker_view"),
58+
new ResolvedImage(Constants.RED_ICON_ID, "red_marker"),
59+
};
60+
61+
var features = new List<Feature>();
62+
63+
var feature = new Feature(
64+
new GeoJSON.Text.Geometry.Point(
65+
new GeoJSON.Text.Geometry.Position(latitude: 55.608166, longitude: 12.65147)
66+
),
67+
new Dictionary<string, object> {
68+
{ Constants.ICON_KEY, Constants.BLUE_MARKER_PROPERTY }
69+
}
70+
);
71+
features.Add(feature);
72+
73+
var feature1 = new Feature(
74+
new GeoJSON.Text.Geometry.Point(
75+
new GeoJSON.Text.Geometry.Position(latitude: 55.70651, longitude: 12.554729)
76+
),
77+
new Dictionary<string, object> {
78+
{ Constants.ICON_KEY, Constants.RED_MARKER_PROPERTY }
79+
}
80+
);
81+
features.Add(feature1);
82+
83+
var geoJSONString = JsonSerializer.Serialize(new FeatureCollection(features));
84+
var source = new GeoJSONSource(Constants.SOURCE_ID)
85+
{
86+
Data = new RawGeoJSONObject(geoJSONString),
87+
};
88+
89+
map.Sources = new[] { source };
90+
91+
var rotateExpression = DslExpression.match(
92+
DslExpression.get(Constants.ICON_KEY),
93+
Constants.BLUE_MARKER_PROPERTY,
94+
45,
95+
0
96+
);
97+
var imageExpression = DslExpression.match(
98+
DslExpression.get(Constants.ICON_KEY),
99+
Constants.BLUE_MARKER_PROPERTY,
100+
Constants.BLUE_ICON_ID,
101+
Constants.RED_MARKER_PROPERTY,
102+
Constants.RED_ICON_ID,
103+
Constants.RED_ICON_ID
104+
);
105+
106+
var layer = new SymbolLayer(id: Constants.LAYER_ID)
107+
{
108+
Source = Constants.SOURCE_ID,
109+
IconImage = (PropertyValue<ResolvedImage>)imageExpression,
110+
IconAnchor = IconAnchor.bottom,
111+
IconAllowOverlap = false,
112+
IconRotate = (PropertyValue<double>)rotateExpression
113+
};
114+
115+
map.Layers = new [] { layer };
116+
}
117+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace MapboxMauiQs;
2+
class AddMarkersSymbolExampleInfo : IExampleInfo
3+
{
4+
public string Group => "Annotations";
5+
public string Title => "Add markers to a map";
6+
public string Subtitle => "Add markers that use different icons.";
7+
public string PageRoute => typeof(AddMarkersSymbolExample).FullName;
8+
}
Lines changed: 3 additions & 11 deletions
Loading
Lines changed: 27 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)