@lugg/maps 0.2.0-alpha.3 → 0.2.0-alpha.30
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.
- package/README.md +21 -3
- package/android/src/main/java/com/luggmaps/LuggMapView.kt +265 -0
- package/android/src/main/java/com/luggmaps/{LuggGoogleMapViewManager.kt → LuggMapViewManager.kt} +75 -36
- package/android/src/main/java/com/luggmaps/LuggMapWrapperView.kt +6 -5
- package/android/src/main/java/com/luggmaps/LuggMarkerView.kt +136 -14
- package/android/src/main/java/com/luggmaps/LuggMarkerViewManager.kt +21 -0
- package/android/src/main/java/com/luggmaps/LuggPackage.kt +1 -4
- package/android/src/main/java/com/luggmaps/LuggPolylineView.kt +16 -0
- package/android/src/main/java/com/luggmaps/LuggPolylineViewManager.kt +22 -0
- package/android/src/main/java/com/luggmaps/{LuggGoogleMapView.kt → core/GoogleMapProvider.kt} +251 -241
- package/android/src/main/java/com/luggmaps/core/MapProviderDelegate.kt +55 -0
- package/android/src/main/java/com/luggmaps/core/PolylineAnimator.kt +163 -52
- package/ios/LuggMapView.h +9 -0
- package/ios/LuggMapView.mm +312 -0
- package/ios/LuggMarkerView.h +9 -0
- package/ios/LuggMarkerView.mm +79 -0
- package/ios/LuggPolylineView.h +4 -0
- package/ios/LuggPolylineView.mm +23 -0
- package/ios/core/AppleMapProvider.h +15 -0
- package/ios/core/AppleMapProvider.mm +664 -0
- package/ios/core/GMSPolylineAnimator.h +3 -0
- package/ios/core/GMSPolylineAnimator.m +175 -40
- package/ios/core/GoogleMapProvider.h +13 -0
- package/ios/core/GoogleMapProvider.mm +513 -0
- package/ios/core/MKPolylineAnimator.h +4 -0
- package/ios/core/MKPolylineAnimator.m +224 -68
- package/ios/core/MapProviderDelegate.h +72 -0
- package/ios/core/PolylineAnimatorBase.h +24 -1
- package/ios/core/PolylineAnimatorBase.m +82 -19
- package/ios/extensions/MKMapView+Zoom.h +2 -0
- package/ios/extensions/MKMapView+Zoom.m +14 -4
- package/lib/module/MapProvider.js +13 -0
- package/lib/module/MapProvider.js.map +1 -0
- package/lib/module/MapProvider.types.js +4 -0
- package/lib/module/MapProvider.types.js.map +1 -0
- package/lib/module/MapProvider.web.js +20 -0
- package/lib/module/MapProvider.web.js.map +1 -0
- package/lib/module/MapView.js +29 -16
- package/lib/module/MapView.js.map +1 -1
- package/lib/module/MapView.web.js +290 -0
- package/lib/module/MapView.web.js.map +1 -0
- package/lib/module/components/Marker.js +19 -2
- package/lib/module/components/Marker.js.map +1 -1
- package/lib/module/components/Marker.web.js +33 -0
- package/lib/module/components/Marker.web.js.map +1 -0
- package/lib/module/components/Polyline.js +17 -4
- package/lib/module/components/Polyline.js.map +1 -1
- package/lib/module/components/Polyline.web.js +229 -0
- package/lib/module/components/Polyline.web.js.map +1 -0
- package/lib/module/components/index.js +2 -2
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/components/index.web.js +5 -0
- package/lib/module/components/index.web.js.map +1 -0
- package/lib/module/fabric/{LuggGoogleMapViewNativeComponent.ts → LuggMapViewNativeComponent.ts} +19 -7
- package/lib/module/fabric/LuggMarkerViewNativeComponent.ts +7 -1
- package/lib/module/fabric/LuggPolylineViewNativeComponent.ts +8 -0
- package/lib/module/index.js +4 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +7 -0
- package/lib/module/index.web.js.map +1 -0
- package/lib/typescript/src/MapProvider.d.ts +8 -0
- package/lib/typescript/src/MapProvider.d.ts.map +1 -0
- package/lib/typescript/src/MapProvider.types.d.ts +16 -0
- package/lib/typescript/src/MapProvider.types.d.ts.map +1 -0
- package/lib/typescript/src/MapProvider.web.d.ts +11 -0
- package/lib/typescript/src/MapProvider.web.d.ts.map +1 -0
- package/lib/typescript/src/MapView.d.ts +4 -4
- package/lib/typescript/src/MapView.d.ts.map +1 -1
- package/lib/typescript/src/MapView.types.d.ts +23 -7
- package/lib/typescript/src/MapView.types.d.ts.map +1 -1
- package/lib/typescript/src/MapView.web.d.ts +3 -0
- package/lib/typescript/src/MapView.web.d.ts.map +1 -0
- package/lib/typescript/src/components/Marker.d.ts +25 -1
- package/lib/typescript/src/components/Marker.d.ts.map +1 -1
- package/lib/typescript/src/components/Marker.web.d.ts +3 -0
- package/lib/typescript/src/components/Marker.web.d.ts.map +1 -0
- package/lib/typescript/src/components/Polyline.d.ts +36 -1
- package/lib/typescript/src/components/Polyline.d.ts.map +1 -1
- package/lib/typescript/src/components/Polyline.web.d.ts +3 -0
- package/lib/typescript/src/components/Polyline.web.d.ts.map +1 -0
- package/lib/typescript/src/components/index.d.ts +4 -2
- package/lib/typescript/src/components/index.d.ts.map +1 -1
- package/lib/typescript/src/components/index.web.d.ts +5 -0
- package/lib/typescript/src/components/index.web.d.ts.map +1 -0
- package/lib/typescript/src/fabric/{LuggGoogleMapViewNativeComponent.d.ts → LuggMapViewNativeComponent.d.ts} +8 -4
- package/lib/typescript/src/fabric/LuggMapViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts +4 -1
- package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/fabric/LuggPolylineViewNativeComponent.d.ts +7 -0
- package/lib/typescript/src/fabric/LuggPolylineViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +8 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/index.web.d.ts +10 -0
- package/lib/typescript/src/index.web.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +4 -0
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/package.json +17 -3
- package/src/MapProvider.tsx +10 -0
- package/src/MapProvider.types.ts +16 -0
- package/src/MapProvider.web.tsx +14 -0
- package/src/MapView.tsx +28 -26
- package/src/MapView.types.ts +24 -7
- package/src/MapView.web.tsx +364 -0
- package/src/components/Marker.tsx +50 -4
- package/src/components/Marker.web.tsx +33 -0
- package/src/components/Polyline.tsx +51 -2
- package/src/components/Polyline.web.tsx +287 -0
- package/src/components/index.ts +8 -2
- package/src/components/index.web.ts +4 -0
- package/src/fabric/{LuggGoogleMapViewNativeComponent.ts → LuggMapViewNativeComponent.ts} +19 -7
- package/src/fabric/LuggMarkerViewNativeComponent.ts +7 -1
- package/src/fabric/LuggPolylineViewNativeComponent.ts +8 -0
- package/src/index.ts +18 -2
- package/src/index.web.ts +20 -0
- package/src/types.ts +5 -0
- package/ios/LuggAppleMapView.h +0 -16
- package/ios/LuggAppleMapView.mm +0 -580
- package/ios/LuggGoogleMapView.h +0 -13
- package/ios/LuggGoogleMapView.mm +0 -454
- package/lib/module/fabric/LuggAppleMapViewNativeComponent.ts +0 -83
- package/lib/typescript/src/fabric/LuggAppleMapViewNativeComponent.d.ts +0 -54
- package/lib/typescript/src/fabric/LuggAppleMapViewNativeComponent.d.ts.map +0 -1
- package/lib/typescript/src/fabric/LuggGoogleMapViewNativeComponent.d.ts.map +0 -1
- package/src/fabric/LuggAppleMapViewNativeComponent.ts +0 -83
package/ios/LuggAppleMapView.mm
DELETED
|
@@ -1,580 +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 (oldPolyline) {
|
|
320
|
-
[_mapView removeOverlay:oldPolyline];
|
|
321
|
-
polylineView.polyline = nil;
|
|
322
|
-
polylineView.renderer = nil;
|
|
323
|
-
}
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
CLLocationCoordinate2D *coords = (CLLocationCoordinate2D *)malloc(
|
|
328
|
-
sizeof(CLLocationCoordinate2D) * coordinates.count);
|
|
329
|
-
for (NSUInteger i = 0; i < coordinates.count; i++) {
|
|
330
|
-
coords[i] = coordinates[i].coordinate;
|
|
331
|
-
}
|
|
332
|
-
MKPolyline *newPolyline =
|
|
333
|
-
[MKPolyline polylineWithCoordinates:coords count:coordinates.count];
|
|
334
|
-
free(coords);
|
|
335
|
-
|
|
336
|
-
polylineView.polyline = newPolyline;
|
|
337
|
-
|
|
338
|
-
// If we have an existing renderer, update it in place
|
|
339
|
-
if (renderer && oldPolyline) {
|
|
340
|
-
[renderer updatePolyline:newPolyline];
|
|
341
|
-
renderer.lineWidth = polylineView.strokeWidth;
|
|
342
|
-
renderer.strokeColor = polylineView.strokeColors.firstObject;
|
|
343
|
-
renderer.strokeColors =
|
|
344
|
-
polylineView.strokeColors.count > 1 ? polylineView.strokeColors : nil;
|
|
345
|
-
renderer.animated = polylineView.animated;
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// Otherwise do full add
|
|
350
|
-
if (oldPolyline) {
|
|
351
|
-
[_mapView removeOverlay:oldPolyline];
|
|
352
|
-
}
|
|
353
|
-
[_mapView addOverlay:newPolyline];
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
- (LuggPolylineView *)findPolylineViewForOverlay:(id<MKOverlay>)overlay {
|
|
357
|
-
for (UIView *subview in self.subviews) {
|
|
358
|
-
if ([subview isKindOfClass:[LuggPolylineView class]]) {
|
|
359
|
-
LuggPolylineView *polylineView = (LuggPolylineView *)subview;
|
|
360
|
-
if (polylineView.polyline == overlay) {
|
|
361
|
-
return polylineView;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
return nil;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
#pragma mark - MarkerViewDelegate
|
|
369
|
-
|
|
370
|
-
- (void)markerViewDidLayout:(LuggMarkerView *)markerView {
|
|
371
|
-
AppleMarkerAnnotation *annotation =
|
|
372
|
-
(AppleMarkerAnnotation *)markerView.marker;
|
|
373
|
-
if (annotation) {
|
|
374
|
-
[self updateAnnotationViewFrame:annotation];
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
- (void)markerViewDidUpdate:(LuggMarkerView *)markerView {
|
|
379
|
-
AppleMarkerAnnotation *annotation =
|
|
380
|
-
(AppleMarkerAnnotation *)markerView.marker;
|
|
381
|
-
|
|
382
|
-
if (!annotation) {
|
|
383
|
-
RCTLogWarn(@"markerViewDidUpdate called without annotation");
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
annotation.coordinate = markerView.coordinate;
|
|
388
|
-
annotation.title = markerView.title;
|
|
389
|
-
annotation.subtitle = markerView.markerDescription;
|
|
390
|
-
|
|
391
|
-
[self updateAnnotationViewFrame:annotation];
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
#pragma mark - MKMapViewDelegate
|
|
395
|
-
|
|
396
|
-
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated {
|
|
397
|
-
_isDragging = [self isUserInteracting:mapView];
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
- (BOOL)isUserInteracting:(MKMapView *)mapView {
|
|
401
|
-
UIView *mapContainerView = mapView.subviews.firstObject;
|
|
402
|
-
for (UIGestureRecognizer *gesture in mapContainerView.gestureRecognizers) {
|
|
403
|
-
if (gesture.state == UIGestureRecognizerStateBegan ||
|
|
404
|
-
gesture.state == UIGestureRecognizerStateChanged) {
|
|
405
|
-
return YES;
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
return NO;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
- (void)mapViewDidChangeVisibleRegion:(MKMapView *)mapView {
|
|
412
|
-
CameraMoveEvent{mapView.centerCoordinate.latitude,
|
|
413
|
-
mapView.centerCoordinate.longitude, mapView.zoomLevel,
|
|
414
|
-
_isDragging}
|
|
415
|
-
.emit<LuggAppleMapViewEventEmitter>(_eventEmitter);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
|
|
419
|
-
BOOL wasDragging = _isDragging;
|
|
420
|
-
_isDragging = NO;
|
|
421
|
-
CameraIdleEvent{mapView.centerCoordinate.latitude,
|
|
422
|
-
mapView.centerCoordinate.longitude, mapView.zoomLevel,
|
|
423
|
-
static_cast<bool>(wasDragging)}
|
|
424
|
-
.emit<LuggAppleMapViewEventEmitter>(_eventEmitter);
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
- (MKAnnotationView *)mapView:(MKMapView *)mapView
|
|
428
|
-
viewForAnnotation:(id<MKAnnotation>)annotation {
|
|
429
|
-
if (![annotation isKindOfClass:[AppleMarkerAnnotation class]]) {
|
|
430
|
-
return nil;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
AppleMarkerAnnotation *markerAnnotation = (AppleMarkerAnnotation *)annotation;
|
|
434
|
-
LuggMarkerView *markerView = markerAnnotation.markerView;
|
|
435
|
-
|
|
436
|
-
if (!markerView || !markerView.hasCustomView) {
|
|
437
|
-
return nil;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
MKAnnotationView *annotationView =
|
|
441
|
-
[[MKAnnotationView alloc] initWithAnnotation:annotation
|
|
442
|
-
reuseIdentifier:nil];
|
|
443
|
-
annotationView.canShowCallout = YES;
|
|
444
|
-
annotationView.displayPriority = MKFeatureDisplayPriorityRequired;
|
|
445
|
-
annotationView.collisionMode = MKAnnotationViewCollisionModeNone;
|
|
446
|
-
|
|
447
|
-
UIView *iconView = markerView.iconView;
|
|
448
|
-
[iconView removeFromSuperview];
|
|
449
|
-
[annotationView addSubview:iconView];
|
|
450
|
-
|
|
451
|
-
// Set frame and centerOffset based on iconView
|
|
452
|
-
CGRect frame = iconView.frame;
|
|
453
|
-
if (frame.size.width > 0 && frame.size.height > 0) {
|
|
454
|
-
annotationView.frame =
|
|
455
|
-
CGRectMake(0, 0, frame.size.width, frame.size.height);
|
|
456
|
-
iconView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
|
|
457
|
-
|
|
458
|
-
CGPoint anchor = markerView.anchor;
|
|
459
|
-
annotationView.centerOffset =
|
|
460
|
-
CGPointMake(frame.size.width * (anchor.x - 0.5),
|
|
461
|
-
-frame.size.height * (anchor.y - 0.5));
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
markerAnnotation.annotationView = annotationView;
|
|
465
|
-
|
|
466
|
-
return annotationView;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView
|
|
470
|
-
rendererForOverlay:(id<MKOverlay>)overlay {
|
|
471
|
-
if ([overlay isKindOfClass:[MKPolyline class]]) {
|
|
472
|
-
LuggPolylineView *polylineView = [self findPolylineViewForOverlay:overlay];
|
|
473
|
-
MKPolyline *polyline = (MKPolyline *)overlay;
|
|
474
|
-
|
|
475
|
-
if (polylineView) {
|
|
476
|
-
NSArray<UIColor *> *colors = polylineView.strokeColors;
|
|
477
|
-
|
|
478
|
-
MKPolylineAnimator *renderer =
|
|
479
|
-
[[MKPolylineAnimator alloc] initWithPolyline:polyline];
|
|
480
|
-
renderer.lineWidth = polylineView.strokeWidth;
|
|
481
|
-
renderer.strokeColor = colors.firstObject;
|
|
482
|
-
if (colors.count > 1) {
|
|
483
|
-
renderer.strokeColors = colors;
|
|
484
|
-
}
|
|
485
|
-
renderer.animated = polylineView.animated;
|
|
486
|
-
polylineView.renderer = renderer;
|
|
487
|
-
return renderer;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
MKPolylineRenderer *renderer =
|
|
491
|
-
[[MKPolylineRenderer alloc] initWithPolyline:polyline];
|
|
492
|
-
return renderer;
|
|
493
|
-
}
|
|
494
|
-
return nil;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
#pragma mark - Commands
|
|
498
|
-
|
|
499
|
-
- (void)moveCamera:(double)latitude
|
|
500
|
-
longitude:(double)longitude
|
|
501
|
-
zoom:(double)zoom
|
|
502
|
-
duration:(double)duration {
|
|
503
|
-
if (!_mapView) {
|
|
504
|
-
return;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
if (duration < 0) {
|
|
508
|
-
[self setCameraWithLatitude:latitude
|
|
509
|
-
longitude:longitude
|
|
510
|
-
zoom:zoom
|
|
511
|
-
animated:YES];
|
|
512
|
-
} else if (duration > 0) {
|
|
513
|
-
CLLocationCoordinate2D center =
|
|
514
|
-
CLLocationCoordinate2DMake(latitude, longitude);
|
|
515
|
-
MKCoordinateRegion region = [_mapView regionForCenterCoordinate:center
|
|
516
|
-
zoomLevel:zoom];
|
|
517
|
-
[UIView animateWithDuration:duration / 1000.0
|
|
518
|
-
animations:^{
|
|
519
|
-
[self->_mapView setRegion:region animated:NO];
|
|
520
|
-
}];
|
|
521
|
-
} else {
|
|
522
|
-
[self setCameraWithLatitude:latitude
|
|
523
|
-
longitude:longitude
|
|
524
|
-
zoom:zoom
|
|
525
|
-
animated:NO];
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
- (void)fitCoordinates:(NSArray *)coordinates
|
|
530
|
-
paddingTop:(double)paddingTop
|
|
531
|
-
paddingLeft:(double)paddingLeft
|
|
532
|
-
paddingBottom:(double)paddingBottom
|
|
533
|
-
paddingRight:(double)paddingRight
|
|
534
|
-
duration:(double)duration {
|
|
535
|
-
if (!_mapView || coordinates.count == 0) {
|
|
536
|
-
return;
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
CLLocationCoordinate2D *coords = (CLLocationCoordinate2D *)malloc(
|
|
540
|
-
sizeof(CLLocationCoordinate2D) * coordinates.count);
|
|
541
|
-
for (NSUInteger i = 0; i < coordinates.count; i++) {
|
|
542
|
-
NSDictionary *coord = coordinates[i];
|
|
543
|
-
coords[i] = CLLocationCoordinate2DMake([coord[@"latitude"] doubleValue],
|
|
544
|
-
[coord[@"longitude"] doubleValue]);
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
MKMapRect mapRect = MKMapRectNull;
|
|
548
|
-
for (NSUInteger i = 0; i < coordinates.count; i++) {
|
|
549
|
-
MKMapPoint point = MKMapPointForCoordinate(coords[i]);
|
|
550
|
-
MKMapRect pointRect = MKMapRectMake(point.x, point.y, 0, 0);
|
|
551
|
-
mapRect = MKMapRectUnion(mapRect, pointRect);
|
|
552
|
-
}
|
|
553
|
-
free(coords);
|
|
554
|
-
|
|
555
|
-
UIEdgeInsets edgePadding =
|
|
556
|
-
UIEdgeInsetsMake(paddingTop, paddingLeft, paddingBottom, paddingRight);
|
|
557
|
-
|
|
558
|
-
if (duration < 0) {
|
|
559
|
-
[_mapView setVisibleMapRect:mapRect edgePadding:edgePadding animated:YES];
|
|
560
|
-
} else if (duration > 0) {
|
|
561
|
-
[UIView animateWithDuration:duration / 1000.0
|
|
562
|
-
animations:^{
|
|
563
|
-
[self->_mapView setVisibleMapRect:mapRect
|
|
564
|
-
edgePadding:edgePadding
|
|
565
|
-
animated:NO];
|
|
566
|
-
}];
|
|
567
|
-
} else {
|
|
568
|
-
[_mapView setVisibleMapRect:mapRect edgePadding:edgePadding animated:NO];
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
- (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args {
|
|
573
|
-
RCTLuggAppleMapViewHandleCommand(self, commandName, args);
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
Class<RCTComponentViewProtocol> LuggAppleMapViewCls(void) {
|
|
577
|
-
return LuggAppleMapView.class;
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
@end
|
package/ios/LuggGoogleMapView.h
DELETED
|
@@ -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
|