@maplibre/maplibre-react-native 10.1.0 → 10.1.1

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 (152) hide show
  1. package/ios/MLRN/CameraStop.h +1 -1
  2. package/ios/MLRN/CameraStop.m +58 -60
  3. package/ios/MLRN/CameraUpdateItem.h +2 -1
  4. package/ios/MLRN/CameraUpdateItem.m +132 -132
  5. package/ios/MLRN/CameraUpdateQueue.m +43 -47
  6. package/ios/MLRN/FilterParser.h +1 -1
  7. package/ios/MLRN/FilterParser.m +5 -6
  8. package/ios/MLRN/MLRNBackgroundLayer.m +10 -9
  9. package/ios/MLRN/MLRNBackgroundLayerManager.m +4 -5
  10. package/ios/MLRN/MLRNCallout.h +1 -1
  11. package/ios/MLRN/MLRNCallout.m +37 -36
  12. package/ios/MLRN/MLRNCalloutManager.m +2 -3
  13. package/ios/MLRN/MLRNCamera.h +1 -1
  14. package/ios/MLRN/MLRNCamera.m +169 -182
  15. package/ios/MLRN/MLRNCameraManager.m +4 -6
  16. package/ios/MLRN/MLRNCircleLayer.m +17 -14
  17. package/ios/MLRN/MLRNCircleLayerManager.m +4 -5
  18. package/ios/MLRN/MLRNCustomHeaders.h +2 -2
  19. package/ios/MLRN/MLRNCustomHeaders.m +63 -63
  20. package/ios/MLRN/MLRNEvent.h +3 -3
  21. package/ios/MLRN/MLRNEvent.m +19 -24
  22. package/ios/MLRN/MLRNEventProtocol.h +1 -1
  23. package/ios/MLRN/MLRNFillExtrusionLayer.m +18 -14
  24. package/ios/MLRN/MLRNFillExtrusionLayerManager.m +4 -5
  25. package/ios/MLRN/MLRNFillLayer.m +16 -14
  26. package/ios/MLRN/MLRNFillLayerManager.m +4 -5
  27. package/ios/MLRN/MLRNHeatmapLayer.m +17 -14
  28. package/ios/MLRN/MLRNHeatmapLayerManager.m +4 -5
  29. package/ios/MLRN/MLRNImageQueue.h +4 -1
  30. package/ios/MLRN/MLRNImageQueue.m +29 -32
  31. package/ios/MLRN/MLRNImageQueueOperation.h +1 -1
  32. package/ios/MLRN/MLRNImageQueueOperation.m +92 -91
  33. package/ios/MLRN/MLRNImageSource.m +36 -38
  34. package/ios/MLRN/MLRNImageSourceManager.m +2 -3
  35. package/ios/MLRN/MLRNImageUtils.h +3 -3
  36. package/ios/MLRN/MLRNImageUtils.m +15 -14
  37. package/ios/MLRN/MLRNImages.h +0 -1
  38. package/ios/MLRN/MLRNImages.m +89 -91
  39. package/ios/MLRN/MLRNImagesManager.m +4 -5
  40. package/ios/MLRN/MLRNLayer.h +9 -11
  41. package/ios/MLRN/MLRNLayer.m +170 -182
  42. package/ios/MLRN/MLRNLight.m +21 -23
  43. package/ios/MLRN/MLRNLightManager.m +2 -3
  44. package/ios/MLRN/MLRNLineLayer.m +17 -15
  45. package/ios/MLRN/MLRNLineLayerManager.m +4 -6
  46. package/ios/MLRN/MLRNLocation.h +1 -1
  47. package/ios/MLRN/MLRNLocation.m +16 -17
  48. package/ios/MLRN/MLRNLocationManager.m +109 -124
  49. package/ios/MLRN/MLRNLocationManagerDelegate.h +3 -3
  50. package/ios/MLRN/MLRNLocationModule.h +1 -1
  51. package/ios/MLRN/MLRNLocationModule.m +40 -55
  52. package/ios/MLRN/MLRNLogging.h +1 -4
  53. package/ios/MLRN/MLRNLogging.m +84 -89
  54. package/ios/MLRN/MLRNMapTouchEvent.h +2 -2
  55. package/ios/MLRN/MLRNMapTouchEvent.m +50 -49
  56. package/ios/MLRN/MLRNMapView.h +43 -36
  57. package/ios/MLRN/MLRNMapView.m +409 -440
  58. package/ios/MLRN/MLRNMapViewManager.m +489 -502
  59. package/ios/MLRN/MLRNModule.h +1 -1
  60. package/ios/MLRN/MLRNModule.m +111 -105
  61. package/ios/MLRN/MLRNNativeUserLocation.m +24 -27
  62. package/ios/MLRN/MLRNNativeUserLocationManager.m +4 -8
  63. package/ios/MLRN/MLRNOfflineModule.h +1 -1
  64. package/ios/MLRN/MLRNOfflineModule.m +416 -421
  65. package/ios/MLRN/MLRNPointAnnotation.h +2 -2
  66. package/ios/MLRN/MLRNPointAnnotation.m +154 -175
  67. package/ios/MLRN/MLRNPointAnnotationManager.m +2 -3
  68. package/ios/MLRN/MLRNRasterLayer.m +16 -12
  69. package/ios/MLRN/MLRNRasterLayerManager.m +4 -5
  70. package/ios/MLRN/MLRNRasterSource.m +21 -17
  71. package/ios/MLRN/MLRNRasterSourceManager.m +2 -3
  72. package/ios/MLRN/MLRNShapeSource.h +17 -16
  73. package/ios/MLRN/MLRNShapeSource.m +94 -102
  74. package/ios/MLRN/MLRNShapeSourceManager.h +2 -2
  75. package/ios/MLRN/MLRNShapeSourceManager.m +86 -90
  76. package/ios/MLRN/MLRNSnapshotModule.h +1 -1
  77. package/ios/MLRN/MLRNSnapshotModule.m +51 -53
  78. package/ios/MLRN/MLRNSource.h +12 -12
  79. package/ios/MLRN/MLRNSource.m +82 -88
  80. package/ios/MLRN/MLRNStyleValue.h +1 -1
  81. package/ios/MLRN/MLRNStyleValue.m +128 -128
  82. package/ios/MLRN/MLRNSymbolLayer.m +17 -13
  83. package/ios/MLRN/MLRNSymbolLayerManager.m +4 -5
  84. package/ios/MLRN/MLRNTileSource.h +1 -1
  85. package/ios/MLRN/MLRNTileSource.m +21 -20
  86. package/ios/MLRN/MLRNUserLocation.h +1 -1
  87. package/ios/MLRN/MLRNUserLocation.m +10 -12
  88. package/ios/MLRN/MLRNUtils.h +18 -11
  89. package/ios/MLRN/MLRNUtils.m +168 -160
  90. package/ios/MLRN/MLRNVectorLayer.m +28 -34
  91. package/ios/MLRN/MLRNVectorSource.h +3 -1
  92. package/ios/MLRN/MLRNVectorSource.m +14 -11
  93. package/ios/MLRN/MLRNVectorSourceManager.h +2 -2
  94. package/ios/MLRN/MLRNVectorSourceManager.m +36 -39
  95. package/ios/MLRN/ViewManager.h +1 -1
  96. package/ios/MLRN/ViewManager.m +29 -35
  97. package/lib/commonjs/components/MarkerView.js +1 -1
  98. package/lib/commonjs/components/UserLocation.js +8 -38
  99. package/lib/commonjs/components/UserLocation.js.map +1 -1
  100. package/lib/commonjs/components/UserLocationPuck.js +52 -0
  101. package/lib/commonjs/components/UserLocationPuck.js.map +1 -0
  102. package/lib/commonjs/components/{HeadingIndicator.js → UserLocationPuckHeading.js} +12 -9
  103. package/lib/commonjs/components/UserLocationPuckHeading.js.map +1 -0
  104. package/lib/module/components/MarkerView.js +1 -1
  105. package/lib/module/components/UserLocation.js +7 -36
  106. package/lib/module/components/UserLocation.js.map +1 -1
  107. package/lib/module/components/UserLocationPuck.js +48 -0
  108. package/lib/module/components/UserLocationPuck.js.map +1 -0
  109. package/lib/module/components/{HeadingIndicator.js → UserLocationPuckHeading.js} +11 -7
  110. package/lib/module/components/UserLocationPuckHeading.js.map +1 -0
  111. package/lib/typescript/commonjs/src/components/MarkerView.d.ts +1 -1
  112. package/lib/typescript/commonjs/src/components/UserLocation.d.ts +0 -1
  113. package/lib/typescript/commonjs/src/components/UserLocation.d.ts.map +1 -1
  114. package/lib/typescript/commonjs/src/components/UserLocationPuck.d.ts +9 -0
  115. package/lib/typescript/commonjs/src/components/UserLocationPuck.d.ts.map +1 -0
  116. package/lib/typescript/commonjs/src/components/UserLocationPuckHeading.d.ts +9 -0
  117. package/lib/typescript/commonjs/src/components/UserLocationPuckHeading.d.ts.map +1 -0
  118. package/lib/typescript/commonjs/src/utils/animated/AbstractAnimatedCoordinates.d.ts +0 -1
  119. package/lib/typescript/commonjs/src/utils/animated/AbstractAnimatedCoordinates.d.ts.map +1 -1
  120. package/lib/typescript/commonjs/src/utils/animated/AnimatedExtractCoordinateFromArray.d.ts +0 -1
  121. package/lib/typescript/commonjs/src/utils/animated/AnimatedExtractCoordinateFromArray.d.ts.map +1 -1
  122. package/lib/typescript/commonjs/src/utils/animated/AnimatedPoint.d.ts +0 -1
  123. package/lib/typescript/commonjs/src/utils/animated/AnimatedPoint.d.ts.map +1 -1
  124. package/lib/typescript/commonjs/src/utils/animated/AnimatedShape.d.ts +0 -1
  125. package/lib/typescript/commonjs/src/utils/animated/AnimatedShape.d.ts.map +1 -1
  126. package/lib/typescript/module/src/components/MarkerView.d.ts +1 -1
  127. package/lib/typescript/module/src/components/UserLocation.d.ts +0 -1
  128. package/lib/typescript/module/src/components/UserLocation.d.ts.map +1 -1
  129. package/lib/typescript/module/src/components/UserLocationPuck.d.ts +9 -0
  130. package/lib/typescript/module/src/components/UserLocationPuck.d.ts.map +1 -0
  131. package/lib/typescript/module/src/components/UserLocationPuckHeading.d.ts +9 -0
  132. package/lib/typescript/module/src/components/UserLocationPuckHeading.d.ts.map +1 -0
  133. package/lib/typescript/module/src/utils/animated/AbstractAnimatedCoordinates.d.ts +0 -1
  134. package/lib/typescript/module/src/utils/animated/AbstractAnimatedCoordinates.d.ts.map +1 -1
  135. package/lib/typescript/module/src/utils/animated/AnimatedExtractCoordinateFromArray.d.ts +0 -1
  136. package/lib/typescript/module/src/utils/animated/AnimatedExtractCoordinateFromArray.d.ts.map +1 -1
  137. package/lib/typescript/module/src/utils/animated/AnimatedPoint.d.ts +0 -1
  138. package/lib/typescript/module/src/utils/animated/AnimatedPoint.d.ts.map +1 -1
  139. package/lib/typescript/module/src/utils/animated/AnimatedShape.d.ts +0 -1
  140. package/lib/typescript/module/src/utils/animated/AnimatedShape.d.ts.map +1 -1
  141. package/package.json +8 -8
  142. package/src/components/MarkerView.tsx +1 -1
  143. package/src/components/UserLocation.tsx +13 -51
  144. package/src/components/UserLocationPuck.tsx +62 -0
  145. package/src/components/UserLocationPuckHeading.tsx +33 -0
  146. package/lib/commonjs/components/HeadingIndicator.js.map +0 -1
  147. package/lib/module/components/HeadingIndicator.js.map +0 -1
  148. package/lib/typescript/commonjs/src/components/HeadingIndicator.d.ts +0 -7
  149. package/lib/typescript/commonjs/src/components/HeadingIndicator.d.ts.map +0 -1
  150. package/lib/typescript/module/src/components/HeadingIndicator.d.ts +0 -7
  151. package/lib/typescript/module/src/components/HeadingIndicator.d.ts.map +0 -1
  152. package/src/components/HeadingIndicator.tsx +0 -26
