@rnmapbox/maps 10.0.15-rc.1 → 10.1.0-beta.2

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 (88) hide show
  1. package/android/build.gradle +20 -0
  2. package/android/src/main/java-v10/com/mapbox/rctmgl/RCTMGLPackage.java +109 -12
  3. package/android/src/main/java-v10/com/mapbox/rctmgl/components/AbstractEventEmitter.kt +2 -3
  4. package/android/src/main/java-v10/com/mapbox/rctmgl/components/mapview/NativeMapViewModule.kt +193 -0
  5. package/android/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLAndroidTextureMapViewManager.kt +16 -2
  6. package/android/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.kt +1 -1
  7. package/android/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapViewManager.kt +75 -160
  8. package/android/src/main/java-v10/com/mapbox/rctmgl/mapbox/Light.kt +6 -0
  9. package/android/src/main/old-arch/com/facebook/react/viewmanagers/MBXAndroidTextureMapViewManagerDelegate.java +89 -0
  10. package/android/src/main/old-arch/com/facebook/react/viewmanagers/MBXAndroidTextureMapViewManagerInterface.java +37 -0
  11. package/android/src/main/old-arch/com/facebook/react/viewmanagers/MBXMapViewManagerDelegate.java +89 -0
  12. package/android/src/main/old-arch/com/facebook/react/viewmanagers/MBXMapViewManagerInterface.java +37 -0
  13. package/android/src/main/old-arch/com/mapbox/rctmgl/NativeMapViewModuleSpec.java +88 -0
  14. package/ios/RCTMGL-v10/CustomHttpHeaders.swift +18 -0
  15. package/ios/RCTMGL-v10/MBXMapViewComponentView.h +18 -0
  16. package/ios/RCTMGL-v10/MBXMapViewComponentView.mm +203 -0
  17. package/ios/RCTMGL-v10/MBXMapViewManager.m +37 -0
  18. package/ios/RCTMGL-v10/MBXMapViewManager.swift +250 -0
  19. package/ios/RCTMGL-v10/MBXMapViewModule.h +18 -0
  20. package/ios/RCTMGL-v10/MBXMapViewModule.mm +167 -0
  21. package/ios/RCTMGL-v10/MGLModule.swift +15 -1
  22. package/ios/RCTMGL-v10/MGLSnapshotModule.swift +7 -1
  23. package/ios/RCTMGL-v10/RCTMGLAtmosphere.swift +4 -0
  24. package/ios/RCTMGL-v10/RCTMGLBackgroundLayer.swift +2 -1
  25. package/ios/RCTMGL-v10/RCTMGLCamera.swift +23 -0
  26. package/ios/RCTMGL-v10/RCTMGLCircleLayer.swift +4 -0
  27. package/ios/RCTMGL-v10/RCTMGLFillExtrustionLayer.swift +4 -0
  28. package/ios/RCTMGL-v10/RCTMGLFillLayer.swift +4 -0
  29. package/ios/RCTMGL-v10/RCTMGLHeatmapLayer.swift +4 -1
  30. package/ios/RCTMGL-v10/RCTMGLImageSource.swift +4 -0
  31. package/ios/RCTMGL-v10/RCTMGLImages.swift +14 -2
  32. package/ios/RCTMGL-v10/RCTMGLLayer.swift +35 -11
  33. package/ios/RCTMGL-v10/RCTMGLLight.swift +14 -4
  34. package/ios/RCTMGL-v10/RCTMGLLineLayer.swift +4 -0
  35. package/ios/RCTMGL-v10/RCTMGLLocationModule.swift +65 -12
  36. package/ios/RCTMGL-v10/RCTMGLLocationModuleV11.swift +32 -0
  37. package/ios/RCTMGL-v10/RCTMGLMapView.swift +115 -27
  38. package/ios/RCTMGL-v10/RCTMGLNativeUserLocation.swift +4 -0
  39. package/ios/RCTMGL-v10/RCTMGLOfflineModule.swift +17 -0
  40. package/ios/RCTMGL-v10/RCTMGLRasterDemSource.swift +4 -0
  41. package/ios/RCTMGL-v10/RCTMGLRasterLayer.swift +4 -0
  42. package/ios/RCTMGL-v10/RCTMGLRasterSource.swift +4 -0
  43. package/ios/RCTMGL-v10/RCTMGLShapeSource.swift +65 -3
  44. package/ios/RCTMGL-v10/RCTMGLSource.swift +4 -0
  45. package/ios/RCTMGL-v10/RCTMGLStyleValue.swift +60 -1
  46. package/ios/RCTMGL-v10/RCTMGLSymbolLayer.swift +4 -0
  47. package/ios/RCTMGL-v10/RCTMGLVectorSource.swift +4 -0
  48. package/ios/RCTMGL-v10/rnmapbox_maps.h +1 -0
  49. package/lib/commonjs/components/MapView.js +47 -11
  50. package/lib/commonjs/components/MapView.js.map +1 -1
  51. package/lib/commonjs/specs/MBXAndroidTextureMapViewNativeComponent.js +13 -0
  52. package/lib/commonjs/specs/MBXAndroidTextureMapViewNativeComponent.js.map +1 -0
  53. package/lib/commonjs/specs/MBXMapViewNativeComponent.js +11 -0
  54. package/lib/commonjs/specs/MBXMapViewNativeComponent.js.map +1 -0
  55. package/lib/commonjs/specs/NativeMapViewModule.js +11 -0
  56. package/lib/commonjs/specs/NativeMapViewModule.js.map +1 -0
  57. package/lib/commonjs/specs/codegenUtils.js +2 -0
  58. package/lib/commonjs/specs/codegenUtils.js.map +1 -0
  59. package/lib/module/components/MapView.js +47 -10
  60. package/lib/module/components/MapView.js.map +1 -1
  61. package/lib/module/specs/MBXAndroidTextureMapViewNativeComponent.js +5 -0
  62. package/lib/module/specs/MBXAndroidTextureMapViewNativeComponent.js.map +1 -0
  63. package/lib/module/specs/MBXMapViewNativeComponent.js +3 -0
  64. package/lib/module/specs/MBXMapViewNativeComponent.js.map +1 -0
  65. package/lib/module/specs/NativeMapViewModule.js +5 -0
  66. package/lib/module/specs/NativeMapViewModule.js.map +1 -0
  67. package/lib/module/specs/codegenUtils.js +2 -0
  68. package/lib/module/specs/codegenUtils.js.map +1 -0
  69. package/lib/typescript/components/MapView.d.ts +13 -3
  70. package/lib/typescript/components/MapView.d.ts.map +1 -1
  71. package/lib/typescript/specs/MBXAndroidTextureMapViewNativeComponent.d.ts +52 -0
  72. package/lib/typescript/specs/MBXAndroidTextureMapViewNativeComponent.d.ts.map +1 -0
  73. package/lib/typescript/specs/MBXMapViewNativeComponent.d.ts +52 -0
  74. package/lib/typescript/specs/MBXMapViewNativeComponent.d.ts.map +1 -0
  75. package/lib/typescript/specs/NativeMapViewModule.d.ts +21 -0
  76. package/lib/typescript/specs/NativeMapViewModule.d.ts.map +1 -0
  77. package/lib/typescript/specs/codegenUtils.d.ts +2 -0
  78. package/lib/typescript/specs/codegenUtils.d.ts.map +1 -0
  79. package/package.json +9 -1
  80. package/rnmapbox-maps.podspec +22 -4
  81. package/setup-jest.js +16 -0
  82. package/src/components/MapView.tsx +56 -12
  83. package/src/specs/MBXAndroidTextureMapViewNativeComponent.ts +63 -0
  84. package/src/specs/MBXMapViewNativeComponent.ts +63 -0
  85. package/src/specs/NativeMapViewModule.ts +54 -0
  86. package/src/specs/codegenUtils.ts +4 -0
  87. package/ios/RCTMGL-v10/RCTMGLMapViewManager.m +0 -107
  88. package/ios/RCTMGL-v10/RCTMGLMapViewManager.swift +0 -285
