@lugg/maps 0.2.0-alpha.26 → 0.2.0-alpha.28
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/android/src/main/java/com/luggmaps/LuggMapView.kt +8 -2
- package/android/src/main/java/com/luggmaps/LuggMapViewManager.kt +17 -0
- package/android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt +29 -0
- package/android/src/main/java/com/luggmaps/core/MapProviderDelegate.kt +1 -0
- package/ios/LuggMapView.mm +12 -0
- package/ios/core/AppleMapProvider.mm +57 -0
- package/ios/core/GoogleMapProvider.mm +62 -6
- package/ios/core/MKPolylineAnimator.m +64 -27
- package/ios/core/MapProviderDelegate.h +3 -0
- package/ios/core/PolylineAnimatorBase.h +10 -1
- package/ios/core/PolylineAnimatorBase.m +49 -19
- package/lib/module/MapView.js +16 -2
- package/lib/module/MapView.js.map +1 -1
- package/lib/module/MapView.web.js +42 -27
- package/lib/module/MapView.web.js.map +1 -1
- package/lib/module/components/Marker.js +12 -4
- package/lib/module/components/Marker.js.map +1 -1
- package/lib/module/components/Polyline.js +12 -4
- package/lib/module/components/Polyline.js.map +1 -1
- package/lib/module/components/index.js +2 -2
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/fabric/LuggMapViewNativeComponent.ts +9 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +2 -1
- package/lib/module/index.web.js.map +1 -1
- package/lib/typescript/src/MapView.d.ts +3 -2
- package/lib/typescript/src/MapView.d.ts.map +1 -1
- package/lib/typescript/src/MapView.types.d.ts +8 -1
- package/lib/typescript/src/MapView.types.d.ts.map +1 -1
- package/lib/typescript/src/MapView.web.d.ts.map +1 -1
- package/lib/typescript/src/components/Marker.d.ts +4 -1
- package/lib/typescript/src/components/Marker.d.ts.map +1 -1
- package/lib/typescript/src/components/Polyline.d.ts +4 -1
- package/lib/typescript/src/components/Polyline.d.ts.map +1 -1
- 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/fabric/LuggMapViewNativeComponent.d.ts +1 -0
- package/lib/typescript/src/fabric/LuggMapViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +5 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/index.web.d.ts +4 -1
- package/lib/typescript/src/index.web.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/MapView.tsx +13 -3
- package/src/MapView.types.ts +9 -1
- package/src/MapView.web.tsx +54 -37
- package/src/components/Marker.tsx +14 -2
- package/src/components/Polyline.tsx +14 -2
- package/src/components/index.ts +8 -2
- package/src/fabric/LuggMapViewNativeComponent.ts +9 -1
- package/src/index.ts +9 -1
- package/src/index.web.ts +4 -1
|
@@ -220,9 +220,15 @@ class LuggMapView(private val reactContext: ThemedReactContext) :
|
|
|
220
220
|
provider?.setTheme(value)
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
-
fun setEdgeInsets(
|
|
223
|
+
fun setEdgeInsets(
|
|
224
|
+
top: Int,
|
|
225
|
+
left: Int,
|
|
226
|
+
bottom: Int,
|
|
227
|
+
right: Int,
|
|
228
|
+
duration: Int = 0
|
|
229
|
+
) {
|
|
224
230
|
edgeInsets = EdgeInsets(top, left, bottom, right)
|
|
225
|
-
provider?.setEdgeInsets(edgeInsets)
|
|
231
|
+
provider?.setEdgeInsets(edgeInsets, duration)
|
|
226
232
|
}
|
|
227
233
|
|
|
228
234
|
// endregion
|
|
@@ -159,6 +159,23 @@ class LuggMapViewManager :
|
|
|
159
159
|
view.moveCamera(latitude, longitude, zoom, duration.toInt())
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
+
override fun setEdgeInsets(
|
|
163
|
+
view: LuggMapView,
|
|
164
|
+
top: Double,
|
|
165
|
+
left: Double,
|
|
166
|
+
bottom: Double,
|
|
167
|
+
right: Double,
|
|
168
|
+
duration: Double
|
|
169
|
+
) {
|
|
170
|
+
view.setEdgeInsets(
|
|
171
|
+
top.toFloat().dpToPx().toInt(),
|
|
172
|
+
left.toFloat().dpToPx().toInt(),
|
|
173
|
+
bottom.toFloat().dpToPx().toInt(),
|
|
174
|
+
right.toFloat().dpToPx().toInt(),
|
|
175
|
+
duration.toInt()
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
|
|
162
179
|
override fun fitCoordinates(
|
|
163
180
|
view: LuggMapView,
|
|
164
181
|
coordinates: ReadableArray?,
|
|
@@ -88,6 +88,9 @@ class GoogleMapProvider(private val context: Context) :
|
|
|
88
88
|
pendingPolylineViews.clear()
|
|
89
89
|
polylineAnimators.values.forEach { it.destroy() }
|
|
90
90
|
polylineAnimators.clear()
|
|
91
|
+
googleMap?.setOnCameraMoveStartedListener(null)
|
|
92
|
+
googleMap?.setOnCameraMoveListener(null)
|
|
93
|
+
googleMap?.setOnCameraIdleListener(null)
|
|
91
94
|
googleMap?.clear()
|
|
92
95
|
googleMap = null
|
|
93
96
|
_isMapReady = false
|
|
@@ -206,8 +209,34 @@ class GoogleMapProvider(private val context: Context) :
|
|
|
206
209
|
}
|
|
207
210
|
|
|
208
211
|
override fun setEdgeInsets(edgeInsets: EdgeInsets) {
|
|
212
|
+
val oldInsets = this.edgeInsets
|
|
209
213
|
this.edgeInsets = edgeInsets
|
|
210
214
|
applyEdgeInsets()
|
|
215
|
+
|
|
216
|
+
val map = googleMap
|
|
217
|
+
if (map != null && oldInsets != edgeInsets) {
|
|
218
|
+
mapView?.post {
|
|
219
|
+
setEdgeInsets(edgeInsets, 0)
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
override fun setEdgeInsets(edgeInsets: EdgeInsets, duration: Int) {
|
|
225
|
+
val map = googleMap
|
|
226
|
+
val oldInsets = this.edgeInsets
|
|
227
|
+
this.edgeInsets = edgeInsets
|
|
228
|
+
|
|
229
|
+
if (map != null && oldInsets != edgeInsets) {
|
|
230
|
+
val cameraUpdate = CameraUpdateFactory.newCameraPosition(map.cameraPosition)
|
|
231
|
+
applyEdgeInsets()
|
|
232
|
+
when {
|
|
233
|
+
duration < 0 -> map.animateCamera(cameraUpdate)
|
|
234
|
+
duration > 0 -> map.animateCamera(cameraUpdate, duration, null)
|
|
235
|
+
else -> map.moveCamera(cameraUpdate)
|
|
236
|
+
}
|
|
237
|
+
} else {
|
|
238
|
+
applyEdgeInsets()
|
|
239
|
+
}
|
|
211
240
|
}
|
|
212
241
|
|
|
213
242
|
// endregion
|
package/ios/LuggMapView.mm
CHANGED
|
@@ -273,6 +273,18 @@ using namespace luggmaps::events;
|
|
|
273
273
|
duration:duration];
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
+
- (void)setEdgeInsets:(double)top
|
|
277
|
+
left:(double)left
|
|
278
|
+
bottom:(double)bottom
|
|
279
|
+
right:(double)right
|
|
280
|
+
duration:(double)duration {
|
|
281
|
+
UIEdgeInsets oldInsets = _edgeInsets;
|
|
282
|
+
_edgeInsets = UIEdgeInsetsMake(top, left, bottom, right);
|
|
283
|
+
[_provider setEdgeInsets:_edgeInsets
|
|
284
|
+
oldEdgeInsets:oldInsets
|
|
285
|
+
duration:duration];
|
|
286
|
+
}
|
|
287
|
+
|
|
276
288
|
- (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args {
|
|
277
289
|
RCTLuggMapViewHandleCommand(self, commandName, args);
|
|
278
290
|
}
|
|
@@ -29,6 +29,13 @@
|
|
|
29
29
|
double _minZoom;
|
|
30
30
|
double _maxZoom;
|
|
31
31
|
NSMapTable<id<MKOverlay>, LuggPolylineView *> *_overlayToPolylineMap;
|
|
32
|
+
|
|
33
|
+
// Edge insets animation
|
|
34
|
+
CADisplayLink *_edgeInsetsDisplayLink;
|
|
35
|
+
UIEdgeInsets _edgeInsetsFrom;
|
|
36
|
+
UIEdgeInsets _edgeInsetsTo;
|
|
37
|
+
CFTimeInterval _edgeInsetsAnimationStart;
|
|
38
|
+
CFTimeInterval _edgeInsetsAnimationDuration;
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
@synthesize delegate = _delegate;
|
|
@@ -76,6 +83,7 @@
|
|
|
76
83
|
}
|
|
77
84
|
|
|
78
85
|
- (void)destroy {
|
|
86
|
+
[self stopEdgeInsetsAnimation];
|
|
79
87
|
[_mapView removeFromSuperview];
|
|
80
88
|
_mapView = nil;
|
|
81
89
|
_isMapReady = NO;
|
|
@@ -151,6 +159,55 @@
|
|
|
151
159
|
}
|
|
152
160
|
}
|
|
153
161
|
|
|
162
|
+
- (void)setEdgeInsets:(UIEdgeInsets)edgeInsets
|
|
163
|
+
oldEdgeInsets:(UIEdgeInsets)oldEdgeInsets
|
|
164
|
+
duration:(double)duration {
|
|
165
|
+
[self stopEdgeInsetsAnimation];
|
|
166
|
+
|
|
167
|
+
if (duration != 0 && _mapView) {
|
|
168
|
+
double actualDuration = duration < 0 ? 0.3 : duration / 1000.0;
|
|
169
|
+
_edgeInsetsFrom = oldEdgeInsets;
|
|
170
|
+
_edgeInsetsTo = edgeInsets;
|
|
171
|
+
_edgeInsetsAnimationDuration = actualDuration;
|
|
172
|
+
_edgeInsetsAnimationStart = CACurrentMediaTime();
|
|
173
|
+
|
|
174
|
+
_edgeInsetsDisplayLink = [CADisplayLink
|
|
175
|
+
displayLinkWithTarget:self
|
|
176
|
+
selector:@selector(edgeInsetsAnimationTick:)];
|
|
177
|
+
[_edgeInsetsDisplayLink addToRunLoop:[NSRunLoop mainRunLoop]
|
|
178
|
+
forMode:NSRunLoopCommonModes];
|
|
179
|
+
} else {
|
|
180
|
+
[self setEdgeInsets:edgeInsets oldEdgeInsets:oldEdgeInsets];
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
- (void)edgeInsetsAnimationTick:(CADisplayLink *)displayLink {
|
|
185
|
+
CFTimeInterval elapsed = CACurrentMediaTime() - _edgeInsetsAnimationStart;
|
|
186
|
+
CGFloat progress = MIN(elapsed / _edgeInsetsAnimationDuration, 1.0);
|
|
187
|
+
|
|
188
|
+
// Ease out cubic
|
|
189
|
+
CGFloat t = 1.0 - (1.0 - progress) * (1.0 - progress) * (1.0 - progress);
|
|
190
|
+
|
|
191
|
+
UIEdgeInsets current = UIEdgeInsetsMake(
|
|
192
|
+
_edgeInsetsFrom.top + (_edgeInsetsTo.top - _edgeInsetsFrom.top) * t,
|
|
193
|
+
_edgeInsetsFrom.left + (_edgeInsetsTo.left - _edgeInsetsFrom.left) * t,
|
|
194
|
+
_edgeInsetsFrom.bottom +
|
|
195
|
+
(_edgeInsetsTo.bottom - _edgeInsetsFrom.bottom) * t,
|
|
196
|
+
_edgeInsetsFrom.right +
|
|
197
|
+
(_edgeInsetsTo.right - _edgeInsetsFrom.right) * t);
|
|
198
|
+
|
|
199
|
+
[self setEdgeInsets:current oldEdgeInsets:_mapView.layoutMargins];
|
|
200
|
+
|
|
201
|
+
if (progress >= 1.0) {
|
|
202
|
+
[self stopEdgeInsetsAnimation];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
- (void)stopEdgeInsetsAnimation {
|
|
207
|
+
[_edgeInsetsDisplayLink invalidate];
|
|
208
|
+
_edgeInsetsDisplayLink = nil;
|
|
209
|
+
}
|
|
210
|
+
|
|
154
211
|
- (CLLocationDistance)cameraDistanceForZoomLevel:(double)zoomLevel {
|
|
155
212
|
return 128000000.0 / pow(2, zoomLevel);
|
|
156
213
|
}
|
|
@@ -19,6 +19,13 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
|
|
|
19
19
|
NSMutableArray<LuggMarkerView *> *_pendingMarkerViews;
|
|
20
20
|
NSMutableArray<LuggPolylineView *> *_pendingPolylineViews;
|
|
21
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;
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
@synthesize delegate = _delegate;
|
|
@@ -86,6 +93,7 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
|
|
|
86
93
|
}
|
|
87
94
|
|
|
88
95
|
- (void)destroy {
|
|
96
|
+
[self stopEdgeInsetsAnimation];
|
|
89
97
|
[_pendingMarkerViews removeAllObjects];
|
|
90
98
|
[_pendingPolylineViews removeAllObjects];
|
|
91
99
|
[_polylineAnimators removeAllObjects];
|
|
@@ -155,13 +163,61 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
|
|
|
155
163
|
|
|
156
164
|
- (void)setEdgeInsets:(UIEdgeInsets)edgeInsets
|
|
157
165
|
oldEdgeInsets:(UIEdgeInsets)oldEdgeInsets {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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))
|
|
162
173
|
return;
|
|
163
|
-
|
|
164
|
-
|
|
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;
|
|
165
221
|
}
|
|
166
222
|
|
|
167
223
|
#pragma mark - GMSMapViewDelegate
|
|
@@ -35,6 +35,8 @@
|
|
|
35
35
|
NSArray<NSNumber *> *_cumulativeDistances;
|
|
36
36
|
CGFloat _totalLength;
|
|
37
37
|
CGColorSpaceRef _colorSpace;
|
|
38
|
+
RGBAComponents *_colorCache;
|
|
39
|
+
NSUInteger _colorCacheCount;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
- (id)initWithPolyline:(MKPolyline *)polyline {
|
|
@@ -59,6 +61,7 @@
|
|
|
59
61
|
|
|
60
62
|
- (void)dealloc {
|
|
61
63
|
[self stopAnimation];
|
|
64
|
+
free(_colorCache);
|
|
62
65
|
if (_colorSpace) {
|
|
63
66
|
CGColorSpaceRelease(_colorSpace);
|
|
64
67
|
_colorSpace = NULL;
|
|
@@ -199,34 +202,60 @@
|
|
|
199
202
|
self.path = path;
|
|
200
203
|
}
|
|
201
204
|
|
|
202
|
-
- (UIColor *)
|
|
203
|
-
|
|
204
|
-
|
|
205
|
+
- (void)setStrokeColors:(NSArray<UIColor *> *)strokeColors {
|
|
206
|
+
_strokeColors = strokeColors;
|
|
207
|
+
[self rebuildColorCache];
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
- (void)rebuildColorCache {
|
|
211
|
+
free(_colorCache);
|
|
212
|
+
_colorCache = NULL;
|
|
213
|
+
_colorCacheCount = _strokeColors.count;
|
|
214
|
+
if (_colorCacheCount == 0) return;
|
|
215
|
+
|
|
216
|
+
_colorCache = (RGBAComponents *)malloc(sizeof(RGBAComponents) * _colorCacheCount);
|
|
217
|
+
for (NSUInteger i = 0; i < _colorCacheCount; i++) {
|
|
218
|
+
[_strokeColors[i] getRed:&_colorCache[i].r
|
|
219
|
+
green:&_colorCache[i].g
|
|
220
|
+
blue:&_colorCache[i].b
|
|
221
|
+
alpha:&_colorCache[i].a];
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
- (void)colorAtGradientPosition:(CGFloat)position rgba:(RGBAComponents *)out {
|
|
226
|
+
if (_colorCacheCount == 0) {
|
|
227
|
+
CGFloat r, g, b, a;
|
|
228
|
+
[self.strokeColor getRed:&r green:&g blue:&b alpha:&a];
|
|
229
|
+
*out = (RGBAComponents){r, g, b, a};
|
|
230
|
+
return;
|
|
205
231
|
}
|
|
206
|
-
if (
|
|
207
|
-
|
|
232
|
+
if (_colorCacheCount == 1) {
|
|
233
|
+
*out = _colorCache[0];
|
|
234
|
+
return;
|
|
208
235
|
}
|
|
209
236
|
|
|
210
237
|
position = MAX(0, MIN(1, position));
|
|
211
|
-
CGFloat scaledPos = position * (
|
|
212
|
-
NSUInteger index = (NSUInteger)
|
|
238
|
+
CGFloat scaledPos = position * (_colorCacheCount - 1);
|
|
239
|
+
NSUInteger index = (NSUInteger)scaledPos;
|
|
213
240
|
CGFloat t = scaledPos - index;
|
|
214
241
|
|
|
215
|
-
if (index >=
|
|
216
|
-
|
|
242
|
+
if (index >= _colorCacheCount - 1) {
|
|
243
|
+
*out = _colorCache[_colorCacheCount - 1];
|
|
244
|
+
return;
|
|
217
245
|
}
|
|
218
246
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
247
|
+
RGBAComponents c1 = _colorCache[index];
|
|
248
|
+
RGBAComponents c2 = _colorCache[index + 1];
|
|
249
|
+
out->r = c1.r + (c2.r - c1.r) * t;
|
|
250
|
+
out->g = c1.g + (c2.g - c1.g) * t;
|
|
251
|
+
out->b = c1.b + (c2.b - c1.b) * t;
|
|
252
|
+
out->a = c1.a + (c2.a - c1.a) * t;
|
|
253
|
+
}
|
|
225
254
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
255
|
+
- (UIColor *)colorAtGradientPosition:(CGFloat)position {
|
|
256
|
+
RGBAComponents rgba;
|
|
257
|
+
[self colorAtGradientPosition:position rgba:&rgba];
|
|
258
|
+
return [UIColor colorWithRed:rgba.r green:rgba.g blue:rgba.b alpha:rgba.a];
|
|
230
259
|
}
|
|
231
260
|
|
|
232
261
|
- (void)drawMapRect:(MKMapRect)mapRect
|
|
@@ -311,11 +340,15 @@
|
|
|
311
340
|
CGFloat gradientStart = (drawStartDist - tailDist) / visibleLength;
|
|
312
341
|
CGFloat gradientEnd = (drawEndDist - tailDist) / visibleLength;
|
|
313
342
|
|
|
314
|
-
|
|
315
|
-
|
|
343
|
+
RGBAComponents startRGBA, endRGBA;
|
|
344
|
+
[self colorAtGradientPosition:gradientStart rgba:&startRGBA];
|
|
345
|
+
[self colorAtGradientPosition:gradientEnd rgba:&endRGBA];
|
|
316
346
|
|
|
317
|
-
|
|
318
|
-
|
|
347
|
+
CGFloat components[] = {
|
|
348
|
+
startRGBA.r, startRGBA.g, startRGBA.b, startRGBA.a,
|
|
349
|
+
endRGBA.r, endRGBA.g, endRGBA.b, endRGBA.a
|
|
350
|
+
};
|
|
351
|
+
CGGradientRef gradient = CGGradientCreateWithColorComponents(_colorSpace, components, NULL, 2);
|
|
319
352
|
|
|
320
353
|
CGContextSaveGState(context);
|
|
321
354
|
CGContextBeginPath(context);
|
|
@@ -341,11 +374,15 @@
|
|
|
341
374
|
CGFloat gradientStart = (CGFloat)i / segmentCount;
|
|
342
375
|
CGFloat gradientEnd = (CGFloat)(i + 1) / segmentCount;
|
|
343
376
|
|
|
344
|
-
|
|
345
|
-
|
|
377
|
+
RGBAComponents startRGBA, endRGBA;
|
|
378
|
+
[self colorAtGradientPosition:gradientStart rgba:&startRGBA];
|
|
379
|
+
[self colorAtGradientPosition:gradientEnd rgba:&endRGBA];
|
|
346
380
|
|
|
347
|
-
|
|
348
|
-
|
|
381
|
+
CGFloat components[] = {
|
|
382
|
+
startRGBA.r, startRGBA.g, startRGBA.b, startRGBA.a,
|
|
383
|
+
endRGBA.r, endRGBA.g, endRGBA.b, endRGBA.a
|
|
384
|
+
};
|
|
385
|
+
CGGradientRef gradient = CGGradientCreateWithColorComponents(_colorSpace, components, NULL, 2);
|
|
349
386
|
|
|
350
387
|
CGContextSaveGState(context);
|
|
351
388
|
CGContextBeginPath(context);
|
|
@@ -39,6 +39,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
39
39
|
- (void)setMaxZoom:(double)maxZoom;
|
|
40
40
|
- (void)setEdgeInsets:(UIEdgeInsets)edgeInsets
|
|
41
41
|
oldEdgeInsets:(UIEdgeInsets)oldEdgeInsets;
|
|
42
|
+
- (void)setEdgeInsets:(UIEdgeInsets)edgeInsets
|
|
43
|
+
oldEdgeInsets:(UIEdgeInsets)oldEdgeInsets
|
|
44
|
+
duration:(double)duration;
|
|
42
45
|
|
|
43
46
|
// Children
|
|
44
47
|
- (void)addMarkerView:(LuggMarkerView *)markerView;
|
|
@@ -24,13 +24,22 @@
|
|
|
24
24
|
|
|
25
25
|
@end
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
typedef struct {
|
|
28
|
+
CGFloat r, g, b, a;
|
|
29
|
+
} RGBAComponents;
|
|
30
|
+
|
|
31
|
+
@interface PolylineAnimatorBase : NSObject {
|
|
32
|
+
@protected
|
|
33
|
+
RGBAComponents *_colorCache;
|
|
34
|
+
NSUInteger _colorCacheCount;
|
|
35
|
+
}
|
|
28
36
|
|
|
29
37
|
@property(nonatomic, strong) NSArray<CLLocation *> *coordinates;
|
|
30
38
|
@property(nonatomic, strong) NSArray<UIColor *> *strokeColors;
|
|
31
39
|
@property(nonatomic, strong) PolylineAnimatedOptions *animatedOptions;
|
|
32
40
|
|
|
33
41
|
- (UIColor *)colorAtGradientPosition:(CGFloat)position;
|
|
42
|
+
- (void)colorAtGradientPosition:(CGFloat)position rgba:(RGBAComponents *)out;
|
|
34
43
|
- (CGFloat)applyEasing:(CGFloat)t;
|
|
35
44
|
|
|
36
45
|
@end
|
|
@@ -18,10 +18,36 @@
|
|
|
18
18
|
- (instancetype)init {
|
|
19
19
|
if (self = [super init]) {
|
|
20
20
|
_animatedOptions = [PolylineAnimatedOptions defaultOptions];
|
|
21
|
+
_colorCache = NULL;
|
|
22
|
+
_colorCacheCount = 0;
|
|
21
23
|
}
|
|
22
24
|
return self;
|
|
23
25
|
}
|
|
24
26
|
|
|
27
|
+
- (void)dealloc {
|
|
28
|
+
free(_colorCache);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
- (void)setStrokeColors:(NSArray<UIColor *> *)strokeColors {
|
|
32
|
+
_strokeColors = strokeColors;
|
|
33
|
+
[self rebuildColorCache];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
- (void)rebuildColorCache {
|
|
37
|
+
free(_colorCache);
|
|
38
|
+
_colorCache = NULL;
|
|
39
|
+
_colorCacheCount = _strokeColors.count;
|
|
40
|
+
if (_colorCacheCount == 0) return;
|
|
41
|
+
|
|
42
|
+
_colorCache = (RGBAComponents *)malloc(sizeof(RGBAComponents) * _colorCacheCount);
|
|
43
|
+
for (NSUInteger i = 0; i < _colorCacheCount; i++) {
|
|
44
|
+
[_strokeColors[i] getRed:&_colorCache[i].r
|
|
45
|
+
green:&_colorCache[i].g
|
|
46
|
+
blue:&_colorCache[i].b
|
|
47
|
+
alpha:&_colorCache[i].a];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
25
51
|
- (CGFloat)applyEasing:(CGFloat)t {
|
|
26
52
|
NSString *easing = self.animatedOptions.easing ?: @"linear";
|
|
27
53
|
|
|
@@ -35,34 +61,38 @@
|
|
|
35
61
|
return t;
|
|
36
62
|
}
|
|
37
63
|
|
|
38
|
-
- (
|
|
39
|
-
if (
|
|
40
|
-
|
|
64
|
+
- (void)colorAtGradientPosition:(CGFloat)position rgba:(RGBAComponents *)out {
|
|
65
|
+
if (_colorCacheCount == 0) {
|
|
66
|
+
*out = (RGBAComponents){0, 0, 0, 1};
|
|
67
|
+
return;
|
|
41
68
|
}
|
|
42
|
-
if (
|
|
43
|
-
|
|
69
|
+
if (_colorCacheCount == 1) {
|
|
70
|
+
*out = _colorCache[0];
|
|
71
|
+
return;
|
|
44
72
|
}
|
|
45
73
|
|
|
46
74
|
position = MAX(0, MIN(1, position));
|
|
47
|
-
CGFloat scaledPos = position * (
|
|
48
|
-
NSUInteger index = (NSUInteger)
|
|
75
|
+
CGFloat scaledPos = position * (_colorCacheCount - 1);
|
|
76
|
+
NSUInteger index = (NSUInteger)scaledPos;
|
|
49
77
|
CGFloat t = scaledPos - index;
|
|
50
78
|
|
|
51
|
-
if (index >=
|
|
52
|
-
|
|
79
|
+
if (index >= _colorCacheCount - 1) {
|
|
80
|
+
*out = _colorCache[_colorCacheCount - 1];
|
|
81
|
+
return;
|
|
53
82
|
}
|
|
54
83
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
84
|
+
RGBAComponents c1 = _colorCache[index];
|
|
85
|
+
RGBAComponents c2 = _colorCache[index + 1];
|
|
86
|
+
out->r = c1.r + (c2.r - c1.r) * t;
|
|
87
|
+
out->g = c1.g + (c2.g - c1.g) * t;
|
|
88
|
+
out->b = c1.b + (c2.b - c1.b) * t;
|
|
89
|
+
out->a = c1.a + (c2.a - c1.a) * t;
|
|
90
|
+
}
|
|
61
91
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
92
|
+
- (UIColor *)colorAtGradientPosition:(CGFloat)position {
|
|
93
|
+
RGBAComponents rgba;
|
|
94
|
+
[self colorAtGradientPosition:position rgba:&rgba];
|
|
95
|
+
return [UIColor colorWithRed:rgba.r green:rgba.g blue:rgba.b alpha:rgba.a];
|
|
66
96
|
}
|
|
67
97
|
|
|
68
98
|
@end
|
package/lib/module/MapView.js
CHANGED
|
@@ -30,7 +30,7 @@ export class MapView extends React.Component {
|
|
|
30
30
|
const first = coordinates[0];
|
|
31
31
|
if (!ref || !first) return;
|
|
32
32
|
const {
|
|
33
|
-
|
|
33
|
+
padding,
|
|
34
34
|
duration = -1
|
|
35
35
|
} = options ?? {};
|
|
36
36
|
const {
|
|
@@ -38,7 +38,7 @@ export class MapView extends React.Component {
|
|
|
38
38
|
left = 0,
|
|
39
39
|
bottom = 0,
|
|
40
40
|
right = 0
|
|
41
|
-
} =
|
|
41
|
+
} = padding ?? {};
|
|
42
42
|
if (coordinates.length === 1) {
|
|
43
43
|
const zoom = this.props.initialZoom ?? 10;
|
|
44
44
|
this.moveCamera(first, {
|
|
@@ -49,6 +49,20 @@ export class MapView extends React.Component {
|
|
|
49
49
|
}
|
|
50
50
|
Commands.fitCoordinates(ref, coordinates, top, left, bottom, right, duration);
|
|
51
51
|
}
|
|
52
|
+
setEdgeInsets(edgeInsets, options) {
|
|
53
|
+
const ref = this.nativeRef.current;
|
|
54
|
+
if (!ref) return;
|
|
55
|
+
const {
|
|
56
|
+
top = 0,
|
|
57
|
+
left = 0,
|
|
58
|
+
bottom = 0,
|
|
59
|
+
right = 0
|
|
60
|
+
} = edgeInsets;
|
|
61
|
+
const {
|
|
62
|
+
duration = -1
|
|
63
|
+
} = options ?? {};
|
|
64
|
+
Commands.setEdgeInsets(ref, top, left, bottom, right, duration);
|
|
65
|
+
}
|
|
52
66
|
render() {
|
|
53
67
|
const {
|
|
54
68
|
provider,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Platform","StyleSheet","LuggMapViewNativeComponent","Commands","LuggMapWrapperViewNativeComponent","jsx","_jsx","jsxs","_jsxs","MapView","Component","defaultProps","provider","OS","initialZoom","zoomEnabled","scrollEnabled","rotateEnabled","pitchEnabled","theme","nativeRef","createRef","moveCamera","coordinate","options","ref","current","zoom","duration","latitude","longitude","fitCoordinates","coordinates","first","
|
|
1
|
+
{"version":3,"names":["React","Platform","StyleSheet","LuggMapViewNativeComponent","Commands","LuggMapWrapperViewNativeComponent","jsx","_jsx","jsxs","_jsxs","MapView","Component","defaultProps","provider","OS","initialZoom","zoomEnabled","scrollEnabled","rotateEnabled","pitchEnabled","theme","nativeRef","createRef","moveCamera","coordinate","options","ref","current","zoom","duration","latitude","longitude","fitCoordinates","coordinates","first","padding","top","left","bottom","right","length","props","setEdgeInsets","edgeInsets","render","mapId","initialCoordinate","minZoom","maxZoom","userLocationEnabled","myLocationButtonEnabled","onCameraMove","onCameraIdle","onReady","children","rest","style","absoluteFill"],"sourceRoot":"../../src","sources":["MapView.tsx"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,QAAQ,EAAEC,UAAU,QAAQ,cAAc;AACnD,OAAOC,0BAA0B,IAC/BC,QAAQ,QACH,qCAAqC;AAC5C,OAAOC,iCAAiC,MAAM,4CAA4C;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAU3F,OAAO,MAAMC,OAAO,SACVV,KAAK,CAACW,SAAS,CAEzB;EACE,OAAOC,YAAY,GAA0B;IAC3CC,QAAQ,EAAEZ,QAAQ,CAACa,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,IAAI;IAClBC,KAAK,EAAE;EACT,CAAC;EAEOC,SAAS,gBAAGrB,KAAK,CAACsB,SAAS,CAAM,CAAC;EAE1CC,UAAUA,CAACC,UAAsB,EAAEC,OAA2B,EAAE;IAC9D,MAAMC,GAAG,GAAG,IAAI,CAACL,SAAS,CAACM,OAAO;IAClC,IAAI,CAACD,GAAG,EAAE;IAEV,MAAM;MAAEE,IAAI,GAAG,CAAC;MAAEC,QAAQ,GAAG,CAAC;IAAE,CAAC,GAAGJ,OAAO,IAAI,CAAC,CAAC;IACjDrB,QAAQ,CAACmB,UAAU,CACjBG,GAAG,EACHF,UAAU,CAACM,QAAQ,EACnBN,UAAU,CAACO,SAAS,EACpBH,IAAI,EACJC,QACF,CAAC;EACH;EAEAG,cAAcA,CAACC,WAA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