@@ -1,66 +1,64 @@
1
1
  #import <React/RCTUIManager.h>
2
2
 
3
- #import "MLRNMapViewManager.h"
4
- #import "MLRNMapView.h"
5
- #import "MLRNEventTypes.h"
6
- #import "MLRNEvent.h"
7
- #import "MLRNMapTouchEvent.h"
8
- #import "MLRNUtils.h"
9
3
  #import "CameraStop.h"
10
4
  #import "CameraUpdateQueue.h"
11
- #import "MLRNUserLocation.h"
12
5
  #import "FilterParser.h"
6
+ #import "MLRNEvent.h"
7
+ #import "MLRNEventTypes.h"
13
8
  #import "MLRNImages.h"
9
+ #import "MLRNMapTouchEvent.h"
10
+ #import "MLRNMapView.h"
11
+ #import "MLRNMapViewManager.h"
12
+ #import "MLRNUserLocation.h"
13
+ #import "MLRNUtils.h"
14
14
 
15
- @interface MLRNMapViewManager() <MLNMapViewDelegate>
15
+ @interface MLRNMapViewManager () <MLNMapViewDelegate>
16
16
  @end
17
17
 
18
18
  @implementation MLRNMapViewManager
19
19
 
20
-
21
20
  RCT_EXPORT_MODULE(MLRNMapView)
22
21
 
23
- - (BOOL)requiresMainQueueSetup
24
- {
25
- return YES;
22
+ - (BOOL)requiresMainQueueSetup {
23
+ return YES;
26
24
  }
27
25
 
28
26
  // prevents SDK from crashing and cluttering logs
29
27
  // since we don't have access to the frame right away
30
- - (CGRect)defaultFrame
31
- {
32
- return [[UIScreen mainScreen] bounds];
33
- }
34
-
35
- - (UIView *)view
36
- {
37
- MLRNMapView *mapView = [[MLRNMapView alloc] initWithFrame:[self defaultFrame]];
38
- mapView.delegate = self;
39
-
40
-
41
- // setup map gesture recongizers
42
- UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:nil];
43
- doubleTap.numberOfTapsRequired = 2;
44
-
45
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapMap:)];
46
- [tap requireGestureRecognizerToFail:doubleTap];
47
-
48
- UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(didLongPressMap:)];
49
-
50
- // this allows the internal annotation gestures to take precedents over the map tap gesture
51
- for (int i = 0; i < mapView.gestureRecognizers.count; i++) {
52
- UIGestureRecognizer *gestuerReconginer = mapView.gestureRecognizers[i];
53
-
54
- if ([gestuerReconginer isKindOfClass:[UITapGestureRecognizer class]]) {
55
- [tap requireGestureRecognizerToFail:gestuerReconginer];
56
- }
28
+ - (CGRect)defaultFrame {
29
+ return [[UIScreen mainScreen] bounds];
30
+ }
31
+
32
+ - (UIView *)view {
33
+ MLRNMapView *mapView = [[MLRNMapView alloc] initWithFrame:[self defaultFrame]];
34
+ mapView.delegate = self;
35
+
36
+ // setup map gesture recongizers
37
+ UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self
38
+ action:nil];
39
+ doubleTap.numberOfTapsRequired = 2;
40
+
41
+ UITapGestureRecognizer *tap =
42
+ [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapMap:)];
43
+ [tap requireGestureRecognizerToFail:doubleTap];
44
+
45
+ UILongPressGestureRecognizer *longPress =
46
+ [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(didLongPressMap:)];
47
+
48
+ // this allows the internal annotation gestures to take precedents over the map tap gesture
49
+ for (int i = 0; i < mapView.gestureRecognizers.count; i++) {
50
+ UIGestureRecognizer *gestuerReconginer = mapView.gestureRecognizers[i];
51
+
52
+ if ([gestuerReconginer isKindOfClass:[UITapGestureRecognizer class]]) {
53
+ [tap requireGestureRecognizerToFail:gestuerReconginer];
57
54
  }
58
-
59
- [mapView addGestureRecognizer:doubleTap];
60
- [mapView addGestureRecognizer:tap];
61
- [mapView addGestureRecognizer:longPress];
62
-
63
- return mapView;
55
+ }
56
+
57
+ [mapView addGestureRecognizer:doubleTap];
58
+ [mapView addGestureRecognizer:tap];
59
+ [mapView addGestureRecognizer:longPress];
60
+
61
+ return mapView;
64
62
  }
65
63
 
66
64
  #pragma mark - React View Props
@@ -91,527 +89,516 @@ RCT_EXPORT_VIEW_PROPERTY(onMapChange, RCTBubblingEventBlock)
91
89
 
92
90
  #pragma mark - React Methods
93
91
 
