1
- namespace MapboxMaui ;
1
+ using GeoJSON . Text . Geometry ;
2
+ using Point = Microsoft . Maui . Graphics . Point ;
3
+
4
+ namespace MapboxMaui ;
2
5
3
6
public static class GeometryExtensions
4
7
{
@@ -17,35 +20,35 @@ internal static Com.Mapbox.Geojson.IGeometry ToNative(this GeoJSON.Text.Geometry
17
20
point . Coordinates . Longitude ,
18
21
point . Coordinates . Latitude ) ,
19
22
20
- GeoJSON . Text . Geometry . LineString line => Com . Mapbox . Geojson . LineString . FromLngLats (
23
+ LineString line => Com . Mapbox . Geojson . LineString . FromLngLats (
21
24
Com . Mapbox . Geojson . MultiPoint . FromLngLats (
22
25
line . Coordinates . Select ( ToGeoPoint ) . ToList ( )
23
26
)
24
27
) ,
25
28
26
- GeoJSON . Text . Geometry . Polygon polygon => Com . Mapbox . Geojson . Polygon . FromLngLats (
29
+ Polygon polygon => Com . Mapbox . Geojson . Polygon . FromLngLats (
27
30
polygon . Coordinates
28
31
. Select (
29
32
x => x . Coordinates . Select ( ToGeoPoint ) . ToList ( )
30
33
as IList < Com . Mapbox . Geojson . Point > )
31
34
. ToList ( )
32
35
) ,
33
36
34
- GeoJSON . Text . Geometry . MultiPoint multiPoint => Com . Mapbox . Geojson . MultiPoint . FromLngLats (
37
+ MultiPoint multiPoint => Com . Mapbox . Geojson . MultiPoint . FromLngLats (
35
38
multiPoint . Coordinates
36
39
. Select ( x => x . Coordinates . ToGeoPoint ( ) )
37
40
. ToList ( )
38
41
) ,
39
42
40
- GeoJSON . Text . Geometry . MultiLineString multiLineString => Com . Mapbox . Geojson . Polygon . FromLngLats (
43
+ MultiLineString multiLineString => Com . Mapbox . Geojson . Polygon . FromLngLats (
41
44
multiLineString . Coordinates
42
45
. Select (
43
46
x => x . Coordinates . Select ( ToGeoPoint ) . ToList ( )
44
47
as IList < Com . Mapbox . Geojson . Point > )
45
48
. ToList ( )
46
49
) ,
47
50
48
- GeoJSON . Text . Geometry . MultiPolygon multiPolygon => Com . Mapbox . Geojson . Polygon . FromLngLats (
51
+ MultiPolygon multiPolygon => Com . Mapbox . Geojson . Polygon . FromLngLats (
49
52
multiPolygon . Coordinates
50
53
. Select (
51
54
x => x . Coordinates
@@ -63,5 +66,80 @@ internal static Com.Mapbox.Geojson.Point ToNative(this Point xvalue)
63
66
{
64
67
return Com . Mapbox . Geojson . Point . FromLngLat ( xvalue . Y , xvalue . X ) ;
65
68
}
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
+ }
66
144
}
67
145
0 commit comments