@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
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
#import "GoogleMapProvider.h"
|
|
2
|
+
#import "../LuggMarkerView.h"
|
|
3
|
+
#import "../LuggPolylineView.h"
|
|
4
|
+
#import "GMSPolylineAnimator.h"
|
|
5
|
+
#import "PolylineAnimatorBase.h"
|
|
6
|
+
|
|
7
|
+
static NSString *const kDemoMapId = @"DEMO_MAP_ID";
|
|
8
|
+
|
|
9
|
+
@interface GoogleMapProvider () <LuggMarkerViewDelegate,
|
|
10
|
+
LuggPolylineViewDelegate>
|
|
11
|
+
@end
|
|
12
|
+
|
|
13
|
+
@implementation GoogleMapProvider {
|
|
14
|
+
GMSMapView *_mapView;
|
|
15
|
+
BOOL _isMapReady;
|
|
16
|
+
BOOL _isDragging;
|
|
17
|
+
NSInteger _theme;
|
|
18
|
+
UIEdgeInsets _edgeInsets;
|
|
19
|
+
NSMutableArray<LuggMarkerView *> *_pendingMarkerViews;
|
|
20
|
+
NSMutableArray<LuggPolylineView *> *_pendingPolylineViews;
|
|
21
|
+
NSMapTable<LuggPolylineView *, GMSPolylineAnimator *> *_polylineAnimators;
|
|
22
|
+
|
|
23
|
+
// Edge insets animation
|
|
24
|
+
CADisplayLink *_edgeInsetsDisplayLink;
|
|
25
|
+
UIEdgeInsets _edgeInsetsFrom;
|
|
26
|
+
UIEdgeInsets _edgeInsetsTo;
|
|
27
|
+
CFTimeInterval _edgeInsetsAnimationStart;
|
|
28
|
+
CFTimeInterval _edgeInsetsAnimationDuration;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@synthesize delegate = _delegate;
|
|
32
|
+
|
|
33
|
+
- (instancetype)init {
|
|
34
|
+
if (self = [super init]) {
|
|
35
|
+
_isMapReady = NO;
|
|
36
|
+
_mapId = kDemoMapId;
|
|
37
|
+
_pendingMarkerViews = [NSMutableArray array];
|
|
38
|
+
_pendingPolylineViews = [NSMutableArray array];
|
|
39
|
+
_polylineAnimators = [NSMapTable weakToStrongObjectsMapTable];
|
|
40
|
+
}
|
|
41
|
+
return self;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
- (BOOL)isMapReady {
|
|
45
|
+
return _isMapReady;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
- (GMSMapView *)mapView {
|
|
49
|
+
return _mapView;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#pragma mark - MapProvider
|
|
53
|
+
|
|
54
|
+
- (void)initializeMapInView:(UIView *)wrapperView
|
|
55
|
+
initialCoordinate:(CLLocationCoordinate2D)coordinate
|
|
56
|
+
initialZoom:(double)zoom {
|
|
57
|
+
if (_mapView)
|
|
58
|
+
return;
|
|
59
|
+
|
|
60
|
+
GMSMapID *gmsMapId;
|
|
61
|
+
if ([_mapId isEqualToString:kDemoMapId] || _mapId.length == 0) {
|
|
62
|
+
gmsMapId = [GMSMapID demoMapID];
|
|
63
|
+
} else {
|
|
64
|
+
gmsMapId = [GMSMapID mapIDWithIdentifier:_mapId];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
GMSCameraPosition *camera =
|
|
68
|
+
[GMSCameraPosition cameraWithLatitude:coordinate.latitude
|
|
69
|
+
longitude:coordinate.longitude
|
|
70
|
+
zoom:zoom];
|
|
71
|
+
|
|
72
|
+
GMSMapViewOptions *options = [[GMSMapViewOptions alloc] init];
|
|
73
|
+
options.frame = wrapperView.bounds;
|
|
74
|
+
options.camera = camera;
|
|
75
|
+
options.mapID = gmsMapId;
|
|
76
|
+
|
|
77
|
+
_mapView = [[GMSMapView alloc] initWithOptions:options];
|
|
78
|
+
_mapView.autoresizingMask =
|
|
79
|
+
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
80
|
+
_mapView.delegate = self;
|
|
81
|
+
_mapView.paddingAdjustmentBehavior =
|
|
82
|
+
kGMSMapViewPaddingAdjustmentBehaviorNever;
|
|
83
|
+
|
|
84
|
+
[wrapperView addSubview:_mapView];
|
|
85
|
+
|
|
86
|
+
[self applyTheme];
|
|
87
|
+
|
|
88
|
+
_isMapReady = YES;
|
|
89
|
+
[self processPendingMarkers];
|
|
90
|
+
[self processPendingPolylines];
|
|
91
|
+
|
|
92
|
+
[_delegate mapProviderDidReady];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
- (void)destroy {
|
|
96
|
+
[self stopEdgeInsetsAnimation];
|
|
97
|
+
[_pendingMarkerViews removeAllObjects];
|
|
98
|
+
[_pendingPolylineViews removeAllObjects];
|
|
99
|
+
[_polylineAnimators removeAllObjects];
|
|
100
|
+
[_mapView clear];
|
|
101
|
+
[_mapView removeFromSuperview];
|
|
102
|
+
_mapView = nil;
|
|
103
|
+
_isMapReady = NO;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
#pragma mark - Props
|
|
107
|
+
|
|
108
|
+
- (void)setZoomEnabled:(BOOL)enabled {
|
|
109
|
+
_mapView.settings.zoomGestures = enabled;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
- (void)setScrollEnabled:(BOOL)enabled {
|
|
113
|
+
_mapView.settings.scrollGestures = enabled;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
- (void)setRotateEnabled:(BOOL)enabled {
|
|
117
|
+
_mapView.settings.rotateGestures = enabled;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
- (void)setPitchEnabled:(BOOL)enabled {
|
|
121
|
+
_mapView.settings.tiltGestures = enabled;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
- (void)setUserLocationEnabled:(BOOL)enabled {
|
|
125
|
+
_mapView.myLocationEnabled = enabled;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
- (void)setTheme:(NSInteger)theme {
|
|
129
|
+
_theme = theme;
|
|
130
|
+
[self applyTheme];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
- (void)applyTheme {
|
|
134
|
+
if (!_mapView)
|
|
135
|
+
return;
|
|
136
|
+
|
|
137
|
+
switch (_theme) {
|
|
138
|
+
case 1: // Dark
|
|
139
|
+
_mapView.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
|
|
140
|
+
break;
|
|
141
|
+
case 0: // Light
|
|
142
|
+
_mapView.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
|
|
143
|
+
break;
|
|
144
|
+
default: // System
|
|
145
|
+
_mapView.overrideUserInterfaceStyle = UIUserInterfaceStyleUnspecified;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
- (void)setMinZoom:(double)minZoom {
|
|
151
|
+
if (!_mapView)
|
|
152
|
+
return;
|
|
153
|
+
float min = minZoom > 0 ? (float)minZoom : _mapView.minZoom;
|
|
154
|
+
[_mapView setMinZoom:min maxZoom:_mapView.maxZoom];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
- (void)setMaxZoom:(double)maxZoom {
|
|
158
|
+
if (!_mapView)
|
|
159
|
+
return;
|
|
160
|
+
float max = maxZoom > 0 ? (float)maxZoom : _mapView.maxZoom;
|
|
161
|
+
[_mapView setMinZoom:_mapView.minZoom maxZoom:max];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
- (void)setEdgeInsets:(UIEdgeInsets)edgeInsets
|
|
165
|
+
oldEdgeInsets:(UIEdgeInsets)oldEdgeInsets {
|
|
166
|
+
[self setEdgeInsets:edgeInsets oldEdgeInsets:oldEdgeInsets duration:0];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
- (void)setEdgeInsets:(UIEdgeInsets)edgeInsets
|
|
170
|
+
oldEdgeInsets:(UIEdgeInsets)oldEdgeInsets
|
|
171
|
+
duration:(double)duration {
|
|
172
|
+
if (UIEdgeInsetsEqualToEdgeInsets(_edgeInsets, edgeInsets))
|
|
173
|
+
return;
|
|
174
|
+
|
|
175
|
+
[self stopEdgeInsetsAnimation];
|
|
176
|
+
|
|
177
|
+
if (duration != 0 && _mapView) {
|
|
178
|
+
double actualDuration = duration < 0 ? 0.3 : duration / 1000.0;
|
|
179
|
+
_edgeInsetsFrom = _edgeInsets;
|
|
180
|
+
_edgeInsetsTo = edgeInsets;
|
|
181
|
+
_edgeInsets = edgeInsets;
|
|
182
|
+
_edgeInsetsAnimationDuration = actualDuration;
|
|
183
|
+
_edgeInsetsAnimationStart = CACurrentMediaTime();
|
|
184
|
+
|
|
185
|
+
_edgeInsetsDisplayLink = [CADisplayLink
|
|
186
|
+
displayLinkWithTarget:self
|
|
187
|
+
selector:@selector(edgeInsetsAnimationTick:)];
|
|
188
|
+
[_edgeInsetsDisplayLink addToRunLoop:[NSRunLoop mainRunLoop]
|
|
189
|
+
forMode:NSRunLoopCommonModes];
|
|
190
|
+
} else {
|
|
191
|
+
_edgeInsets = edgeInsets;
|
|
192
|
+
_mapView.padding = edgeInsets;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
- (void)edgeInsetsAnimationTick:(CADisplayLink *)displayLink {
|
|
197
|
+
CFTimeInterval elapsed = CACurrentMediaTime() - _edgeInsetsAnimationStart;
|
|
198
|
+
CGFloat progress = MIN(elapsed / _edgeInsetsAnimationDuration, 1.0);
|
|
199
|
+
|
|
200
|
+
// Ease out cubic
|
|
201
|
+
CGFloat t = 1.0 - (1.0 - progress) * (1.0 - progress) * (1.0 - progress);
|
|
202
|
+
|
|
203
|
+
UIEdgeInsets current = UIEdgeInsetsMake(
|
|
204
|
+
_edgeInsetsFrom.top + (_edgeInsetsTo.top - _edgeInsetsFrom.top) * t,
|
|
205
|
+
_edgeInsetsFrom.left + (_edgeInsetsTo.left - _edgeInsetsFrom.left) * t,
|
|
206
|
+
_edgeInsetsFrom.bottom +
|
|
207
|
+
(_edgeInsetsTo.bottom - _edgeInsetsFrom.bottom) * t,
|
|
208
|
+
_edgeInsetsFrom.right +
|
|
209
|
+
(_edgeInsetsTo.right - _edgeInsetsFrom.right) * t);
|
|
210
|
+
|
|
211
|
+
_mapView.padding = current;
|
|
212
|
+
|
|
213
|
+
if (progress >= 1.0) {
|
|
214
|
+
[self stopEdgeInsetsAnimation];
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
- (void)stopEdgeInsetsAnimation {
|
|
219
|
+
[_edgeInsetsDisplayLink invalidate];
|
|
220
|
+
_edgeInsetsDisplayLink = nil;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
#pragma mark - GMSMapViewDelegate
|
|
224
|
+
|
|
225
|
+
- (void)mapView:(GMSMapView *)mapView willMove:(BOOL)gesture {
|
|
226
|
+
_isDragging = gesture;
|
|
227
|
+
if (_isDragging) {
|
|
228
|
+
for (GMSPolylineAnimator *animator in _polylineAnimators.objectEnumerator) {
|
|
229
|
+
[animator pause];
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
- (void)mapView:(GMSMapView *)mapView
|
|
235
|
+
didChangeCameraPosition:(GMSCameraPosition *)position {
|
|
236
|
+
[_delegate mapProviderDidMoveCamera:position.target.latitude
|
|
237
|
+
longitude:position.target.longitude
|
|
238
|
+
zoom:position.zoom
|
|
239
|
+
gesture:_isDragging];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
- (void)mapView:(GMSMapView *)mapView
|
|
243
|
+
idleAtCameraPosition:(GMSCameraPosition *)position {
|
|
244
|
+
BOOL wasDragging = _isDragging;
|
|
245
|
+
_isDragging = NO;
|
|
246
|
+
if (wasDragging) {
|
|
247
|
+
for (GMSPolylineAnimator *animator in _polylineAnimators.objectEnumerator) {
|
|
248
|
+
[animator resume];
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
[_delegate mapProviderDidIdleCamera:position.target.latitude
|
|
252
|
+
longitude:position.target.longitude
|
|
253
|
+
zoom:position.zoom
|
|
254
|
+
gesture:wasDragging];
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
#pragma mark - MarkerViewDelegate
|
|
258
|
+
|
|
259
|
+
- (void)markerViewDidLayout:(LuggMarkerView *)markerView {
|
|
260
|
+
[self syncMarkerView:markerView];
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
- (void)markerViewDidUpdate:(LuggMarkerView *)markerView {
|
|
264
|
+
[self syncMarkerView:markerView];
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
#pragma mark - PolylineViewDelegate
|
|
268
|
+
|
|
269
|
+
- (void)polylineViewDidUpdate:(LuggPolylineView *)polylineView {
|
|
270
|
+
[self syncPolylineView:polylineView];
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
#pragma mark - Marker Management
|
|
274
|
+
|
|
275
|
+
- (void)addMarkerView:(LuggMarkerView *)markerView {
|
|
276
|
+
markerView.delegate = self;
|
|
277
|
+
[self syncMarkerView:markerView];
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
- (void)removeMarkerView:(LuggMarkerView *)markerView {
|
|
281
|
+
GMSAdvancedMarker *marker = (GMSAdvancedMarker *)markerView.marker;
|
|
282
|
+
if (marker) {
|
|
283
|
+
marker.iconView = nil;
|
|
284
|
+
marker.map = nil;
|
|
285
|
+
markerView.marker = nil;
|
|
286
|
+
}
|
|
287
|
+
[markerView resetIconViewTransform];
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
- (void)syncMarkerView:(LuggMarkerView *)markerView {
|
|
291
|
+
if (!_mapView) {
|
|
292
|
+
if (![_pendingMarkerViews containsObject:markerView]) {
|
|
293
|
+
[_pendingMarkerViews addObject:markerView];
|
|
294
|
+
}
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (!markerView.marker) {
|
|
299
|
+
[self addMarkerViewToMap:markerView];
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
GMSAdvancedMarker *marker = (GMSAdvancedMarker *)markerView.marker;
|
|
304
|
+
marker.position = markerView.coordinate;
|
|
305
|
+
marker.title = markerView.title;
|
|
306
|
+
marker.snippet = markerView.markerDescription;
|
|
307
|
+
marker.zIndex = (int)markerView.zIndex;
|
|
308
|
+
[self applyMarkerStyle:markerView marker:marker];
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
- (void)processPendingMarkers {
|
|
312
|
+
if (!_mapView)
|
|
313
|
+
return;
|
|
314
|
+
|
|
315
|
+
for (LuggMarkerView *markerView in _pendingMarkerViews) {
|
|
316
|
+
[self addMarkerViewToMap:markerView];
|
|
317
|
+
}
|
|
318
|
+
[_pendingMarkerViews removeAllObjects];
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
- (void)addMarkerViewToMap:(LuggMarkerView *)markerView {
|
|
322
|
+
if (!_mapView)
|
|
323
|
+
return;
|
|
324
|
+
|
|
325
|
+
GMSAdvancedMarker *marker = [[GMSAdvancedMarker alloc] init];
|
|
326
|
+
marker.position = markerView.coordinate;
|
|
327
|
+
marker.title = markerView.title;
|
|
328
|
+
marker.snippet = markerView.markerDescription;
|
|
329
|
+
marker.zIndex = (int)markerView.zIndex;
|
|
330
|
+
|
|
331
|
+
[self applyMarkerStyle:markerView marker:marker];
|
|
332
|
+
|
|
333
|
+
marker.map = _mapView;
|
|
334
|
+
markerView.marker = marker;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
- (void)applyMarkerStyle:(LuggMarkerView *)markerView
|
|
338
|
+
marker:(GMSAdvancedMarker *)marker {
|
|
339
|
+
if (markerView.hasCustomView) {
|
|
340
|
+
if (markerView.rasterize) {
|
|
341
|
+
marker.iconView = nil;
|
|
342
|
+
marker.icon = [markerView createScaledIconImage];
|
|
343
|
+
marker.rotation = markerView.rotate;
|
|
344
|
+
} else {
|
|
345
|
+
UIView *iconView = markerView.iconView;
|
|
346
|
+
if (marker.iconView != iconView) {
|
|
347
|
+
[iconView removeFromSuperview];
|
|
348
|
+
marker.iconView = iconView;
|
|
349
|
+
}
|
|
350
|
+
CGFloat scale = markerView.scale;
|
|
351
|
+
CGFloat radians = markerView.rotate * M_PI / 180.0;
|
|
352
|
+
iconView.transform =
|
|
353
|
+
CGAffineTransformConcat(CGAffineTransformMakeScale(scale, scale),
|
|
354
|
+
CGAffineTransformMakeRotation(radians));
|
|
355
|
+
marker.rotation = 0;
|
|
356
|
+
}
|
|
357
|
+
marker.groundAnchor = markerView.anchor;
|
|
358
|
+
} else {
|
|
359
|
+
marker.iconView = nil;
|
|
360
|
+
marker.icon = nil;
|
|
361
|
+
marker.rotation = markerView.rotate;
|
|
362
|
+
marker.groundAnchor = CGPointMake(0.5, 1);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
#pragma mark - Polyline Management
|
|
367
|
+
|
|
368
|
+
- (void)addPolylineView:(LuggPolylineView *)polylineView {
|
|
369
|
+
polylineView.delegate = self;
|
|
370
|
+
[self syncPolylineView:polylineView];
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
- (void)removePolylineView:(LuggPolylineView *)polylineView {
|
|
374
|
+
[_polylineAnimators removeObjectForKey:polylineView];
|
|
375
|
+
GMSPolyline *polyline = (GMSPolyline *)polylineView.polyline;
|
|
376
|
+
if (polyline) {
|
|
377
|
+
polyline.map = nil;
|
|
378
|
+
polylineView.polyline = nil;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
- (void)syncPolylineView:(LuggPolylineView *)polylineView {
|
|
383
|
+
if (!_mapView) {
|
|
384
|
+
if (![_pendingPolylineViews containsObject:polylineView]) {
|
|
385
|
+
[_pendingPolylineViews addObject:polylineView];
|
|
386
|
+
}
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (!polylineView.polyline) {
|
|
391
|
+
[self addPolylineViewToMap:polylineView];
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
GMSPolyline *polyline = (GMSPolyline *)polylineView.polyline;
|
|
396
|
+
polyline.strokeWidth = polylineView.strokeWidth;
|
|
397
|
+
polyline.zIndex = (int)polylineView.zIndex;
|
|
398
|
+
|
|
399
|
+
GMSPolylineAnimator *animator =
|
|
400
|
+
[_polylineAnimators objectForKey:polylineView];
|
|
401
|
+
if (animator) {
|
|
402
|
+
animator.coordinates = polylineView.coordinates;
|
|
403
|
+
animator.strokeColors = polylineView.strokeColors;
|
|
404
|
+
animator.animatedOptions = polylineView.animatedOptions;
|
|
405
|
+
animator.animated = polylineView.animated;
|
|
406
|
+
[animator update];
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
- (void)processPendingPolylines {
|
|
411
|
+
if (!_mapView)
|
|
412
|
+
return;
|
|
413
|
+
|
|
414
|
+
for (LuggPolylineView *polylineView in _pendingPolylineViews) {
|
|
415
|
+
[self addPolylineViewToMap:polylineView];
|
|
416
|
+
}
|
|
417
|
+
[_pendingPolylineViews removeAllObjects];
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
- (void)addPolylineViewToMap:(LuggPolylineView *)polylineView {
|
|
421
|
+
if (!_mapView)
|
|
422
|
+
return;
|
|
423
|
+
|
|
424
|
+
GMSPolyline *polyline = [GMSPolyline polylineWithPath:[GMSMutablePath path]];
|
|
425
|
+
polyline.strokeWidth = polylineView.strokeWidth;
|
|
426
|
+
polyline.zIndex = (int)polylineView.zIndex;
|
|
427
|
+
polyline.map = _mapView;
|
|
428
|
+
polylineView.polyline = polyline;
|
|
429
|
+
|
|
430
|
+
GMSPolylineAnimator *animator = [[GMSPolylineAnimator alloc] init];
|
|
431
|
+
animator.polyline = polyline;
|
|
432
|
+
animator.coordinates = polylineView.coordinates;
|
|
433
|
+
animator.strokeColors = polylineView.strokeColors;
|
|
434
|
+
animator.animatedOptions = polylineView.animatedOptions;
|
|
435
|
+
animator.animated = polylineView.animated;
|
|
436
|
+
[animator update];
|
|
437
|
+
|
|
438
|
+
[_polylineAnimators setObject:animator forKey:polylineView];
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
#pragma mark - Lifecycle
|
|
442
|
+
|
|
443
|
+
- (void)pauseAnimations {
|
|
444
|
+
for (GMSPolylineAnimator *animator in _polylineAnimators.objectEnumerator) {
|
|
445
|
+
[animator pause];
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
- (void)resumeAnimations {
|
|
450
|
+
for (GMSPolylineAnimator *animator in _polylineAnimators.objectEnumerator) {
|
|
451
|
+
[animator resume];
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
#pragma mark - Commands
|
|
456
|
+
|
|
457
|
+
- (void)moveCamera:(double)latitude
|
|
458
|
+
longitude:(double)longitude
|
|
459
|
+
zoom:(double)zoom
|
|
460
|
+
duration:(double)duration {
|
|
461
|
+
if (!_mapView)
|
|
462
|
+
return;
|
|
463
|
+
|
|
464
|
+
float targetZoom = zoom > 0 ? (float)zoom : _mapView.camera.zoom;
|
|
465
|
+
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude
|
|
466
|
+
longitude:longitude
|
|
467
|
+
zoom:targetZoom];
|
|
468
|
+
if (duration < 0) {
|
|
469
|
+
[_mapView animateToCameraPosition:camera];
|
|
470
|
+
} else if (duration > 0) {
|
|
471
|
+
[CATransaction begin];
|
|
472
|
+
[CATransaction setAnimationDuration:duration / 1000.0];
|
|
473
|
+
[_mapView animateToCameraPosition:camera];
|
|
474
|
+
[CATransaction commit];
|
|
475
|
+
} else {
|
|
476
|
+
[_mapView setCamera:camera];
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
- (void)fitCoordinates:(NSArray *)coordinates
|
|
481
|
+
edgeInsetsTop:(double)edgeInsetsTop
|
|
482
|
+
edgeInsetsLeft:(double)edgeInsetsLeft
|
|
483
|
+
edgeInsetsBottom:(double)edgeInsetsBottom
|
|
484
|
+
edgeInsetsRight:(double)edgeInsetsRight
|
|
485
|
+
duration:(double)duration {
|
|
486
|
+
if (!_mapView || coordinates.count == 0)
|
|
487
|
+
return;
|
|
488
|
+
|
|
489
|
+
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] init];
|
|
490
|
+
for (NSDictionary *coord in coordinates) {
|
|
491
|
+
double lat = [coord[@"latitude"] doubleValue];
|
|
492
|
+
double lng = [coord[@"longitude"] doubleValue];
|
|
493
|
+
bounds = [bounds includingCoordinate:CLLocationCoordinate2DMake(lat, lng)];
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
UIEdgeInsets insets = UIEdgeInsetsMake(edgeInsetsTop, edgeInsetsLeft,
|
|
497
|
+
edgeInsetsBottom, edgeInsetsRight);
|
|
498
|
+
GMSCameraUpdate *cameraUpdate = [GMSCameraUpdate fitBounds:bounds
|
|
499
|
+
withEdgeInsets:insets];
|
|
500
|
+
|
|
501
|
+
if (duration < 0) {
|
|
502
|
+
[_mapView animateWithCameraUpdate:cameraUpdate];
|
|
503
|
+
} else if (duration > 0) {
|
|
504
|
+
[CATransaction begin];
|
|
505
|
+
[CATransaction setAnimationDuration:duration / 1000.0];
|
|
506
|
+
[_mapView animateWithCameraUpdate:cameraUpdate];
|
|
507
|
+
[CATransaction commit];
|
|
508
|
+
} else {
|
|
509
|
+
[_mapView moveCamera:cameraUpdate];
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
@end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#import "PolylineAnimatorBase.h"
|
|
1
2
|
#import <MapKit/MapKit.h>
|
|
2
3
|
|
|
3
4
|
@interface MKPolylineAnimator : MKOverlayPathRenderer
|
|
@@ -6,7 +7,10 @@
|
|
|
6
7
|
|
|
7
8
|
@property(nonatomic, strong) NSArray<UIColor *> *strokeColors;
|
|
8
9
|
@property(nonatomic, assign) BOOL animated;
|
|
10
|
+
@property(nonatomic, strong) PolylineAnimatedOptions *animatedOptions;
|
|
9
11
|
|
|
10
12
|
- (void)updatePolyline:(MKPolyline *)polyline;
|
|
13
|
+
- (void)pause;
|
|
14
|
+
- (void)resume;
|
|
11
15
|
|
|
12
16
|
@end
|