|
1 | 1 |
|
| 2 | +using MapboxCommon; |
| 3 | + |
2 | 4 | namespace MapboxMaui;
|
3 | 5 |
|
4 | 6 | using Foundation;
|
@@ -182,51 +184,43 @@ private static void HandleGeoJSONSource(TMBMapboxMap style, string sourceId, NSD
|
182 | 184 | {
|
183 | 185 | var sourceExists = style.SourceExistsWithId(sourceId);
|
184 | 186 |
|
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 | + } |
230 | 224 | }
|
231 | 225 |
|
232 | 226 | private static void HandleCameraOptionsChanged(MapboxViewHandler handler, IMapboxView view)
|
|
0 commit comments