94
- RCT_EXPORT_METHOD(getPointInView:(nonnull NSNumber*)reactTag
95
- atCoordinate:(NSArray<NSNumber*>*)coordinate
96
- resolver:(RCTPromiseResolveBlock)resolve
97
- rejecter:(RCTPromiseRejectBlock)reject)
98
- {
99
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary<NSNumber*, UIView*> *viewRegistry) {
100
- id view = viewRegistry[reactTag];
101
-
102
- if (![view isKindOfClass:[MLRNMapView class]]) {
103
- RCTLogError(@"Invalid react tag, could not find MLRNMapView");
104
- return;
105
- }
106
-
107
- MLRNMapView *reactMapView = (MLRNMapView*)view;
108
-
109
- CGPoint pointInView = [reactMapView convertCoordinate:CLLocationCoordinate2DMake([coordinate[1] doubleValue], [coordinate[0] doubleValue])
110
- toPointToView:reactMapView];
111
-
112
- resolve(@{ @"pointInView": @[@(pointInView.x), @(pointInView.y)] });
113
- }];
114
- }
115
-
116
- RCT_EXPORT_METHOD(getCoordinateFromView:(nonnull NSNumber*)reactTag
117
- atPoint:(CGPoint)point
118
- resolver:(RCTPromiseResolveBlock)resolve
119
- rejecter:(RCTPromiseRejectBlock)reject)
120
- {
121
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary<NSNumber*, UIView*> *viewRegistry) {
92
+ RCT_EXPORT_METHOD(getPointInView : (nonnull NSNumber *)reactTag atCoordinate : (
93
+ NSArray<NSNumber *> *)coordinate resolver : (RCTPromiseResolveBlock)
94
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
95
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager,
96
+ NSDictionary<NSNumber *, UIView *> *viewRegistry) {
122
97
  id view = viewRegistry[reactTag];
123
-
98
+
124
99
  if (![view isKindOfClass:[MLRNMapView class]]) {
125
100
  RCTLogError(@"Invalid react tag, could not find MLRNMapView");
126
101
  return;
127
102
  }
128
-
129
- MLRNMapView *reactMapView = (MLRNMapView*)view;
130
-
103
+
104
+ MLRNMapView *reactMapView = (MLRNMapView *)view;
105
+
106
+ CGPoint pointInView =
107
+ [reactMapView convertCoordinate:CLLocationCoordinate2DMake([coordinate[1] doubleValue],
108
+ [coordinate[0] doubleValue])
109
+ toPointToView:reactMapView];
110
+
111
+ resolve(@{@"pointInView" : @[ @(pointInView.x), @(pointInView.y) ]});
112
+ }];
113
+ }
114
+
115
+ RCT_EXPORT_METHOD(getCoordinateFromView : (nonnull NSNumber *)reactTag atPoint : (CGPoint)
116
+ point resolver : (RCTPromiseResolveBlock)
117
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
118
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager,
119
+ NSDictionary<NSNumber *, UIView *> *viewRegistry) {
120
+ id view = viewRegistry[reactTag];
121
+
122
+ if (![view isKindOfClass:[MLRNMapView class]]) {
123
+ RCTLogError(@"Invalid react tag, could not find MLRNMapView");
124
+ return;
125
+ }
126
+
127
+ MLRNMapView *reactMapView = (MLRNMapView *)view;
128
+
131
129
  CLLocationCoordinate2D coordinate = [reactMapView convertPoint:point
132
- toCoordinateFromView:reactMapView];
133
-
134
- resolve(@{ @"coordinateFromView": @[@(coordinate.longitude), @(coordinate.latitude)] });
130
+ toCoordinateFromView:reactMapView];
131
+
132
+ resolve(@{@"coordinateFromView" : @[ @(coordinate.longitude), @(coordinate.latitude) ]});
135
133
  }];
136
134
  }
137
135
 
136
+ RCT_EXPORT_METHOD(takeSnap : (nonnull NSNumber *)reactTag writeToDisk : (BOOL)
137
+ writeToDisk resolver : (RCTPromiseResolveBlock)
138
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
139
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager,
140
+ NSDictionary<NSNumber *, UIView *> *viewRegistry) {
141
+ id view = viewRegistry[reactTag];
142
+
143
+ if (![view isKindOfClass:[MLRNMapView class]]) {
144
+ RCTLogError(@"Invalid react tag, could not find MLRNMapView");
145
+ return;
146
+ }
138
147
 
139
- RCT_EXPORT_METHOD(takeSnap:(nonnull NSNumber*)reactTag
140
- writeToDisk:(BOOL)writeToDisk
141
- resolver:(RCTPromiseResolveBlock)resolve
142
- rejecter:(RCTPromiseRejectBlock)reject)
143
- {
144
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary<NSNumber*, UIView*> *viewRegistry) {
145
- id view = viewRegistry[reactTag];
146
-
147
- if (![view isKindOfClass:[MLRNMapView class]]) {
148
- RCTLogError(@"Invalid react tag, could not find MLRNMapView");
149
- return;
150
- }
151
-
152
- MLRNMapView *reactMapView = (MLRNMapView*)view;
153
- NSString *uri = [reactMapView takeSnap:writeToDisk];
154
- resolve(@{ @"uri": uri });
155
- }];
156
- }
157
-
158
- RCT_EXPORT_METHOD(getVisibleBounds:(nonnull NSNumber*)reactTag
159
- resolver:(RCTPromiseResolveBlock)resolve
160
- rejecter:(RCTPromiseRejectBlock)reject)
161
- {
162
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary<NSNumber*, UIView*> *viewRegistry) {
163
- id view = viewRegistry[reactTag];
164
-
165
- if (![view isKindOfClass:[MLRNMapView class]]) {
166
- RCTLogError(@"Invalid react tag, could not find MLRNMapView");
167
- return;
168
- }
169
-
170
- MLRNMapView *reactMapView = (MLRNMapView*)view;
171
- resolve(@{ @"visibleBounds": [MLRNUtils fromCoordinateBounds:reactMapView.visibleCoordinateBounds] });
172
- }];
173
- }
174
-
175
- RCT_EXPORT_METHOD(getZoom:(nonnull NSNumber*)reactTag
176
- resolver:(RCTPromiseResolveBlock)resolve
177
- rejecter:(RCTPromiseRejectBlock)reject)
178
- {
179
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary<NSNumber*, UIView*> *viewRegistry) {
180
- id view = viewRegistry[reactTag];
181
-
182
- if (![view isKindOfClass:[MLRNMapView class]]) {
183
- RCTLogError(@"Invalid react tag, could not find MLRNMapView");
184
- return;
185
- }
186
-
187
- MLRNMapView *reactMapView = (MLRNMapView*)view;
188
- resolve(@{ @"zoom": @(reactMapView.zoomLevel) });
189
- }];
190
- }
191
-
192
- RCT_EXPORT_METHOD(getCenter:(nonnull NSNumber*)reactTag
193
- resolver:(RCTPromiseResolveBlock)resolve
194
- rejecter:(RCTPromiseRejectBlock)reject)
195
- {
196
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary<NSNumber*, UIView*> *viewRegistry) {
197
- id view = viewRegistry[reactTag];
198
-
199
- if (![view isKindOfClass:[MLRNMapView class]]) {
200
- RCTLogError(@"Invalid react tag, could not find MLRNMapView");
201
- return;
202
- }
203
-
204
- MLRNMapView *reactMapView = (MLRNMapView*)view;
205
- resolve(@{ @"center": @[@(reactMapView.centerCoordinate.longitude), @(reactMapView.centerCoordinate.latitude)]});
206
- }];
207
- }
208
-
209
- RCT_EXPORT_METHOD(queryRenderedFeaturesAtPoint:(nonnull NSNumber*)reactTag
210
- atPoint:(NSArray<NSNumber*>*)point
211
- withFilter:(NSArray*)filter
212
- withLayerIDs:(NSArray<NSString*>*)layerIDs
213
- resolver:(RCTPromiseResolveBlock)resolve
214
- rejecter:(RCTPromiseRejectBlock)reject)
215
- {
216
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary<NSNumber*, UIView*> *viewRegistry) {
217
- id view = viewRegistry[reactTag];
218
-
219
- if (![view isKindOfClass:[MLRNMapView class]]) {
220
- RCTLogError(@"Invalid react tag, could not find MLRNMapView");
221
- return;
222
- }
223
-
224
- NSSet *layerIDSet = nil;
225
- if (layerIDs != nil && layerIDs.count > 0) {
226
- layerIDSet = [NSSet setWithArray:layerIDs];
227
- }
228
-
229
- MLRNMapView *reactMapView = (MLRNMapView*)view;
230
- NSPredicate* predicate = [FilterParser parse:filter];
231
- NSArray<id<MLNFeature>> *shapes = [reactMapView visibleFeaturesAtPoint:CGPointMake([point[0] floatValue], [point[1] floatValue])
232
- inStyleLayersWithIdentifiers:layerIDSet
233
- predicate:predicate];
234
-
235
- NSMutableArray<NSDictionary*> *features = [[NSMutableArray alloc] init];
236
- for (int i = 0; i < shapes.count; i++) {
237
- [features addObject:shapes[i].geoJSONDictionary];
238
- }
239
-
240
- resolve(@{
241
- @"data": @{ @"type": @"FeatureCollection", @"features": features }
242
- });
243
- }];
244
- }
245
-
246
- RCT_EXPORT_METHOD(queryRenderedFeaturesInRect:(nonnull NSNumber*)reactTag
247
- withBBox:(NSArray<NSNumber*>*)bbox
248
- withFilter:(NSArray*)filter
249
- withLayerIDs:(NSArray<NSString*>*)layerIDs
250
- resolver:(RCTPromiseResolveBlock)resolve
251
- rejecter:(RCTPromiseRejectBlock)reject)
252
- {
253
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary<NSNumber*, UIView*> *viewRegistry) {
254
- id view = viewRegistry[reactTag];
255
-
256
- if (![view isKindOfClass:[MLRNMapView class]]) {
257
- RCTLogError(@"Invalid react tag, could not find MLRNMapView");
258
- return;
259
- }
260
-
261
- MLRNMapView *reactMapView = (MLRNMapView*)view;
262
-
263
- // bbox[top, right, bottom, left]
264
- CGFloat width = [bbox[1] floatValue] - [bbox[3] floatValue];
265
- CGFloat height = [bbox[0] floatValue] - [bbox[2] floatValue];
266
- CGRect rect = CGRectMake([bbox[3] floatValue], [bbox[2] floatValue], width, height);
267
-
268
- NSSet *layerIDSet = nil;
269
- if (layerIDs != nil && layerIDs.count > 0) {
270
- layerIDSet = [NSSet setWithArray:layerIDs];
271
- }
272
-
273
- NSPredicate* predicate = [FilterParser parse:filter];
274
- NSArray<id<MLNFeature>> *shapes = [reactMapView visibleFeaturesInRect:rect
275
- inStyleLayersWithIdentifiers:layerIDSet
276
- predicate:predicate];
277
-
278
- NSArray<NSDictionary*>* features = [self featuresToJSON:shapes];
279
-
280
- resolve(@{ @"data": @{ @"type": @"FeatureCollection", @"features": features }});
281
- }];
282
- }
283
-
284
- RCT_EXPORT_METHOD(showAttribution:(nonnull NSNumber *)reactTag
285
- resolver:(RCTPromiseResolveBlock)resolve
286
- rejecter:(RCTPromiseRejectBlock)reject)
287
- {
288
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary<NSNumber*, UIView*> *viewRegistry) {
289
- id view = viewRegistry[reactTag];
290
-
291
- if (![view isKindOfClass:[MLRNMapView class]]) {
292
- RCTLogError(@"Invalid react tag, could not find MLRNMapView");
293
- return;
294
- }
295
-
296
- __weak MLRNMapView *reactMapView = (MLRNMapView*)view;
297
- [reactMapView showAttribution:reactMapView];
298
- resolve(nil);
299
- }];
300
- }
301
-
302
- RCT_EXPORT_METHOD(setSourceVisibility:(nonnull NSNumber *)reactTag
303
- visible:(BOOL)visible
304
- sourceId:(nonnull NSString*)sourceId
305
- sourceLayerId:(nullable NSString*)sourceLayerId
306
- resolver:(RCTPromiseResolveBlock)resolve
307
- rejecter:(RCTPromiseRejectBlock)reject)
308
- {
309
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager, NSDictionary<NSNumber*, UIView*> *viewRegistry) {
310
- id view = viewRegistry[reactTag];
311
-
312
- if (![view isKindOfClass:[MLRNMapView class]]) {
313
- RCTLogError(@"Invalid react tag, could not find MLRNMapView");
314
- return;
315
- }
316
-
317
- __weak MLRNMapView *reactMapView = (MLRNMapView*)view;
318
- [reactMapView setSourceVisibility:visible sourceId:sourceId sourceLayerId:sourceLayerId];
319
- resolve(nil);
320
- }];
148
+ MLRNMapView *reactMapView = (MLRNMapView *)view;
149
+ NSString *uri = [reactMapView takeSnap:writeToDisk];
150
+ resolve(@{@"uri" : uri});
151
+ }];
321
152
  }
