@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.
Files changed (124) hide show
  1. package/README.md +21 -3
  2. package/android/src/main/java/com/luggmaps/LuggMapView.kt +265 -0
  3. package/android/src/main/java/com/luggmaps/{LuggGoogleMapViewManager.kt → LuggMapViewManager.kt} +75 -36
  4. package/android/src/main/java/com/luggmaps/LuggMapWrapperView.kt +6 -5
  5. package/android/src/main/java/com/luggmaps/LuggMarkerView.kt +136 -14
  6. package/android/src/main/java/com/luggmaps/LuggMarkerViewManager.kt +21 -0
  7. package/android/src/main/java/com/luggmaps/LuggPackage.kt +1 -4
  8. package/android/src/main/java/com/luggmaps/LuggPolylineView.kt +16 -0
  9. package/android/src/main/java/com/luggmaps/LuggPolylineViewManager.kt +22 -0
  10. package/android/src/main/java/com/luggmaps/{LuggGoogleMapView.kt → core/GoogleMapProvider.kt} +251 -241
  11. package/android/src/main/java/com/luggmaps/core/MapProviderDelegate.kt +55 -0
  12. package/android/src/main/java/com/luggmaps/core/PolylineAnimator.kt +163 -52
  13. package/ios/LuggMapView.h +9 -0
  14. package/ios/LuggMapView.mm +312 -0
  15. package/ios/LuggMarkerView.h +9 -0
  16. package/ios/LuggMarkerView.mm +79 -0
  17. package/ios/LuggPolylineView.h +4 -0
  18. package/ios/LuggPolylineView.mm +23 -0
  19. package/ios/core/AppleMapProvider.h +15 -0
  20. package/ios/core/AppleMapProvider.mm +664 -0
  21. package/ios/core/GMSPolylineAnimator.h +3 -0
  22. package/ios/core/GMSPolylineAnimator.m +175 -40
  23. package/ios/core/GoogleMapProvider.h +13 -0
  24. package/ios/core/GoogleMapProvider.mm +513 -0
  25. package/ios/core/MKPolylineAnimator.h +4 -0
  26. package/ios/core/MKPolylineAnimator.m +224 -68
  27. package/ios/core/MapProviderDelegate.h +72 -0
  28. package/ios/core/PolylineAnimatorBase.h +24 -1
  29. package/ios/core/PolylineAnimatorBase.m +82 -19
  30. package/ios/extensions/MKMapView+Zoom.h +2 -0
  31. package/ios/extensions/MKMapView+Zoom.m +14 -4
  32. package/lib/module/MapProvider.js +13 -0
  33. package/lib/module/MapProvider.js.map +1 -0
  34. package/lib/module/MapProvider.types.js +4 -0
  35. package/lib/module/MapProvider.types.js.map +1 -0
  36. package/lib/module/MapProvider.web.js +20 -0
  37. package/lib/module/MapProvider.web.js.map +1 -0
  38. package/lib/module/MapView.js +29 -16
  39. package/lib/module/MapView.js.map +1 -1
  40. package/lib/module/MapView.web.js +290 -0
  41. package/lib/module/MapView.web.js.map +1 -0
  42. package/lib/module/components/Marker.js +19 -2
  43. package/lib/module/components/Marker.js.map +1 -1
  44. package/lib/module/components/Marker.web.js +33 -0
  45. package/lib/module/components/Marker.web.js.map +1 -0
  46. package/lib/module/components/Polyline.js +17 -4
  47. package/lib/module/components/Polyline.js.map +1 -1
  48. package/lib/module/components/Polyline.web.js +229 -0
  49. package/lib/module/components/Polyline.web.js.map +1 -0
  50. package/lib/module/components/index.js +2 -2
  51. package/lib/module/components/index.js.map +1 -1
  52. package/lib/module/components/index.web.js +5 -0
  53. package/lib/module/components/index.web.js.map +1 -0
  54. package/lib/module/fabric/{LuggGoogleMapViewNativeComponent.ts → LuggMapViewNativeComponent.ts} +19 -7
  55. package/lib/module/fabric/LuggMarkerViewNativeComponent.ts +7 -1
  56. package/lib/module/fabric/LuggPolylineViewNativeComponent.ts +8 -0
  57. package/lib/module/index.js +4 -2
  58. package/lib/module/index.js.map +1 -1
  59. package/lib/module/index.web.js +7 -0
  60. package/lib/module/index.web.js.map +1 -0
  61. package/lib/typescript/src/MapProvider.d.ts +8 -0
  62. package/lib/typescript/src/MapProvider.d.ts.map +1 -0
  63. package/lib/typescript/src/MapProvider.types.d.ts +16 -0
  64. package/lib/typescript/src/MapProvider.types.d.ts.map +1 -0
  65. package/lib/typescript/src/MapProvider.web.d.ts +11 -0
  66. package/lib/typescript/src/MapProvider.web.d.ts.map +1 -0
  67. package/lib/typescript/src/MapView.d.ts +4 -4
  68. package/lib/typescript/src/MapView.d.ts.map +1 -1
  69. package/lib/typescript/src/MapView.types.d.ts +23 -7
  70. package/lib/typescript/src/MapView.types.d.ts.map +1 -1
  71. package/lib/typescript/src/MapView.web.d.ts +3 -0
  72. package/lib/typescript/src/MapView.web.d.ts.map +1 -0
  73. package/lib/typescript/src/components/Marker.d.ts +25 -1
  74. package/lib/typescript/src/components/Marker.d.ts.map +1 -1
  75. package/lib/typescript/src/components/Marker.web.d.ts +3 -0
  76. package/lib/typescript/src/components/Marker.web.d.ts.map +1 -0
  77. package/lib/typescript/src/components/Polyline.d.ts +36 -1
  78. package/lib/typescript/src/components/Polyline.d.ts.map +1 -1
  79. package/lib/typescript/src/components/Polyline.web.d.ts +3 -0
  80. package/lib/typescript/src/components/Polyline.web.d.ts.map +1 -0
  81. package/lib/typescript/src/components/index.d.ts +4 -2
  82. package/lib/typescript/src/components/index.d.ts.map +1 -1
  83. package/lib/typescript/src/components/index.web.d.ts +5 -0
  84. package/lib/typescript/src/components/index.web.d.ts.map +1 -0
  85. package/lib/typescript/src/fabric/{LuggGoogleMapViewNativeComponent.d.ts → LuggMapViewNativeComponent.d.ts} +8 -4
  86. package/lib/typescript/src/fabric/LuggMapViewNativeComponent.d.ts.map +1 -0
  87. package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts +4 -1
  88. package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts.map +1 -1
  89. package/lib/typescript/src/fabric/LuggPolylineViewNativeComponent.d.ts +7 -0
  90. package/lib/typescript/src/fabric/LuggPolylineViewNativeComponent.d.ts.map +1 -1
  91. package/lib/typescript/src/index.d.ts +8 -3
  92. package/lib/typescript/src/index.d.ts.map +1 -1
  93. package/lib/typescript/src/index.web.d.ts +10 -0
  94. package/lib/typescript/src/index.web.d.ts.map +1 -0
  95. package/lib/typescript/src/types.d.ts +4 -0
  96. package/lib/typescript/src/types.d.ts.map +1 -1
  97. package/package.json +17 -3
  98. package/src/MapProvider.tsx +10 -0
  99. package/src/MapProvider.types.ts +16 -0
  100. package/src/MapProvider.web.tsx +14 -0
  101. package/src/MapView.tsx +28 -26
  102. package/src/MapView.types.ts +24 -7
  103. package/src/MapView.web.tsx +364 -0
  104. package/src/components/Marker.tsx +50 -4
  105. package/src/components/Marker.web.tsx +33 -0
  106. package/src/components/Polyline.tsx +51 -2
  107. package/src/components/Polyline.web.tsx +287 -0
  108. package/src/components/index.ts +8 -2
  109. package/src/components/index.web.ts +4 -0
  110. package/src/fabric/{LuggGoogleMapViewNativeComponent.ts → LuggMapViewNativeComponent.ts} +19 -7
  111. package/src/fabric/LuggMarkerViewNativeComponent.ts +7 -1
  112. package/src/fabric/LuggPolylineViewNativeComponent.ts +8 -0
  113. package/src/index.ts +18 -2
  114. package/src/index.web.ts +20 -0
  115. package/src/types.ts +5 -0
  116. package/ios/LuggAppleMapView.h +0 -16
  117. package/ios/LuggAppleMapView.mm +0 -580
  118. package/ios/LuggGoogleMapView.h +0 -13
  119. package/ios/LuggGoogleMapView.mm +0 -454
  120. package/lib/module/fabric/LuggAppleMapViewNativeComponent.ts +0 -83
  121. package/lib/typescript/src/fabric/LuggAppleMapViewNativeComponent.d.ts +0 -54
  122. package/lib/typescript/src/fabric/LuggAppleMapViewNativeComponent.d.ts.map +0 -1
  123. package/lib/typescript/src/fabric/LuggGoogleMapViewNativeComponent.d.ts.map +0 -1
  124. 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
