Skip to content

Commit df8c363

Browse files
committed
- WIP: IconSizeChangeExample
1 parent a342639 commit df8c363

21 files changed

+600
-71
lines changed

src/libs/Mapbox.Maui/IMapboxView.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using System.Windows.Input;
44
using MapboxMaui.Annotations;
5+
using MapboxMaui.Query;
56
using MapboxMaui.Styles;
67

78
public partial interface IMapboxView : IView
@@ -27,10 +28,11 @@ public partial interface IMapboxView : IView
2728

2829
IAnnotationController AnnotationController { get; }
2930

30-
ICommand Command { get; }
31+
IMapFeatureQueryable QueryManager { get; }
3132
}
3233

33-
partial interface IMapboxView {
34+
partial interface IMapboxView
35+
{
3436
event EventHandler MapReady;
3537
ICommand MapReadyCommand { get; set; }
3638

@@ -39,12 +41,30 @@ partial interface IMapboxView {
3941

4042
event EventHandler MapLoaded;
4143
ICommand MapLoadedCommand { get; set; }
44+
45+
event EventHandler<MapTappedEventArgs> MapTapped;
46+
ICommand Command { get; }
4247
}
4348

4449
public interface IAnnotationController
4550
{
4651
IPolygonAnnotationManager CreatePolygonAnnotationManager(string id, LayerPosition layerPosition);
4752
ICircleAnnotationManager CreateCircleAnnotationManager(string id, LayerPosition layerPosition);
4853
IPointAnnotationManager CreatePointAnnotationManager(string id, LayerPosition layerPosition, ClusterOptions clusterOptions = null);
49-
public IPolylineAnnotationManager CreatePolylineAnnotationManager(string id, LayerPosition layerPosition);
54+
IPolylineAnnotationManager CreatePolylineAnnotationManager(string id, LayerPosition layerPosition);
55+
}
56+
57+
public interface IMapFeatureQueryable
58+
{
59+
Task<IEnumerable<QueriedFeature>> QueryRenderedFeaturesWith(Point point, RenderedQueryOptions options);
5060
}
61+
62+
public class MapTappedEventArgs : EventArgs
63+
{
64+
public MapTappedPosition Position { get; }
65+
66+
public MapTappedEventArgs(MapTappedPosition position)
67+
{
68+
Position = position;
69+
}
70+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
<None Remove="Models\Offline\" />
7373
<None Remove="Platforms\iOS\Offline\" />
7474
<None Remove="Platforms\Android\Offline\" />
75+
<None Remove="Models\Query\" />
7576
</ItemGroup>
7677
<ItemGroup>
7778
<Folder Include="Models\Styles\" />
@@ -84,6 +85,7 @@
8485
<Folder Include="Models\Offline\" />
8586
<Folder Include="Platforms\iOS\Offline\" />
8687
<Folder Include="Platforms\Android\Offline\" />
88+
<Folder Include="Models\Query\" />
8789
</ItemGroup>
8890
<ProjectExtensions>
8991
<MonoDevelop>

src/libs/Mapbox.Maui/MapboxView.Events.cs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44

55
partial class MapboxView
66
{
7+
public event EventHandler<MapTappedEventArgs> MapTapped;
8+
internal void InvokeMapTapped(MapTappedPosition point)
9+
{
10+
MapTapped?.Invoke(this, new MapTappedEventArgs(point));
11+
12+
if (Command?.CanExecute(point) == true)
13+
{
14+
Command.Execute(point);
15+
}
16+
}
17+
18+
public static readonly BindableProperty CommandProperty = BindableProperty.Create(
19+
nameof(Command),
20+
typeof(ICommand),
21+
typeof(MapboxView)
22+
);
23+
public ICommand Command
24+
{
25+
get => (ICommand)GetValue(CommandProperty);
26+
set => SetValue(CommandProperty, value);
27+
}
28+
729
public event EventHandler MapReady;
830
internal void InvokeMapReady()
931
{
@@ -38,17 +60,6 @@ internal void InvokeStyleLoaded()
3860
}
3961
}
4062

41-
public event EventHandler MapTapped;
42-
internal void InvokeMapTapped(Point point)
43-
{
44-
MapTapped?.Invoke(this, new MapTappedEventArgs(point));
45-
46-
if (Command?.CanExecute(point) == true)
47-
{
48-
Command.Execute(point);
49-
}
50-
}
51-
5263
public static readonly BindableProperty StyleLoadedCommandProperty = BindableProperty.Create(
5364
nameof(StyleLoadedCommand),
5465
typeof(ICommand),
@@ -85,13 +96,10 @@ public ICommand MapLoadedCommand
8596
}
8697
}
8798

88-
public class MapTappedEventArgs : EventArgs
99+
public class MapTappedPosition
89100
{
90-
public Point Position { get; }
101+
public Point ScreenPosition { get; set; }
91102

92-
public MapTappedEventArgs(Point position)
93-
{
94-
Position = position;
95-
}
103+
public GeoJSON.Text.Geometry.Point Point { get; set; }
96104
}
97105

src/libs/Mapbox.Maui/MapboxView.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
namespace MapboxMaui;
22

3-
using System.Windows.Input;
43
using MapboxMaui.Annotations;
54
using MapboxMaui.Styles;
65

76
public partial class MapboxView : View, IMapboxView
87
{
9-
public static readonly BindableProperty CommandProperty = BindableProperty.Create(
10-
nameof(Command),
11-
typeof(ICommand),
12-
typeof(MapboxView)
13-
);
14-
public ICommand Command
15-
{
16-
get => (ICommand)GetValue(CommandProperty);
17-
set => SetValue(CommandProperty, value);
18-
}
19-
208
public static readonly BindableProperty AnnotationsProperty = BindableProperty.Create(
219
nameof(Annotations),
2210
typeof(IEnumerable<IAnnotation>),
@@ -221,4 +209,5 @@ public MapboxStyle MapboxStyle
221209
}
222210

223211
public IAnnotationController AnnotationController { get; internal set; }
212+
public IMapFeatureQueryable QueryManager { get; internal set; }
224213
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using GeoJSON.Text.Feature;
2+
3+
namespace MapboxMaui.Query;
4+
5+
public class QueriedFeature
6+
{
7+
public Feature Feature { get; internal set; }
8+
public string Source { get; internal set; }
9+
public string SourceLayer { get; internal set; }
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace MapboxMaui.Query;
2+
3+
public class RenderedQueryOptions
4+
{
5+
public string[] LayerIds { get; set; }
6+
public object Filter { get; set; }
7+
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using MapboxMaui.Styles;
1111
using System.Collections;
1212
using MapboxMaui.Expressions;
13+
using AndroidX.Fragment.App;
1314

1415
static class AdditionalExtensions
1516
{
@@ -258,9 +259,12 @@ internal static PlatformValue GetVolatileProperties(this MapboxSource source)
258259
}
259260

260261
internal static MapView GetMapView(this MapboxViewHandler handler)
262+
=> handler.PlatformView.GetMapView();
263+
264+
internal static MapView GetMapView(this FragmentContainerView container)
261265
{
262-
var mainActivity = (MauiAppCompatActivity)handler.Context.GetActivity();
263-
var tag = $"mapbox-maui-{handler.PlatformView.Id}";
266+
var mainActivity = (MauiAppCompatActivity)container.Context.GetActivity();
267+
var tag = $"mapbox-maui-{container.Id}";
264268
var fragnent = mainActivity.SupportFragmentManager.FindFragmentByTag(tag);
265269
return (fragnent as MapboxFragment)?.MapView;
266270
}

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

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
namespace MapboxMaui;
1+
using GeoJSON.Text.Geometry;
2+
using Point = Microsoft.Maui.Graphics.Point;
3+
4+
namespace MapboxMaui;
25

36
public static class GeometryExtensions
47
{
@@ -17,35 +20,35 @@ internal static Com.Mapbox.Geojson.IGeometry ToNative(this GeoJSON.Text.Geometry
1720
point.Coordinates.Longitude,
1821
point.Coordinates.Latitude),
1922

20-
GeoJSON.Text.Geometry.LineString line => Com.Mapbox.Geojson.LineString.FromLngLats(
23+
LineString line => Com.Mapbox.Geojson.LineString.FromLngLats(
2124
Com.Mapbox.Geojson.MultiPoint.FromLngLats(
2225
line.Coordinates.Select(ToGeoPoint).ToList()
2326
)
2427
),
2528

26-
GeoJSON.Text.Geometry.Polygon polygon => Com.Mapbox.Geojson.Polygon.FromLngLats(
29+
Polygon polygon => Com.Mapbox.Geojson.Polygon.FromLngLats(
2730
polygon.Coordinates
2831
.Select(
2932
x => x.Coordinates.Select(ToGeoPoint).ToList()
3033
as IList<Com.Mapbox.Geojson.Point>)
3134
.ToList()
3235
),
3336

34-
GeoJSON.Text.Geometry.MultiPoint multiPoint => Com.Mapbox.Geojson.MultiPoint.FromLngLats(
37+
MultiPoint multiPoint => Com.Mapbox.Geojson.MultiPoint.FromLngLats(
3538
multiPoint.Coordinates
3639
.Select(x => x.Coordinates.ToGeoPoint())
3740
.ToList()
3841
),
3942

40-
GeoJSON.Text.Geometry.MultiLineString multiLineString => Com.Mapbox.Geojson.Polygon.FromLngLats(
43+
MultiLineString multiLineString => Com.Mapbox.Geojson.Polygon.FromLngLats(
4144
multiLineString.Coordinates
4245
.Select(
4346
x => x.Coordinates.Select(ToGeoPoint).ToList()
4447
as IList<Com.Mapbox.Geojson.Point>)
4548
.ToList()
4649
),
4750

48-
GeoJSON.Text.Geometry.MultiPolygon multiPolygon => Com.Mapbox.Geojson.Polygon.FromLngLats(
51+
MultiPolygon multiPolygon => Com.Mapbox.Geojson.Polygon.FromLngLats(
4952
multiPolygon.Coordinates
5053
.Select(
5154
x => x.Coordinates
@@ -63,5 +66,80 @@ internal static Com.Mapbox.Geojson.Point ToNative(this Point xvalue)
6366
{
6467
return Com.Mapbox.Geojson.Point.FromLngLat(xvalue.Y, xvalue.X);
6568
}
69+
70+
internal static GeoJSON.Text.Feature.Feature ToX(this Com.Mapbox.Geojson.Feature src)
71+
=> new GeoJSON.Text.Feature.Feature(
72+
src.Geometry().ToX(),
73+
src.Properties(),
74+
src.Id());
75+
76+
internal static IGeometryObject ToX(this Com.Mapbox.Geojson.IGeometry src)
77+
{
78+
switch(src)
79+
{
80+
case Com.Mapbox.Geojson.Point point:
81+
return new GeoJSON.Text.Geometry.Point(
82+
new Position(
83+
point.Latitude(), point.Longitude(),
84+
point.HasAltitude ? point.Altitude() : null
85+
)
86+
);
87+
case Com.Mapbox.Geojson.LineString lineString:
88+
return new LineString(
89+
lineString
90+
.Coordinates()
91+
.Select(x => new [] { x.Longitude(), x.Latitude() })
92+
.ToList()
93+
);
94+
case Com.Mapbox.Geojson.Polygon polygon:
95+
return new Polygon(
96+
polygon
97+
.Coordinates()
98+
.Select(
99+
y => y.Select(
100+
x => new[] { x.Longitude(), x.Latitude() }
101+
))
102+
.ToList()
103+
);
104+
case Com.Mapbox.Geojson.MultiPoint multiPoint:
105+
return new MultiPoint(
106+
multiPoint
107+
.Coordinates()
108+
.Select(x => new[] { x.Longitude(), x.Latitude() })
109+
.ToList()
110+
);
111+
case Com.Mapbox.Geojson.MultiLineString multiLineString:
112+
return new MultiLineString(
113+
multiLineString
114+
.Coordinates()
115+
.Select(
116+
y => y.Select(
117+
x => new[] { x.Longitude(), x.Latitude() }
118+
))
119+
.ToList()
120+
);
121+
case Com.Mapbox.Geojson.MultiPolygon multiPolygon:
122+
return new MultiPolygon(
123+
multiPolygon
124+
.Coordinates()
125+
.Select(
126+
z => z.Select(
127+
y => y.Select(
128+
x => new[] { x.Longitude(), x.Latitude() }
129+
)
130+
)
131+
)
132+
.ToList()
133+
);
134+
case Com.Mapbox.Geojson.GeometryCollection geometryCollection:
135+
return new GeometryCollection(
136+
geometryCollection
137+
.Geometries()
138+
.Select(x => x.ToX())
139+
.ToList()
140+
);
141+
}
142+
throw new NotSupportedException("Invalid geometry type");
143+
}
66144
}
67145

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public partial class MapboxFragment : Fragment
1616
public event Action<MapView> MapViewReady;
1717
public event Action<MapView> StyleLoaded;
1818
public event Action<MapView> MapLoaded;
19-
public event Action<Microsoft.Maui.Graphics.Point> MapClicked;
19+
public event Action<MapTappedPosition> MapClicked;
2020

2121
public MapView MapView { get; private set; }
2222

@@ -118,7 +118,17 @@ public bool OnMapClick(Point point)
118118
var xpoint = new Microsoft.Maui.Graphics.Point(
119119
point.Latitude(),
120120
point.Longitude());
121-
MapClicked?.Invoke(xpoint);
121+
MapClicked?.Invoke(new MapTappedPosition
122+
{
123+
ScreenPosition = xpoint,
124+
Point = new GeoJSON.Text.Geometry.Point(
125+
new GeoJSON.Text.Geometry.Position(
126+
point.Latitude(),
127+
point.Longitude(),
128+
point.HasAltitude ? point.Altitude() : null
129+
)
130+
)
131+
});
122132
return true;
123133
}
124134

0 commit comments

Comments
 (0)