322
153
 
323
- #pragma mark - UIGestureRecognizers
154
+ RCT_EXPORT_METHOD(getVisibleBounds : (nonnull NSNumber *)reactTag resolver : (
155
+ RCTPromiseResolveBlock)resolve rejecter : (RCTPromiseRejectBlock)reject) {
156
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager,
157
+ NSDictionary<NSNumber *, UIView *> *viewRegistry) {
158
+ id view = viewRegistry[reactTag];
324
159
 
325
- - (void)didTapMap:(UITapGestureRecognizer *)recognizer
326
- {
327
- MLRNMapView *mapView = (MLRNMapView*)recognizer.view;
328
- CGPoint screenPoint = [recognizer locationInView:mapView];
329
- NSArray<MLRNSource *> *touchableSources = [mapView getAllTouchableSources];
330
-
331
- NSMutableDictionary<NSString *, NSArray<id<MLNFeature>>* > *hits = [[NSMutableDictionary alloc] init];
332
- NSMutableArray<MLRNSource *> *hitTouchableSources = [[NSMutableArray alloc] init];
333
- for (MLRNSource *touchableSource in touchableSources) {
334
- NSDictionary<NSString *, NSNumber *> *hitbox = touchableSource.hitbox;
335
- float halfWidth = [hitbox[@"width"] floatValue] / 2.f;
336
- float halfHeight = [hitbox[@"height"] floatValue] / 2.f;
337
-
338
- CGFloat top = screenPoint.y - halfHeight;
339
- CGFloat left = screenPoint.x - halfWidth;
340
- CGRect hitboxRect = CGRectMake(left, top, [hitbox[@"width"] floatValue], [hitbox[@"height"] floatValue]);
341
-
342
- NSArray<id<MLNFeature>> *features = [mapView visibleFeaturesInRect:hitboxRect
343
- inStyleLayersWithIdentifiers:[NSSet setWithArray:[touchableSource getLayerIDs]]
344
- predicate:nil];
345
-
346
- if (features.count > 0) {
347
- hits[touchableSource.id] = features;
348
- [hitTouchableSources addObject:touchableSource];
349
- }
160
+ if (![view isKindOfClass:[MLRNMapView class]]) {
161
+ RCTLogError(@"Invalid react tag, could not find MLRNMapView");
162
+ return;
350
163
  }
351
-
352
- if (hits.count > 0) {
353
- MLRNSource *source = [mapView getTouchableSourceWithHighestZIndex:hitTouchableSources];
354
- if (source != nil && source.hasPressListener) {
355
- NSArray* geoJSONDicts = [self featuresToJSON: hits[source.id]];
356
-
357
- NSString *eventType = RCT_MAPBOX_VECTOR_SOURCE_LAYER_PRESS;
358
- if ([source isKindOfClass:[MLRNShapeSource class]]) {
359
- eventType = RCT_MAPBOX_SHAPE_SOURCE_LAYER_PRESS;
360
- }
361
-
362
- CLLocationCoordinate2D coordinate = [mapView convertPoint:screenPoint
363
- toCoordinateFromView:mapView];
364
-
365
- MLRNEvent *event = [MLRNEvent makeEvent:eventType withPayload: @{
366
- @"features": geoJSONDicts,
367
- @"point": @{
368
- @"x": [NSNumber numberWithDouble: screenPoint.x],
369
- @"y":[NSNumber numberWithDouble: screenPoint.y]
370
- },
371
- @"coordinates": @{
372
- @"latitude": [NSNumber numberWithDouble: coordinate.latitude],
373
- @"longitude": [NSNumber numberWithDouble: coordinate.longitude]
374
- }
375
- }];
376
- [self fireEvent:event withCallback:source.onPress];
377
- return;
378
- }
164
+
165
+ MLRNMapView *reactMapView = (MLRNMapView *)view;
166
+ resolve(@{
167
+ @"visibleBounds" : [MLRNUtils fromCoordinateBounds:reactMapView.visibleCoordinateBounds]
168
+ });
169
+ }];
170
+ }
171
+
172
+ RCT_EXPORT_METHOD(getZoom : (nonnull NSNumber *)reactTag resolver : (RCTPromiseResolveBlock)
173
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
174
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager,
175
+ NSDictionary<NSNumber *, UIView *> *viewRegistry) {
176
+ id view = viewRegistry[reactTag];
177
+
178
+ if (![view isKindOfClass:[MLRNMapView class]]) {
179
+ RCTLogError(@"Invalid react tag, could not find MLRNMapView");
180
+ return;
379
181
  }
380
-
381
- if (mapView.onPress == nil) {
382
- return;
182
+
183
+ MLRNMapView *reactMapView = (MLRNMapView *)view;
184
+ resolve(@{@"zoom" : @(reactMapView.zoomLevel)});
185
+ }];
186
+ }
187
+
188
+ RCT_EXPORT_METHOD(getCenter : (nonnull NSNumber *)reactTag resolver : (RCTPromiseResolveBlock)
189
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
190
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager,
191
+ NSDictionary<NSNumber *, UIView *> *viewRegistry) {
192
+ id view = viewRegistry[reactTag];
193
+
194
+ if (![view isKindOfClass:[MLRNMapView class]]) {
195
+ RCTLogError(@"Invalid react tag, could not find MLRNMapView");
196
+ return;
383
197
  }
384
-
385
- MLRNMapTouchEvent *event = [MLRNMapTouchEvent makeTapEvent:mapView withPoint:screenPoint];
386
- [self fireEvent:event withCallback:mapView.onPress];
198
+
199
+ MLRNMapView *reactMapView = (MLRNMapView *)view;
200
+ resolve(@{
201
+ @"center" :
202
+ @[ @(reactMapView.centerCoordinate.longitude), @(reactMapView.centerCoordinate.latitude) ]
203
+ });
204
+ }];
387
205
  }
