@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
|
@@ -1,15 +1,55 @@
|
|
|
1
1
|
#import "GMSPolylineAnimator.h"
|
|
2
2
|
#import <QuartzCore/QuartzCore.h>
|
|
3
3
|
|
|
4
|
+
static const NSUInteger kMaxAnimationSpans = 16;
|
|
5
|
+
|
|
6
|
+
@interface GMSDisplayLinkProxy : NSObject
|
|
7
|
+
@property(nonatomic, weak) id target;
|
|
8
|
+
@property(nonatomic, assign) SEL selector;
|
|
9
|
+
@end
|
|
10
|
+
|
|
11
|
+
@implementation GMSDisplayLinkProxy
|
|
12
|
+
- (instancetype)initWithTarget:(id)target selector:(SEL)selector {
|
|
13
|
+
if (self = [super init]) {
|
|
14
|
+
_target = target;
|
|
15
|
+
_selector = selector;
|
|
16
|
+
}
|
|
17
|
+
return self;
|
|
18
|
+
}
|
|
19
|
+
- (void)tick:(CADisplayLink *)displayLink {
|
|
20
|
+
if (_target) {
|
|
21
|
+
#pragma clang diagnostic push
|
|
22
|
+
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
|
|
23
|
+
[_target performSelector:_selector withObject:displayLink];
|
|
24
|
+
#pragma clang diagnostic pop
|
|
25
|
+
} else {
|
|
26
|
+
[displayLink invalidate];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
@end
|
|
30
|
+
|
|
4
31
|
@implementation GMSPolylineAnimator {
|
|
5
32
|
CADisplayLink *_displayLink;
|
|
33
|
+
GMSDisplayLinkProxy *_displayLinkProxy;
|
|
6
34
|
CGFloat _animationProgress;
|
|
35
|
+
CGFloat _delayRemaining;
|
|
36
|
+
NSArray<NSNumber *> *_cumulativeDistances;
|
|
37
|
+
CGFloat _totalLength;
|
|
7
38
|
}
|
|
8
39
|
|
|
40
|
+
@synthesize animatedOptions = _animatedOptions;
|
|
41
|
+
|
|
9
42
|
- (void)dealloc {
|
|
10
43
|
[self stopAnimation];
|
|
11
44
|
}
|
|
12
45
|
|
|
46
|
+
- (void)setCoordinates:(NSArray<CLLocation *> *)coordinates {
|
|
47
|
+
[super setCoordinates:coordinates];
|
|
48
|
+
if (_animated && _displayLink) {
|
|
49
|
+
[self computeCumulativeDistances];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
13
53
|
- (void)setAnimated:(BOOL)animated {
|
|
14
54
|
if (_animated == animated) {
|
|
15
55
|
return;
|
|
@@ -24,26 +64,74 @@
|
|
|
24
64
|
}
|
|
25
65
|
}
|
|
26
66
|
|
|
67
|
+
- (void)setAnimatedOptions:(PolylineAnimatedOptions *)animatedOptions {
|
|
68
|
+
_animatedOptions = animatedOptions ?: [PolylineAnimatedOptions defaultOptions];
|
|
69
|
+
if (_animated && _displayLink) {
|
|
70
|
+
[self stopAnimation];
|
|
71
|
+
[self startAnimation];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
27
75
|
- (void)startAnimation {
|
|
28
76
|
if (_displayLink) {
|
|
29
77
|
return;
|
|
30
78
|
}
|
|
79
|
+
[self computeCumulativeDistances];
|
|
31
80
|
_animationProgress = 0;
|
|
32
|
-
|
|
81
|
+
_delayRemaining = self.animatedOptions.delay / 1000.0;
|
|
82
|
+
_displayLinkProxy = [[GMSDisplayLinkProxy alloc] initWithTarget:self selector:@selector(animationTick:)];
|
|
83
|
+
_displayLink = [CADisplayLink displayLinkWithTarget:_displayLinkProxy selector:@selector(tick:)];
|
|
33
84
|
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
|
|
34
85
|
}
|
|
35
86
|
|
|
87
|
+
- (void)computeCumulativeDistances {
|
|
88
|
+
NSMutableArray<NSNumber *> *distances = [NSMutableArray array];
|
|
89
|
+
CGFloat total = 0;
|
|
90
|
+
[distances addObject:@(0)];
|
|
91
|
+
|
|
92
|
+
for (NSUInteger i = 1; i < self.coordinates.count; i++) {
|
|
93
|
+
CLLocation *prev = self.coordinates[i - 1];
|
|
94
|
+
CLLocation *curr = self.coordinates[i];
|
|
95
|
+
total += [prev distanceFromLocation:curr];
|
|
96
|
+
[distances addObject:@(total)];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
_cumulativeDistances = [distances copy];
|
|
100
|
+
_totalLength = total;
|
|
101
|
+
}
|
|
102
|
+
|
|
36
103
|
- (void)stopAnimation {
|
|
37
104
|
[_displayLink invalidate];
|
|
38
105
|
_displayLink = nil;
|
|
106
|
+
_displayLinkProxy = nil;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
- (void)pause {
|
|
110
|
+
_displayLink.paused = YES;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
- (void)resume {
|
|
114
|
+
_displayLink.paused = NO;
|
|
39
115
|
}
|
|
40
116
|
|
|
41
117
|
- (void)animationTick:(CADisplayLink *)displayLink {
|
|
42
|
-
|
|
118
|
+
if (_delayRemaining > 0) {
|
|
119
|
+
_delayRemaining -= displayLink.duration;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
CGFloat duration = self.animatedOptions.duration / 1000.0;
|
|
124
|
+
if (duration <= 0) duration = 2.15;
|
|
125
|
+
|
|
126
|
+
CGFloat trailLength = MAX(0.01, MIN(1.0, self.animatedOptions.trailLength));
|
|
127
|
+
CGFloat maxProgress = (trailLength < 1.0) ? 1.0 : 2.15;
|
|
128
|
+
|
|
129
|
+
CGFloat speed = displayLink.duration / duration;
|
|
43
130
|
_animationProgress += speed;
|
|
44
131
|
|
|
45
|
-
if (_animationProgress >=
|
|
132
|
+
if (_animationProgress >= maxProgress) {
|
|
46
133
|
_animationProgress = 0;
|
|
134
|
+
_delayRemaining = self.animatedOptions.delay / 1000.0;
|
|
47
135
|
}
|
|
48
136
|
|
|
49
137
|
[self updateAnimatedPolyline];
|
|
@@ -71,63 +159,110 @@
|
|
|
71
159
|
}
|
|
72
160
|
}
|
|
73
161
|
|
|
162
|
+
- (NSUInteger)indexForDistance:(CGFloat)distance {
|
|
163
|
+
NSUInteger left = 0;
|
|
164
|
+
NSUInteger right = _cumulativeDistances.count - 1;
|
|
165
|
+
|
|
166
|
+
while (left < right) {
|
|
167
|
+
NSUInteger mid = (left + right + 1) / 2;
|
|
168
|
+
if (_cumulativeDistances[mid].doubleValue <= distance) {
|
|
169
|
+
left = mid;
|
|
170
|
+
} else {
|
|
171
|
+
right = mid - 1;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return MIN(left, _cumulativeDistances.count - 2);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
- (CLLocationCoordinate2D)coordinateAtDistance:(CGFloat)distance {
|
|
179
|
+
if (distance <= 0) {
|
|
180
|
+
return self.coordinates.firstObject.coordinate;
|
|
181
|
+
}
|
|
182
|
+
if (distance >= _totalLength) {
|
|
183
|
+
return self.coordinates.lastObject.coordinate;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
NSUInteger idx = [self indexForDistance:distance];
|
|
187
|
+
CGFloat segStart = _cumulativeDistances[idx].doubleValue;
|
|
188
|
+
CGFloat segEnd = _cumulativeDistances[idx + 1].doubleValue;
|
|
189
|
+
CGFloat segLength = segEnd - segStart;
|
|
190
|
+
|
|
191
|
+
CGFloat t = (segLength > 0) ? (distance - segStart) / segLength : 0;
|
|
192
|
+
CLLocationCoordinate2D c1 = self.coordinates[idx].coordinate;
|
|
193
|
+
CLLocationCoordinate2D c2 = self.coordinates[idx + 1].coordinate;
|
|
194
|
+
|
|
195
|
+
return CLLocationCoordinate2DMake(c1.latitude + (c2.latitude - c1.latitude) * t,
|
|
196
|
+
c1.longitude + (c2.longitude - c1.longitude) * t);
|
|
197
|
+
}
|
|
198
|
+
|
|
74
199
|
- (void)updateAnimatedPolyline {
|
|
75
|
-
if (!_polyline || self.coordinates.count < 2) {
|
|
200
|
+
if (!_polyline || self.coordinates.count < 2 || _totalLength <= 0) {
|
|
76
201
|
return;
|
|
77
202
|
}
|
|
78
203
|
|
|
79
|
-
|
|
80
|
-
CGFloat
|
|
81
|
-
CGFloat
|
|
204
|
+
CGFloat trailLength = MAX(0.01, MIN(1.0, self.animatedOptions.trailLength));
|
|
205
|
+
CGFloat maxProgress = (trailLength < 1.0) ? 1.0 : 2.0;
|
|
206
|
+
CGFloat progress = MIN(_animationProgress, maxProgress);
|
|
207
|
+
CGFloat easedProgress = [self applyEasing:progress / maxProgress] * maxProgress;
|
|
208
|
+
|
|
209
|
+
CGFloat headDist, tailDist;
|
|
82
210
|
|
|
83
|
-
if (
|
|
84
|
-
|
|
85
|
-
|
|
211
|
+
if (trailLength < 1.0) {
|
|
212
|
+
headDist = easedProgress * _totalLength;
|
|
213
|
+
tailDist = MAX(0, headDist - _totalLength * trailLength);
|
|
214
|
+
} else if (easedProgress <= 1.0) {
|
|
215
|
+
tailDist = 0;
|
|
216
|
+
headDist = easedProgress * _totalLength;
|
|
86
217
|
} else {
|
|
87
|
-
CGFloat shrinkProgress =
|
|
88
|
-
|
|
89
|
-
|
|
218
|
+
CGFloat shrinkProgress = easedProgress - 1.0;
|
|
219
|
+
tailDist = shrinkProgress * _totalLength;
|
|
220
|
+
headDist = _totalLength;
|
|
90
221
|
}
|
|
91
222
|
|
|
92
|
-
if (
|
|
223
|
+
if (headDist <= tailDist) {
|
|
93
224
|
_polyline.path = [GMSMutablePath path];
|
|
94
225
|
return;
|
|
95
226
|
}
|
|
96
227
|
|
|
97
|
-
|
|
98
|
-
NSUInteger
|
|
99
|
-
|
|
228
|
+
CGFloat visibleLength = headDist - tailDist;
|
|
229
|
+
NSUInteger startIndex = [self indexForDistance:tailDist];
|
|
230
|
+
NSUInteger endIndex = [self indexForDistance:headDist];
|
|
100
231
|
|
|
101
232
|
GMSMutablePath *path = [GMSMutablePath path];
|
|
102
233
|
NSMutableArray<GMSStyleSpan *> *spans = [NSMutableArray array];
|
|
103
234
|
|
|
104
|
-
|
|
105
|
-
|
|
235
|
+
CLLocationCoordinate2D startCoord = [self coordinateAtDistance:tailDist];
|
|
236
|
+
[path addCoordinate:startCoord];
|
|
106
237
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
coord.latitude = coord.latitude + (nextCoord.latitude - coord.latitude) * t;
|
|
111
|
-
coord.longitude = coord.longitude + (nextCoord.longitude - coord.longitude) * t;
|
|
112
|
-
}
|
|
238
|
+
for (NSUInteger i = startIndex + 1; i <= endIndex; i++) {
|
|
239
|
+
[path addCoordinate:self.coordinates[i].coordinate];
|
|
240
|
+
}
|
|
113
241
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
242
|
+
CLLocationCoordinate2D endCoord = [self coordinateAtDistance:headDist];
|
|
243
|
+
CLLocationCoordinate2D lastAdded =
|
|
244
|
+
(endIndex < self.coordinates.count) ? self.coordinates[endIndex].coordinate : endCoord;
|
|
245
|
+
if (endCoord.latitude != lastAdded.latitude || endCoord.longitude != lastAdded.longitude) {
|
|
246
|
+
[path addCoordinate:endCoord];
|
|
247
|
+
}
|
|
120
248
|
|
|
121
|
-
|
|
249
|
+
NSUInteger pathCount = path.count;
|
|
250
|
+
NSUInteger segmentCount = pathCount - 1;
|
|
122
251
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
252
|
+
if (self.strokeColors.count <= 1) {
|
|
253
|
+
_polyline.path = path;
|
|
254
|
+
_polyline.strokeColor = self.strokeColors.firstObject ?: [UIColor blackColor];
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
NSUInteger spanCount = MIN(segmentCount, kMaxAnimationSpans);
|
|
259
|
+
double segmentsPerSpan = (double)segmentCount / spanCount;
|
|
260
|
+
|
|
261
|
+
for (NSUInteger i = 0; i < spanCount; i++) {
|
|
262
|
+
CGFloat gradientPos = ((CGFloat)i + 0.5) / spanCount;
|
|
263
|
+
UIColor *color = [self colorAtGradientPosition:gradientPos];
|
|
264
|
+
GMSStrokeStyle *style = [GMSStrokeStyle solidColor:color];
|
|
265
|
+
[spans addObject:[GMSStyleSpan spanWithStyle:style segments:segmentsPerSpan]];
|
|
131
266
|
}
|
|
132
267
|
|
|
133
268
|
_polyline.path = path;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#import "MapProviderDelegate.h"
|
|
2
|
+
#import <GoogleMaps/GoogleMaps.h>
|
|
3
|
+
|
|
4
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
5
|
+
|
|
6
|
+
@interface GoogleMapProvider : NSObject <MapProvider, GMSMapViewDelegate>
|
|
7
|
+
|
|
8
|
+
@property(nonatomic, copy, nullable) NSString *mapId;
|
|
9
|
+
@property(nonatomic, readonly, nullable) GMSMapView *mapView;
|
|
10
|
+
|
|
11
|
+
@end
|
|
12
|
+
|
|
13
|
+
NS_ASSUME_NONNULL_END
|