@lugg/maps 0.2.0-alpha.8 → 1.0.0-beta.0

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 (173) hide show
  1. package/README.md +20 -19
  2. package/android/src/main/java/com/luggmaps/LuggMapView.kt +290 -0
  3. package/android/src/main/java/com/luggmaps/{LuggGoogleMapViewManager.kt → LuggMapViewManager.kt} +99 -36
  4. package/android/src/main/java/com/luggmaps/LuggMapWrapperView.kt +13 -5
  5. package/android/src/main/java/com/luggmaps/LuggMarkerView.kt +157 -13
  6. package/android/src/main/java/com/luggmaps/LuggMarkerViewManager.kt +28 -0
  7. package/android/src/main/java/com/luggmaps/LuggPackage.kt +1 -4
  8. package/android/src/main/java/com/luggmaps/LuggPolygonView.kt +85 -0
  9. package/android/src/main/java/com/luggmaps/LuggPolygonViewManager.kt +100 -0
  10. package/android/src/main/java/com/luggmaps/LuggPolylineView.kt +16 -0
  11. package/android/src/main/java/com/luggmaps/LuggPolylineViewManager.kt +22 -0
  12. package/android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt +698 -0
  13. package/android/src/main/java/com/luggmaps/core/MapProviderDelegate.kt +60 -0
  14. package/android/src/main/java/com/luggmaps/core/PolylineAnimator.kt +89 -24
  15. package/android/src/main/java/com/luggmaps/events/LongPressEvent.kt +29 -0
  16. package/android/src/main/java/com/luggmaps/events/MarkerDragEvent.kt +41 -0
  17. package/android/src/main/java/com/luggmaps/events/MarkerPressEvent.kt +34 -0
  18. package/android/src/main/java/com/luggmaps/events/PolygonPressEvent.kt +12 -0
  19. package/android/src/main/java/com/luggmaps/events/PressEvent.kt +29 -0
  20. package/ios/LuggMapView.h +9 -0
  21. package/ios/LuggMapView.mm +343 -0
  22. package/ios/LuggMarkerView.h +13 -0
  23. package/ios/LuggMarkerView.mm +119 -0
  24. package/ios/LuggPolygonView.h +31 -0
  25. package/ios/LuggPolygonView.mm +151 -0
  26. package/ios/LuggPolylineView.h +4 -0
  27. package/ios/LuggPolylineView.mm +23 -0
  28. package/ios/core/AppleMapProvider.h +15 -0
  29. package/ios/core/AppleMapProvider.mm +1029 -0
  30. package/ios/core/GMSPolylineAnimator.h +3 -0
  31. package/ios/core/GMSPolylineAnimator.m +101 -15
  32. package/ios/core/GoogleMapProvider.h +13 -0
  33. package/ios/core/GoogleMapProvider.mm +689 -0
  34. package/ios/core/MKPolylineAnimator.h +4 -0
  35. package/ios/core/MKPolylineAnimator.m +167 -42
  36. package/ios/core/MapProviderDelegate.h +84 -0
  37. package/ios/core/PolylineAnimatorBase.h +24 -1
  38. package/ios/core/PolylineAnimatorBase.m +82 -19
  39. package/ios/events/LongPressEvent.h +29 -0
  40. package/ios/events/MarkerDragEvent.h +69 -0
  41. package/ios/events/MarkerPressEvent.h +29 -0
  42. package/ios/events/PolygonPressEvent.h +20 -0
  43. package/ios/events/PressEvent.h +29 -0
  44. package/ios/extensions/MKMapView+Zoom.h +2 -0
  45. package/ios/extensions/MKMapView+Zoom.m +14 -4
  46. package/lib/module/MapProvider.js +2 -4
  47. package/lib/module/MapProvider.js.map +1 -1
  48. package/lib/module/MapProvider.web.js +12 -7
  49. package/lib/module/MapProvider.web.js.map +1 -1
  50. package/lib/module/MapView.js +33 -16
  51. package/lib/module/MapView.js.map +1 -1
  52. package/lib/module/MapView.web.js +315 -217
  53. package/lib/module/MapView.web.js.map +1 -1
  54. package/lib/module/components/GeoJson.js +159 -0
  55. package/lib/module/components/GeoJson.js.map +1 -0
  56. package/lib/module/components/GeoJson.types.js +4 -0
  57. package/lib/module/components/GeoJson.types.js.map +1 -0
  58. package/lib/module/components/Marker.js +28 -4
  59. package/lib/module/components/Marker.js.map +1 -1
  60. package/lib/module/components/Marker.types.js +4 -0
  61. package/lib/module/components/Marker.types.js.map +1 -0
  62. package/lib/module/components/Marker.web.js +98 -27
  63. package/lib/module/components/Marker.web.js.map +1 -1
  64. package/lib/module/components/Polygon.js +46 -0
  65. package/lib/module/components/Polygon.js.map +1 -0
  66. package/lib/module/components/Polygon.types.js +4 -0
  67. package/lib/module/components/Polygon.types.js.map +1 -0
  68. package/lib/module/components/Polygon.web.js +87 -0
  69. package/lib/module/components/Polygon.web.js.map +1 -0
  70. package/lib/module/components/Polyline.js +17 -4
  71. package/lib/module/components/Polyline.js.map +1 -1
  72. package/lib/module/components/Polyline.types.js +4 -0
  73. package/lib/module/components/Polyline.types.js.map +1 -0
  74. package/lib/module/components/Polyline.web.js +108 -31
  75. package/lib/module/components/Polyline.web.js.map +1 -1
  76. package/lib/module/components/index.js +4 -2
  77. package/lib/module/components/index.js.map +1 -1
  78. package/lib/module/components/index.web.js +2 -0
  79. package/lib/module/components/index.web.js.map +1 -1
  80. package/lib/module/fabric/{LuggGoogleMapViewNativeComponent.ts → LuggMapViewNativeComponent.ts} +43 -7
  81. package/lib/module/fabric/LuggMarkerViewNativeComponent.ts +49 -1
  82. package/lib/module/fabric/LuggPolygonViewNativeComponent.ts +25 -0
  83. package/lib/module/fabric/LuggPolylineViewNativeComponent.ts +8 -0
  84. package/lib/module/index.js +4 -1
  85. package/lib/module/index.js.map +1 -1
  86. package/lib/module/index.web.js +4 -1
  87. package/lib/module/index.web.js.map +1 -1
  88. package/lib/typescript/src/MapProvider.d.ts +1 -1
  89. package/lib/typescript/src/MapProvider.d.ts.map +1 -1
  90. package/lib/typescript/src/MapProvider.web.d.ts +17 -1
  91. package/lib/typescript/src/MapProvider.web.d.ts.map +1 -1
  92. package/lib/typescript/src/MapView.d.ts +4 -4
  93. package/lib/typescript/src/MapView.d.ts.map +1 -1
  94. package/lib/typescript/src/MapView.types.d.ts +35 -9
  95. package/lib/typescript/src/MapView.types.d.ts.map +1 -1
  96. package/lib/typescript/src/MapView.web.d.ts +2 -11
  97. package/lib/typescript/src/MapView.web.d.ts.map +1 -1
  98. package/lib/typescript/src/components/GeoJson.d.ts +4 -0
  99. package/lib/typescript/src/components/GeoJson.d.ts.map +1 -0
  100. package/lib/typescript/src/components/GeoJson.types.d.ts +79 -0
  101. package/lib/typescript/src/components/GeoJson.types.d.ts.map +1 -0
  102. package/lib/typescript/src/components/Marker.d.ts +6 -33
  103. package/lib/typescript/src/components/Marker.d.ts.map +1 -1
  104. package/lib/typescript/src/components/Marker.types.d.ts +74 -0
  105. package/lib/typescript/src/components/Marker.types.d.ts.map +1 -0
  106. package/lib/typescript/src/components/Marker.web.d.ts +2 -5
  107. package/lib/typescript/src/components/Marker.web.d.ts.map +1 -1
  108. package/lib/typescript/src/components/Polygon.d.ts +10 -0
  109. package/lib/typescript/src/components/Polygon.d.ts.map +1 -0
  110. package/lib/typescript/src/components/Polygon.types.d.ts +33 -0
  111. package/lib/typescript/src/components/Polygon.types.d.ts.map +1 -0
  112. package/lib/typescript/src/components/Polygon.web.d.ts +3 -0
  113. package/lib/typescript/src/components/Polygon.web.d.ts.map +1 -0
  114. package/lib/typescript/src/components/Polyline.d.ts +6 -21
  115. package/lib/typescript/src/components/Polyline.d.ts.map +1 -1
  116. package/lib/typescript/src/components/Polyline.types.d.ts +53 -0
  117. package/lib/typescript/src/components/Polyline.types.d.ts.map +1 -0
  118. package/lib/typescript/src/components/Polyline.web.d.ts +2 -5
  119. package/lib/typescript/src/components/Polyline.web.d.ts.map +1 -1
  120. package/lib/typescript/src/components/index.d.ts +8 -2
  121. package/lib/typescript/src/components/index.d.ts.map +1 -1
  122. package/lib/typescript/src/components/index.web.d.ts +6 -2
  123. package/lib/typescript/src/components/index.web.d.ts.map +1 -1
  124. package/lib/typescript/src/fabric/{LuggGoogleMapViewNativeComponent.d.ts → LuggMapViewNativeComponent.d.ts} +30 -4
  125. package/lib/typescript/src/fabric/LuggMapViewNativeComponent.d.ts.map +1 -0
  126. package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts +45 -1
  127. package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts.map +1 -1
  128. package/lib/typescript/src/fabric/LuggPolygonViewNativeComponent.d.ts +18 -0
  129. package/lib/typescript/src/fabric/LuggPolygonViewNativeComponent.d.ts.map +1 -0
  130. package/lib/typescript/src/fabric/LuggPolylineViewNativeComponent.d.ts +7 -0
  131. package/lib/typescript/src/fabric/LuggPolylineViewNativeComponent.d.ts.map +1 -1
  132. package/lib/typescript/src/index.d.ts +11 -3
  133. package/lib/typescript/src/index.d.ts.map +1 -1
  134. package/lib/typescript/src/index.web.d.ts +9 -1
  135. package/lib/typescript/src/index.web.d.ts.map +1 -1
  136. package/lib/typescript/src/types.d.ts +11 -0
  137. package/lib/typescript/src/types.d.ts.map +1 -1
  138. package/package.json +10 -9
  139. package/src/MapProvider.tsx +1 -3
  140. package/src/MapProvider.web.tsx +12 -3
  141. package/src/MapView.tsx +32 -26
  142. package/src/MapView.types.ts +43 -9
  143. package/src/MapView.web.tsx +376 -244
  144. package/src/components/GeoJson.tsx +221 -0
  145. package/src/components/GeoJson.types.ts +107 -0
  146. package/src/components/Marker.tsx +45 -36
  147. package/src/components/Marker.types.ts +75 -0
  148. package/src/components/Marker.web.tsx +116 -28
  149. package/src/components/Polygon.tsx +52 -0
  150. package/src/components/Polygon.types.ts +33 -0
  151. package/src/components/Polygon.web.tsx +104 -0
  152. package/src/components/Polyline.tsx +23 -22
  153. package/src/components/Polyline.types.ts +55 -0
  154. package/src/components/Polyline.web.tsx +151 -37
  155. package/src/components/index.ts +16 -2
  156. package/src/components/index.web.ts +6 -2
  157. package/src/fabric/{LuggGoogleMapViewNativeComponent.ts → LuggMapViewNativeComponent.ts} +43 -7
  158. package/src/fabric/LuggMarkerViewNativeComponent.ts +49 -1
  159. package/src/fabric/LuggPolygonViewNativeComponent.ts +25 -0
  160. package/src/fabric/LuggPolylineViewNativeComponent.ts +8 -0
  161. package/src/index.ts +28 -1
  162. package/src/index.web.ts +15 -1
  163. package/src/types.ts +13 -0
  164. package/android/src/main/java/com/luggmaps/LuggGoogleMapView.kt +0 -511
  165. package/ios/LuggAppleMapView.h +0 -16
  166. package/ios/LuggAppleMapView.mm +0 -592
  167. package/ios/LuggGoogleMapView.h +0 -13
  168. package/ios/LuggGoogleMapView.mm +0 -455
  169. package/lib/module/fabric/LuggAppleMapViewNativeComponent.ts +0 -83
  170. package/lib/typescript/src/fabric/LuggAppleMapViewNativeComponent.d.ts +0 -54
  171. package/lib/typescript/src/fabric/LuggAppleMapViewNativeComponent.d.ts.map +0 -1
  172. package/lib/typescript/src/fabric/LuggGoogleMapViewNativeComponent.d.ts.map +0 -1
  173. package/src/fabric/LuggAppleMapViewNativeComponent.ts +0 -83
