react-native-google-maps-plus 1.3.0-dev.1 → 1.3.0-dev.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt +107 -5
  2. package/android/src/main/java/com/rngooglemapsplus/LocationHandler.kt +0 -1
  3. package/android/src/main/java/com/rngooglemapsplus/RNGoogleMapsPlusView.kt +48 -4
  4. package/android/src/main/java/com/rngooglemapsplus/extensions/IndoorBuildingExtension.kt +33 -0
  5. package/android/src/main/java/com/rngooglemapsplus/extensions/RNLatLngBoundsExtension.kt +17 -0
  6. package/android/src/main/java/com/rngooglemapsplus/extensions/RNSize.kt +7 -0
  7. package/android/src/main/java/com/rngooglemapsplus/extensions/RNSnapshotFormat.kt +16 -0
  8. package/android/src/main/java/com/rngooglemapsplus/extensions/RNSnapshotResultType.kt +9 -0
  9. package/ios/GoogleMapViewImpl.swift +277 -121
  10. package/ios/RNGoogleMapsPlusView.swift +78 -27
  11. package/ios/extensions/IndoorBuilding+Extension.swift +33 -0
  12. package/ios/extensions/RNLatLngBounds+Extension.swift +16 -0
  13. package/ios/extensions/RNSize+Extension.swift +7 -0
  14. package/ios/extensions/RNSnapshotFormat+Extension.swift +28 -0
  15. package/ios/extensions/RNSnapshotResultType+Extension.swift +12 -0
  16. package/lib/module/types.js.map +1 -1
  17. package/lib/typescript/src/RNGoogleMapsPlusView.nitro.d.ts +8 -3
  18. package/lib/typescript/src/RNGoogleMapsPlusView.nitro.d.ts.map +1 -1
  19. package/lib/typescript/src/types.d.ts +25 -1
  20. package/lib/typescript/src/types.d.ts.map +1 -1
  21. package/nitrogen/generated/android/RNGoogleMapsPlusOnLoad.cpp +4 -0
  22. package/nitrogen/generated/android/c++/JFunc_void_RNIndoorBuilding.hpp +81 -0
  23. package/nitrogen/generated/android/c++/JFunc_void_RNIndoorLevel.hpp +78 -0
  24. package/nitrogen/generated/android/c++/JHybridRNGoogleMapsPlusViewSpec.cpp +99 -7
  25. package/nitrogen/generated/android/c++/JHybridRNGoogleMapsPlusViewSpec.hpp +9 -2
  26. package/nitrogen/generated/android/c++/JRNIndoorBuilding.hpp +86 -0
  27. package/nitrogen/generated/android/c++/JRNIndoorLevel.hpp +66 -0
  28. package/nitrogen/generated/android/c++/JRNLatLngBounds.hpp +58 -0
  29. package/nitrogen/generated/android/c++/JRNSize.hpp +57 -0
  30. package/nitrogen/generated/android/c++/JRNSnapshotFormat.hpp +62 -0
  31. package/nitrogen/generated/android/c++/JRNSnapshotOptions.hpp +71 -0
  32. package/nitrogen/generated/android/c++/JRNSnapshotResultType.hpp +59 -0
  33. package/nitrogen/generated/android/c++/views/JHybridRNGoogleMapsPlusViewStateUpdater.cpp +8 -0
  34. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/Func_void_RNIndoorBuilding.kt +81 -0
  35. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/Func_void_RNIndoorLevel.kt +81 -0
  36. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/HybridRNGoogleMapsPlusViewSpec.kt +42 -2
  37. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNIndoorBuilding.kt +38 -0
  38. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNIndoorLevel.kt +38 -0
  39. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNLatLngBounds.kt +32 -0
  40. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNSize.kt +32 -0
  41. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNSnapshotFormat.kt +22 -0
  42. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNSnapshotOptions.kt +38 -0
  43. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNSnapshotResultType.kt +21 -0
  44. package/nitrogen/generated/ios/RNGoogleMapsPlus-Swift-Cxx-Bridge.cpp +16 -0
  45. package/nitrogen/generated/ios/RNGoogleMapsPlus-Swift-Cxx-Bridge.hpp +148 -0
  46. package/nitrogen/generated/ios/RNGoogleMapsPlus-Swift-Cxx-Umbrella.hpp +21 -0
  47. package/nitrogen/generated/ios/c++/HybridRNGoogleMapsPlusViewSpecSwift.hpp +60 -5
  48. package/nitrogen/generated/ios/c++/views/HybridRNGoogleMapsPlusViewComponent.mm +10 -0
  49. package/nitrogen/generated/ios/swift/Func_void_RNIndoorBuilding.swift +47 -0
  50. package/nitrogen/generated/ios/swift/Func_void_RNIndoorLevel.swift +47 -0
  51. package/nitrogen/generated/ios/swift/HybridRNGoogleMapsPlusViewSpec.swift +7 -2
  52. package/nitrogen/generated/ios/swift/HybridRNGoogleMapsPlusViewSpec_cxx.swift +122 -4
  53. package/nitrogen/generated/ios/swift/RNIndoorBuilding.swift +116 -0
  54. package/nitrogen/generated/ios/swift/RNIndoorLevel.swift +118 -0
  55. package/nitrogen/generated/ios/swift/RNLatLngBounds.swift +46 -0
  56. package/nitrogen/generated/ios/swift/RNSize.swift +46 -0
  57. package/nitrogen/generated/ios/swift/RNSnapshotFormat.swift +44 -0
  58. package/nitrogen/generated/ios/swift/RNSnapshotOptions.swift +87 -0
  59. package/nitrogen/generated/ios/swift/RNSnapshotResultType.swift +40 -0
  60. package/nitrogen/generated/shared/c++/HybridRNGoogleMapsPlusViewSpec.cpp +7 -0
  61. package/nitrogen/generated/shared/c++/HybridRNGoogleMapsPlusViewSpec.hpp +22 -3
  62. package/nitrogen/generated/shared/c++/RNIndoorBuilding.hpp +82 -0
  63. package/nitrogen/generated/shared/c++/RNIndoorLevel.hpp +80 -0
  64. package/nitrogen/generated/shared/c++/RNLatLngBounds.hpp +72 -0
  65. package/nitrogen/generated/shared/c++/RNSize.hpp +71 -0
  66. package/nitrogen/generated/shared/c++/RNSnapshotFormat.hpp +80 -0
  67. package/nitrogen/generated/shared/c++/RNSnapshotOptions.hpp +87 -0
  68. package/nitrogen/generated/shared/c++/RNSnapshotResultType.hpp +76 -0
  69. package/nitrogen/generated/shared/c++/views/HybridRNGoogleMapsPlusViewComponent.cpp +24 -0
  70. package/nitrogen/generated/shared/c++/views/HybridRNGoogleMapsPlusViewComponent.hpp +4 -0
  71. package/nitrogen/generated/shared/json/RNGoogleMapsPlusViewConfig.json +2 -0
  72. package/package.json +1 -1
  73. package/src/RNGoogleMapsPlusView.nitro.ts +19 -2
  74. package/src/types.ts +38 -2