@@ -0,0 +1,167 @@
1
+ #import <React/RCTBridge.h>
2
+ #import <React/RCTUIManager.h>
3
+ #import <React/RCTUIManagerUtils.h>
4
+
5
+ #import "MBXMapViewModule.h"
6
+ #ifdef RCT_NEW_ARCH_ENABLED
7
+ #import "MBXMapViewComponentView.h"
8
+ #endif // RCT_NEW_ARCH_ENABLED
9
+
10
+ // needed for compilation for some reason
11
+ #import <CoreFoundation/CoreFoundation.h>
12
+ #import <CoreLocation/CoreLocation.h>
13
+
14
+ @interface MapView : UIView
15
+ @end
16
+
17
+ #import <rnmapbox_maps-Swift.h>
18
+
19
+
20
+ @implementation MBXMapViewModule
21
+
22
+ RCT_EXPORT_MODULE();
23
+
24
+ #ifdef RCT_NEW_ARCH_ENABLED
25
+ @synthesize viewRegistry_DEPRECATED = _viewRegistry_DEPRECATED;
26
+ #endif // RCT_NEW_ARCH_ENABLED
27
+ @synthesize bridge = _bridge;
28
+
29
+ - (dispatch_queue_t)methodQueue
30
+ {
31
+ // It seems that due to how UIBlocks work with uiManager, we need to call the methods there
32
+ // for the blocks to be dispatched before the batch is completed
33
+ return RCTGetUIManagerQueue();
34
+ }
35
+
36
+ - (void)withMapView:(NSNumber*)viewRef block:(void (^)(MBXMapView *))block reject:(RCTPromiseRejectBlock)reject methodName:(NSString *)methodName
37
+ {
38
+ // void (^upperBlock)(void) = ^{
39
+ #ifdef RCT_NEW_ARCH_ENABLED
40
+ [self.viewRegistry_DEPRECATED addUIBlock:^(RCTViewRegistry *viewRegistry) {
41
+ MBXMapViewComponentView *componentView = [self.viewRegistry_DEPRECATED viewForReactTag:viewRef];
42
+ MBXMapView *view = componentView.contentView;
43
+
44
+ #else
45
+ [self.bridge.uiManager
46
+ addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
47
+ MBXMapView *view = [uiManager viewForReactTag:viewRef];
48
+ #endif // RCT_NEW_ARCH_ENABLED
49
+ if (view != nil) {
50
+ block(view);
51
+ } else {
52
+ reject(methodName, [NSString stringWithFormat:@"Unknown reactTag: %@", viewRef], nil);
53
+ }
54
+ }];
55
+ // [self.bridge performSelector:@selector(batchDidComplete) withObject:self.bridge];
56
+ // };
57
+ // if (self.bridge) {
58
+ // dispatch_async(RCTGetUIManagerQueue(), upperBlock);
59
+ // } else {
60
+ // dispatch_async(dispatch_get_main_queue(), upperBlock);
61
+ // }
62
+ }
63
+
64
+
65
+ RCT_EXPORT_METHOD(takeSnap:(NSNumber*)viewRef writeToDisk:(BOOL)writeToDisk resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
66
+ {
67
+ [self withMapView:viewRef block:^(MBXMapView *view) {
68
+ [MBXMapViewManager takeSnap:view writeToDisk:writeToDisk resolver:resolve];
69
+ } reject:reject methodName:@"takeSnap"];
70
+ }
71
+
72
+ RCT_EXPORT_METHOD(clearData:(NSNumber*)viewRef resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
73
+ [self withMapView:viewRef block:^(MBXMapView *view) {
74
+ [MBXMapViewManager clearData:view resolver:resolve rejecter:reject];
75
+ } reject:reject methodName:@"clearData"];
76
+ }
77
+
78
+
79
+ RCT_EXPORT_METHOD(getCenter:(NSNumber*)viewRef resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
80
+ [self withMapView:viewRef block:^(MBXMapView *view) {
81
+ [MBXMapViewManager getCenter:view resolver:resolve rejecter:reject];
82
+ } reject:reject methodName:@"getCenter"];
83
+ }
84
+
85
+
86
+ RCT_EXPORT_METHOD(getCoordinateFromView:(NSNumber*)viewRef atPoint:(NSArray *)atPoint resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
87
+ [self withMapView:viewRef block:^(MBXMapView *view) {
88
+ NSNumber* a = [atPoint objectAtIndex:0];
89
+ NSNumber* b = [atPoint objectAtIndex:1];
90
+
91
+ [MBXMapViewManager getCoordinateFromView:view atPoint:CGPointMake(a.floatValue, b.floatValue) resolver:resolve rejecter:reject];
92
+ } reject:reject methodName:@"getCoordinateFromView"];
93
+ }
94
+
95
+
96
+ RCT_EXPORT_METHOD(getPointInView:(nonnull NSNumber*)viewRef atCoordinate:(NSArray *)atCoordinate resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
97
+ [self withMapView:viewRef block:^(MBXMapView *view) {
98
+ [MBXMapViewManager getPointInView:view atCoordinate:atCoordinate resolver:resolve rejecter:reject];
99
+ } reject:reject methodName:@"getPointInView"];
100
+ }
101
+
102
+
103
+ RCT_EXPORT_METHOD(getVisibleBounds:(NSNumber*)viewRef resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
104
+ [self withMapView:viewRef block:^(MBXMapView *view) {
105
+ [MBXMapViewManager getVisibleBounds:view resolver:resolve];
106
+ } reject:reject methodName:@"getVisibleBounds"];
107
+ }
108
+
109
+
110
+ RCT_EXPORT_METHOD(getZoom:(NSNumber*)viewRef resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
111
+ [self withMapView:viewRef block:^(MBXMapView *view) {
112
+ [MBXMapViewManager getZoom:view resolver:resolve rejecter:reject];
113
+ } reject:reject methodName:@"getZoom"];
114
+ }
115
+
116
+
117
+ RCT_EXPORT_METHOD(queryRenderedFeaturesAtPoint:(nonnull NSNumber*)viewRef atPoint:(nonnull NSArray *)atPoint withFilter:(NSArray *)withFilter withLayerIDs:(NSArray *)withLayerIDs resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
118
+ [self withMapView:viewRef block:^(MBXMapView *view) {
119
+ [MBXMapViewManager queryRenderedFeaturesAtPoint:view atPoint:atPoint withFilter:withFilter withLayerIDs:withLayerIDs resolver:resolve rejecter:reject];
120
+ } reject:reject methodName:@"queryRenderedFeaturesAtPoint"];
121
+ }
122
+
123
+
124
+ RCT_EXPORT_METHOD(queryRenderedFeaturesInRect:(nonnull NSNumber*)viewRef withBBox:(NSArray *)withBBox withFilter:(NSArray *)withFilter withLayerIDs:(NSArray *)withLayerIDs resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
125
+ [self withMapView:viewRef block:^(MBXMapView *view) {
126
+ [MBXMapViewManager queryRenderedFeaturesInRect:view withBBox:withBBox withFilter:withFilter withLayerIDs:withLayerIDs resolver:resolve rejecter:reject];
127
+ } reject:reject methodName:@"queryRenderedFeaturesInRect"];
128
+ }
129
+
130
+
131
+ RCT_EXPORT_METHOD(queryTerrainElevation:(nonnull NSNumber*)viewRef coordinates:(NSArray *)coordinates resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
132
+ [self withMapView:viewRef block:^(MBXMapView *view) {
133
+ [MBXMapViewManager queryTerrainElevation:view coordinates:coordinates resolver:resolve rejecter:reject];
134
+ } reject:reject methodName:@"queryTerrainElevation"];
135
+ }
136
+
137
+
138
+ RCT_EXPORT_METHOD(setHandledMapChangedEvents:(nonnull NSNumber*)viewRef events:(NSArray *)events resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
139
+ [self withMapView:viewRef block:^(MBXMapView *view) {
140
+ [MBXMapViewManager setHandledMapChangedEvents:view events:events resolver:resolve rejecter:reject];
141
+ } reject:reject methodName:@"setHandledMapChangedEvents"];
142
+ }
143
+
144
+
145
+ RCT_EXPORT_METHOD(setSourceVisibility:(nonnull NSNumber*)viewRef visible:(BOOL)visible sourceId:(NSString *)sourceId sourceLayerId:(NSString *)sourceLayerId resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
146
+ [self withMapView:viewRef block:^(MBXMapView *view) {
147
+ [MBXMapViewManager setSourceVisibility:view visible:visible sourceId:sourceId sourceLayerId:sourceLayerId resolver:resolve rejecter:reject];
148
+ } reject:reject methodName:@"setSourceVisibility"];
149
+ }
150
+
151
+ RCT_EXPORT_METHOD(querySourceFeatures:(nonnull NSNumber*)viewRef sourceId:(NSString*)sourceId withFilter:(NSArray<id>*)withFilter withSourceLayerIDs:(NSArray<NSString*>*)withSourceLayerIDs resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
152
+ [self withMapView:viewRef block:^(MBXMapView *view) {
153
+ [MBXMapViewManager querySourceFeatures:view withSourceId:sourceId withFilter:withFilter withSourceLayerIds:withSourceLayerIDs resolver:resolve rejecter:reject];
154
+ } reject:reject methodName:@"querySourceFeatures"];
155
+ }
156
+
157
+
158
+ // Thanks to this guard, we won't compile this code when we build for the old architecture.
159
+ #ifdef RCT_NEW_ARCH_ENABLED
160
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
161
+ (const facebook::react::ObjCTurboModule::InitParams &)params
162
+ {
163
+ return std::make_shared<facebook::react::NativeMapViewModuleSpecJSI>(params);
164
+ }
165
+ #endif // RCT_NEW_ARCH_ENABLED
166
+
167
+ @end
@@ -1,13 +1,25 @@
1
1
  import Foundation
2
2
  import MapboxMaps
3
+ #if canImport(MapboxMobileEvents)
3
4
  import MapboxMobileEvents
5
+ #endif
4
6
 
5
7
 
6
8
  let DEFAULT_SOURCE_ID = "composite";
7
9
 
8
10
  @objc(MGLModule)
9
11
  class MGLModule : NSObject {
10
- static var accessToken : String?
12
+ #if RNMBX_11
13
+ static var accessToken : String? {
14
+ didSet {
15
+ if let token = accessToken {
16
+ MapboxOptions.accessToken = token
17
+ }
18
+ }
19
+ }
20
+ #else
21
+ static var accessToken : String?
22
+ #endif
11
23
 
12
24
  @objc
13
25
  func constantsToExport() -> [AnyHashable: Any]! {
@@ -91,7 +103,9 @@ class MGLModule : NSObject {
91
103
  }
92
104
 
93
105
  @objc func setTelemetryEnabled(_ telemetryEnabled: Bool) {
106
+ #if !RNMBX_11 // RNMBX_11_TODO
94
107
  UserDefaults.mme_configuration().mme_isCollectionEnabled = telemetryEnabled
108
+ #endif
95
109
  }
96
110
 
97
111
  @objc func setWellKnownTileServer(_ tileServer: String) {
@@ -93,13 +93,19 @@ class MGLSnapshotModule : NSObject {
93
93
  let height = jsOptions["height"] as? NSNumber else {
94
94
  throw RCTMGLError.paramError("width, height: is not a number")
95
95
  }
96
-
96
+ #if RNMBX_11
97
+ let mapSnapshotOptions = MapSnapshotOptions(
98
+ size: CGSize(width: width.doubleValue, height: height.doubleValue),
99
+ pixelRatio: 1.0
100
+ )
101
+ #else
97
102
  let resourceOptions = ResourceOptions(accessToken: MGLModule.accessToken!)
98
103
  let mapSnapshotOptions = MapSnapshotOptions(
99
104
  size: CGSize(width: width.doubleValue, height: height.doubleValue),
100
105
  pixelRatio: 1.0,
101
106
  resourceOptions: resourceOptions
102
107
  )
108
+ #endif
103
109
 
104
110
  return mapSnapshotOptions
105
111
  }
@@ -1,5 +1,9 @@
1
1
  import MapboxMaps
2
2
 
3
+ #if RNMBX_11
4
+ typealias Style = StyleManager
5
+ #endif
6
+
3
7
  @objc(RCTMGLAtmosphere)
4
8
  class RCTMGLAtmosphere : RCTMGLSingletonLayer, RCTMGLMapComponent, RCTMGLSourceConsumer {
5
9
  var atmosphere : Atmosphere? = nil
@@ -5,10 +5,11 @@ class RCTMGLBackgroundLayer: RCTMGLLayer {
5
5
  typealias LayerType = BackgroundLayer
6
6
 
7
7
  override func makeLayer(style: Style) throws -> Layer {
8
- let vectorSource : VectorSource = try self.layerWithSourceID(in: style)
9
8
  var layer = LayerType(id: self.id!)
9
+ #if !RNMBX_11
10
10
  layer.sourceLayer = self.sourceLayerID
11
11
  layer.source = sourceID
12
+ #endif
12
13
  return layer
13
14
  }
14
15
 
@@ -2,6 +2,15 @@ import Foundation
2
2
  import MapboxMaps
3
3
  import Turf
4
4
 
5
+ #if RNMBX_11
6
+ extension NSNumber {
7
+ /// Converts an `NSNumber` to a `CGFloat` value from its `Double` representation.
8
+ internal var CGFloat: CGFloat {
9
+ CoreGraphics.CGFloat(doubleValue)
10
+ }
11
+ }
12
+ #endif
13
+
5
14
  enum RemovalReason {
6
15
  case ViewRemoval, StyleChange, OnDestroy, ComponentChange, Reorder
7
16
  }
@@ -279,16 +288,26 @@ class RCTMGLCamera : RCTMGLMapComponentBase {
279
288
 
280
289
  if let locationModule = RCTMGLLocationModule.shared {
281
290
  var isSameProvider = false
291
+ #if !RNMBX_11
282
292
  if let currentProvider = map.location.locationProvider as? AnyObject, let newProvider = locationModule.locationProvider as? AnyObject {
283
293
  if currentProvider === newProvider {
284
294
  isSameProvider = true
285
295
  }
286
296
  }
297
+ #endif
287
298
  if !isSameProvider {
299
+ #if RNMBX_11
300
+ map.location.override(provider: locationModule.locationProvider)
301
+ #else
288
302
  map.location.overrideLocationProvider(with: locationModule.locationProvider)
303
+ #endif
289
304
  }
290
305
  }
306
+ #if RNMBX_11
307
+ // RNMBX_11_TODO
308
+ #else
291
309
  map.location.locationProvider.requestWhenInUseAuthorization()
310
+ #endif
292
311
  var trackingModeChanged = false
293
312
  var followOptions = FollowPuckViewportStateOptions()
294
313
  switch userTrackingMode {
@@ -427,7 +446,11 @@ class RCTMGLCamera : RCTMGLMapComponentBase {
427
446
  }
428
447
 
429
448
  withMapView { map in
449
+ #if RNMBX_11
450
+ let bounds = [sw, ne]
451
+ #else
430
452
  let bounds = CoordinateBounds(southwest: sw, northeast: ne)
453
+ #endif
431
454
  let camera = map.mapboxMap.camera(
432
455
  for: bounds,
433
456
  padding: padding,
@@ -7,7 +7,11 @@ class RCTMGLCircleLayer: RCTMGLVectorLayer {
7
7
 
8
8
  override func makeLayer(style: Style) throws -> Layer {
9
9
  let _ : VectorSource = try self.layerWithSourceID(in: style)
10
+ #if RNMBX_11
11
+ var layer = LayerType(id: self.id!, source: self.sourceID!)
12
+ #else
10
13
  var layer = LayerType(id: self.id!)
14
+ #endif
11
15
  layer.sourceLayer = self.sourceLayerID
12
16
  layer.source = sourceID
13
17
  return layer
@@ -6,7 +6,11 @@ class RCTMGLFillExtrusionLayer: RCTMGLVectorLayer {
6
6
 
7
7
  override func makeLayer(style: Style) throws -> Layer {
8
8
  let _ : VectorSource = try self.layerWithSourceID(in: style)
9
+ #if RNMBX_11
10
+ var layer = LayerType(id: self.id!, source:sourceID!)
11
+ #else
9
12
  var layer = LayerType(id: self.id!)
13
+ #endif
10
14
  layer.sourceLayer = self.sourceLayerID
11
15
  layer.source = sourceID
12
16
  return layer
@@ -6,7 +6,11 @@ class RCTMGLFillLayer: RCTMGLVectorLayer {
6
6
 
7
7
  override func makeLayer(style: Style) throws -> Layer {
8
8
  let _ : VectorSource = try self.layerWithSourceID(in: style)
9
+ #if RNMBX_11
10
+ var layer: Layer = FillLayer(id: self.id!, source: sourceID!)
11
+ #else
9
12
  var layer: Layer = FillLayer(id: self.id!)
13
+ #endif
10
14
 
11
15
  setOptions(&layer)
12
16
 
@@ -6,8 +6,11 @@ class RCTMGLHeatmapLayer: RCTMGLVectorLayer {
6
6
 
7
7
  override func makeLayer(style: Style) throws -> Layer {
8
8
  let _ : VectorSource = try self.layerWithSourceID(in: style)
9
+ #if RNMBX_11
10
+ var layer: Layer = LayerType(id: self.id!, source: self.sourceID!)
11
+ #else
9
12
  var layer: Layer = LayerType(id: self.id!)
10
-
13
+ #endif
11
14
  setOptions(&layer)
12
15
 
13
16
  return layer
@@ -35,7 +35,11 @@ class RCTMGLImageSource : RCTMGLSource {
35
35
 
36
36
  override func makeSource() -> Source
37
37
  {
38
+ #if RNMBX_11
39
+ var result = ImageSource(id: self.id)
40
+ #else
38
41
  var result = ImageSource()
42
+ #endif
39
43
  if let url = url {
40
44
  result.url = url
41
45
  }
@@ -4,6 +4,18 @@ protocol RCTMGLImageSetter : AnyObject {
4
4
  func addImage(name: String, image: UIImage, sdf: Bool?, stretchX: [[NSNumber]], stretchY: [[NSNumber]], content: [NSNumber]?, log: String) -> Bool
5
5
  }
6
6
 
7
+ func hasImage(style: Style, name: String) -> Bool {
8
+ #if RNMBX_11
9
+ return style.imageExists(withId: name)
10
+ #else
11
+ return (style.styleManager.getStyleImage(forImageId: name) != nil)
12
+ #endif
13
+ }
14
+
15
+ #if RNMBX_11
16
+ typealias StyleImageMissingPayload = StyleImageMissing
17
+ #endif
18
+
7
19
  class RCTMGLImages : UIView, RCTMGLMapComponent {
8
20
 
9
21
  weak var bridge : RCTBridge! = nil
@@ -104,7 +116,7 @@ class RCTMGLImages : UIView, RCTMGLMapComponent {
104
116
  if !sameImage(oldValue: oldImages[name], newValue: images[name]) {
105
117
  missingImages[name] = images[name]
106
118
  } else {
107
- if style.styleManager.getStyleImage(forImageId: name) == nil {
119
+ if !hasImage(style: style, name: name) {
108
120
  logged("RCTMGLImages.addImagePlaceholder") {
109
121
  try? style.addImage(placeholderImage, id: name, stretchX: [], stretchY: [])
110
122
  missingImages[name] = images[name]
@@ -231,7 +243,7 @@ class RCTMGLImages : UIView, RCTMGLMapComponent {
231
243
  func addNativeImages(style: Style, nativeImages: [NativeImageInfo]) {
232
244
  for imageInfo in nativeImages {
233
245
  let imageName = imageInfo.name
234
- if style.styleManager.getStyleImage(forImageId: imageInfo.name) == nil {
246
+ if !hasImage(style: style, name: imageInfo.name) {
235
247
  if let image = UIImage(named: imageName) {
236
248
  logged("RCTMGLImage.addNativeImage: \(imageName)") {
237
249
  try style.addImage(image, id: imageName, sdf: imageInfo.sdf,
@@ -5,6 +5,14 @@ protocol RCTMGLSourceConsumer : class {
5
5
  func removeFromMap(_ map: RCTMGLMapView, style: Style)
6
6
  }
7
7
 
8
+ func styleLayerExists(_ style: Style, id: String) -> Bool {
9
+ #if RNMBX_11
10
+ return style.layerExists(withId: id)
11
+ #else
12
+ return style.styleManager.styleLayerExists(forLayerId: id)
13
+ #endif
14
+ }
15
+
8
16
  @objc(RCTMGLLayer)
9
17
  class RCTMGLLayer : UIView, RCTMGLMapComponent, RCTMGLSourceConsumer {
10
18
  weak var bridge : RCTBridge? = nil
@@ -129,7 +137,7 @@ class RCTMGLLayer : UIView, RCTMGLMapComponent, RCTMGLSourceConsumer {
129
137
  addStyles()
130
138
  if let style = style,
131
139
  let map = map {
132
- if style.styleManager.styleLayerExists(forLayerId: id) {
140
+ if styleLayerExists(style, id: id) {
133
141
  self.updateLayer(map)
134
142
  }
135
143
  }
@@ -215,7 +223,7 @@ class RCTMGLLayer : UIView, RCTMGLMapComponent, RCTMGLSourceConsumer {
215
223
  }
216
224
 
217
225
  do {
218
- if (style.styleManager.styleLayerExists(forLayerId: id)) {
226
+ if (styleLayerExists(style,id: id)) {
219
227
  styleLayer = try findLayer(style: style, id: id)
220
228
  existingLayer = true
221
229
  } else {
@@ -244,14 +252,25 @@ class RCTMGLLayer : UIView, RCTMGLMapComponent, RCTMGLSourceConsumer {
244
252
  removeFromMap(style)
245
253
  }
246
254
 
255
+ func setBaseOptions<T: Layer>(_ layer: inout T) {
256
+ if let minZoom = minZoomLevel {
257
+ layer.minZoom = minZoom.doubleValue
258
+ }
259
+
260
+ if let maxZoom = maxZoomLevel {
261
+ layer.maxZoom = maxZoom.doubleValue
262
+ }
263
+ }
264
+
247
265
  func setOptions(_ layer: inout Layer) {
266
+ setBaseOptions(&layer)
267
+ #if !RNMBX_11
248
268
  if let sourceLayerID = sourceLayerID {
249
269
  layer.sourceLayer = sourceLayerID
250
270
  }
251
271
 
252
272
  if let sourceID = sourceID {
253
273
  if !(existingLayer && sourceID == DEFAULT_SOURCE_ID) && hasSource() {
254
-
255
274
  layer.source = sourceID
256
275
  }
257
276
  }
@@ -265,14 +284,7 @@ class RCTMGLLayer : UIView, RCTMGLMapComponent, RCTMGLSourceConsumer {
265
284
  Logger.log(level: .error, message: "parsing filters failed for layer \(optional: id): \(error.localizedDescription)")
266
285
  }
267
286
  }
268
-
269
- if let minZoom = minZoomLevel {
270
- layer.minZoom = minZoom.doubleValue
271
- }
272
-
273
- if let maxZoom = maxZoomLevel {
274
- layer.maxZoom = maxZoom.doubleValue
275
- }
287
+ #endif
276
288
  }
277
289
 
278
290
  private func optionsChanged() {
@@ -341,3 +353,15 @@ class RCTMGLLayer : UIView, RCTMGLMapComponent, RCTMGLSourceConsumer {
341
353
  return true
342
354
  }
343
355
  }
356
+
357
+ #if RNMBX_11
358
+ protocol LayerWithSource : Layer {
359
+ var source: String? { get set }
360
+ var sourceLayer: String? { get set }
361
+ var filter: Expression? { get set}
362
+ }
363
+ #else
364
+ protocol LayerWithSource : Layer {
365
+
366
+ }
367
+ #endif
@@ -1,4 +1,8 @@
1
- import MapboxMaps
1
+ @_spi(Experimental) import MapboxMaps
2
+
3
+ #if RNMBX_11
4
+ typealias Light = FlatLight
5
+ #endif
2
6
 
3
7
  @objc(RCTMGLLight)
4
8
  class RCTMGLLight: UIView, RCTMGLMapComponent {
@@ -17,9 +21,15 @@ class RCTMGLLight: UIView, RCTMGLMapComponent {
17
21
  }
18
22
 
19
23
  func apply(light: Light) {
20
- let lightData = try! JSONEncoder().encode(light)
21
- let lightDictionary = try! JSONSerialization.jsonObject(with: lightData)
22
- try! self.map.style.setLight(properties: lightDictionary as! [String:Any])
24
+ logged("RCTMGLLight.apply") {
25
+ #if RNMBX_11
26
+ try self.map.setLights(light)
27
+ #else
28
+ let lightData = try JSONEncoder().encode(light)
29
+ let lightDictionary = try JSONSerialization.jsonObject(with: lightData)
30
+ try self.map.style.setLight(properties: lightDictionary as! [String:Any])
31
+ #endif
32
+ }
23
33
  }
24
34
 
25
35
  func addStyles() {
@@ -6,7 +6,11 @@ class RCTMGLLineLayer: RCTMGLVectorLayer {
6
6
 
7
7
  override func makeLayer(style: Style) throws -> Layer {
8
8
  let vectorSource : VectorSource = try self.layerWithSourceID(in: style)
9
+ #if RNMBX_11
10
+ var layer = LayerType(id: self.id!, source: sourceID!)
11
+ #else
9
12
  var layer = LayerType(id: self.id!)
13
+ #endif
10
14
  layer.sourceLayer = self.sourceLayerID
11
15
  layer.source = sourceID
12
16
  return layer
@@ -1,6 +1,8 @@
1
1
  import Foundation
2
2
  import MapboxMaps
3
3
 
4
+ #if !RNMBX_11
5
+
4
6
  @objc(RCTMGLLocation)
5
7
  class RCTMGLLocation: NSObject {
6
8
  var location : CLLocation = CLLocation(latitude: 0.0, longitude: 0.0)
@@ -32,6 +34,10 @@ let RCT_MAPBOX_USER_LOCATION_UPDATE = "MapboxUserLocationUpdate";
32
34
  /// This implementation of LocationProviderDelegate is used by `LocationManager` to work around
33
35
  /// the fact that the `LocationProvider` API does not allow the delegate to be set to `nil`.
34
36
  internal class EmptyLocationProviderDelegate: LocationProviderDelegate {
37
+ #if RNMBX_11
38
+ func onLocationUpdateReceived(for locations: [Location]) {}
39
+ #endif
40
+
35
41
  func locationProvider(_ provider: LocationProvider, didFailWithError error: Error) {}
36
42
  func locationProvider(_ provider: LocationProvider, didUpdateHeading newHeading: CLHeading) {}
37
43
  func locationProvider(_ provider: LocationProvider, didUpdateLocations locations: [CLLocation]) {}
@@ -44,6 +50,18 @@ protocol LocationProviderRCTMGLDelegate : AnyObject {
44
50
 
45
51
  class RCTMGLAppleLocationProvider: NSObject {
46
52
  private var locationProvider: CLLocationManager
53
+
54
+ #if RNMBX_11
55
+ private var observers : [LocationObserver] = []
56
+ private var privateAppleLocationProviderOptions: AppleLocationProvider.Options {
57
+ didSet {
58
+ locationProvider.distanceFilter = privateAppleLocationProviderOptions.distanceFilter
59
+ locationProvider.desiredAccuracy = privateAppleLocationProviderOptions.desiredAccuracy
60
+ locationProvider.activityType = privateAppleLocationProviderOptions.activityType
61
+ }
62
+ }
63
+ private var privateLocationProviderOptions: LocationOptions
64
+ #else
47
65
  private var privateLocationProviderOptions: LocationOptions {
48
66
  didSet {
49
67
  locationProvider.distanceFilter = privateLocationProviderOptions.distanceFilter
@@ -52,6 +70,7 @@ class RCTMGLAppleLocationProvider: NSObject {
52
70
  }
53
71
  }
54
72
  private weak var delegate: LocationProviderDelegate?
73
+ #endif
55
74
 
56
75
  public var headingOrientation: CLDeviceOrientation {
57
76
  didSet { locationProvider.headingOrientation = headingOrientation }
@@ -59,6 +78,9 @@ class RCTMGLAppleLocationProvider: NSObject {
59
78
 
60
79
  public override init() {
61
80
  locationProvider = CLLocationManager()
81
+ #if RNMBX_11
82
+ privateAppleLocationProviderOptions = AppleLocationProvider.Options()
83
+ #endif
62
84
  privateLocationProviderOptions = LocationOptions()
63
85
  headingOrientation = locationProvider.headingOrientation
64
86
  super.init()
@@ -67,6 +89,20 @@ class RCTMGLAppleLocationProvider: NSObject {
67
89
  }
68
90
 
69
91
  extension RCTMGLAppleLocationProvider: LocationProvider {
92
+ #if RNMBX_11
93
+ func addLocationObserver(for observer: LocationObserver) {
94
+ observers.append(observer)
95
+ }
96
+
97
+ func removeLocationObserver(for observer: LocationObserver) {
98
+ observers.removeAll { $0 === observer }
99
+ }
100
+
101
+ func getLastObservedLocation() -> Location? {
102
+ locationProvider.location
103
+ }
104
+ #endif
105
+
70
106
 
71
107
  public var locationProviderOptions: LocationOptions {
72
108
  get { privateLocationProviderOptions }
@@ -132,22 +168,38 @@ extension RCTMGLAppleLocationProvider: LocationProvider {
132
168
  }
133
169
 
134
170
  extension RCTMGLAppleLocationProvider: CLLocationManagerDelegate {
135
- public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
136
- delegate?.locationProvider(self, didUpdateLocations: locations)
137
- }
171
+ public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
172
+ #if RNMBX_11
173
+ observers.forEach { $0.onLocationUpdateReceived(for: locations) }
174
+ #else
175
+ delegate?.locationProvider(self, didUpdateLocations: locations)
176
+ #endif
177
+ }
138
178
 
139
- public func locationManager(_ manager: CLLocationManager, didUpdateHeading heading: CLHeading) {
140
- delegate?.locationProvider(self, didUpdateHeading: heading)
141
- }
179
+ public func locationManager(_ manager: CLLocationManager, didUpdateHeading heading: CLHeading)
180
+ {
181
+ #if RNMBX_11
182
+
183
+ #else
184
+ delegate?.locationProvider(self, didUpdateHeading: heading)
185
+ #endif
186
+ }
142
187
 
143
- public func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
144
- delegate?.locationProvider(self, didFailWithError: error)
145
- }
188
+ public func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
189
+ #if RNMBX_11
190
+
191
+ #else
192
+ delegate?.locationProvider(self, didFailWithError: error)
193
+ #endif
194
+ }
146
195
 
147
196
  @available(iOS 14.0, *)
148
- public func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
149
- delegate?.locationProviderDidChangeAuthorization(self)
150
- }
197
+ public func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
198
+ #if RNMBX_11
199
+ #else
200
+ delegate?.locationProviderDidChangeAuthorization(self)
201
+ #endif
202
+ }
151
203
 
152
204
  public func locationManagerShouldDisplayHeadingCalibration(_ manager: CLLocationManager) -> Bool {
153
205
  guard let calibratingDelegate = delegate as? CalibratingLocationProviderDelegate else {
@@ -573,4 +625,5 @@ class RCTMGLLocationModule: RCTEventEmitter, LocationProviderRCTMGLDelegate {
573
625
  }
574
626
  }
575
627
 
628
+ #endif
576
629