- _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(animationTick:)];
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
- CGFloat speed = displayLink.duration / 1.75;
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 >= 2.15) {
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
- NSUInteger segmentCount = self.coordinates.count - 1;
80
- CGFloat progress = MIN(_animationProgress, 2.0);
81
- CGFloat headPos, tailPos;
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 (progress <= 1.0) {
84
- tailPos = 0;
85
- headPos = progress * segmentCount;
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 = progress - 1.0;
88
- tailPos = shrinkProgress * segmentCount;
89
- headPos = segmentCount;
218
+ CGFloat shrinkProgress = easedProgress - 1.0;
219
+ tailDist = shrinkProgress * _totalLength;
220
+ headDist = _totalLength;
90
221
  }
91
222
 
92
- if (headPos <= tailPos) {
223
+ if (headDist <= tailDist) {
93
224
  _polyline.path = [GMSMutablePath path];
94
225
  return;
95
226
  }
96
227
 
97
- NSUInteger startIndex = (NSUInteger)floor(tailPos);
98
- NSUInteger endIndex = (NSUInteger)ceil(headPos);
99
- CGFloat visibleLength = headPos - tailPos;
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
- for (NSUInteger i = startIndex; i <= endIndex && i < self.coordinates.count; i++) {
105
- CLLocationCoordinate2D coord = self.coordinates[i].coordinate;
235
+ CLLocationCoordinate2D startCoord = [self coordinateAtDistance:tailDist];
236
+ [path addCoordinate:startCoord];
106
237
 
107
- if (i == startIndex && tailPos > (CGFloat)startIndex) {
108
- CGFloat t = tailPos - (CGFloat)startIndex;
109
- CLLocationCoordinate2D nextCoord = self.coordinates[i + 1].coordinate;
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
- if (i == endIndex && headPos < (CGFloat)endIndex && i > 0) {
115
- CGFloat t = headPos - (CGFloat)(endIndex - 1);
116
- CLLocationCoordinate2D prevCoord = self.coordinates[i - 1].coordinate;
117
- coord.latitude = prevCoord.latitude + (coord.latitude - prevCoord.latitude) * t;
118
- coord.longitude = prevCoord.longitude + (coord.longitude - prevCoord.longitude) * t;
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
- [path addCoordinate:coord];
249
+ NSUInteger pathCount = path.count;
250
+ NSUInteger segmentCount = pathCount - 1;
122
251
 
123
- if (i < endIndex && i < segmentCount) {
124
- CGFloat segStartPos = MAX((CGFloat)i, tailPos);
125
- CGFloat segEndPos = MIN((CGFloat)(i + 1), headPos);
126
- CGFloat gradientMid = ((segStartPos + segEndPos) / 2.0 - tailPos) / visibleLength;
127
- UIColor *color = [self colorAtGradientPosition:gradientMid];
128
- GMSStrokeStyle *style = [GMSStrokeStyle solidColor:color];
129
- [spans addObject:[GMSStyleSpan spanWithStyle:style]];
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