388
206
 
389
- - (void)didLongPressMap:(UILongPressGestureRecognizer *)recognizer
390
- {
391
- MLRNMapView *mapView = (MLRNMapView*)recognizer.view;
392
-
393
- if (mapView == nil || mapView.onPress == nil || recognizer.state != UIGestureRecognizerStateBegan) {
394
- return;
207
+ RCT_EXPORT_METHOD(queryRenderedFeaturesAtPoint : (nonnull NSNumber *)reactTag atPoint : (
208
+ NSArray<NSNumber *> *)point withFilter : (NSArray *)
209
+ filter withLayerIDs : (NSArray<NSString *> *)layerIDs resolver : (
210
+ RCTPromiseResolveBlock)resolve rejecter : (RCTPromiseRejectBlock)reject) {
211
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager,
212
+ NSDictionary<NSNumber *, UIView *> *viewRegistry) {
213
+ id view = viewRegistry[reactTag];
214
+
215
+ if (![view isKindOfClass:[MLRNMapView class]]) {
216
+ RCTLogError(@"Invalid react tag, could not find MLRNMapView");
217
+ return;
218
+ }
219
+
220
+ NSSet *layerIDSet = nil;
221
+ if (layerIDs != nil && layerIDs.count > 0) {
222
+ layerIDSet = [NSSet setWithArray:layerIDs];
223
+ }
224
+
225
+ MLRNMapView *reactMapView = (MLRNMapView *)view;
226
+ NSPredicate *predicate = [FilterParser parse:filter];
227
+ NSArray<id<MLNFeature>> *shapes = [reactMapView
228
+ visibleFeaturesAtPoint:CGPointMake([point[0] floatValue], [point[1] floatValue])
229
+ inStyleLayersWithIdentifiers:layerIDSet
230
+ predicate:predicate];
231
+
232
+ NSMutableArray<NSDictionary *> *features = [[NSMutableArray alloc] init];
233
+ for (int i = 0; i < shapes.count; i++) {
234
+ [features addObject:shapes[i].geoJSONDictionary];
395
235
  }
396
-
397
- MLRNMapTouchEvent *event = [MLRNMapTouchEvent makeLongPressEvent:mapView withPoint:[recognizer locationInView:mapView]];
398
- [self fireEvent:event withCallback:mapView.onLongPress];
236
+
237
+ resolve(@{@"data" : @{@"type" : @"FeatureCollection", @"features" : features}});
238
+ }];
399
239
  }
400
240
 
401
- #pragma mark - MLNMapViewDelegate
241
+ RCT_EXPORT_METHOD(queryRenderedFeaturesInRect : (nonnull NSNumber *)reactTag withBBox : (
242
+ NSArray<NSNumber *> *)bbox withFilter : (NSArray *)filter withLayerIDs : (NSArray<NSString *> *)
243
+ layerIDs resolver : (RCTPromiseResolveBlock)
244
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
245
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager,
246
+ NSDictionary<NSNumber *, UIView *> *viewRegistry) {
247
+ id view = viewRegistry[reactTag];
402
248
 
403
- - (MLNAnnotationView *)mapView:(MLNMapView *)mapView viewForAnnotation:(id<MLNAnnotation>)annotation
404
- {
405
- if ([annotation isKindOfClass:[MLNUserLocation class]] && mapView.userLocation != nil) {
406
- MLRNMapView* reactMapView = ((MLRNMapView *) mapView);
407
- if (reactMapView.useNativeUserLocationAnnotationView) {
408
- return nil;
409
- }
410
- return [[MLRNUserLocation sharedInstance] hiddenUserAnnotation];
249
+ if (![view isKindOfClass:[MLRNMapView class]]) {
250
+ RCTLogError(@"Invalid react tag, could not find MLRNMapView");
251
+ return;
411
252
  }
412
- else if ([annotation isKindOfClass:[MLRNPointAnnotation class]]) {
413
- MLRNPointAnnotation *rctAnnotation = (MLRNPointAnnotation *)annotation;
414
- return [rctAnnotation getAnnotationView];
253
+
254
+ MLRNMapView *reactMapView = (MLRNMapView *)view;
255
+
256
+ // bbox[top, right, bottom, left]
257
+ CGFloat width = [bbox[1] floatValue] - [bbox[3] floatValue];
258
+ CGFloat height = [bbox[0] floatValue] - [bbox[2] floatValue];
259
+ CGRect rect = CGRectMake([bbox[3] floatValue], [bbox[2] floatValue], width, height);
260
+
261
+ NSSet *layerIDSet = nil;
262
+ if (layerIDs != nil && layerIDs.count > 0) {
263
+ layerIDSet = [NSSet setWithArray:layerIDs];
415
264
  }
416
- return nil;
265
+
266
+ NSPredicate *predicate = [FilterParser parse:filter];
267
+ NSArray<id<MLNFeature>> *shapes = [reactMapView visibleFeaturesInRect:rect
268
+ inStyleLayersWithIdentifiers:layerIDSet
269
+ predicate:predicate];
270
+
271
+ NSArray<NSDictionary *> *features = [self featuresToJSON:shapes];
272
+
273
+ resolve(@{@"data" : @{@"type" : @"FeatureCollection", @"features" : features}});
274
+ }];
417
275
  }
418
276
 
419
- - (void)mapView:(MLNMapView *)mapView didChangeUserTrackingMode:(MLNUserTrackingMode)mode animated:(BOOL)animated
420
- {
421
- MLRNMapView* reactMapView = ((MLRNMapView *) mapView);
422
- [reactMapView didChangeUserTrackingMode:mode animated:animated];
277
+ RCT_EXPORT_METHOD(showAttribution : (nonnull NSNumber *)reactTag resolver : (RCTPromiseResolveBlock)
278
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
279
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager,
280
+ NSDictionary<NSNumber *, UIView *> *viewRegistry) {
281
+ id view = viewRegistry[reactTag];
282
+
283
+ if (![view isKindOfClass:[MLRNMapView class]]) {
284
+ RCTLogError(@"Invalid react tag, could not find MLRNMapView");
285
+ return;
286
+ }
287
+
288
+ __weak MLRNMapView *reactMapView = (MLRNMapView *)view;
289
+ [reactMapView showAttribution:reactMapView];
290
+ resolve(nil);
291
+ }];
423
292
  }
424
293
 