@@ -3,7 +3,8 @@ import GoogleMaps
3
3
  import GoogleMapsUtils
4
4
  import UIKit
5
5
 
6
- final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
6
+ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate,
7
+ GMSIndoorDisplayDelegate {
7
8
 
8
9
  private let locationHandler: LocationHandler
9
10
  private let markerBuilder: MapMarkerBuilder
@@ -40,6 +41,7 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
40
41
  setupAppLifecycleObservers()
41
42
  }
42
43
 
44
+ @MainActor
43
45
  private func setupAppLifecycleObservers() {
44
46
  NotificationCenter.default.addObserver(
45
47
  self,
@@ -81,6 +83,7 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
81
83
  mapReady = true
82
84
  }
83
85
 
86
+ @MainActor
84
87
  private func initLocationCallbacks() {
85
88
  locationHandler.onUpdate = { [weak self] loc in
86
89
  guard let self = self else { return }
@@ -136,7 +139,10 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
136
139
  myLocationEnabled.map { mapView?.isMyLocationEnabled = $0 }
137
140
  buildingEnabled.map { mapView?.isBuildingsEnabled = $0 }
138
141
  trafficEnabled.map { mapView?.isTrafficEnabled = $0 }
139
- indoorEnabled.map { mapView?.isIndoorEnabled = $0 }
142
+ indoorEnabled.map {
143
+ mapView?.isIndoorEnabled = $0
144
+ mapView?.indoorDisplay.delegate = $0 == true ? self : nil
145
+ }
140
146
  customMapStyle.map { mapView?.mapStyle = $0 }
141
147
  mapType.map { mapView?.mapType = $0 }
142
148
  userInterfaceStyle.map { mapView?.overrideUserInterfaceStyle = $0 }
@@ -187,6 +193,7 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
187
193
  }
188
194
  }
189
195
 
196
+ @MainActor
190
197
  var currentCamera: GMSCameraPosition? {
191
198
  mapView?.camera
192
199
  }
@@ -236,6 +243,7 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
236
243
  var indoorEnabled: Bool? {
237
244
  didSet {
238
245
  mapView?.isIndoorEnabled = indoorEnabled ?? false
246
+ mapView?.indoorDisplay.delegate = indoorEnabled == true ? self : nil
239
247
  }
240
248
  }
241
249
 
@@ -263,7 +271,8 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
263
271
  }
