@@ -59,7 +59,7 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
59
59
scale: ArcgisMapView . convertZoomLevelToMapScale ( Int ( mapOptions. zoom) )
60
60
)
61
61
62
- mapContentView = MapContentView ( mapViewModel : MapViewModel ( viewpoint: viewpoint) )
62
+ mapContentView = MapContentView ( viewModel : MapViewModel ( viewpoint: viewpoint) )
63
63
64
64
// Embed the SwiftUI MapView into a UIHostingController
65
65
hostingController = UIHostingController ( rootView: mapContentView)
@@ -69,28 +69,28 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
69
69
super. init ( )
70
70
71
71
if let isAttributionTextVisible = mapOptions. isAttributionTextVisible {
72
- mapContentView. mapViewModel . attributionBarHidden = !isAttributionTextVisible
72
+ mapContentView. viewModel . attributionBarHidden = !isAttributionTextVisible
73
73
}
74
74
75
75
if mapOptions. basemap != nil {
76
- mapContentView. mapViewModel . map. basemap = Basemap ( style: parseBaseMapStyle ( mapOptions. basemap!) )
76
+ mapContentView. viewModel . map. basemap = Basemap ( style: parseBaseMapStyle ( mapOptions. basemap!) )
77
77
} else {
78
78
let layers = mapOptions. vectorTilesUrls!. map { url in
79
79
ArcGISVectorTiledLayer ( url: URL ( string: url) !)
80
80
}
81
- mapContentView. mapViewModel . map. basemap = Basemap ( baseLayers: layers)
81
+ mapContentView. viewModel . map. basemap = Basemap ( baseLayers: layers)
82
82
}
83
83
84
- mapContentView. mapViewModel . map. minScale = ArcgisMapView . convertZoomLevelToMapScale ( mapOptions. minZoom)
85
- mapContentView. mapViewModel . map. maxScale = ArcgisMapView . convertZoomLevelToMapScale ( mapOptions. maxZoom)
84
+ mapContentView. viewModel . map. minScale = ArcgisMapView . convertZoomLevelToMapScale ( mapOptions. minZoom)
85
+ mapContentView. viewModel . map. maxScale = ArcgisMapView . convertZoomLevelToMapScale ( mapOptions. maxZoom)
86
86
87
- mapContentView. mapViewModel . onScaleChanged = { [ weak self] scale in
87
+ mapContentView. viewModel . onScaleChanged = { [ weak self] scale in
88
88
guard let self = self else { return }
89
89
guard !scale. isNaN else { return }
90
90
let newZoom = self . convertScaleToZoomLevel ( scale)
91
91
self . zoomStreamHandler. addZoom ( zoom: newZoom)
92
92
}
93
- mapContentView. mapViewModel . onVisibleAreaChanged = { [ weak self] polygon in
93
+ mapContentView. viewModel . onVisibleAreaChanged = { [ weak self] polygon in
94
94
guard let self = self else { return }
95
95
let center = polygon. extent. center
96
96
if let wgs84Center = GeometryEngine . project ( center, into: . wgs84) as? Point {
@@ -101,7 +101,7 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
101
101
setMapInteractive ( mapOptions. isInteractive)
102
102
setupMethodChannel ( )
103
103
104
- mapContentView. mapViewModel . onLoadStatusChanged = { [ weak self] status in
104
+ mapContentView. viewModel . onLoadStatusChanged = { [ weak self] status in
105
105
guard let self = self else { return }
106
106
DispatchQueue . main. async {
107
107
self . notifyStatus ( status)
@@ -144,7 +144,7 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
144
144
}
145
145
146
146
private func onZoomIn( _ call: FlutterMethodCall , _ result: @escaping FlutterResult ) {
147
- let currentScale = mapContentView. mapViewModel . viewpoint. targetScale
147
+ let currentScale = mapContentView. viewModel . viewpoint. targetScale
148
148
149
149
guard let args = call. arguments as? [ String : Any ] else {
150
150
result ( FlutterError ( code: " missing_data " , message: " Invalid arguments " , details: nil ) )
@@ -158,7 +158,7 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
158
158
159
159
let currentZoomLevel = convertScaleToZoomLevel ( currentScale)
160
160
let totalZoomLevel = currentZoomLevel + lodFactor
161
- if let maxScale = mapContentView. mapViewModel . map. maxScale {
161
+ if let maxScale = mapContentView. viewModel . map. maxScale {
162
162
if totalZoomLevel > convertScaleToZoomLevel ( maxScale) {
163
163
result ( true )
164
164
return
@@ -167,14 +167,14 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
167
167
let newScale = ArcgisMapView . convertZoomLevelToMapScale ( totalZoomLevel)
168
168
Task {
169
169
do {
170
- await mapContentView. mapViewModel . mapViewProxy? . setViewpointScale ( newScale)
170
+ await mapContentView. viewModel . mapViewProxy? . setViewpointScale ( newScale)
171
171
result ( true )
172
172
}
173
173
}
174
174
}
175
175
176
176
private func onZoomOut( _ call: FlutterMethodCall , _ result: @escaping FlutterResult ) {
177
- let currentScale = mapContentView. mapViewModel . viewpoint. targetScale
177
+ let currentScale = mapContentView. viewModel . viewpoint. targetScale
178
178
179
179
guard let args = call. arguments as? [ String : Any ] else {
180
180
result ( FlutterError ( code: " missing_data " , message: " Invalid arguments " , details: nil ) )
@@ -188,7 +188,7 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
188
188
189
189
let currentZoomLevel = convertScaleToZoomLevel ( currentScale)
190
190
let totalZoomLevel = currentZoomLevel - lodFactor
191
- if let minScale = mapContentView. mapViewModel . map. minScale {
191
+ if let minScale = mapContentView. viewModel . map. minScale {
192
192
if totalZoomLevel < convertScaleToZoomLevel ( minScale) {
193
193
result ( true )
194
194
return
@@ -197,7 +197,7 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
197
197
let newScale = ArcgisMapView . convertZoomLevelToMapScale ( totalZoomLevel)
198
198
Task {
199
199
do {
200
- let success = await mapContentView. mapViewModel . mapViewProxy? . setViewpointScale ( newScale)
200
+ let success = await mapContentView. viewModel . mapViewProxy? . setViewpointScale ( newScale)
201
201
result ( success)
202
202
}
203
203
}
@@ -210,7 +210,7 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
210
210
}
211
211
Task {
212
212
do {
213
- let success = await mapContentView. mapViewModel . mapViewProxy? . setViewpointRotation ( angleDouble)
213
+ let success = await mapContentView. viewModel . mapViewProxy? . setViewpointRotation ( angleDouble)
214
214
result ( success)
215
215
}
216
216
}
@@ -225,7 +225,7 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
225
225
do {
226
226
let padding : ViewPadding = try JsonUtil . objectOfJson ( args)
227
227
228
- mapContentView. mapViewModel . contentInsets = EdgeInsets (
228
+ mapContentView. viewModel . contentInsets = EdgeInsets (
229
229
top: padding. top,
230
230
leading: padding. left,
231
231
bottom: padding. bottom,
@@ -255,9 +255,9 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
255
255
if let zoomLevel = zoomLevel {
256
256
scale = ArcgisMapView . convertZoomLevelToMapScale ( zoomLevel)
257
257
} else {
258
- scale = mapContentView. mapViewModel . viewpoint. targetScale
258
+ scale = mapContentView. viewModel . viewpoint. targetScale
259
259
}
260
- let success = await mapContentView. mapViewModel . mapViewProxy? . setViewpoint (
260
+ let success = await mapContentView. viewModel . mapViewProxy? . setViewpoint (
261
261
Viewpoint ( center: point. toAGSPoint ( ) , scale: scale) ,
262
262
duration: ( animationOptions? . duration ?? 0 ) / 1000 ,
263
263
)
@@ -279,10 +279,10 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
279
279
let polyline = Polyline ( points: payload. points. map { latLng in Point ( x: latLng. longitude, y: latLng. latitude, spatialReference: . wgs84) } )
280
280
281
281
if ( payload. padding != nil ) {
282
- let success = try await mapContentView. mapViewModel . mapViewProxy!. setViewpointGeometry ( polyline. extent, padding: payload. padding!)
282
+ let success = try await mapContentView. viewModel . mapViewProxy!. setViewpointGeometry ( polyline. extent, padding: payload. padding!)
283
283
result ( success)
284
284
} else {
285
- let success = try await mapContentView. mapViewModel . mapViewProxy!. setViewpointGeometry ( polyline. extent)
285
+ let success = try await mapContentView. viewModel . mapViewProxy!. setViewpointGeometry ( polyline. extent)
286
286
result ( success)
287
287
}
288
288
} catch {
@@ -302,7 +302,7 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
302
302
}
303
303
304
304
305
- let existingIds = mapContentView. mapViewModel . defaultGraphicsOverlay. graphics. compactMap { object in
305
+ let existingIds = mapContentView. viewModel . defaultGraphicsOverlay. graphics. compactMap { object in
306
306
let graphic = object as! Graphic
307
307
return graphic. attributes [ " id " ] as? String
308
308
}
@@ -325,7 +325,7 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
325
325
// them in this for loop instead.
326
326
// ArcGis is the best <3.
327
327
newGraphics. forEach {
328
- mapContentView. mapViewModel . defaultGraphicsOverlay. addGraphic ( $0)
328
+ mapContentView. viewModel . defaultGraphicsOverlay. addGraphic ( $0)
329
329
}
330
330
result ( true )
331
331
}
@@ -336,15 +336,15 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
336
336
return
337
337
}
338
338
339
- let selectedGraphics = mapContentView. mapViewModel . defaultGraphicsOverlay. graphics. filter { element in
339
+ let selectedGraphics = mapContentView. viewModel . defaultGraphicsOverlay. graphics. filter { element in
340
340
if let graphic = element as? Graphic ,
341
341
let id = graphic. attributes [ " id " ] as? String {
342
342
return id == graphicId
343
343
}
344
344
return false
345
345
}
346
346
347
- mapContentView. mapViewModel . defaultGraphicsOverlay. removeGraphics ( selectedGraphics)
347
+ mapContentView. viewModel . defaultGraphicsOverlay. removeGraphics ( selectedGraphics)
348
348
result ( true )
349
349
}
350
350
@@ -354,14 +354,14 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
354
354
return
355
355
}
356
356
357
- mapContentView. mapViewModel . map. basemap = Basemap ( style: parseBaseMapStyle ( baseMapString) )
357
+ mapContentView. viewModel . map. basemap = Basemap ( style: parseBaseMapStyle ( baseMapString) )
358
358
result ( true )
359
359
}
360
360
361
361
private func onRetryLoad( _ call: FlutterMethodCall , _ result: @escaping FlutterResult ) {
362
362
Task {
363
363
do {
364
- try await mapContentView. mapViewModel . map. retryLoad ( )
364
+ try await mapContentView. viewModel . map. retryLoad ( )
365
365
result ( true )
366
366
}
367
367
}
@@ -387,7 +387,7 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
387
387
}
388
388
389
389
private func setMapInteractive( _ enabled: Bool ) {
390
- mapContentView. mapViewModel . interactionModes = enabled ? . all : [ ]
390
+ mapContentView. viewModel . interactionModes = enabled ? . all : [ ]
391
391
}
392
392
393
393
private func parseBaseMapStyle( _ string: String ) -> Basemap . Style {
@@ -421,7 +421,7 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
421
421
private func onStartLocationDisplayDataSource( _ call: FlutterMethodCall , _ result: @escaping FlutterResult ) {
422
422
Task {
423
423
do {
424
- try await mapContentView. mapViewModel . locationDisplay. dataSource. start ( ) ;
424
+ try await mapContentView. viewModel . locationDisplay. dataSource. start ( ) ;
425
425
result ( true )
426
426
}
427
427
catch {
@@ -438,22 +438,22 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
438
438
private func onStopLocationDisplayDataSource( _ call: FlutterMethodCall , _ result: @escaping FlutterResult ) {
439
439
Task {
440
440
do {
441
- await mapContentView. mapViewModel . locationDisplay. dataSource. stop ( )
441
+ await mapContentView. viewModel . locationDisplay. dataSource. stop ( )
442
442
result ( true )
443
443
}
444
444
}
445
445
}
446
446
447
447
private func onSetLocationDisplayDefaultSymbol( _ call: FlutterMethodCall , _ result: @escaping FlutterResult ) {
448
- operationWithSymbol ( call, result) { mapContentView. mapViewModel . locationDisplay. defaultSymbol = $0 }
448
+ operationWithSymbol ( call, result) { mapContentView. viewModel . locationDisplay. defaultSymbol = $0 }
449
449
}
450
450
451
451
private func onSetLocationDisplayAccuracySymbol( _ call: FlutterMethodCall , _ result: @escaping FlutterResult ) {
452
- operationWithSymbol ( call, result) { mapContentView. mapViewModel . locationDisplay. accuracySymbol = $0 }
452
+ operationWithSymbol ( call, result) { mapContentView. viewModel . locationDisplay. accuracySymbol = $0 }
453
453
}
454
454
455
455
private func onSetLocationDisplayPingAnimationSymbol( _ call: FlutterMethodCall , _ result: @escaping FlutterResult ) {
456
- operationWithSymbol ( call, result) { mapContentView. mapViewModel . locationDisplay. pingAnimationSymbol = $0 }
456
+ operationWithSymbol ( call, result) { mapContentView. viewModel . locationDisplay. pingAnimationSymbol = $0 }
457
457
}
458
458
459
459
private func onSetLocationDisplayUseCourseSymbolOnMove( _ call: FlutterMethodCall , _ result: @escaping FlutterResult ) {
@@ -462,12 +462,12 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
462
462
return
463
463
}
464
464
465
- mapContentView. mapViewModel . locationDisplay. usesCourseSymbolOnMovement = active
465
+ mapContentView. viewModel . locationDisplay. usesCourseSymbolOnMovement = active
466
466
result ( true )
467
467
}
468
468
469
469
private func onUpdateLocationDisplaySourcePositionManually( _ call: FlutterMethodCall , _ result: @escaping FlutterResult ) {
470
- let dataSource = mapContentView. mapViewModel . locationDisplay. dataSource
470
+ let dataSource = mapContentView. viewModel . locationDisplay. dataSource
471
471
guard let source = dataSource as? CustomLocationDataSource < CustomLocationProvider > else {
472
472
result ( FlutterError ( code: " invalid_state " , message: " Expected ManualLocationDataSource but got \( dataSource) " , details: nil ) )
473
473
return
@@ -493,14 +493,14 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
493
493
return
494
494
}
495
495
496
- mapContentView. mapViewModel . locationDisplay. autoPanMode = autoPanMode
496
+ mapContentView. viewModel . locationDisplay. autoPanMode = autoPanMode
497
497
result ( true )
498
498
}
499
499
500
500
private func onGetAutoPanMode( _ call: FlutterMethodCall , _ result: @escaping FlutterResult ) {
501
501
// autoPanMode.rawValue is any of [0; 3]:
502
502
// https://developers.arcgis.com/ios/api-reference/_a_g_s_location_display_8h.html
503
- guard let stringName = mapContentView. mapViewModel . locationDisplay. autoPanMode. toName ( ) else {
503
+ guard let stringName = mapContentView. viewModel . locationDisplay. autoPanMode. toName ( ) else {
504
504
result ( FlutterError ( code: " invalid_data " , message: " AutoPanMode has invalid state " , details: nil ) )
505
505
return
506
506
}
@@ -513,16 +513,16 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
513
513
return
514
514
}
515
515
516
- mapContentView. mapViewModel . locationDisplay. wanderExtentFactor = Float ( factor)
516
+ mapContentView. viewModel . locationDisplay. wanderExtentFactor = Float ( factor)
517
517
result ( true )
518
518
}
519
519
520
520
private func onGetWanderExtentFactor( _ call: FlutterMethodCall , _ result: @escaping FlutterResult ) {
521
- return result ( mapContentView. mapViewModel . locationDisplay. wanderExtentFactor)
521
+ return result ( mapContentView. viewModel . locationDisplay. wanderExtentFactor)
522
522
}
523
523
524
524
private func onSetLocationDisplayDataSourceType( _ call: FlutterMethodCall , _ result: @escaping FlutterResult ) {
525
- if ( mapContentView. mapViewModel . locationDisplay. dataSource. status == . started) {
525
+ if ( mapContentView. viewModel . locationDisplay. dataSource. status == . started) {
526
526
result ( FlutterError ( code: " invalid_state " , message: " Current data source is running. Make sure to stop it before setting a new data source " , details: nil ) )
527
527
return
528
528
}
@@ -534,12 +534,12 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
534
534
535
535
switch ( type) {
536
536
case " manual " :
537
- mapContentView. mapViewModel . locationDisplay. dataSource = CustomLocationDataSource {
537
+ mapContentView. viewModel . locationDisplay. dataSource = CustomLocationDataSource {
538
538
return CustomLocationProvider ( )
539
539
}
540
540
result ( true )
541
541
case " system " :
542
- mapContentView. mapViewModel . locationDisplay. dataSource = SystemLocationDataSource ( )
542
+ mapContentView. viewModel . locationDisplay. dataSource = SystemLocationDataSource ( )
543
543
result ( true )
544
544
default :
545
545
result ( FlutterError ( code: " invalid_data " , message: " Unknown data source type \( String ( describing: type) ) " , details: nil ) )
@@ -552,14 +552,14 @@ class ArcgisMapView: NSObject, FlutterPlatformView {
552
552
return
553
553
}
554
554
555
- mapContentView. mapViewModel . attributionBarHidden = !isVisible
555
+ mapContentView. viewModel . attributionBarHidden = !isVisible
556
556
result ( true )
557
557
}
558
558
559
559
private func onExportImage( _ result: @escaping FlutterResult ) {
560
560
Task {
561
561
do {
562
- let image = try await mapContentView. mapViewModel . mapViewProxy!. exportImage ( )
562
+ let image = try await mapContentView. viewModel . mapViewProxy!. exportImage ( )
563
563
if let imageData = image. pngData ( ) {
564
564
result ( FlutterStandardTypedData ( bytes: imageData) )
565
565
} else {
0 commit comments