425
- - (void)mapView:(MLNMapView *)mapView didSelectAnnotation:(nonnull id<MLNAnnotation>)annotation
426
- {
427
- if ([annotation isKindOfClass:[MLRNPointAnnotation class]]) {
428
- MLRNPointAnnotation *rctAnnotation = (MLRNPointAnnotation *)annotation;
429
-
430
- if (rctAnnotation.onSelected != nil) {
431
- MLRNMapTouchEvent *event = [MLRNMapTouchEvent makeAnnotationTapEvent:rctAnnotation];
432
- rctAnnotation.onSelected([event toJSON]);
433
- }
294
+ RCT_EXPORT_METHOD(setSourceVisibility : (nonnull NSNumber *)reactTag visible : (
295
+ BOOL)visible sourceId : (nonnull NSString *)sourceId sourceLayerId : (nullable NSString *)
296
+ sourceLayerId resolver : (RCTPromiseResolveBlock)
297
+ resolve rejecter : (RCTPromiseRejectBlock)reject) {
298
+ [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *manager,
299
+ NSDictionary<NSNumber *, UIView *> *viewRegistry) {
300
+ id view = viewRegistry[reactTag];
301
+
302
+ if (![view isKindOfClass:[MLRNMapView class]]) {
303
+ RCTLogError(@"Invalid react tag, could not find MLRNMapView");
304
+ return;
434
305
  }
306
+
307
+ __weak MLRNMapView *reactMapView = (MLRNMapView *)view;
308
+ [reactMapView setSourceVisibility:visible sourceId:sourceId sourceLayerId:sourceLayerId];
309
+ resolve(nil);
310
+ }];
435
311
  }
436
312
 
437
- - (void)mapView:(MLNMapView *)mapView didDeselectAnnotation:(nonnull id<MLNAnnotation>)annotation
438
- {
439
- if ([annotation isKindOfClass:[MLRNPointAnnotation class]]) {
440
- MLRNPointAnnotation *rctAnnotation = (MLRNPointAnnotation *)annotation;
441
-
442
- if (rctAnnotation.onDeselected != nil) {
443
- rctAnnotation.onDeselected(nil);
444
- }
313
+ #pragma mark - UIGestureRecognizers
314
+
315
+ - (void)didTapMap:(UITapGestureRecognizer *)recognizer {
316
+ MLRNMapView *mapView = (MLRNMapView *)recognizer.view;
317
+ CGPoint screenPoint = [recognizer locationInView:mapView];
318
+ NSArray<MLRNSource *> *touchableSources = [mapView getAllTouchableSources];
319
+
320
+ NSMutableDictionary<NSString *, NSArray<id<MLNFeature>> *> *hits =
321
+ [[NSMutableDictionary alloc] init];
322
+ NSMutableArray<MLRNSource *> *hitTouchableSources = [[NSMutableArray alloc] init];
323
+ for (MLRNSource *touchableSource in touchableSources) {
324
+ NSDictionary<NSString *, NSNumber *> *hitbox = touchableSource.hitbox;
325
+ float halfWidth = [hitbox[@"width"] floatValue] / 2.f;
326
+ float halfHeight = [hitbox[@"height"] floatValue] / 2.f;
327
+
328
+ CGFloat top = screenPoint.y - halfHeight;
329
+ CGFloat left = screenPoint.x - halfWidth;
330
+ CGRect hitboxRect =
331
+ CGRectMake(left, top, [hitbox[@"width"] floatValue], [hitbox[@"height"] floatValue]);
332
+
333
+ NSArray<id<MLNFeature>> *features =
334
+ [mapView visibleFeaturesInRect:hitboxRect
335
+ inStyleLayersWithIdentifiers:[NSSet setWithArray:[touchableSource getLayerIDs]]
336
+ predicate:nil];
337
+
338
+ if (features.count > 0) {
339
+ hits[touchableSource.id] = features;
340
+ [hitTouchableSources addObject:touchableSource];
445
341
  }
342
+ }
343
+
344
+ if (hits.count > 0) {
345
+ MLRNSource *source = [mapView getTouchableSourceWithHighestZIndex:hitTouchableSources];
346
+ if (source != nil && source.hasPressListener) {
347
+ NSArray *geoJSONDicts = [self featuresToJSON:hits[source.id]];
348
+
349
+ NSString *eventType = RCT_MAPBOX_VECTOR_SOURCE_LAYER_PRESS;
350
+ if ([source isKindOfClass:[MLRNShapeSource class]]) {
351
+ eventType = RCT_MAPBOX_SHAPE_SOURCE_LAYER_PRESS;
352
+ }
353
+
354
+ CLLocationCoordinate2D coordinate = [mapView convertPoint:screenPoint
355
+ toCoordinateFromView:mapView];
356
+
357
+ MLRNEvent *event =
358
+ [MLRNEvent makeEvent:eventType
359
+ withPayload:@{
360
+ @"features" : geoJSONDicts,
361
+ @"point" : @{
362
+ @"x" : [NSNumber numberWithDouble:screenPoint.x],
363
+ @"y" : [NSNumber numberWithDouble:screenPoint.y]
364
+ },
365
+ @"coordinates" : @{
366
+ @"latitude" : [NSNumber numberWithDouble:coordinate.latitude],
367
+ @"longitude" : [NSNumber numberWithDouble:coordinate.longitude]
368
+ }
369
+ }];
370
+ [self fireEvent:event withCallback:source.onPress];
371
+ return;
372
+ }
373
+ }
374
+
375
+ if (mapView.onPress == nil) {
376
+ return;
377
+ }
378
+
379
+ MLRNMapTouchEvent *event = [MLRNMapTouchEvent makeTapEvent:mapView withPoint:screenPoint];
380
+ [self fireEvent:event withCallback:mapView.onPress];
446
381
  }
447
382
 
448
- - (BOOL)mapView:(MLNMapView *)mapView annotationCanShowCallout:(id<MLNAnnotation>)annotation {
449
- if ([annotation isKindOfClass:[MLRNPointAnnotation class]]) {
450
- MLRNPointAnnotation *rctAnnotation = (MLRNPointAnnotation *)annotation;
451
- return rctAnnotation.calloutView != nil;
383
+ - (void)didLongPressMap:(UILongPressGestureRecognizer *)recognizer {
384
+ MLRNMapView *mapView = (MLRNMapView *)recognizer.view;
385
+
386
+ if (mapView == nil || mapView.onPress == nil ||
387
+ recognizer.state != UIGestureRecognizerStateBegan) {
388
+ return;
389
+ }
390
+
391
+ MLRNMapTouchEvent *event =
392
+ [MLRNMapTouchEvent makeLongPressEvent:mapView withPoint:[recognizer locationInView:mapView]];
393
+ [self fireEvent:event withCallback:mapView.onLongPress];
394
+ }
395
+
396
+ #pragma mark - MLNMapViewDelegate
397
+
398
+ - (MLNAnnotationView *)mapView:(MLNMapView *)mapView
399
+ viewForAnnotation:(id<MLNAnnotation>)annotation {
400
+ if ([annotation isKindOfClass:[MLNUserLocation class]] && mapView.userLocation != nil) {
401
+ MLRNMapView *reactMapView = ((MLRNMapView *)mapView);
402
+ if (reactMapView.useNativeUserLocationAnnotationView) {
403
+ return nil;
452
404
  }
453
- return NO;
405
+ return [[MLRNUserLocation sharedInstance] hiddenUserAnnotation];
406
+ } else if ([annotation isKindOfClass:[MLRNPointAnnotation class]]) {
407
+ MLRNPointAnnotation *rctAnnotation = (MLRNPointAnnotation *)annotation;
408
+ return [rctAnnotation getAnnotationView];
409
+ }
410
+ return nil;
411
+ }
412
+
413
+ - (void)mapView:(MLNMapView *)mapView
414
+ didChangeUserTrackingMode:(MLNUserTrackingMode)mode
415
+ animated:(BOOL)animated {
416
+ MLRNMapView *reactMapView = ((MLRNMapView *)mapView);
417
+ [reactMapView didChangeUserTrackingMode:mode animated:animated];
454
418
  }
455
419
 
456
- - (UIView<MLNCalloutView> *)mapView:(MLNMapView *)mapView calloutViewForAnnotation:(id<MLNAnnotation>)annotation
457
- {
458
- if ([annotation isKindOfClass:[MLRNPointAnnotation class]]) {
459
- MLRNPointAnnotation *rctAnnotation = (MLRNPointAnnotation *)annotation;
460
- return rctAnnotation.calloutView;
420
+ - (void)mapView:(MLNMapView *)mapView didSelectAnnotation:(nonnull id<MLNAnnotation>)annotation {
421
+ if ([annotation isKindOfClass:[MLRNPointAnnotation class]]) {
422
+ MLRNPointAnnotation *rctAnnotation = (MLRNPointAnnotation *)annotation;
423
+
424
+ if (rctAnnotation.onSelected != nil) {
425
+ MLRNMapTouchEvent *event = [MLRNMapTouchEvent makeAnnotationTapEvent:rctAnnotation];
426
+ rctAnnotation.onSelected([event toJSON]);
461
427
  }
462
- return nil;
428
+ }
463
429
  }
464
430
 
465
- - (BOOL)mapView:(MLNMapView *)mapView shouldChangeFromCamera:(MLNMapCamera *)oldCamera toCamera:(MLNMapCamera *)newCamera
466
- {
467
- MLRNMapView* reactMapView = ((MLRNMapView *) mapView);
468
- return MLNCoordinateBoundsIsEmpty(reactMapView.maxBounds) || MLNCoordinateInCoordinateBounds(newCamera.centerCoordinate, reactMapView.maxBounds);
431
+ - (void)mapView:(MLNMapView *)mapView didDeselectAnnotation:(nonnull id<MLNAnnotation>)annotation {
432
+ if ([annotation isKindOfClass:[MLRNPointAnnotation class]]) {
433
+ MLRNPointAnnotation *rctAnnotation = (MLRNPointAnnotation *)annotation;
434
+
435
+ if (rctAnnotation.onDeselected != nil) {
436
+ rctAnnotation.onDeselected(nil);
437
+ }
438
+ }
469
439
  }
470
440
 
471
- - (void)mapView:(MLNMapView *)mapView regionWillChangeWithReason:(MLNCameraChangeReason)reason animated:(BOOL)animated
472
- {
473
- ((MLRNMapView *) mapView).isUserInteraction = (BOOL)(reason & ~MLNCameraChangeReasonProgrammatic);
474
- NSDictionary *payload = [self _makeRegionPayload:mapView animated:animated];
475
- [self reactMapDidChange:mapView eventType:RCT_MAPBOX_REGION_WILL_CHANGE_EVENT andPayload:payload];
441
+ - (BOOL)mapView:(MLNMapView *)mapView annotationCanShowCallout:(id<MLNAnnotation>)annotation {
442
+ if ([annotation isKindOfClass:[MLRNPointAnnotation class]]) {
443
+ MLRNPointAnnotation *rctAnnotation = (MLRNPointAnnotation *)annotation;
444
+ return rctAnnotation.calloutView != nil;
445
+ }
446
+ return NO;
476
447
  }
477
448
 
478
- - (void)mapViewRegionIsChanging:(MLNMapView *)mapView
479
- {
480
- NSDictionary *payload = [self _makeRegionPayload:mapView animated:false];
481
- [self reactMapDidChange:mapView eventType:RCT_MAPBOX_REGION_IS_CHANGING andPayload:payload];
449
+ - (UIView<MLNCalloutView> *)mapView:(MLNMapView *)mapView
450
+ calloutViewForAnnotation:(id<MLNAnnotation>)annotation {
451
+ if ([annotation isKindOfClass:[MLRNPointAnnotation class]]) {
452
+ MLRNPointAnnotation *rctAnnotation = (MLRNPointAnnotation *)annotation;
453
+ return rctAnnotation.calloutView;
454
+ }
455
+ return nil;
482
456
  }
483
457
 
484
- - (void)mapView:(MLNMapView *)mapView regionDidChangeWithReason:(MLNCameraChangeReason)reason animated:(BOOL)animated
485
- {
486
- if (((reason & MLNCameraChangeReasonTransitionCancelled) == MLNCameraChangeReasonTransitionCancelled)
487
- && ((reason & MLNCameraChangeReasonGesturePan) != MLNCameraChangeReasonGesturePan)) return;
458
+ - (BOOL)mapView:(MLNMapView *)mapView
459
+ shouldChangeFromCamera:(MLNMapCamera *)oldCamera
460
+ toCamera:(MLNMapCamera *)newCamera {
461
+ MLRNMapView *reactMapView = ((MLRNMapView *)mapView);
462
+ return MLNCoordinateBoundsIsEmpty(reactMapView.maxBounds) ||
463
+ MLNCoordinateInCoordinateBounds(newCamera.centerCoordinate, reactMapView.maxBounds);
464
+ }
488
465
 
489
- ((MLRNMapView *) mapView).isUserInteraction = (BOOL)(reason & ~MLNCameraChangeReasonProgrammatic);
490
-
491
- NSDictionary *payload = [self _makeRegionPayload:mapView animated:animated];
492
- [self reactMapDidChange:mapView eventType:RCT_MAPBOX_REGION_DID_CHANGE andPayload:payload];
466
+ - (void)mapView:(MLNMapView *)mapView
467
+ regionWillChangeWithReason:(MLNCameraChangeReason)reason
468
+ animated:(BOOL)animated {
469
+ ((MLRNMapView *)mapView).isUserInteraction = (BOOL)(reason & ~MLNCameraChangeReasonProgrammatic);
470
+ NSDictionary *payload = [self _makeRegionPayload:mapView animated:animated];
471
+ [self reactMapDidChange:mapView eventType:RCT_MAPBOX_REGION_WILL_CHANGE_EVENT andPayload:payload];
493
472
  }
494
473
 
495
- - (void)mapViewWillStartLoadingMap:(MLNMapView *)mapView
496
- {
497
- [self reactMapDidChange:mapView eventType:RCT_MAPBOX_WILL_START_LOADING_MAP];
474
+ - (void)mapViewRegionIsChanging:(MLNMapView *)mapView {
475
+ NSDictionary *payload = [self _makeRegionPayload:mapView animated:false];
476
+ [self reactMapDidChange:mapView eventType:RCT_MAPBOX_REGION_IS_CHANGING andPayload:payload];
498
477
  }
499
478
 
500
- - (void)mapViewDidFinishLoadingMap:(MLNMapView *)mapView
501
- {
502
- [self reactMapDidChange:mapView eventType:RCT_MAPBOX_DID_FINISH_LOADING_MAP];
479
+ - (void)mapView:(MLNMapView *)mapView
480
+ regionDidChangeWithReason:(MLNCameraChangeReason)reason
481
+ animated:(BOOL)animated {
482
+ if (((reason & MLNCameraChangeReasonTransitionCancelled) ==
483
+ MLNCameraChangeReasonTransitionCancelled) &&
484
+ ((reason & MLNCameraChangeReasonGesturePan) != MLNCameraChangeReasonGesturePan))
485
+ return;
486
+
487
+ ((MLRNMapView *)mapView).isUserInteraction = (BOOL)(reason & ~MLNCameraChangeReasonProgrammatic);
488
+
489
+ NSDictionary *payload = [self _makeRegionPayload:mapView animated:animated];
490
+ [self reactMapDidChange:mapView eventType:RCT_MAPBOX_REGION_DID_CHANGE andPayload:payload];
503
491
  }
504
492
 
505
- - (void)mapViewDidFailLoadingMap:(MLNMapView *)mapView withError:(NSError *)error
506
- {
507
- NSLog(@"Failed loading map %@", error);
508
- [self reactMapDidChange:mapView eventType:RCT_MAPBOX_DID_FAIL_LOADING_MAP];
493
+ - (void)mapViewWillStartLoadingMap:(MLNMapView *)mapView {
494
+ [self reactMapDidChange:mapView eventType:RCT_MAPBOX_WILL_START_LOADING_MAP];
509
495
  }
510
496
 
511
- - (void)mapViewWillStartRenderingFrame:(MLNMapView *)mapView
512
- {
513
- [self reactMapDidChange:mapView eventType:RCT_MAPBOX_WILL_START_RENDERING_FRAME];
497
+ - (void)mapViewDidFinishLoadingMap:(MLNMapView *)mapView {
498
+ [self reactMapDidChange:mapView eventType:RCT_MAPBOX_DID_FINISH_LOADING_MAP];
514
499
  }
515
500
 
516
- - (void)mapViewDidFinishRenderingFrame:(MLNMapView *)mapView fullyRendered:(BOOL)fullyRendered
517
- {
518
- if (fullyRendered) {
519
- [self reactMapDidChange:mapView eventType:RCT_MAPBOX_DID_FINISH_RENDERING_FRAME_FULLY];
520
- } else {
521
- [self reactMapDidChange:mapView eventType:RCT_MAPBOX_DID_FINSIH_RENDERING_FRAME];
522
- }
501
+ - (void)mapViewDidFailLoadingMap:(MLNMapView *)mapView withError:(NSError *)error {
502
+ NSLog(@"Failed loading map %@", error);
503
+ [self reactMapDidChange:mapView eventType:RCT_MAPBOX_DID_FAIL_LOADING_MAP];
523
504
  }
524
505
 
525
- - (void)mapViewWillStartRenderingMap:(MLNMapView *)mapView
526
- {
527
- [self reactMapDidChange:mapView eventType:RCT_MAPBOX_WILL_START_RENDERING_MAP];
506
+ - (void)mapViewWillStartRenderingFrame:(MLNMapView *)mapView {
507
+ [self reactMapDidChange:mapView eventType:RCT_MAPBOX_WILL_START_RENDERING_FRAME];
528
508
  }
529
509
 
530
- - (void)mapViewDidFinishRenderingMap:(MLNMapView *)mapView fullyRendered:(BOOL)fullyRendered
531
- {
532
- if (fullyRendered) {
533
- [self reactMapDidChange:mapView eventType:RCT_MAPBOX_DID_FINISH_RENDERING_MAP_FULLY];
534
- } else {
535
- [self reactMapDidChange:mapView eventType:RCT_MAPBOX_DID_FINISH_RENDERING_MAP];
536
- }
510
+ - (void)mapViewDidFinishRenderingFrame:(MLNMapView *)mapView fullyRendered:(BOOL)fullyRendered {
511
+ if (fullyRendered) {
512
+ [self reactMapDidChange:mapView eventType:RCT_MAPBOX_DID_FINISH_RENDERING_FRAME_FULLY];
513
+ } else {
514
+ [self reactMapDidChange:mapView eventType:RCT_MAPBOX_DID_FINSIH_RENDERING_FRAME];
515
+ }
537
516
  }
538
517
 
539
- - (void)mapView:(MLNMapView *)mapView didFinishLoadingStyle:(MLNStyle *)style
540
- {
541
- MLRNMapView *reactMapView = (MLRNMapView*)mapView;
542
- if(reactMapView.reactLocalizeLabels == true) {
543
- [style localizeLabelsIntoLocale:nil];
544
- }
545
-
546
- for (int i = 0; i < reactMapView.sources.count; i++) {
547
- MLRNSource *source = reactMapView.sources[i];
548
- source.map = reactMapView;
549
- }
550
- for (int i = 0; i < reactMapView.layers.count; i++) {
551
- MLRNLayer *layer = reactMapView.layers[i];
552
- layer.map = reactMapView;
553
- }
554
-
555
- if (reactMapView.light != nil) {
556
- reactMapView.light.map = reactMapView;
557
- }
558
-
559
- [reactMapView notifyStyleLoaded];
560
- [self reactMapDidChange:reactMapView eventType:RCT_MAPBOX_DID_FINISH_LOADING_STYLE];
561
- }
562
-
563
- -(UIImage *)mapView:(MLNMapView *)mapView didFailToLoadImage:(NSString *)imageName
564
- {
565
- MLRNMapView* reactMapView = ((MLRNMapView *) mapView);
566
- NSArray<MLRNImages *> *allImages = [reactMapView getAllImages];
567
- for (MLRNImages *images in allImages) {
568
- if([images addMissingImageToStyle:imageName]) {
569
- // The image was added inside addMissingImageToStyle so we can return nil
570
- return nil;
571
- }
572
- }
573
-
574
- for (MLRNImages *images in allImages) {
575
- [images sendImageMissingEvent:imageName];
576
- }
577
- return nil;
578
- }
579
-
580
- - (void)reactMapDidChange:(MLNMapView*)mapView eventType:(NSString*)type
581
- {
582
- [self reactMapDidChange:mapView eventType:type andPayload:nil];
583
- }
584
-
585
- - (void)reactMapDidChange:(MLNMapView*)mapView eventType:(NSString*)type andPayload:(NSDictionary*)payload
586
- {
587
- MLRNMapView *reactMapView = (MLRNMapView*)mapView;
588
- MLRNEvent *event = [MLRNEvent makeEvent:type withPayload:payload];
589
- [self fireEvent:event withCallback:reactMapView.onMapChange];
590
- }
591
-
592
- - (NSDictionary*)_makeRegionPayload:(MLNMapView*)mapView animated:(BOOL)animated
593
- {
594
- MLRNMapView *rctMapView = (MLRNMapView *)mapView;
595
- MLNPointFeature *feature = [[MLNPointFeature alloc] init];
596
- feature.coordinate = mapView.centerCoordinate;
597
- feature.attributes = @{
598
- @"zoomLevel": [NSNumber numberWithDouble:mapView.zoomLevel],
599
- @"heading": [NSNumber numberWithDouble:mapView.camera.heading],
600
- @"pitch": [NSNumber numberWithDouble:mapView.camera.pitch],
601
- @"animated": [NSNumber numberWithBool:animated],
602
- @"isUserInteraction": @(rctMapView.isUserInteraction),
603
- @"visibleBounds": [MLRNUtils fromCoordinateBounds:mapView.visibleCoordinateBounds]
604
- };
605
- return feature.geoJSONDictionary;
606
- }
607
-
608
- - (NSArray<NSDictionary*> *) featuresToJSON:(NSArray<id<MLNFeature>> *) features
609
- {
610
- NSMutableArray<NSDictionary*> *json = [[NSMutableArray alloc] init];
611
- for(id<MLNFeature> feature in features) {
612
- [json addObject:feature.geoJSONDictionary];
518
+ - (void)mapViewWillStartRenderingMap:(MLNMapView *)mapView {
519
+ [self reactMapDidChange:mapView eventType:RCT_MAPBOX_WILL_START_RENDERING_MAP];
520
+ }
521
+
522
+ - (void)mapViewDidFinishRenderingMap:(MLNMapView *)mapView fullyRendered:(BOOL)fullyRendered {
523
+ if (fullyRendered) {
524
+ [self reactMapDidChange:mapView eventType:RCT_MAPBOX_DID_FINISH_RENDERING_MAP_FULLY];
525
+ } else {
526
+ [self reactMapDidChange:mapView eventType:RCT_MAPBOX_DID_FINISH_RENDERING_MAP];
527
+ }
528
+ }
529
+
530
+ - (void)mapView:(MLNMapView *)mapView didFinishLoadingStyle:(MLNStyle *)style {
531
+ MLRNMapView *reactMapView = (MLRNMapView *)mapView;
532
+ if (reactMapView.reactLocalizeLabels == true) {
533
+ [style localizeLabelsIntoLocale:nil];
534
+ }
535
+
536
+ for (int i = 0; i < reactMapView.sources.count; i++) {
537
+ MLRNSource *source = reactMapView.sources[i];
538
+ source.map = reactMapView;
539
+ }
540
+ for (int i = 0; i < reactMapView.layers.count; i++) {
541
+ MLRNLayer *layer = reactMapView.layers[i];
542
+ layer.map = reactMapView;
543
+ }
544
+
545
+ if (reactMapView.light != nil) {
546
+ reactMapView.light.map = reactMapView;
547
+ }
548
+
549
+ [reactMapView notifyStyleLoaded];
550
+ [self reactMapDidChange:reactMapView eventType:RCT_MAPBOX_DID_FINISH_LOADING_STYLE];
551
+ }
552
+
553
+ - (UIImage *)mapView:(MLNMapView *)mapView didFailToLoadImage:(NSString *)imageName {
554
+ MLRNMapView *reactMapView = ((MLRNMapView *)mapView);
555
+ NSArray<MLRNImages *> *allImages = [reactMapView getAllImages];
556
+ for (MLRNImages *images in allImages) {
557
+ if ([images addMissingImageToStyle:imageName]) {
558
+ // The image was added inside addMissingImageToStyle so we can return nil
559
+ return nil;
613
560
  }
614
- return json;
561
+ }
562
+
563
+ for (MLRNImages *images in allImages) {
564
+ [images sendImageMissingEvent:imageName];
565
+ }
566
+ return nil;
567
+ }
568
+
569
+ - (void)reactMapDidChange:(MLNMapView *)mapView eventType:(NSString *)type {
570
+ [self reactMapDidChange:mapView eventType:type andPayload:nil];
571
+ }
572
+
573
+ - (void)reactMapDidChange:(MLNMapView *)mapView
574
+ eventType:(NSString *)type
575
+ andPayload:(NSDictionary *)payload {
576
+ MLRNMapView *reactMapView = (MLRNMapView *)mapView;
577
+ MLRNEvent *event = [MLRNEvent makeEvent:type withPayload:payload];
578
+ [self fireEvent:event withCallback:reactMapView.onMapChange];
579
+ }
580
+
581
+ - (NSDictionary *)_makeRegionPayload:(MLNMapView *)mapView animated:(BOOL)animated {
582
+ MLRNMapView *rctMapView = (MLRNMapView *)mapView;
583
+ MLNPointFeature *feature = [[MLNPointFeature alloc] init];
584
+ feature.coordinate = mapView.centerCoordinate;
585
+ feature.attributes = @{
586
+ @"zoomLevel" : [NSNumber numberWithDouble:mapView.zoomLevel],
587
+ @"heading" : [NSNumber numberWithDouble:mapView.camera.heading],
588
+ @"pitch" : [NSNumber numberWithDouble:mapView.camera.pitch],
589
+ @"animated" : [NSNumber numberWithBool:animated],
590
+ @"isUserInteraction" : @(rctMapView.isUserInteraction),
591
+ @"visibleBounds" : [MLRNUtils fromCoordinateBounds:mapView.visibleCoordinateBounds]
592
+ };
593
+ return feature.geoJSONDictionary;
594
+ }
595
+
596
+ - (NSArray<NSDictionary *> *)featuresToJSON:(NSArray<id<MLNFeature>> *)features {
597
+ NSMutableArray<NSDictionary *> *json = [[NSMutableArray alloc] init];
598
+ for (id<MLNFeature> feature in features) {
599
+ [json addObject:feature.geoJSONDictionary];
600
+ }
601
+ return json;
615
602
  }
616
603
 
617
604
  @end