@@ -1,16 +0,0 @@
1
- #import <MapKit/MapKit.h>
2
- #import <React/RCTViewComponentView.h>
3
- #import <UIKit/UIKit.h>
4
-
5
- NS_ASSUME_NONNULL_BEGIN
6
-
7
- @interface LuggAppleMapViewContent : MKMapView
8
- @end
9
-
10
- @interface LuggAppleMapView : RCTViewComponentView
11
-
12
- - (MKMapView *)mapView;
13
-
14
- @end
15
-
16
- NS_ASSUME_NONNULL_END
@@ -1,592 +0,0 @@
1
- #import "LuggAppleMapView.h"
2
- #import "LuggMapWrapperView.h"
3
- #import "LuggMarkerView.h"
4
- #import "LuggPolylineView.h"
5
- #import "core/MKPolylineAnimator.h"
6
- #import "events/CameraIdleEvent.h"
7
- #import "events/CameraMoveEvent.h"
8
- #import "events/ReadyEvent.h"
9
- #import "extensions/MKMapView+Zoom.h"
10
-
11
- #import <react/renderer/components/RNMapsSpec/ComponentDescriptors.h>
12
- #import <react/renderer/components/RNMapsSpec/EventEmitters.h>
13
- #import <react/renderer/components/RNMapsSpec/Props.h>
14
- #import <react/renderer/components/RNMapsSpec/RCTComponentViewHelpers.h>
15
-
16
- #import "RCTFabricComponentsPlugins.h"
17
-
18
- using namespace facebook::react;
19
- using namespace luggmaps::events;
20
-
21
- @interface AppleMarkerAnnotation : NSObject <MKAnnotation>
22
- @property(nonatomic, assign) CLLocationCoordinate2D coordinate;
23
- @property(nonatomic, copy, nullable) NSString *title;
24
- @property(nonatomic, copy, nullable) NSString *subtitle;
25
- @property(nonatomic, strong) LuggMarkerView *markerView;
26
- @property(nonatomic, weak) MKAnnotationView *annotationView;
27
- @end
28
-
29
- @implementation AppleMarkerAnnotation
30
- @end
31
-
32
- @implementation LuggAppleMapViewContent
33
- @end
34
-
35
- @interface LuggAppleMapView () <RCTLuggAppleMapViewViewProtocol,
36
- MKMapViewDelegate, LuggMarkerViewDelegate,
37
- LuggPolylineViewDelegate>
38
- @end
39
-
40
- @implementation LuggAppleMapView {
41
- LuggAppleMapViewContent *_mapView;
42
- LuggMapWrapperView *_mapWrapperView;
43
- BOOL _isMapReady;
44
- BOOL _isDragging;
45
- double _minZoom;
46
- double _maxZoom;
47
- }
48
-
49
- + (ComponentDescriptorProvider)componentDescriptorProvider {
50
- return concreteComponentDescriptorProvider<
51
- LuggAppleMapViewComponentDescriptor>();
52
- }
53
-
54
- - (instancetype)initWithFrame:(CGRect)frame {
55
- if (self = [super initWithFrame:frame]) {
56
- static const auto defaultProps =
57
- std::make_shared<const LuggAppleMapViewProps>();
58
- _props = defaultProps;
59
- }
60
-
61
- return self;
62
- }
63
-
64
- #pragma mark - View Lifecycle
65
-
66
- - (void)mountChildComponentView:
67
- (UIView<RCTComponentViewProtocol> *)childComponentView
68
- index:(NSInteger)index {
69
- [super mountChildComponentView:childComponentView index:index];
70
-
71
- if ([childComponentView isKindOfClass:[LuggMapWrapperView class]]) {
72
- _mapWrapperView = (LuggMapWrapperView *)childComponentView;
73
- } else if ([childComponentView isKindOfClass:[LuggMarkerView class]]) {
74
- LuggMarkerView *markerView = (LuggMarkerView *)childComponentView;
75
- markerView.delegate = self;
76
-
77
- AppleMarkerAnnotation *annotation = [[AppleMarkerAnnotation alloc] init];
78
- annotation.markerView = markerView;
79
- markerView.marker = annotation;
80
-
81
- if (_mapView) {
82
- [_mapView addAnnotation:annotation];
83
- }
84
-
85
- [self markerViewDidUpdate:markerView];
86
- } else if ([childComponentView isKindOfClass:[LuggPolylineView class]]) {
87
- LuggPolylineView *polylineView = (LuggPolylineView *)childComponentView;
88
- polylineView.delegate = self;
89
- [self addPolylineViewToMap:polylineView];
90
- }
91
- }
92
-
93
- - (void)unmountChildComponentView:
94
- (UIView<RCTComponentViewProtocol> *)childComponentView
95
- index:(NSInteger)index {
96
- if ([childComponentView isKindOfClass:[LuggMarkerView class]]) {
97
- LuggMarkerView *markerView = (LuggMarkerView *)childComponentView;
98
- markerView.delegate = nil;
99
-
100
- AppleMarkerAnnotation *annotation =
101
- (AppleMarkerAnnotation *)markerView.marker;
102
-
103
- if (annotation) {
104
- annotation.markerView = nil;
105
- annotation.annotationView = nil;
106
- [_mapView removeAnnotation:annotation];
107
- markerView.marker = nil;
108
- }
109
- } else if ([childComponentView isKindOfClass:[LuggPolylineView class]]) {
110
- LuggPolylineView *polylineView = (LuggPolylineView *)childComponentView;
111
- polylineView.delegate = nil;
112
- MKPolyline *polyline = (MKPolyline *)polylineView.polyline;
113
- if (polyline) {
114
- [_mapView removeOverlay:polyline];
115
- polylineView.polyline = nil;
116
- }
117
- }
118
-
119
- [super unmountChildComponentView:childComponentView index:index];
120
- }
121
-
122
- - (void)didMoveToWindow {
123
- [super didMoveToWindow];
124
- if (self.window && !_mapView && _mapWrapperView) {
125
- [self initializeMap];
126
- }
127
- }
128
-
129
- - (void)prepareForRecycle {
130
- [super prepareForRecycle];
131
-
132
- [_mapView removeFromSuperview];
133
- _mapView = nil;
134
- _mapWrapperView = nil;
135
- _isMapReady = NO;
136
- }
137
-
138
- #pragma mark - Map Initialization
139
-
140
- - (void)initializeMap {
141
- if (_mapView || !_mapWrapperView) {
142
- return;
143
- }
144
-
145
- const auto &viewProps =
146
- *std::static_pointer_cast<LuggAppleMapViewProps const>(_props);
147
-
148
- _mapView =
149
- [[LuggAppleMapViewContent alloc] initWithFrame:_mapWrapperView.bounds];
150
- _mapView.autoresizingMask =
151
- UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
152
- _mapView.delegate = self;
153
- _mapView.insetsLayoutMarginsFromSafeArea = NO;
154
- _mapView.zoomEnabled = viewProps.zoomEnabled;
155
- _mapView.scrollEnabled = viewProps.scrollEnabled;
156
- _mapView.rotateEnabled = viewProps.rotateEnabled;
157
- _mapView.pitchEnabled = viewProps.pitchEnabled;
158
- _mapView.showsUserLocation = viewProps.userLocationEnabled;
159
-
160
- _minZoom = viewProps.minZoom;
161
- _maxZoom = viewProps.maxZoom;
162
- [self applyZoomRange];
163
-
164
- _mapView.layoutMargins =
165
- UIEdgeInsetsMake(viewProps.padding.top, viewProps.padding.left,
166
- viewProps.padding.bottom, viewProps.padding.right);
167
-
168
- [_mapWrapperView addSubview:_mapView];
169
-
170
- [self setCameraWithLatitude:viewProps.initialCoordinate.latitude
171
- longitude:viewProps.initialCoordinate.longitude
172
- zoom:viewProps.initialZoom
173
- animated:NO];
174
-
175
- // Add annotations for any markers that were mounted before map was ready
176
- for (UIView *subview in self.subviews) {
177
- if ([subview isKindOfClass:[LuggMarkerView class]]) {
178
- LuggMarkerView *markerView = (LuggMarkerView *)subview;
179
- AppleMarkerAnnotation *annotation =
180
- (AppleMarkerAnnotation *)markerView.marker;
181
- if (annotation) {
182
- [_mapView addAnnotation:annotation];
183
- }
184
- } else if ([subview isKindOfClass:[LuggPolylineView class]]) {
185
- LuggPolylineView *polylineView = (LuggPolylineView *)subview;
186
- [self addPolylineViewToMap:polylineView];
187
- }
188
- }
189
-
190
- _isMapReady = YES;
191
-
192
- ReadyEvent::emit<LuggAppleMapViewEventEmitter>(_eventEmitter);
193
- }
194
-
195
- - (void)setCameraWithLatitude:(double)latitude
196
- longitude:(double)longitude
197
- zoom:(double)zoom
198
- animated:(BOOL)animated {
199
- CLLocationCoordinate2D center =
200
- CLLocationCoordinate2DMake(latitude, longitude);
201
- [_mapView setCenterCoordinate:center zoomLevel:zoom animated:animated];
202
- }
203
-
204
- - (CLLocationDistance)cameraDistanceForZoomLevel:(double)zoomLevel {
205
- // Approximate conversion: at zoom 0, altitude ~128M km
206
- // Each zoom level halves the altitude
207
- return 128000000.0 / pow(2, zoomLevel);
208
- }
209
-
210
- - (void)applyZoomRange {
211
- if (!_mapView)
212
- return;
213
-
214
- CLLocationDistance minDistance =
215
- _maxZoom > 0 ? [self cameraDistanceForZoomLevel:_maxZoom] : 0;
216
- CLLocationDistance maxDistance =
217
- _minZoom > 0 ? [self cameraDistanceForZoomLevel:_minZoom] : -1;
218
-
219
- MKMapCameraZoomRange *zoomRange = [[MKMapCameraZoomRange alloc]
220
- initWithMinCenterCoordinateDistance:minDistance
221
- maxCenterCoordinateDistance:maxDistance];
222
- _mapView.cameraZoomRange = zoomRange;
223
- }
224
-
225
- - (MKMapView *)mapView {
226
- return _mapView;
227
- }
228
-
229
- #pragma mark - Property Setters
230
-
231
- - (void)updateProps:(Props::Shared const &)props
232
- oldProps:(Props::Shared const &)oldProps {
233
- const auto &newViewProps =
234
- *std::static_pointer_cast<LuggAppleMapViewProps const>(props);
235
-
236
- if (_mapView) {
237
- _mapView.zoomEnabled = newViewProps.zoomEnabled;
238
- _mapView.scrollEnabled = newViewProps.scrollEnabled;
239
- _mapView.rotateEnabled = newViewProps.rotateEnabled;
240
- _mapView.pitchEnabled = newViewProps.pitchEnabled;
241
- _mapView.showsUserLocation = newViewProps.userLocationEnabled;
242
- _mapView.layoutMargins = UIEdgeInsetsMake(
243
- newViewProps.padding.top, newViewProps.padding.left,
244
- newViewProps.padding.bottom, newViewProps.padding.right);
245
-
246
- _minZoom = newViewProps.minZoom;
247
- _maxZoom = newViewProps.maxZoom;
248
- [self applyZoomRange];
249
- }
250
-
251
- [super updateProps:props oldProps:oldProps];
252
- }
253
-
254
- #pragma mark - Annotation Helpers
255
-
256
- - (void)updateAnnotationViewFrame:(AppleMarkerAnnotation *)annotation {
257
- MKAnnotationView *annotationView = annotation.annotationView;
258
- LuggMarkerView *markerView = annotation.markerView;
259
-
260
- if (!annotationView || !markerView) {
261
- return;
262
- }
263
-
264
- UIView *iconView = markerView.iconView;
265
- CGRect frame = iconView.frame;
266
- if (frame.size.width > 0 && frame.size.height > 0) {
267
- annotationView.frame = frame;
268
-
269
- CGPoint anchor = markerView.anchor;
270
- annotationView.centerOffset =
271
- CGPointMake(frame.size.width * (anchor.x - 0.5),
272
- -frame.size.height * (anchor.y - 0.5));
273
- }
274
- }
275
-
276
- #pragma mark - PolylineViewDelegate
277
-
278
- - (void)polylineViewDidUpdate:(LuggPolylineView *)polylineView {
279
- [self syncPolylineView:polylineView];
280
- }
281
-
282
- #pragma mark - Polyline Management
283
-
284
- - (void)addPolylineViewToMap:(LuggPolylineView *)polylineView {
285
- if (!_mapView) {
286
- return;
287
- }
288
-
289
- NSArray<CLLocation *> *coordinates = polylineView.coordinates;
290
- if (coordinates.count == 0) {
291
- return;
292
- }
293
-
294
- CLLocationCoordinate2D *coords = (CLLocationCoordinate2D *)malloc(
295
- sizeof(CLLocationCoordinate2D) * coordinates.count);
296
- for (NSUInteger i = 0; i < coordinates.count; i++) {
297
- coords[i] = coordinates[i].coordinate;
298
- }
299
-
300
- MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords
301
- count:coordinates.count];
302
- free(coords);
303
-
304
- polylineView.polyline = polyline;
305
- [_mapView addOverlay:polyline];
306
- }
307
-
308
- - (void)syncPolylineView:(LuggPolylineView *)polylineView {
309
- if (!_mapView) {
310
- return;
311
- }
312
-
313
- MKPolylineAnimator *renderer = (MKPolylineAnimator *)polylineView.renderer;
314
- MKPolyline *oldPolyline = (MKPolyline *)polylineView.polyline;
315
-
316
- // Build new polyline from coordinates
317
- NSArray<CLLocation *> *coordinates = polylineView.coordinates;
318
- if (coordinates.count == 0) {
319
- if (renderer) {
320
- renderer.animated = NO;
321
- }
322
- if (oldPolyline) {
323
- [_mapView removeOverlay:oldPolyline];
324
- polylineView.polyline = nil;
325
- polylineView.renderer = nil;
326
- }
327
- return;
328
- }
329
-
330
- CLLocationCoordinate2D *coords = (CLLocationCoordinate2D *)malloc(
331
- sizeof(CLLocationCoordinate2D) * coordinates.count);
332
- for (NSUInteger i = 0; i < coordinates.count; i++) {
333
- coords[i] = coordinates[i].coordinate;
334
- }
335
- MKPolyline *newPolyline =
336
- [MKPolyline polylineWithCoordinates:coords count:coordinates.count];
337
- free(coords);
338
-
339
- polylineView.polyline = newPolyline;
340
-
341
- // If we have an existing renderer, update it in place
342
- if (renderer && oldPolyline) {
343
- [_mapView removeOverlay:oldPolyline];
344
- [_mapView addOverlay:newPolyline];
345
- [renderer updatePolyline:newPolyline];
346
- renderer.lineWidth = polylineView.strokeWidth;
347
- renderer.strokeColor = polylineView.strokeColors.firstObject;
348
- renderer.strokeColors =
349
- polylineView.strokeColors.count > 1 ? polylineView.strokeColors : nil;
350
- renderer.animated = polylineView.animated;
351
- return;
352
- }
353
-
354
- // Otherwise do full add
355
- if (oldPolyline) {
356
- [_mapView removeOverlay:oldPolyline];
357
- }
358
- [_mapView addOverlay:newPolyline];
359
- }
360
-
361
- - (LuggPolylineView *)findPolylineViewForOverlay:(id<MKOverlay>)overlay {
362
- for (UIView *subview in self.subviews) {
363
- if ([subview isKindOfClass:[LuggPolylineView class]]) {
364
- LuggPolylineView *polylineView = (LuggPolylineView *)subview;
365
- if (polylineView.polyline == overlay) {
366
- return polylineView;
367
- }
368
- }
369
- }
370
- return nil;
371
- }
372
-
373
- #pragma mark - MarkerViewDelegate
374
-
375
- - (void)markerViewDidLayout:(LuggMarkerView *)markerView {
376
- AppleMarkerAnnotation *annotation =
377
- (AppleMarkerAnnotation *)markerView.marker;
378
- if (annotation) {
379
- [self updateAnnotationViewFrame:annotation];
380
- }
381
- }
382
-
383
- - (void)markerViewDidUpdate:(LuggMarkerView *)markerView {
384
- AppleMarkerAnnotation *annotation =
385
- (AppleMarkerAnnotation *)markerView.marker;
386
-
387
- if (!annotation) {
388
- RCTLogWarn(@"markerViewDidUpdate called without annotation");
389
- return;
390
- }
391
-
392
- annotation.coordinate = markerView.coordinate;
393
- annotation.title = markerView.title;
394
- annotation.subtitle = markerView.markerDescription;
395
-
396
- MKAnnotationView *annotationView = annotation.annotationView;
397
- if (annotationView) {
398
- annotationView.layer.zPosition = markerView.zIndex;
399
- annotationView.zPriority = markerView.zIndex;
400
- }
401
-
402
- [self updateAnnotationViewFrame:annotation];
403
- }
404
-
405
- #pragma mark - MKMapViewDelegate
406
-
407
- - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated {
408
- _isDragging = [self isUserInteracting:mapView];
409
- }
410
-
411
- - (BOOL)isUserInteracting:(MKMapView *)mapView {
412
- UIView *mapContainerView = mapView.subviews.firstObject;
413
- for (UIGestureRecognizer *gesture in mapContainerView.gestureRecognizers) {
414
- if (gesture.state == UIGestureRecognizerStateBegan ||
415
- gesture.state == UIGestureRecognizerStateChanged) {
416
- return YES;
417
- }
418
- }
419
- return NO;
420
- }
421
-
422
- - (void)mapViewDidChangeVisibleRegion:(MKMapView *)mapView {
423
- CameraMoveEvent{mapView.centerCoordinate.latitude,
424
- mapView.centerCoordinate.longitude, mapView.zoomLevel,
425
- _isDragging}
426
- .emit<LuggAppleMapViewEventEmitter>(_eventEmitter);
427
- }
428
-
429
- - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
430
- BOOL wasDragging = _isDragging;
431
- _isDragging = NO;
432
- CameraIdleEvent{mapView.centerCoordinate.latitude,
433
- mapView.centerCoordinate.longitude, mapView.zoomLevel,
434
- static_cast<bool>(wasDragging)}
435
- .emit<LuggAppleMapViewEventEmitter>(_eventEmitter);
436
- }
437
-
438
- - (MKAnnotationView *)mapView:(MKMapView *)mapView
439
- viewForAnnotation:(id<MKAnnotation>)annotation {
440
- if (![annotation isKindOfClass:[AppleMarkerAnnotation class]]) {
441
- return nil;
442
- }
443
-
444
- AppleMarkerAnnotation *markerAnnotation = (AppleMarkerAnnotation *)annotation;
445
- LuggMarkerView *markerView = markerAnnotation.markerView;
446
-
447
- if (!markerView || !markerView.hasCustomView) {
448
- return nil;
449
- }
450
-
451
- MKAnnotationView *annotationView =
452
- [[MKAnnotationView alloc] initWithAnnotation:annotation
453
- reuseIdentifier:nil];
454
- annotationView.canShowCallout = YES;
455
- annotationView.displayPriority = MKFeatureDisplayPriorityRequired;
456
- annotationView.layer.zPosition = markerView.zIndex;
457
- annotationView.zPriority = markerView.zIndex;
458
-
459
- UIView *iconView = markerView.iconView;
460
- [iconView removeFromSuperview];
461
- [annotationView addSubview:iconView];
462
-
463
- // Set frame and centerOffset based on iconView
464
- CGRect frame = iconView.frame;
465
- if (frame.size.width > 0 && frame.size.height > 0) {
466
- annotationView.frame =
467
- CGRectMake(0, 0, frame.size.width, frame.size.height);
468
- iconView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
469
-
470
- CGPoint anchor = markerView.anchor;
471
- annotationView.centerOffset =
472
- CGPointMake(frame.size.width * (anchor.x - 0.5),
473
- -frame.size.height * (anchor.y - 0.5));
474
- }
475
-
476
- markerAnnotation.annotationView = annotationView;
477
-
478
- return annotationView;
479
- }
480
-
481
- - (MKOverlayRenderer *)mapView:(MKMapView *)mapView
482
- rendererForOverlay:(id<MKOverlay>)overlay {
483
- if ([overlay isKindOfClass:[MKPolyline class]]) {
484
- LuggPolylineView *polylineView = [self findPolylineViewForOverlay:overlay];
485
- MKPolyline *polyline = (MKPolyline *)overlay;
486
-
487
- if (polylineView) {
488
- NSArray<UIColor *> *colors = polylineView.strokeColors;
489
-
490
- MKPolylineAnimator *renderer =
491
- [[MKPolylineAnimator alloc] initWithPolyline:polyline];
492
- renderer.lineWidth = polylineView.strokeWidth;
493
- renderer.strokeColor = colors.firstObject;
494
- if (colors.count > 1) {
495
- renderer.strokeColors = colors;
496
- }
497
- renderer.animated = polylineView.animated;
498
- polylineView.renderer = renderer;
499
- return renderer;
500
- }
501
-
502
- MKPolylineRenderer *renderer =
503
- [[MKPolylineRenderer alloc] initWithPolyline:polyline];
504
- return renderer;
505
- }
506
- return nil;
507
- }
508
-
509
- #pragma mark - Commands
510
-
511
- - (void)moveCamera:(double)latitude
512
- longitude:(double)longitude
513
- zoom:(double)zoom
514
- duration:(double)duration {
515
- if (!_mapView) {
516
- return;
517
- }
518
-
519
- if (duration < 0) {
520
- [self setCameraWithLatitude:latitude
521
- longitude:longitude
522
- zoom:zoom
523
- animated:YES];
524
- } else if (duration > 0) {
525
- CLLocationCoordinate2D center =
526
- CLLocationCoordinate2DMake(latitude, longitude);
527
- MKCoordinateRegion region = [_mapView regionForCenterCoordinate:center
528
- zoomLevel:zoom];
529
- [UIView animateWithDuration:duration / 1000.0
530
- animations:^{
531
- [self->_mapView setRegion:region animated:NO];
532
- }];
533
- } else {
534
- [self setCameraWithLatitude:latitude
535
- longitude:longitude
536
- zoom:zoom
537
- animated:NO];
538
- }
539
- }
540
-
541
- - (void)fitCoordinates:(NSArray *)coordinates
542
- paddingTop:(double)paddingTop
543
- paddingLeft:(double)paddingLeft
544
- paddingBottom:(double)paddingBottom
545
- paddingRight:(double)paddingRight
546
- duration:(double)duration {
547
- if (!_mapView || coordinates.count == 0) {
548
- return;
549
- }
550
-
551
- CLLocationCoordinate2D *coords = (CLLocationCoordinate2D *)malloc(
552
- sizeof(CLLocationCoordinate2D) * coordinates.count);
553
- for (NSUInteger i = 0; i < coordinates.count; i++) {
554
- NSDictionary *coord = coordinates[i];
555
- coords[i] = CLLocationCoordinate2DMake([coord[@"latitude"] doubleValue],
556
- [coord[@"longitude"] doubleValue]);
557
- }
558
-
559
- MKMapRect mapRect = MKMapRectNull;
560
- for (NSUInteger i = 0; i < coordinates.count; i++) {
561
- MKMapPoint point = MKMapPointForCoordinate(coords[i]);
562
- MKMapRect pointRect = MKMapRectMake(point.x, point.y, 0, 0);
563
- mapRect = MKMapRectUnion(mapRect, pointRect);
564
- }
565
- free(coords);
566
-
567
- UIEdgeInsets edgePadding =
568
- UIEdgeInsetsMake(paddingTop, paddingLeft, paddingBottom, paddingRight);
569
-
570
- if (duration < 0) {
571
- [_mapView setVisibleMapRect:mapRect edgePadding:edgePadding animated:YES];
572
- } else if (duration > 0) {
573
- [UIView animateWithDuration:duration / 1000.0
574
- animations:^{
575
- [self->_mapView setVisibleMapRect:mapRect
576
- edgePadding:edgePadding
577
- animated:NO];
578
- }];
579
- } else {
580
- [_mapView setVisibleMapRect:mapRect edgePadding:edgePadding animated:NO];
581
- }
582
- }
583
-
584
- - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args {
585
- RCTLuggAppleMapViewHandleCommand(self, commandName, args);
586
- }
587
-
588
- Class<RCTComponentViewProtocol> LuggAppleMapViewCls(void) {
589
- return LuggAppleMapView.class;
590
- }
591
-
592
- @end
@@ -1,13 +0,0 @@
1
- #import <GoogleMaps/GoogleMaps.h>
2
- #import <React/RCTViewComponentView.h>
3
- #import <UIKit/UIKit.h>
4
-
5
- NS_ASSUME_NONNULL_BEGIN
6
-
7
- @interface LuggGoogleMapView : RCTViewComponentView
8
-
9
- @property(nonatomic, readonly, nullable) GMSMapView *mapView;
10
-
11
- @end
12
-
13
- NS_ASSUME_NONNULL_END