Skip to content

Commit 84a691c

Browse files
Support geojson string ios (#12)
1 parent 04739b5 commit 84a691c

File tree

4 files changed

+44
-62
lines changed

4 files changed

+44
-62
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<PackageReference Include="Xamarin.Kotlin.StdLib.Common" Version="1.9.23.1" PrivateAssets="none" />
7171
</ItemGroup>
7272
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
73-
<PackageReference Include="MapboxMapsObjC.iOS" Version="11.3.0.2" />
73+
<PackageReference Include="MapboxMapsObjC.iOS" Version="11.3.0.3" />
7474
<PackageReference Include="MapboxMaps.iOS" Version="11.3.0.2" />
7575
</ItemGroup>
7676
<ItemGroup>

src/libs/Mapbox.Maui/Models/Styles/Enums.cs

+3-15
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,9 @@ public static MapboxMapsObjC.TMBVisibility ToPlatform(this Visibility value)
3636

3737
public static Visibility ToPlatform(this MapboxMapsObjC.TMBVisibility value)
3838
{
39-
return value switch
40-
{
41-
MapboxMapsObjC.TMBVisibility.Visible => "visible",
42-
MapboxMapsObjC.TMBVisibility.None => "none"
43-
};
44-
}
45-
46-
public static Visibility VisibilityX(this Foundation.NSNumber value)
47-
{
48-
return ((MapboxMapsObjC.TMBVisibility)value.Int32Value).ToPlatform();
49-
}
50-
51-
public static Foundation.NSNumber AsNumber(this Visibility value)
52-
{
53-
return Foundation.NSNumber.FromInt32((int)ToPlatform(value));
39+
return value == TMBVisibility.Visible
40+
? Visibility.Visible
41+
: Visibility.None;
5442
}
5543
}
5644
#endif

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

+39-45
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
using MapboxCommon;
3+
24
namespace MapboxMaui;
35

46
using Foundation;
@@ -182,51 +184,43 @@ private static void HandleGeoJSONSource(TMBMapboxMap style, string sourceId, NSD
182184
{
183185
var sourceExists = style.SourceExistsWithId(sourceId);
184186

185-
throw new NotImplementedException();
186-
//switch(data) {
187-
// //case RawGeoJSONObject raw:
188-
// // if (sourceExists)
189-
// // {
190-
// // style.UpdateGeoJSONSourceWithId(
191-
// // sourceId, raw.Data,
192-
// // (error) =>
193-
// // {
194-
// // if (error == null) return;
195-
196-
// // System.Diagnostics.Debug.WriteLine(error.LocalizedDescription);
197-
// // });
198-
// // return;
199-
// // }
200-
201-
// // style.AddGeoJSONSourceWithId(
202-
// // sourceId, platformValue, raw.Data,
203-
// // (error) =>
204-
// // {
205-
// // if (error == null) return;
206-
207-
// // System.Diagnostics.Debug.WriteLine(error.LocalizedDescription);
208-
// // });
209-
// // break;
210-
// //case GeoJSON.Text.Geometry.IGeometryObject geometry:
211-
// // if (sourceExists) {
212-
// // style.UpdateGeoJSONSourceWithId(
213-
// // sourceId, geometry.ToNative(),
214-
// // (error) => {
215-
// // if (error == null) return;
216-
217-
// // System.Diagnostics.Debug.WriteLine(error.LocalizedDescription);
218-
// // });
219-
// // return;
220-
// // }
221-
// // style.AddSourceWithId(
222-
// // sourceId, geometry.ToNative(),
223-
// // (error) => {
224-
// // if (error == null) return;
225-
226-
// // System.Diagnostics.Debug.WriteLine(error.LocalizedDescription);
227-
// // });
228-
// // break;
229-
//}
187+
switch (data)
188+
{
189+
case RawGeoJSONObject raw:
190+
191+
var sourceData = TMBGeoJSONSourceData.FromString(raw.Data);
192+
193+
if (sourceExists)
194+
{
195+
style.UpdateGeoJSONSourceWithId(sourceId, sourceData, null);
196+
return;
197+
}
198+
199+
var source = new TMBGeoJSONSource(sourceId);
200+
source.Data = sourceData;
201+
202+
style.AddSource(source , sourceId, (error) =>
203+
{
204+
if (error == null) return;
205+
System.Diagnostics.Debug.WriteLine(error.LocalizedDescription);
206+
});
207+
break;
208+
209+
case GeoJSON.Text.Geometry.IGeometryObject geometry:
210+
211+
var feature = new MBXFeature(new NSString(sourceId), geometry.ToNative(), platformValue);
212+
213+
if (sourceExists) {
214+
style.UpdateGeoJSONSourceFeaturesForSourceId(
215+
sourceId, [feature], null);
216+
return;
217+
}
218+
219+
style.AddGeoJSONSourceFeaturesForSourceId(
220+
sourceId, [feature], null);
221+
222+
break;
223+
}
230224
}
231225

232226
private static void HandleCameraOptionsChanged(MapboxViewHandler handler, IMapboxView view)

src/qs/MapboxMauiQs/MapboxMauiQs.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<PackageReference Include="Xamarin.Kotlin.StdLib.Common" Version="1.9.23.1" PrivateAssets="none" />
8080
</ItemGroup>
8181
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
82-
<PackageReference Include="MapboxMapsObjC.iOS" Version="11.3.0.2" />
82+
<PackageReference Include="MapboxMapsObjC.iOS" Version="11.3.0.3" />
8383
<PackageReference Include="MapboxMaps.iOS" Version="11.3.0.2" />
8484
</ItemGroup>
8585
<!--

0 commit comments

Comments
 (0)