@lugg/maps 0.2.0-alpha.2 → 0.2.0-alpha.20
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 +17 -4
- package/android/src/main/java/com/luggmaps/LuggGoogleMapView.kt +31 -37
- 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/LuggPolylineView.kt +16 -0
- package/android/src/main/java/com/luggmaps/LuggPolylineViewManager.kt +22 -0
- package/android/src/main/java/com/luggmaps/core/PolylineAnimator.kt +157 -52
- package/ios/LuggAppleMapView.mm +154 -42
- package/ios/LuggGoogleMapView.mm +52 -22
- 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/GMSPolylineAnimator.h +3 -0
- package/ios/core/GMSPolylineAnimator.m +164 -41
- package/ios/core/MKPolylineAnimator.h +4 -0
- package/ios/core/MKPolylineAnimator.m +162 -43
- package/ios/core/PolylineAnimatorBase.h +14 -0
- package/ios/core/PolylineAnimatorBase.m +33 -0
- 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 +2 -2
- package/lib/module/MapView.js.map +1 -1
- package/lib/module/MapView.web.js +272 -0
- package/lib/module/MapView.web.js.map +1 -0
- package/lib/module/components/Marker.js +10 -1
- 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 +8 -3
- 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/LuggMarkerViewNativeComponent.ts +7 -1
- package/lib/module/fabric/LuggPolylineViewNativeComponent.ts +8 -0
- package/lib/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +6 -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 +1 -1
- package/lib/typescript/src/MapView.d.ts.map +1 -1
- package/lib/typescript/src/MapView.types.d.ts +2 -2
- 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 +21 -0
- 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 +32 -0
- 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.web.d.ts +5 -0
- package/lib/typescript/src/components/index.web.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 +3 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/index.web.d.ts +7 -0
- package/lib/typescript/src/index.web.d.ts.map +1 -0
- package/package.json +15 -2
- package/src/MapProvider.tsx +10 -0
- package/src/MapProvider.types.ts +16 -0
- package/src/MapProvider.web.tsx +14 -0
- package/src/MapView.tsx +2 -2
- package/src/MapView.types.ts +2 -2
- package/src/MapView.web.tsx +337 -0
- package/src/components/Marker.tsx +37 -3
- package/src/components/Marker.web.tsx +33 -0
- package/src/components/Polyline.tsx +38 -1
- package/src/components/Polyline.web.tsx +287 -0
- package/src/components/index.web.ts +4 -0
- package/src/fabric/LuggMarkerViewNativeComponent.ts +7 -1
- package/src/fabric/LuggPolylineViewNativeComponent.ts +8 -0
- package/src/index.ts +8 -1
- package/src/index.web.ts +17 -0
|
@@ -1,10 +1,40 @@
|
|
|
1
1
|
#import "MKPolylineAnimator.h"
|
|
2
2
|
#import <QuartzCore/QuartzCore.h>
|
|
3
3
|
|
|
4
|
+
@interface MKDisplayLinkProxy : NSObject
|
|
5
|
+
@property(nonatomic, weak) id target;
|
|
6
|
+
@property(nonatomic, assign) SEL selector;
|
|
7
|
+
@end
|
|
8
|
+
|
|
9
|
+
@implementation MKDisplayLinkProxy
|
|
10
|
+
- (instancetype)initWithTarget:(id)target selector:(SEL)selector {
|
|
11
|
+
if (self = [super init]) {
|
|
12
|
+
_target = target;
|
|
13
|
+
_selector = selector;
|
|
14
|
+
}
|
|
15
|
+
return self;
|
|
16
|
+
}
|
|
17
|
+
- (void)tick:(CADisplayLink *)displayLink {
|
|
18
|
+
if (_target) {
|
|
19
|
+
#pragma clang diagnostic push
|
|
20
|
+
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
|
|
21
|
+
[_target performSelector:_selector withObject:displayLink];
|
|
22
|
+
#pragma clang diagnostic pop
|
|
23
|
+
} else {
|
|
24
|
+
[displayLink invalidate];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
@end
|
|
28
|
+
|
|
4
29
|
@implementation MKPolylineAnimator {
|
|
5
30
|
MKPolyline *_polyline;
|
|
6
31
|
CADisplayLink *_displayLink;
|
|
7
|
-
|
|
32
|
+
MKDisplayLinkProxy *_displayLinkProxy;
|
|
33
|
+
CGFloat _animationProgress;
|
|
34
|
+
CGFloat _delayRemaining;
|
|
35
|
+
NSArray<NSNumber *> *_cumulativeDistances;
|
|
36
|
+
CGFloat _totalLength;
|
|
37
|
+
CGColorSpaceRef _colorSpace;
|
|
8
38
|
}
|
|
9
39
|
|
|
10
40
|
- (id)initWithPolyline:(MKPolyline *)polyline {
|
|
@@ -12,13 +42,27 @@
|
|
|
12
42
|
if (self) {
|
|
13
43
|
_polyline = polyline;
|
|
14
44
|
_animationProgress = 0;
|
|
45
|
+
_animatedOptions = [PolylineAnimatedOptions defaultOptions];
|
|
46
|
+
_colorSpace = CGColorSpaceCreateDeviceRGB();
|
|
15
47
|
[self createPath];
|
|
16
48
|
}
|
|
17
49
|
return self;
|
|
18
50
|
}
|
|
19
51
|
|
|
52
|
+
- (void)setAnimatedOptions:(PolylineAnimatedOptions *)animatedOptions {
|
|
53
|
+
_animatedOptions = animatedOptions ?: [PolylineAnimatedOptions defaultOptions];
|
|
54
|
+
if (_animated && _displayLink) {
|
|
55
|
+
[self stopAnimation];
|
|
56
|
+
[self startAnimation];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
20
60
|
- (void)dealloc {
|
|
21
61
|
[self stopAnimation];
|
|
62
|
+
if (_colorSpace) {
|
|
63
|
+
CGColorSpaceRelease(_colorSpace);
|
|
64
|
+
_colorSpace = NULL;
|
|
65
|
+
}
|
|
22
66
|
}
|
|
23
67
|
|
|
24
68
|
- (void)setAnimated:(BOOL)animated {
|
|
@@ -38,24 +82,91 @@
|
|
|
38
82
|
if (_displayLink) {
|
|
39
83
|
return;
|
|
40
84
|
}
|
|
85
|
+
[self computeCumulativeDistances];
|
|
41
86
|
_animationProgress = 0;
|
|
42
|
-
|
|
87
|
+
_delayRemaining = _animatedOptions.delay / 1000.0;
|
|
88
|
+
_displayLinkProxy = [[MKDisplayLinkProxy alloc] initWithTarget:self selector:@selector(animationTick:)];
|
|
89
|
+
_displayLink = [CADisplayLink displayLinkWithTarget:_displayLinkProxy selector:@selector(tick:)];
|
|
43
90
|
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
|
|
44
91
|
}
|
|
45
92
|
|
|
93
|
+
- (void)computeCumulativeDistances {
|
|
94
|
+
NSMutableArray<NSNumber *> *distances = [NSMutableArray array];
|
|
95
|
+
CGFloat total = 0;
|
|
96
|
+
[distances addObject:@(0)];
|
|
97
|
+
|
|
98
|
+
for (NSUInteger i = 1; i < _polyline.pointCount; i++) {
|
|
99
|
+
MKMapPoint p1 = _polyline.points[i - 1];
|
|
100
|
+
MKMapPoint p2 = _polyline.points[i];
|
|
101
|
+
total += MKMetersBetweenMapPoints(p1, p2);
|
|
102
|
+
[distances addObject:@(total)];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
_cumulativeDistances = [distances copy];
|
|
106
|
+
_totalLength = total;
|
|
107
|
+
}
|
|
108
|
+
|
|
46
109
|
- (void)stopAnimation {
|
|
47
110
|
[_displayLink invalidate];
|
|
48
111
|
_displayLink = nil;
|
|
112
|
+
_displayLinkProxy = nil;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
- (void)pause {
|
|
116
|
+
_displayLink.paused = YES;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
- (void)resume {
|
|
120
|
+
_displayLink.paused = NO;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
- (NSUInteger)indexForDistance:(CGFloat)distance {
|
|
124
|
+
NSUInteger left = 0;
|
|
125
|
+
NSUInteger right = _cumulativeDistances.count - 1;
|
|
126
|
+
|
|
127
|
+
while (left < right) {
|
|
128
|
+
NSUInteger mid = (left + right + 1) / 2;
|
|
129
|
+
if (_cumulativeDistances[mid].doubleValue <= distance) {
|
|
130
|
+
left = mid;
|
|
131
|
+
} else {
|
|
132
|
+
right = mid - 1;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return MIN(left, _cumulativeDistances.count - 2);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
- (CGFloat)applyEasing:(CGFloat)t {
|
|
140
|
+
NSString *easing = _animatedOptions.easing ?: @"linear";
|
|
141
|
+
|
|
142
|
+
if ([easing isEqualToString:@"easeIn"]) {
|
|
143
|
+
return t * t;
|
|
144
|
+
} else if ([easing isEqualToString:@"easeOut"]) {
|
|
145
|
+
return t * (2 - t);
|
|
146
|
+
} else if ([easing isEqualToString:@"easeInOut"]) {
|
|
147
|
+
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
|
|
148
|
+
}
|
|
149
|
+
return t;
|
|
49
150
|
}
|
|
50
151
|
|
|
51
152
|
- (void)animationTick:(CADisplayLink *)displayLink {
|
|
52
|
-
|
|
53
|
-
|
|
153
|
+
if (_delayRemaining > 0) {
|
|
154
|
+
_delayRemaining -= displayLink.duration;
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
CGFloat duration = _animatedOptions.duration / 1000.0;
|
|
159
|
+
if (duration <= 0) duration = 2.15;
|
|
160
|
+
|
|
161
|
+
CGFloat trailLength = MAX(0.01, MIN(1.0, _animatedOptions.trailLength));
|
|
162
|
+
CGFloat maxProgress = (trailLength < 1.0) ? 1.0 : 2.15;
|
|
163
|
+
|
|
164
|
+
CGFloat speed = displayLink.duration / duration;
|
|
54
165
|
_animationProgress += speed;
|
|
55
166
|
|
|
56
|
-
|
|
57
|
-
if (_animationProgress >= 2.15) { // 2.0 + 0.15 pause (~300ms at this speed)
|
|
167
|
+
if (_animationProgress >= maxProgress) {
|
|
58
168
|
_animationProgress = 0;
|
|
169
|
+
_delayRemaining = _animatedOptions.delay / 1000.0;
|
|
59
170
|
}
|
|
60
171
|
|
|
61
172
|
MKMapRect bounds = _polyline.boundingMapRect;
|
|
@@ -67,6 +178,9 @@
|
|
|
67
178
|
_polyline = polyline;
|
|
68
179
|
[self invalidatePath];
|
|
69
180
|
[self createPath];
|
|
181
|
+
if (_animated) {
|
|
182
|
+
[self computeCumulativeDistances];
|
|
183
|
+
}
|
|
70
184
|
[self setNeedsDisplay];
|
|
71
185
|
}
|
|
72
186
|
|
|
@@ -135,65 +249,73 @@
|
|
|
135
249
|
}
|
|
136
250
|
|
|
137
251
|
// Snake animation: grow from start, then shrink from start
|
|
138
|
-
if (_animated && _polyline.pointCount > 1) {
|
|
139
|
-
CGFloat
|
|
140
|
-
CGFloat
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
252
|
+
if (_animated && _polyline.pointCount > 1 && _totalLength > 0) {
|
|
253
|
+
CGFloat trailLength = MAX(0.01, MIN(1.0, _animatedOptions.trailLength));
|
|
254
|
+
CGFloat maxProgress = (trailLength < 1.0) ? 1.0 : 2.0;
|
|
255
|
+
CGFloat progress = MIN(_animationProgress, maxProgress);
|
|
256
|
+
CGFloat easedProgress = [self applyEasing:progress / maxProgress] * maxProgress;
|
|
257
|
+
|
|
258
|
+
CGFloat headDist, tailDist;
|
|
259
|
+
|
|
260
|
+
if (trailLength < 1.0) {
|
|
261
|
+
headDist = easedProgress * _totalLength;
|
|
262
|
+
tailDist = MAX(0, headDist - _totalLength * trailLength);
|
|
263
|
+
} else if (easedProgress <= 1.0) {
|
|
264
|
+
tailDist = 0;
|
|
265
|
+
headDist = easedProgress * _totalLength;
|
|
146
266
|
} else {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
headPos = segmentCount;
|
|
267
|
+
CGFloat shrinkProgress = easedProgress - 1.0;
|
|
268
|
+
tailDist = shrinkProgress * _totalLength;
|
|
269
|
+
headDist = _totalLength;
|
|
151
270
|
}
|
|
152
271
|
|
|
153
|
-
if (
|
|
272
|
+
if (headDist <= tailDist) {
|
|
154
273
|
return;
|
|
155
274
|
}
|
|
156
275
|
|
|
157
|
-
|
|
158
|
-
NSUInteger
|
|
159
|
-
|
|
276
|
+
CGFloat visibleLength = headDist - tailDist;
|
|
277
|
+
NSUInteger startIndex = [self indexForDistance:tailDist];
|
|
278
|
+
NSUInteger endIndex = [self indexForDistance:headDist];
|
|
279
|
+
|
|
280
|
+
for (NSUInteger i = startIndex; i <= endIndex && i < segmentCount; i++) {
|
|
281
|
+
CGFloat segStartDist = _cumulativeDistances[i].doubleValue;
|
|
282
|
+
CGFloat segEndDist = _cumulativeDistances[i + 1].doubleValue;
|
|
283
|
+
|
|
284
|
+
if (segEndDist <= tailDist || segStartDist >= headDist) {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
160
287
|
|
|
161
|
-
for (NSUInteger i = startIndex; i < endIndex && i < segmentCount; i++) {
|
|
162
288
|
CGPoint segStart = [self pointForMapPoint:_polyline.points[i]];
|
|
163
289
|
CGPoint segEnd = [self pointForMapPoint:_polyline.points[i + 1]];
|
|
164
290
|
|
|
165
291
|
CGPoint drawStart = segStart;
|
|
166
292
|
CGPoint drawEnd = segEnd;
|
|
167
|
-
CGFloat
|
|
168
|
-
CGFloat
|
|
293
|
+
CGFloat drawStartDist = segStartDist;
|
|
294
|
+
CGFloat drawEndDist = segEndDist;
|
|
295
|
+
CGFloat segLength = segEndDist - segStartDist;
|
|
169
296
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
CGFloat t = tailPos - segStartPos;
|
|
297
|
+
if (segStartDist < tailDist && segLength > 0) {
|
|
298
|
+
CGFloat t = (tailDist - segStartDist) / segLength;
|
|
173
299
|
drawStart.x = segStart.x + (segEnd.x - segStart.x) * t;
|
|
174
300
|
drawStart.y = segStart.y + (segEnd.y - segStart.y) * t;
|
|
175
|
-
|
|
301
|
+
drawStartDist = tailDist;
|
|
176
302
|
}
|
|
177
303
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
CGFloat t = headPos - (CGFloat)i;
|
|
304
|
+
if (segEndDist > headDist && segLength > 0) {
|
|
305
|
+
CGFloat t = (headDist - segStartDist) / segLength;
|
|
181
306
|
drawEnd.x = segStart.x + (segEnd.x - segStart.x) * t;
|
|
182
307
|
drawEnd.y = segStart.y + (segEnd.y - segStart.y) * t;
|
|
183
|
-
|
|
308
|
+
drawEndDist = headDist;
|
|
184
309
|
}
|
|
185
310
|
|
|
186
|
-
|
|
187
|
-
CGFloat
|
|
188
|
-
CGFloat gradientEnd = (segEndPos - tailPos) / visibleLength;
|
|
311
|
+
CGFloat gradientStart = (drawStartDist - tailDist) / visibleLength;
|
|
312
|
+
CGFloat gradientEnd = (drawEndDist - tailDist) / visibleLength;
|
|
189
313
|
|
|
190
314
|
UIColor *startColor = [self colorAtGradientPosition:gradientStart];
|
|
191
315
|
UIColor *endColor = [self colorAtGradientPosition:gradientEnd];
|
|
192
316
|
|
|
193
|
-
// Draw gradient line segment
|
|
194
|
-
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
|
195
317
|
NSArray *colors = @[(__bridge id)startColor.CGColor, (__bridge id)endColor.CGColor];
|
|
196
|
-
CGGradientRef gradient = CGGradientCreateWithColors(
|
|
318
|
+
CGGradientRef gradient = CGGradientCreateWithColors(_colorSpace, (__bridge CFArrayRef)colors, NULL);
|
|
197
319
|
|
|
198
320
|
CGContextSaveGState(context);
|
|
199
321
|
CGContextBeginPath(context);
|
|
@@ -206,7 +328,6 @@
|
|
|
206
328
|
|
|
207
329
|
CGContextRestoreGState(context);
|
|
208
330
|
CGGradientRelease(gradient);
|
|
209
|
-
CGColorSpaceRelease(colorSpace);
|
|
210
331
|
}
|
|
211
332
|
return;
|
|
212
333
|
}
|
|
@@ -223,9 +344,8 @@
|
|
|
223
344
|
UIColor *startColor = [self colorAtGradientPosition:gradientStart];
|
|
224
345
|
UIColor *endColor = [self colorAtGradientPosition:gradientEnd];
|
|
225
346
|
|
|
226
|
-
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
|
227
347
|
NSArray *colors = @[(__bridge id)startColor.CGColor, (__bridge id)endColor.CGColor];
|
|
228
|
-
CGGradientRef gradient = CGGradientCreateWithColors(
|
|
348
|
+
CGGradientRef gradient = CGGradientCreateWithColors(_colorSpace, (__bridge CFArrayRef)colors, NULL);
|
|
229
349
|
|
|
230
350
|
CGContextSaveGState(context);
|
|
231
351
|
CGContextBeginPath(context);
|
|
@@ -238,7 +358,6 @@
|
|
|
238
358
|
|
|
239
359
|
CGContextRestoreGState(context);
|
|
240
360
|
CGGradientRelease(gradient);
|
|
241
|
-
CGColorSpaceRelease(colorSpace);
|
|
242
361
|
}
|
|
243
362
|
return;
|
|
244
363
|
}
|
|
@@ -2,11 +2,23 @@
|
|
|
2
2
|
#import <Foundation/Foundation.h>
|
|
3
3
|
#import <UIKit/UIKit.h>
|
|
4
4
|
|
|
5
|
+
@interface PolylineAnimatedOptions : NSObject
|
|
6
|
+
|
|
7
|
+
@property(nonatomic, assign) NSTimeInterval duration;
|
|
8
|
+
@property(nonatomic, copy) NSString *easing;
|
|
9
|
+
@property(nonatomic, assign) CGFloat trailLength;
|
|
10
|
+
@property(nonatomic, assign) NSTimeInterval delay;
|
|
11
|
+
|
|
12
|
+
+ (instancetype)defaultOptions;
|
|
13
|
+
|
|
14
|
+
@end
|
|
15
|
+
|
|
5
16
|
@protocol PolylineAnimator <NSObject>
|
|
6
17
|
|
|
7
18
|
@property(nonatomic, strong) NSArray<CLLocation *> *coordinates;
|
|
8
19
|
@property(nonatomic, strong) NSArray<UIColor *> *strokeColors;
|
|
9
20
|
@property(nonatomic, assign) BOOL animated;
|
|
21
|
+
@property(nonatomic, strong) PolylineAnimatedOptions *animatedOptions;
|
|
10
22
|
|
|
11
23
|
- (void)update;
|
|
12
24
|
|
|
@@ -16,7 +28,9 @@
|
|
|
16
28
|
|
|
17
29
|
@property(nonatomic, strong) NSArray<CLLocation *> *coordinates;
|
|
18
30
|
@property(nonatomic, strong) NSArray<UIColor *> *strokeColors;
|
|
31
|
+
@property(nonatomic, strong) PolylineAnimatedOptions *animatedOptions;
|
|
19
32
|
|
|
20
33
|
- (UIColor *)colorAtGradientPosition:(CGFloat)position;
|
|
34
|
+
- (CGFloat)applyEasing:(CGFloat)t;
|
|
21
35
|
|
|
22
36
|
@end
|
|
@@ -1,7 +1,40 @@
|
|
|
1
1
|
#import "PolylineAnimatorBase.h"
|
|
2
2
|
|
|
3
|
+
@implementation PolylineAnimatedOptions
|
|
4
|
+
|
|
5
|
+
+ (instancetype)defaultOptions {
|
|
6
|
+
PolylineAnimatedOptions *options = [[PolylineAnimatedOptions alloc] init];
|
|
7
|
+
options.duration = 2.15;
|
|
8
|
+
options.easing = @"linear";
|
|
9
|
+
options.trailLength = 1.0;
|
|
10
|
+
options.delay = 0;
|
|
11
|
+
return options;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@end
|
|
15
|
+
|
|
3
16
|
@implementation PolylineAnimatorBase
|
|
4
17
|
|
|
18
|
+
- (instancetype)init {
|
|
19
|
+
if (self = [super init]) {
|
|
20
|
+
_animatedOptions = [PolylineAnimatedOptions defaultOptions];
|
|
21
|
+
}
|
|
22
|
+
return self;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
- (CGFloat)applyEasing:(CGFloat)t {
|
|
26
|
+
NSString *easing = self.animatedOptions.easing ?: @"linear";
|
|
27
|
+
|
|
28
|
+
if ([easing isEqualToString:@"easeIn"]) {
|
|
29
|
+
return t * t;
|
|
30
|
+
} else if ([easing isEqualToString:@"easeOut"]) {
|
|
31
|
+
return t * (2 - t);
|
|
32
|
+
} else if ([easing isEqualToString:@"easeInOut"]) {
|
|
33
|
+
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
|
|
34
|
+
}
|
|
35
|
+
return t;
|
|
36
|
+
}
|
|
37
|
+
|
|
5
38
|
- (UIColor *)colorAtGradientPosition:(CGFloat)position {
|
|
6
39
|
if (!_strokeColors || _strokeColors.count == 0) {
|
|
7
40
|
return [UIColor blackColor];
|
|
@@ -19,12 +19,21 @@
|
|
|
19
19
|
|
|
20
20
|
#pragma mark - Public Methods
|
|
21
21
|
|
|
22
|
+
// Constant for altitude/zoom conversion (meters at zoom level 0)
|
|
23
|
+
static const double kAltitudeAtZoomZero = 220000000.0;
|
|
24
|
+
|
|
22
25
|
- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate
|
|
23
26
|
zoomLevel:(double)zoomLevel
|
|
24
27
|
animated:(BOOL)animated
|
|
25
28
|
{
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
// Use camera API directly to avoid region/margin interaction
|
|
30
|
+
CLLocationDistance altitude = kAltitudeAtZoomZero / pow(2, zoomLevel);
|
|
31
|
+
MKMapCamera *camera = [MKMapCamera cameraLookingAtCenterCoordinate:centerCoordinate
|
|
32
|
+
fromEyeCoordinate:centerCoordinate
|
|
33
|
+
eyeAltitude:altitude];
|
|
34
|
+
camera.pitch = self.camera.pitch;
|
|
35
|
+
camera.heading = self.camera.heading;
|
|
36
|
+
[self setCamera:camera animated:animated];
|
|
28
37
|
}
|
|
29
38
|
|
|
30
39
|
- (MKCoordinateRegion)regionForCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate
|
|
@@ -37,8 +46,9 @@
|
|
|
37
46
|
|
|
38
47
|
- (double)zoomLevel
|
|
39
48
|
{
|
|
40
|
-
|
|
41
|
-
|
|
49
|
+
// Use camera altitude which isn't affected by layoutMargins
|
|
50
|
+
CLLocationDistance altitude = self.camera.altitude;
|
|
51
|
+
double zoomLevel = log2(kAltitudeAtZoomZero / altitude);
|
|
42
52
|
return zoomLevel;
|
|
43
53
|
}
|
|
44
54
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Provider component for map configuration.
|
|
5
|
+
* On web, wraps children with Google Maps APIProvider.
|
|
6
|
+
* On native, passes children through.
|
|
7
|
+
*/
|
|
8
|
+
export function MapProvider({
|
|
9
|
+
children
|
|
10
|
+
}) {
|
|
11
|
+
return children;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=MapProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["MapProvider","children"],"sourceRoot":"../../src","sources":["MapProvider.tsx"],"mappings":";;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,WAAWA,CAAC;EAAEC;AAA2B,CAAC,EAAE;EAC1D,OAAOA,QAAQ;AACjB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["MapProvider.types.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { createContext, useContext } from 'react';
|
|
4
|
+
import { APIProvider } from '@vis.gl/react-google-maps';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
export const MapContext = /*#__PURE__*/createContext({
|
|
7
|
+
map: null,
|
|
8
|
+
isDragging: false
|
|
9
|
+
});
|
|
10
|
+
export const useMapContext = () => useContext(MapContext);
|
|
11
|
+
export function MapProvider({
|
|
12
|
+
apiKey = '',
|
|
13
|
+
children
|
|
14
|
+
}) {
|
|
15
|
+
return /*#__PURE__*/_jsx(APIProvider, {
|
|
16
|
+
apiKey: apiKey,
|
|
17
|
+
children: children
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=MapProvider.web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createContext","useContext","APIProvider","jsx","_jsx","MapContext","map","isDragging","useMapContext","MapProvider","apiKey","children"],"sourceRoot":"../../src","sources":["MapProvider.web.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,UAAU,QAAQ,OAAO;AACjD,SAASC,WAAW,QAAQ,2BAA2B;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAGxD,OAAO,MAAMC,UAAU,gBAAGL,aAAa,CAGpC;EAAEM,GAAG,EAAE,IAAI;EAAEC,UAAU,EAAE;AAAM,CAAC,CAAC;AAEpC,OAAO,MAAMC,aAAa,GAAGA,CAAA,KAAMP,UAAU,CAACI,UAAU,CAAC;AAEzD,OAAO,SAASI,WAAWA,CAAC;EAAEC,MAAM,GAAG,EAAE;EAAEC;AAA2B,CAAC,EAAE;EACvE,oBAAOP,IAAA,CAACF,WAAW;IAACQ,MAAM,EAAEA,MAAO;IAAAC,QAAA,EAAEA;EAAQ,CAAc,CAAC;AAC9D","ignoreList":[]}
|
package/lib/module/MapView.js
CHANGED
|
@@ -25,9 +25,9 @@ export class MapView extends React.Component {
|
|
|
25
25
|
const ref = this.nativeRef.current;
|
|
26
26
|
if (!ref) return;
|
|
27
27
|
const {
|
|
28
|
-
zoom,
|
|
28
|
+
zoom = 0,
|
|
29
29
|
duration = -1
|
|
30
|
-
} = options;
|
|
30
|
+
} = options ?? {};
|
|
31
31
|
this.nativeCommands.moveCamera(ref, coordinate.latitude, coordinate.longitude, zoom, duration);
|
|
32
32
|
}
|
|
33
33
|
fitCoordinates(coordinates, options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Platform","StyleSheet","LuggGoogleMapViewNativeComponent","Commands","GoogleMapCommands","LuggAppleMapViewNativeComponent","AppleMapCommands","LuggMapWrapperViewNativeComponent","jsx","_jsx","jsxs","_jsxs","MapView","Component","defaultProps","provider","OS","initialZoom","zoomEnabled","scrollEnabled","rotateEnabled","pitchEnabled","nativeRef","createRef","nativeCommands","props","isApple","moveCamera","coordinate","options","ref","current","zoom","duration","latitude","longitude","fitCoordinates","coordinates","first","padding","top","left","bottom","right","length","render","mapId","initialCoordinate","minZoom","maxZoom","userLocationEnabled","onCameraMove","onCameraIdle","onReady","children","rest","NativeMapView","style","absoluteFill"],"sourceRoot":"../../src","sources":["MapView.tsx"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,QAAQ,EAAEC,UAAU,QAAQ,cAAc;AACnD,OAAOC,gCAAgC,IACrCC,QAAQ,IAAIC,iBAAiB,QACxB,2CAA2C;AAClD,OAAOC,+BAA+B,IACpCF,QAAQ,IAAIG,gBAAgB,QACvB,0CAA0C;AACjD,OAAOC,iCAAiC,MAAM,4CAA4C;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAS3F,OAAO,MAAMC,OAAO,SACVb,KAAK,CAACc,SAAS,CAEzB;EACE,OAAOC,YAAY,GAA0B;IAC3CC,QAAQ,EAAEf,QAAQ,CAACgB,EAAE,KAAK,KAAK,GAAG,OAAO,GAAG,QAAQ;IACpDC,WAAW,EAAE,EAAE;IACfC,WAAW,EAAE,IAAI;IACjBC,aAAa,EAAE,IAAI;IACnBC,aAAa,EAAE,IAAI;IACnBC,YAAY,EAAE;EAChB,CAAC;EAEOC,SAAS,gBAAGvB,KAAK,CAACwB,SAAS,CAAM,CAAC;EAE1C,IAAYC,cAAcA,CAAA,EAAG;IAC3B,MAAMT,QAAQ,GAAG,IAAI,CAACU,KAAK,CAACV,QAAQ,IAAIH,OAAO,CAACE,YAAY,CAACC,QAAQ;IACrE,MAAMW,OAAO,GAAG1B,QAAQ,CAACgB,EAAE,KAAK,KAAK,IAAID,QAAQ,KAAK,OAAO;IAC7D,OAAOW,OAAO,GAAGpB,gBAAgB,GAAGF,iBAAiB;EACvD;EAEAuB,UAAUA,CAACC,UAAsB,EAAEC,
|
|
1
|
+
{"version":3,"names":["React","Platform","StyleSheet","LuggGoogleMapViewNativeComponent","Commands","GoogleMapCommands","LuggAppleMapViewNativeComponent","AppleMapCommands","LuggMapWrapperViewNativeComponent","jsx","_jsx","jsxs","_jsxs","MapView","Component","defaultProps","provider","OS","initialZoom","zoomEnabled","scrollEnabled","rotateEnabled","pitchEnabled","nativeRef","createRef","nativeCommands","props","isApple","moveCamera","coordinate","options","ref","current","zoom","duration","latitude","longitude","fitCoordinates","coordinates","first","padding","top","left","bottom","right","length","render","mapId","initialCoordinate","minZoom","maxZoom","userLocationEnabled","onCameraMove","onCameraIdle","onReady","children","rest","NativeMapView","style","absoluteFill"],"sourceRoot":"../../src","sources":["MapView.tsx"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,QAAQ,EAAEC,UAAU,QAAQ,cAAc;AACnD,OAAOC,gCAAgC,IACrCC,QAAQ,IAAIC,iBAAiB,QACxB,2CAA2C;AAClD,OAAOC,+BAA+B,IACpCF,QAAQ,IAAIG,gBAAgB,QACvB,0CAA0C;AACjD,OAAOC,iCAAiC,MAAM,4CAA4C;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAS3F,OAAO,MAAMC,OAAO,SACVb,KAAK,CAACc,SAAS,CAEzB;EACE,OAAOC,YAAY,GAA0B;IAC3CC,QAAQ,EAAEf,QAAQ,CAACgB,EAAE,KAAK,KAAK,GAAG,OAAO,GAAG,QAAQ;IACpDC,WAAW,EAAE,EAAE;IACfC,WAAW,EAAE,IAAI;IACjBC,aAAa,EAAE,IAAI;IACnBC,aAAa,EAAE,IAAI;IACnBC,YAAY,EAAE;EAChB,CAAC;EAEOC,SAAS,gBAAGvB,KAAK,CAACwB,SAAS,CAAM,CAAC;EAE1C,IAAYC,cAAcA,CAAA,EAAG;IAC3B,MAAMT,QAAQ,GAAG,IAAI,CAACU,KAAK,CAACV,QAAQ,IAAIH,OAAO,CAACE,YAAY,CAACC,QAAQ;IACrE,MAAMW,OAAO,GAAG1B,QAAQ,CAACgB,EAAE,KAAK,KAAK,IAAID,QAAQ,KAAK,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