264
272
  }
265
273
 
266
- @MainActor var mapPadding: RNMapPadding? {
274
+ @MainActor
275
+ var mapPadding: RNMapPadding? {
267
276
  didSet {
268
277
  mapView?.padding =
269
278
  mapPadding.map {
@@ -277,13 +286,15 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
277
286
  }
278
287
  }
279
288
 
280
- @MainActor var mapType: GMSMapViewType? {
289
+ @MainActor
290
+ var mapType: GMSMapViewType? {
281
291
  didSet {
282
292
  mapView?.mapType = mapType ?? .normal
283
293
  }
284
294
  }
285
295
 
286
- @MainActor var locationConfig: RNLocationConfig? {
296
+ @MainActor
297
+ var locationConfig: RNLocationConfig? {
287
298
  didSet {
288
299
  locationHandler.desiredAccuracy =
289
300
  locationConfig?.ios?.desiredAccuracy?.toCLLocationAccuracy
@@ -304,15 +315,18 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
304
315
  var onMarkerDragStart: ((String?, RNLatLng) -> Void)?
305
316
  var onMarkerDrag: ((String?, RNLatLng) -> Void)?
306
317
  var onMarkerDragEnd: ((String?, RNLatLng) -> Void)?
318
+ var onIndoorBuildingFocused: ((RNIndoorBuilding) -> Void)?
319
+ var onIndoorLevelActivated: ((RNIndoorLevel) -> Void)?
307
320
  var onCameraChangeStart: ((RNRegion, RNCamera, Bool) -> Void)?
308
321
  var onCameraChange: ((RNRegion, RNCamera, Bool) -> Void)?
309
322
  var onCameraChangeComplete: ((RNRegion, RNCamera, Bool) -> Void)?
310
323
 
311
- func setCamera(camera: GMSCameraPosition, animated: Bool, durationMS: Double) {
324
+ @MainActor
325
+ func setCamera(camera: GMSCameraPosition, animated: Bool, durationMs: Double) {
312
326
  if animated {
313
327
  withCATransaction(
314
328
  disableActions: false,
315
- duration: durationMS / 1000.0
329
+ duration: durationMs / 1000.0
316
330
  ) {
317
331
  mapView?.animate(to: camera)
318
332
  }
@@ -322,11 +336,12 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
322
336
  }
323
337
  }
324
338
 
339
+ @MainActor
325
340
  func setCameraToCoordinates(
326
341
  coordinates: [RNLatLng],
327
342
  padding: RNMapPadding,
328
343
  animated: Bool,
329
- durationMS: Double
344
+ durationMs: Double
330
345
  ) {
331
346
  if coordinates.isEmpty {
332
347
  return
@@ -362,7 +377,7 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
362
377
  if animated {
363
378
  withCATransaction(
364
379
  disableActions: false,
365
- duration: durationMS / 1000.0
380
+ duration: durationMs / 1000.0
366
381
  ) {
367
382
  mapView?.animate(with: update)
368
383
  }
@@ -371,6 +386,90 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
371
386
  }
372
387
  }
373
388
 
389
+ @MainActor
390
+ func setCameraBounds(_ bounds: GMSCoordinateBounds?) {
391
+ mapView?.cameraTargetBounds = bounds
392
+ }
393
+
394
+ @MainActor
395
+ func animateToBounds(
396
+ _ bounds: GMSCoordinateBounds,
397
+ padding: Double,
398
+ durationMs: Double,
399
+ lockBounds: Bool
400
+ ) {
401
+ if lockBounds {
402
+ mapView?.cameraTargetBounds = bounds
403
+ }
404
+
405
+ let update = GMSCameraUpdate.fit(bounds, withPadding: CGFloat(padding))
406
+ mapView?.animate(with: update)
407
+ }
408
+
409
+ @MainActor
410
+ func snapshot(
411
+ size: CGSize?,
412
+ format: String,
413
+ imageFormat: ImageFormat,
414
+ quality: CGFloat,
415
+ resultIsFile: Bool
416
+ ) -> NitroModules.Promise<String?> {
417
+ let promise = Promise<String?>()
418
+
419
+ DispatchQueue.main.async {
420
+ guard let mapView = self.mapView else {
421
+ promise.resolve(withResult: nil)
422
+ return
423
+ }
424
+
425
+ let renderer = UIGraphicsImageRenderer(bounds: mapView.bounds)
426
+ let image = renderer.image { ctx in
427
+ mapView.layer.render(in: ctx.cgContext)
428
+ }
429
+
430
+ var finalImage = image
431
+
432
+ size.map {
433
+ UIGraphicsBeginImageContextWithOptions($0, false, 0.0)
434
+ image.draw(in: CGRect(origin: .zero, size: $0))
435
+ finalImage = UIGraphicsGetImageFromCurrentImageContext() ?? image
436
+ UIGraphicsEndImageContext()
437
+ }
438
+
439
+ let data: Data?
440
+ switch imageFormat {
441
+ case .jpeg:
442
+ data = finalImage.jpegData(compressionQuality: quality)
443
+ case .png:
444
+ data = finalImage.pngData()
445
+ }
446
+
447
+ guard let imageData = data else {
448
+ promise.resolve(withResult: nil)
449
+ return
450
+ }
451
+
452
+ // Rückgabe
453
+ if resultIsFile {
454
+ let filename =
455
+ "map_snapshot_\(Int(Date().timeIntervalSince1970)).\(format)"
456
+ let fileURL = URL(fileURLWithPath: NSTemporaryDirectory())
457
+ .appendingPathComponent(filename)
458
+ do {
459
+ try imageData.write(to: fileURL)
460
+ promise.resolve(withResult: fileURL.path)
461
+ } catch {
462
+ promise.resolve(withResult: nil)
463
+ }
464
+ } else {
465
+ let base64 = imageData.base64EncodedString()
466
+ promise.resolve(withResult: "data:image/\(format);base64,\(base64)")
467
+ }
468
+ }
469
+
470
+ return promise
471
+ }
472
+
374
473
  @MainActor
375
474
  func addMarker(id: String, marker: GMSMarker) {
376
475
  if mapView == nil {
@@ -612,158 +711,215 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
612
711
  }
613
712
 
614
713
  func mapView(_ mapView: GMSMapView, willMove gesture: Bool) {
615
- let visibleRegion = mapView.projection.visibleRegion()
616
- let bounds = GMSCoordinateBounds(region: visibleRegion)
617
-
618
- let center = CLLocationCoordinate2D(
619
- latitude: (bounds.northEast.latitude + bounds.southWest.latitude) / 2.0,
620
- longitude: (bounds.northEast.longitude + bounds.southWest.longitude) / 2.0
621
- )
714
+ onMain {
715
+ let visibleRegion = mapView.projection.visibleRegion()
716
+ let bounds = GMSCoordinateBounds(region: visibleRegion)
717
+
718
+ let center = CLLocationCoordinate2D(
719
+ latitude: (bounds.northEast.latitude + bounds.southWest.latitude) / 2.0,
720
+ longitude: (bounds.northEast.longitude + bounds.southWest.longitude)
721
+ / 2.0
722
+ )
622
723
 
623
- let latDelta = bounds.northEast.latitude - bounds.southWest.latitude
624
- let lngDelta = bounds.northEast.longitude - bounds.southWest.longitude
724
+ let latDelta = bounds.northEast.latitude - bounds.southWest.latitude
725
+ let lngDelta = bounds.northEast.longitude - bounds.southWest.longitude
625
726
 
626
- let cp = mapView.camera
627
- let region = RNRegion(
628
- center: RNLatLng(center.latitude, center.longitude),
629
- latitudeDelta: latDelta,
630
- longitudeDelta: lngDelta
631
- )
632
- let cam = RNCamera(
633
- center: RNLatLng(
634
- latitude: cp.target.latitude,
635
- longitude: cp.target.longitude
636
- ),
637
- zoom: Double(cp.zoom),
638
- bearing: cp.bearing,
639
- tilt: cp.viewingAngle
640
- )
641
- cameraMoveReasonIsGesture = gesture
727
+ let cp = mapView.camera
728
+ let region = RNRegion(
729
+ center: RNLatLng(center.latitude, center.longitude),
730
+ latitudeDelta: latDelta,
731
+ longitudeDelta: lngDelta
732
+ )
733
+ let cam = RNCamera(
734
+ center: RNLatLng(
735
+ latitude: cp.target.latitude,
736
+ longitude: cp.target.longitude
737
+ ),
738
+ zoom: Double(cp.zoom),
739
+ bearing: cp.bearing,
740
+ tilt: cp.viewingAngle
741
+ )
742
+ self.cameraMoveReasonIsGesture = gesture
642
743
 
643
- onCameraChangeStart?(region, cam, gesture)
744
+ self.onCameraChangeStart?(region, cam, gesture)
745
+ }
644
746
  }
645
747
 
646
748
  func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
647
- if let last = lastSubmittedCameraPosition,
648
- last.target.latitude == position.target.latitude,
649
- last.target.longitude == position.target.longitude,
650
- last.zoom == position.zoom,
651
- last.bearing == position.bearing,
652
- last.viewingAngle == position.viewingAngle {
653
- return
654
- }
655
- let visibleRegion = mapView.projection.visibleRegion()
656
- let bounds = GMSCoordinateBounds(region: visibleRegion)
749
+ onMain {
750
+ if let last = self.lastSubmittedCameraPosition,
751
+ last.target.latitude == position.target.latitude,
752
+ last.target.longitude == position.target.longitude,
753
+ last.zoom == position.zoom,
754
+ last.bearing == position.bearing,
755
+ last.viewingAngle == position.viewingAngle {
756
+ return
757
+ }
657
758
 
658
- let center = CLLocationCoordinate2D(
659
- latitude: (bounds.northEast.latitude + bounds.southWest.latitude) / 2.0,
660
- longitude: (bounds.northEast.longitude + bounds.southWest.longitude) / 2.0
661
- )
759
+ self.lastSubmittedCameraPosition = position
760
+ let visibleRegion = mapView.projection.visibleRegion()
761
+ let bounds = GMSCoordinateBounds(region: visibleRegion)
662
762
 
663
- let latDelta = bounds.northEast.latitude - bounds.southWest.latitude
664
- let lngDelta = bounds.northEast.longitude - bounds.southWest.longitude
763
+ let center = CLLocationCoordinate2D(
764
+ latitude: (bounds.northEast.latitude + bounds.southWest.latitude) / 2.0,
765
+ longitude: (bounds.northEast.longitude + bounds.southWest.longitude)
766
+ / 2.0
767
+ )
665
768
 
666
- let cp = mapView.camera
667
- let region = RNRegion(
668
- center: RNLatLng(center.latitude, center.longitude),
669
- latitudeDelta: latDelta,
670
- longitudeDelta: lngDelta
671
- )
672
- let cam = RNCamera(
673
- center: RNLatLng(
674
- latitude: cp.target.latitude,
675
- longitude: cp.target.longitude
676
- ),
677
- zoom: Double(cp.zoom),
678
- bearing: cp.bearing,
679
- tilt: cp.viewingAngle
680
- )
681
- onCameraChange?(region, cam, cameraMoveReasonIsGesture)
682
- lastSubmittedCameraPosition = position
769
+ let latDelta = bounds.northEast.latitude - bounds.southWest.latitude
770
+ let lngDelta = bounds.northEast.longitude - bounds.southWest.longitude
771
+
772
+ let cp = mapView.camera
773
+ let region = RNRegion(
774
+ center: RNLatLng(center.latitude, center.longitude),
775
+ latitudeDelta: latDelta,
776
+ longitudeDelta: lngDelta
777
+ )
778
+ let cam = RNCamera(
779
+ center: RNLatLng(
780
+ latitude: cp.target.latitude,
781
+ longitude: cp.target.longitude
782
+ ),
783
+ zoom: Double(cp.zoom),
784
+ bearing: cp.bearing,
785
+ tilt: cp.viewingAngle
786
+ )
787
+ self.onCameraChange?(region, cam, self.cameraMoveReasonIsGesture)
788
+ }
683
789
  }
684
790
 
685
791
  func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) {
686
- let visibleRegion = mapView.projection.visibleRegion()
687
- let bounds = GMSCoordinateBounds(region: visibleRegion)
688
-
689
- let center = CLLocationCoordinate2D(
690
- latitude: (bounds.northEast.latitude + bounds.southWest.latitude) / 2.0,
691
- longitude: (bounds.northEast.longitude + bounds.southWest.longitude) / 2.0
692
- )
792
+ onMain {
793
+ let visibleRegion = mapView.projection.visibleRegion()
794
+ let bounds = GMSCoordinateBounds(region: visibleRegion)
795
+
796
+ let center = CLLocationCoordinate2D(
797
+ latitude: (bounds.northEast.latitude + bounds.southWest.latitude) / 2.0,
798
+ longitude: (bounds.northEast.longitude + bounds.southWest.longitude)
799
+ / 2.0
800
+ )
693
801
 
694
- let latDelta = bounds.northEast.latitude - bounds.southWest.latitude
695
- let lngDelta = bounds.northEast.longitude - bounds.southWest.longitude
802
+ let latDelta = bounds.northEast.latitude - bounds.southWest.latitude
803
+ let lngDelta = bounds.northEast.longitude - bounds.southWest.longitude
696
804
 
697
- let cp = mapView.camera
698
- let region = RNRegion(
699
- center: RNLatLng(center.latitude, center.longitude),
700
- latitudeDelta: latDelta,
701
- longitudeDelta: lngDelta
702
- )
703
- let cam = RNCamera(
704
- center: RNLatLng(
705
- latitude: cp.target.latitude,
706
- longitude: cp.target.longitude
707
- ),
708
- zoom: Double(cp.zoom),
709
- bearing: cp.bearing,
710
- tilt: cp.viewingAngle
711
- )
712
- onCameraChangeComplete?(region, cam, cameraMoveReasonIsGesture)
805
+ let cp = mapView.camera
806
+ let region = RNRegion(
807
+ center: RNLatLng(center.latitude, center.longitude),
808
+ latitudeDelta: latDelta,
809
+ longitudeDelta: lngDelta
810
+ )
811
+ let cam = RNCamera(
812
+ center: RNLatLng(
813
+ latitude: cp.target.latitude,
814
+ longitude: cp.target.longitude
815
+ ),
816
+ zoom: Double(cp.zoom),
817
+ bearing: cp.bearing,
818
+ tilt: cp.viewingAngle
819
+ )
820
+ self.onCameraChangeComplete?(region, cam, self.cameraMoveReasonIsGesture)
821
+ }
713
822
  }
714
823
 
715
824
  func mapView(
716
825
  _ mapView: GMSMapView,
717
826
  didTapAt coordinate: CLLocationCoordinate2D
718
827
  ) {
719
- onMapPress?(
720
- RNLatLng(
721
- latitude: coordinate.latitude,
722
- longitude: coordinate.longitude
828
+ onMain {
829
+ self.onMapPress?(
830
+ RNLatLng(
831
+ latitude: coordinate.latitude,
832
+ longitude: coordinate.longitude
833
+ )
723
834
  )
724
- )
835
+ }
725
836
  }
726
837
 
727
838
  func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
728
- mapView.selectedMarker = marker
729
- onMarkerPress?(marker.userData as? String, )
839
+ onMain {
840
+ mapView.selectedMarker = marker
841
+ self.onMarkerPress?(marker.userData as? String, )
842
+ }
730
843
  return true
731
844
  }
732
845
 
733
846
  func mapView(_ mapView: GMSMapView, didTap overlay: GMSOverlay) {
734
- switch overlay {
735
- case let circle as GMSCircle:
736
- onCirclePress?(circle.userData as? String, )
847
+ onMain {
848
+ switch overlay {
849
+ case let circle as GMSCircle:
850
+ self.onCirclePress?(circle.userData as? String, )
737
851
 
738
- case let polygon as GMSPolygon:
739
- onPolygonPress?(polygon.userData as? String, )
852
+ case let polygon as GMSPolygon:
853
+ self.onPolygonPress?(polygon.userData as? String, )
740
854
 
741
- case let polyline as GMSPolyline:
742
- onPolylinePress?(polyline.userData as? String, )
855
+ case let polyline as GMSPolyline:
856
+ self.onPolylinePress?(polyline.userData as? String, )
743
857
 
744
- default:
745
- break
858
+ default:
859
+ break
860
+ }
746
861
  }
747
862
  }
748
863
 
749
864
  func mapView(_ mapView: GMSMapView, didBeginDragging marker: GMSMarker) {
750
- onMarkerDragStart?(
751
- marker.userData as? String,
752
- RNLatLng(marker.position.latitude, marker.position.longitude)
753
- )
865
+ onMain {
866
+ self.onMarkerDragStart?(
867
+ marker.userData as? String,
868
+ RNLatLng(marker.position.latitude, marker.position.longitude)
869
+ )
870
+ }
754
871
  }
755
872
 
756
873
  func mapView(_ mapView: GMSMapView, didDrag marker: GMSMarker) {
757
- onMarkerDrag?(
758
- marker.userData as? String,
759
- RNLatLng(marker.position.latitude, marker.position.longitude)
760
- )
874
+ onMain {
875
+ self.onMarkerDrag?(
876
+ marker.userData as? String,
877
+ RNLatLng(marker.position.latitude, marker.position.longitude)
878
+ )
879
+ }
761
880
  }
762
881
 
763
882
  func mapView(_ mapView: GMSMapView, didEndDragging marker: GMSMarker) {
764
- onMarkerDragEnd?(
765
- marker.userData as? String,
766
- RNLatLng(marker.position.latitude, marker.position.longitude)
767
- )
883
+ onMain {
884
+ self.onMarkerDragEnd?(
885
+ marker.userData as? String,
886
+ RNLatLng(marker.position.latitude, marker.position.longitude)
887
+ )
888
+ }
889
+ }
890
+
891
+ func didChangeActiveBuilding(_ building: GMSIndoorBuilding?) {
892
+ onMain {
893
+ guard let display = self.mapView?.indoorDisplay, let building else {
894
+ return
895
+ }
896
+ self.onIndoorBuildingFocused?(building.toRNIndoorBuilding(from: display))
897
+ }
898
+ }
899
+
900
+ func didChangeActiveLevel(_ level: GMSIndoorLevel?) {
901
+ onMain {
902
+ guard
903
+ let display = self.mapView?.indoorDisplay,
904
+ let building = display.activeBuilding,
905
+ let level,
906
+ let index = building.levels.firstIndex(where: {
907
+ $0.name == level.name && $0.shortName == level.shortName
908
+ })
909
+ else { return }
910
+
911
+ self.onIndoorLevelActivated?(
912
+ level.toRNIndoorLevel(index: index, active: true)
913
+ )
914
+ }
915
+ }
916
+ }
917
+
918
+ @inline(__always)
919
+ func onMain(_ block: @escaping () -> Void) {
920
+ if Thread.isMainThread {
921
+ block()
922
+ } else {
923
+ DispatchQueue.main.async { block() }
768
924
  }
769
925
  }