react-native-maps 0.31.0 → 1.0.0-beta.2
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 +1 -5
- package/android/src/main/AndroidManifest.xml +0 -3
- package/android/src/main/java/com/airbnb/android/react/maps/AirMapLocalTile.java +11 -4
- package/android/src/main/java/com/airbnb/android/react/maps/AirMapLocalTileManager.java +5 -1
- package/android/src/main/java/com/airbnb/android/react/maps/AirMapManager.java +2 -41
- package/android/src/main/java/com/airbnb/android/react/maps/AirMapTileProvider.java +5 -5
- package/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java +0 -32
- package/ios/AirGoogleMaps/AIRGoogleMap.m +37 -31
- package/ios/AirGoogleMaps/AIRGoogleMapManager.m +0 -95
- package/ios/AirMaps/AIRMap.h +0 -1
- package/ios/AirMaps/AIRMap.m +0 -12
- package/ios/AirMaps/AIRMapManager.m +2 -132
- package/lib/AnimatedRegion.d.ts +19 -0
- package/lib/AnimatedRegion.js +134 -0
- package/lib/Geojson.d.ts +166 -0
- package/lib/Geojson.js +165 -0
- package/lib/MapCallout.d.ts +40 -0
- package/lib/MapCallout.js +51 -0
- package/lib/MapCalloutSubview.d.ts +34 -0
- package/lib/MapCalloutSubview.js +48 -0
- package/lib/MapCircle.d.ts +117 -0
- package/lib/MapCircle.js +53 -0
- package/lib/MapHeatmap.d.ts +77 -0
- package/lib/MapHeatmap.js +59 -0
- package/lib/MapLocalTile.d.ts +35 -0
- package/lib/MapLocalTile.js +44 -0
- package/lib/MapMarker.d.ts +289 -0
- package/lib/MapMarker.js +113 -0
- package/lib/MapOverlay.d.ts +86 -0
- package/lib/MapOverlay.js +63 -0
- package/lib/MapPolygon.d.ts +156 -0
- package/lib/MapPolygon.js +74 -0
- package/lib/MapPolyline.d.ts +156 -0
- package/lib/MapPolyline.js +53 -0
- package/lib/MapUrlTile.d.ts +134 -0
- package/lib/MapUrlTile.js +44 -0
- package/lib/MapView.d.ts +825 -0
- package/lib/MapView.js +418 -0
- package/{src/MapView.web.js → lib/MapView.web.d.ts} +0 -0
- package/lib/MapView.web.js +9 -0
- package/lib/MapWMSTile.d.ts +116 -0
- package/lib/MapWMSTile.js +44 -0
- package/lib/ProviderConstants.d.ts +2 -0
- package/lib/ProviderConstants.js +5 -0
- package/lib/decorateMapComponent.d.ts +35 -0
- package/lib/decorateMapComponent.js +80 -0
- package/{src/index.js → lib/index.d.ts} +5 -16
- package/lib/index.js +66 -0
- package/lib/sharedTypes.d.ts +82 -0
- package/lib/sharedTypes.js +2 -0
- package/package.json +19 -28
- package/react-native-google-maps.podspec +1 -1
- package/react-native-maps.podspec +1 -1
- package/index.d.ts +0 -637
- package/src/AnimatedRegion.js +0 -164
- package/src/Geojson.js +0 -334
- package/src/MapCallout.js +0 -51
- package/src/MapCalloutSubview.js +0 -44
- package/src/MapCircle.js +0 -150
- package/src/MapHeatmap.js +0 -99
- package/src/MapLocalTile.js +0 -52
- package/src/MapMarker.js +0 -377
- package/src/MapOverlay.js +0 -86
- package/src/MapPolygon.js +0 -202
- package/src/MapPolyline.js +0 -168
- package/src/MapUrlTile.js +0 -131
- package/src/MapView.js +0 -1160
- package/src/MapWMSTile.js +0 -122
- package/src/ProviderConstants.js +0 -2
- package/src/decorateMapComponent.js +0 -112
|
@@ -28,8 +28,6 @@
|
|
|
28
28
|
#import "AIRMapSnapshot.h"
|
|
29
29
|
#import "RCTConvert+AirMap.h"
|
|
30
30
|
#import "AIRMapOverlay.h"
|
|
31
|
-
#import "AIRWeakTimerReference.h"
|
|
32
|
-
#import "AIRWeakMapReference.h"
|
|
33
31
|
#import <MapKit/MapKit.h>
|
|
34
32
|
|
|
35
33
|
static NSString *const RCTMapViewKey = @"MapView";
|
|
@@ -278,31 +276,6 @@ RCT_EXPORT_METHOD(animateCamera:(nonnull NSNumber *)reactTag
|
|
|
278
276
|
}];
|
|
279
277
|
}
|
|
280
278
|
|
|
281
|
-
|
|
282
|
-
RCT_EXPORT_METHOD(animateToNavigation:(nonnull NSNumber *)reactTag
|
|
283
|
-
withRegion:(MKCoordinateRegion)region
|
|
284
|
-
withBearing:(CGFloat)bearing
|
|
285
|
-
withAngle:(double)angle
|
|
286
|
-
withDuration:(CGFloat)duration)
|
|
287
|
-
{
|
|
288
|
-
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
|
289
|
-
id view = viewRegistry[reactTag];
|
|
290
|
-
if (![view isKindOfClass:[AIRMap class]]) {
|
|
291
|
-
RCTLogError(@"Invalid view returned from registry, expecting AIRMap, got: %@", view);
|
|
292
|
-
} else {
|
|
293
|
-
AIRMap *mapView = (AIRMap *)view;
|
|
294
|
-
MKMapCamera *mapCamera = [[mapView camera] copy];
|
|
295
|
-
[mapCamera setPitch:angle];
|
|
296
|
-
[mapCamera setHeading:bearing];
|
|
297
|
-
|
|
298
|
-
[AIRMap animateWithDuration:duration/1000 animations:^{
|
|
299
|
-
[(AIRMap *)view setRegion:region animated:YES];
|
|
300
|
-
[mapView setCamera:mapCamera animated:YES];
|
|
301
|
-
}];
|
|
302
|
-
}
|
|
303
|
-
}];
|
|
304
|
-
}
|
|
305
|
-
|
|
306
279
|
RCT_EXPORT_METHOD(animateToRegion:(nonnull NSNumber *)reactTag
|
|
307
280
|
withRegion:(MKCoordinateRegion)region
|
|
308
281
|
withDuration:(CGFloat)duration)
|
|
@@ -319,68 +292,6 @@ RCT_EXPORT_METHOD(animateToRegion:(nonnull NSNumber *)reactTag
|
|
|
319
292
|
}];
|
|
320
293
|
}
|
|
321
294
|
|
|
322
|
-
RCT_EXPORT_METHOD(animateToCoordinate:(nonnull NSNumber *)reactTag
|
|
323
|
-
withRegion:(CLLocationCoordinate2D)latlng
|
|
324
|
-
withDuration:(CGFloat)duration)
|
|
325
|
-
{
|
|
326
|
-
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
|
327
|
-
id view = viewRegistry[reactTag];
|
|
328
|
-
if (![view isKindOfClass:[AIRMap class]]) {
|
|
329
|
-
RCTLogError(@"Invalid view returned from registry, expecting AIRMap, got: %@", view);
|
|
330
|
-
} else {
|
|
331
|
-
AIRMap *mapView = (AIRMap *)view;
|
|
332
|
-
MKCoordinateRegion region;
|
|
333
|
-
region.span = mapView.region.span;
|
|
334
|
-
region.center = latlng;
|
|
335
|
-
[AIRMap animateWithDuration:duration/1000 animations:^{
|
|
336
|
-
[mapView setRegion:region animated:YES];
|
|
337
|
-
}];
|
|
338
|
-
}
|
|
339
|
-
}];
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
RCT_EXPORT_METHOD(animateToViewingAngle:(nonnull NSNumber *)reactTag
|
|
343
|
-
withAngle:(double)angle
|
|
344
|
-
withDuration:(CGFloat)duration)
|
|
345
|
-
{
|
|
346
|
-
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
|
347
|
-
id view = viewRegistry[reactTag];
|
|
348
|
-
if (![view isKindOfClass:[AIRMap class]]) {
|
|
349
|
-
RCTLogError(@"Invalid view returned from registry, expecting AIRMap, got: %@", view);
|
|
350
|
-
} else {
|
|
351
|
-
AIRMap *mapView = (AIRMap *)view;
|
|
352
|
-
|
|
353
|
-
MKMapCamera *mapCamera = [[mapView camera] copy];
|
|
354
|
-
[mapCamera setPitch:angle];
|
|
355
|
-
|
|
356
|
-
[AIRMap animateWithDuration:duration/1000 animations:^{
|
|
357
|
-
[mapView setCamera:mapCamera animated:YES];
|
|
358
|
-
}];
|
|
359
|
-
}
|
|
360
|
-
}];
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
RCT_EXPORT_METHOD(animateToBearing:(nonnull NSNumber *)reactTag
|
|
364
|
-
withBearing:(CGFloat)bearing
|
|
365
|
-
withDuration:(CGFloat)duration)
|
|
366
|
-
{
|
|
367
|
-
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
|
368
|
-
id view = viewRegistry[reactTag];
|
|
369
|
-
if (![view isKindOfClass:[AIRMap class]]) {
|
|
370
|
-
RCTLogError(@"Invalid view returned from registry, expecting AIRMap, got: %@", view);
|
|
371
|
-
} else {
|
|
372
|
-
AIRMap *mapView = (AIRMap *)view;
|
|
373
|
-
|
|
374
|
-
MKMapCamera *mapCamera = [[mapView camera] copy];
|
|
375
|
-
[mapCamera setHeading:bearing];
|
|
376
|
-
|
|
377
|
-
[AIRMap animateWithDuration:duration/1000 animations:^{
|
|
378
|
-
[mapView setCamera:mapCamera animated:YES];
|
|
379
|
-
}];
|
|
380
|
-
}
|
|
381
|
-
}];
|
|
382
|
-
}
|
|
383
|
-
|
|
384
295
|
RCT_EXPORT_METHOD(fitToElements:(nonnull NSNumber *)reactTag
|
|
385
296
|
edgePadding:(nonnull NSDictionary *)edgePadding
|
|
386
297
|
animated:(BOOL)animated)
|
|
@@ -677,24 +588,6 @@ RCT_EXPORT_METHOD(getAddressFromCoordinates:(nonnull NSNumber *)reactTag
|
|
|
677
588
|
else if ([result isEqualToString:@"base64"]) {
|
|
678
589
|
callback(@[[NSNull null], [data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn]]);
|
|
679
590
|
}
|
|
680
|
-
else if ([result isEqualToString:@"legacy"]) {
|
|
681
|
-
|
|
682
|
-
// In the initial (iOS only) implementation of takeSnapshot,
|
|
683
|
-
// both the uri and the base64 encoded string were returned.
|
|
684
|
-
// Returning both is rarely useful and in fact causes a
|
|
685
|
-
// performance penalty when only the file URI is desired.
|
|
686
|
-
// In that case the base64 encoded string was always marshalled
|
|
687
|
-
// over the JS-bridge (which is quite slow).
|
|
688
|
-
// A new more flexible API was created to cover this.
|
|
689
|
-
// This code should be removed in a future release when the
|
|
690
|
-
// old API is fully deprecated.
|
|
691
|
-
[data writeToFile:filePath atomically:YES];
|
|
692
|
-
NSDictionary *snapshotData = @{
|
|
693
|
-
@"uri": filePath,
|
|
694
|
-
@"data": [data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn]
|
|
695
|
-
};
|
|
696
|
-
callback(@[[NSNull null], snapshotData]);
|
|
697
|
-
}
|
|
698
591
|
}
|
|
699
592
|
UIGraphicsEndImageContext();
|
|
700
593
|
}];
|
|
@@ -1048,30 +941,14 @@ static int kDragCenterContext;
|
|
|
1048
941
|
|
|
1049
942
|
}
|
|
1050
943
|
|
|
1051
|
-
- (void)
|
|
944
|
+
- (void)mapViewDidChangeVisibleRegion:(AIRMap *)mapView
|
|
1052
945
|
{
|
|
1053
|
-
|
|
1054
|
-
// started rendering, as these won't represent the final location
|
|
1055
|
-
if(mapView.hasStartedRendering){
|
|
1056
|
-
[self _regionChanged:mapView];
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
AIRWeakTimerReference *weakTarget = [[AIRWeakTimerReference alloc] initWithTarget:self andSelector:@selector(_onTick:)];
|
|
1060
|
-
|
|
1061
|
-
mapView.regionChangeObserveTimer = [NSTimer timerWithTimeInterval:AIRMapRegionChangeObserveInterval
|
|
1062
|
-
target:weakTarget
|
|
1063
|
-
selector:@selector(timerDidFire:)
|
|
1064
|
-
userInfo:@{ RCTMapViewKey: [[AIRWeakMapReference alloc] initWithMapView: mapView] }
|
|
1065
|
-
repeats:YES];
|
|
1066
|
-
|
|
1067
|
-
[[NSRunLoop mainRunLoop] addTimer:mapView.regionChangeObserveTimer forMode:NSRunLoopCommonModes];
|
|
946
|
+
[self _regionChanged:mapView];
|
|
1068
947
|
}
|
|
1069
948
|
|
|
1070
949
|
- (void)mapView:(AIRMap *)mapView regionDidChangeAnimated:(__unused BOOL)animated
|
|
1071
950
|
{
|
|
1072
951
|
CGFloat zoomLevel = [self zoomLevel:mapView];
|
|
1073
|
-
[mapView.regionChangeObserveTimer invalidate];
|
|
1074
|
-
mapView.regionChangeObserveTimer = nil;
|
|
1075
952
|
|
|
1076
953
|
// Don't send region did change events until map has
|
|
1077
954
|
// started rendering, as these won't represent the final location
|
|
@@ -1103,7 +980,6 @@ static int kDragCenterContext;
|
|
|
1103
980
|
mapView.hasStartedRendering = YES;
|
|
1104
981
|
}
|
|
1105
982
|
[mapView beginLoading];
|
|
1106
|
-
[self _emitRegionChangeEvent:mapView continuous:NO];
|
|
1107
983
|
}
|
|
1108
984
|
|
|
1109
985
|
- (void)mapViewDidFinishRenderingMap:(AIRMap *)mapView fullyRendered:(BOOL)fullyRendered
|
|
@@ -1113,12 +989,6 @@ static int kDragCenterContext;
|
|
|
1113
989
|
|
|
1114
990
|
#pragma mark Private
|
|
1115
991
|
|
|
1116
|
-
- (void)_onTick:(NSTimer *)timer
|
|
1117
|
-
{
|
|
1118
|
-
AIRWeakMapReference *weakRef = timer.userInfo[RCTMapViewKey];
|
|
1119
|
-
[self _regionChanged:weakRef.mapView];
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
992
|
- (void)_regionChanged:(AIRMap *)mapView
|
|
1123
993
|
{
|
|
1124
994
|
BOOL needZoom = NO;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Animated } from 'react-native';
|
|
2
|
+
import { Region } from './sharedTypes';
|
|
3
|
+
declare const AnimatedWithChildren: any;
|
|
4
|
+
declare type Props = Partial<Region> | undefined;
|
|
5
|
+
export default class AnimatedMapRegion extends AnimatedWithChildren {
|
|
6
|
+
constructor(valueIn?: Props);
|
|
7
|
+
setValue(value: Region): void;
|
|
8
|
+
setOffset(offset: Region): void;
|
|
9
|
+
flattenOffset(): void;
|
|
10
|
+
private __getValue;
|
|
11
|
+
private __attach;
|
|
12
|
+
private __detach;
|
|
13
|
+
stopAnimation(callback: (region: Region) => void): void;
|
|
14
|
+
addListener(callback: (region: Region) => void): string;
|
|
15
|
+
removeListener(id: string): void;
|
|
16
|
+
spring(config: Animated.SpringAnimationConfig & Region): Animated.CompositeAnimation;
|
|
17
|
+
timing(config: Animated.TimingAnimationConfig & Region): Animated.CompositeAnimation;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_native_1 = require("react-native");
|
|
4
|
+
const AnimatedWithChildren = Object.getPrototypeOf(react_native_1.Animated.ValueXY);
|
|
5
|
+
if (__DEV__) {
|
|
6
|
+
if (AnimatedWithChildren.name !== 'AnimatedWithChildren') {
|
|
7
|
+
console.error('AnimatedRegion could not obtain AnimatedWithChildren base class');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const configTypes = [
|
|
11
|
+
'latitude',
|
|
12
|
+
'longitude',
|
|
13
|
+
'latitudeDelta',
|
|
14
|
+
'longitudeDelta',
|
|
15
|
+
];
|
|
16
|
+
const defaultValues = {
|
|
17
|
+
// probably want to come up with better defaults
|
|
18
|
+
latitude: 0,
|
|
19
|
+
longitude: 0,
|
|
20
|
+
latitudeDelta: 0,
|
|
21
|
+
longitudeDelta: 0,
|
|
22
|
+
};
|
|
23
|
+
let _uniqueId = 1;
|
|
24
|
+
const getAnimatedValue = (valueIn, fallback) => {
|
|
25
|
+
if (valueIn instanceof react_native_1.Animated.Value) {
|
|
26
|
+
return valueIn;
|
|
27
|
+
}
|
|
28
|
+
else if (typeof valueIn === 'number') {
|
|
29
|
+
return new react_native_1.Animated.Value(valueIn);
|
|
30
|
+
}
|
|
31
|
+
return new react_native_1.Animated.Value(fallback);
|
|
32
|
+
};
|
|
33
|
+
class AnimatedMapRegion extends AnimatedWithChildren {
|
|
34
|
+
constructor(valueIn = {}) {
|
|
35
|
+
super();
|
|
36
|
+
this.latitude = getAnimatedValue(valueIn.latitude, defaultValues.latitude);
|
|
37
|
+
this.longitude = getAnimatedValue(valueIn.longitude, defaultValues.longitude);
|
|
38
|
+
this.latitudeDelta = getAnimatedValue(valueIn.latitudeDelta, defaultValues.latitudeDelta);
|
|
39
|
+
this.longitudeDelta = getAnimatedValue(valueIn.longitudeDelta, defaultValues.longitudeDelta);
|
|
40
|
+
this._regionListeners = {};
|
|
41
|
+
}
|
|
42
|
+
setValue(value) {
|
|
43
|
+
this.latitude._value = value.latitude;
|
|
44
|
+
this.longitude._value = value.longitude;
|
|
45
|
+
this.latitudeDelta._value = value.latitudeDelta;
|
|
46
|
+
this.longitudeDelta._value = value.longitudeDelta;
|
|
47
|
+
}
|
|
48
|
+
setOffset(offset) {
|
|
49
|
+
this.latitude.setOffset(offset.latitude);
|
|
50
|
+
this.longitude.setOffset(offset.longitude);
|
|
51
|
+
this.latitudeDelta.setOffset(offset.latitudeDelta);
|
|
52
|
+
this.longitudeDelta.setOffset(offset.longitudeDelta);
|
|
53
|
+
}
|
|
54
|
+
flattenOffset() {
|
|
55
|
+
this.latitude.flattenOffset();
|
|
56
|
+
this.longitude.flattenOffset();
|
|
57
|
+
this.latitudeDelta.flattenOffset();
|
|
58
|
+
this.longitudeDelta.flattenOffset();
|
|
59
|
+
}
|
|
60
|
+
__getValue() {
|
|
61
|
+
return {
|
|
62
|
+
latitude: this.latitude.__getValue(),
|
|
63
|
+
longitude: this.longitude.__getValue(),
|
|
64
|
+
latitudeDelta: this.latitudeDelta.__getValue(),
|
|
65
|
+
longitudeDelta: this.longitudeDelta.__getValue(),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
__attach() {
|
|
69
|
+
this.latitude.__addChild(this);
|
|
70
|
+
this.longitude.__addChild(this);
|
|
71
|
+
this.latitudeDelta.__addChild(this);
|
|
72
|
+
this.longitudeDelta.__addChild(this);
|
|
73
|
+
}
|
|
74
|
+
__detach() {
|
|
75
|
+
this.latitude.__removeChild(this);
|
|
76
|
+
this.longitude.__removeChild(this);
|
|
77
|
+
this.latitudeDelta.__removeChild(this);
|
|
78
|
+
this.longitudeDelta.__removeChild(this);
|
|
79
|
+
}
|
|
80
|
+
stopAnimation(callback) {
|
|
81
|
+
this.latitude.stopAnimation();
|
|
82
|
+
this.longitude.stopAnimation();
|
|
83
|
+
this.latitudeDelta.stopAnimation();
|
|
84
|
+
this.longitudeDelta.stopAnimation();
|
|
85
|
+
callback && callback(this.__getValue());
|
|
86
|
+
}
|
|
87
|
+
addListener(callback) {
|
|
88
|
+
const id = String(_uniqueId++);
|
|
89
|
+
const jointCallback = () => /*{value}*/ callback(this.__getValue());
|
|
90
|
+
this._regionListeners[id] = {
|
|
91
|
+
latitude: this.latitude.addListener(jointCallback),
|
|
92
|
+
longitude: this.longitude.addListener(jointCallback),
|
|
93
|
+
latitudeDelta: this.latitudeDelta.addListener(jointCallback),
|
|
94
|
+
longitudeDelta: this.longitudeDelta.addListener(jointCallback),
|
|
95
|
+
};
|
|
96
|
+
return id;
|
|
97
|
+
}
|
|
98
|
+
removeListener(id) {
|
|
99
|
+
this.latitude.removeListener(this._regionListeners[id].latitude);
|
|
100
|
+
this.longitude.removeListener(this._regionListeners[id].longitude);
|
|
101
|
+
this.latitudeDelta.removeListener(this._regionListeners[id].latitudeDelta);
|
|
102
|
+
this.longitudeDelta.removeListener(this._regionListeners[id].longitudeDelta);
|
|
103
|
+
delete this._regionListeners[id];
|
|
104
|
+
}
|
|
105
|
+
spring(config) {
|
|
106
|
+
const animations = [];
|
|
107
|
+
for (const type of configTypes) {
|
|
108
|
+
if (config.hasOwnProperty(type)) {
|
|
109
|
+
animations.push(react_native_1.Animated.spring(this[type], {
|
|
110
|
+
...config,
|
|
111
|
+
toValue: config[type],
|
|
112
|
+
// may help to eliminate some dev warnings and perf issues
|
|
113
|
+
useNativeDriver: !!config?.useNativeDriver,
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return react_native_1.Animated.parallel(animations);
|
|
118
|
+
}
|
|
119
|
+
timing(config) {
|
|
120
|
+
const animations = [];
|
|
121
|
+
for (const type of configTypes) {
|
|
122
|
+
if (config.hasOwnProperty(type)) {
|
|
123
|
+
animations.push(react_native_1.Animated.timing(this[type], {
|
|
124
|
+
...config,
|
|
125
|
+
toValue: config[type],
|
|
126
|
+
// may help to eliminate some dev warnings and perf issues
|
|
127
|
+
useNativeDriver: !!config?.useNativeDriver,
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return react_native_1.Animated.parallel(animations);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.default = AnimatedMapRegion;
|
package/lib/Geojson.d.ts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Feature, FeatureCollection, Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon } from 'geojson';
|
|
3
|
+
import { Props as MarkerProps } from './MapMarker';
|
|
4
|
+
import { Props as PolygonProps } from './MapPolygon';
|
|
5
|
+
import { Props as PolylineProps } from './MapPolyline';
|
|
6
|
+
import { LatLng } from './sharedTypes';
|
|
7
|
+
declare type Props = {
|
|
8
|
+
/**
|
|
9
|
+
* The pincolor used on markers
|
|
10
|
+
*
|
|
11
|
+
* @platform iOS: Supported
|
|
12
|
+
* @platform Android: Supported
|
|
13
|
+
*/
|
|
14
|
+
color?: MarkerProps['pinColor'];
|
|
15
|
+
/**
|
|
16
|
+
* The fill color to use for the path.
|
|
17
|
+
*
|
|
18
|
+
* @platform iOS: Supported
|
|
19
|
+
* @platform Android: Supported
|
|
20
|
+
*/
|
|
21
|
+
fillColor?: PolygonProps['fillColor'];
|
|
22
|
+
/**
|
|
23
|
+
* [Geojson](https://geojson.org/) description of object.
|
|
24
|
+
*
|
|
25
|
+
* @platform iOS: Supported
|
|
26
|
+
* @platform Android: Supported
|
|
27
|
+
*/
|
|
28
|
+
geojson: FeatureCollection;
|
|
29
|
+
/**
|
|
30
|
+
* A custom image to be used as the marker's icon. Only local image resources are allowed to be
|
|
31
|
+
* used.
|
|
32
|
+
*
|
|
33
|
+
* @platform iOS: Supported
|
|
34
|
+
* @platform Android: Supported
|
|
35
|
+
*/
|
|
36
|
+
image?: MarkerProps['image'];
|
|
37
|
+
/**
|
|
38
|
+
* The line cap style to apply to the open ends of the path.
|
|
39
|
+
* The default style is `round`.
|
|
40
|
+
*
|
|
41
|
+
* @platform iOS: Apple Maps only
|
|
42
|
+
* @platform Android: Supported
|
|
43
|
+
*/
|
|
44
|
+
lineCap?: PolylineProps['lineCap'];
|
|
45
|
+
/**
|
|
46
|
+
* An array of numbers specifying the dash pattern to use for the path.
|
|
47
|
+
*
|
|
48
|
+
* The array contains one or more numbers that indicate the lengths (measured in points) of the
|
|
49
|
+
* line segments and gaps in the pattern. The values in the array alternate, starting with the
|
|
50
|
+
* first line segment length, followed by the first gap length, followed by the second line
|
|
51
|
+
* segment length, and so on.
|
|
52
|
+
*
|
|
53
|
+
* This property is set to `null` by default, which indicates no line dash pattern.
|
|
54
|
+
*
|
|
55
|
+
* @platform iOS: Supported
|
|
56
|
+
* @platform Android: Supported
|
|
57
|
+
*/
|
|
58
|
+
lineDashPattern?: PolylineProps['lineDashPattern'];
|
|
59
|
+
/**
|
|
60
|
+
* The offset (in points) at which to start drawing the dash pattern.
|
|
61
|
+
*
|
|
62
|
+
* Use this property to start drawing a dashed line partway through a segment or gap. For
|
|
63
|
+
* example, a phase value of 6 for the patter 5-2-3-2 would cause drawing to begin in the
|
|
64
|
+
* middle of the first gap.
|
|
65
|
+
*
|
|
66
|
+
* The default value of this property is 0.
|
|
67
|
+
*
|
|
68
|
+
* @platform iOS: Apple Maps only
|
|
69
|
+
* @platform Android: Not supported
|
|
70
|
+
*/
|
|
71
|
+
lineDashPhase?: PolylineProps['lineDashPhase'];
|
|
72
|
+
/**
|
|
73
|
+
* The line join style to apply to corners of the path.
|
|
74
|
+
* The default style is `round`.
|
|
75
|
+
*
|
|
76
|
+
* @platform iOS: Apple Maps only
|
|
77
|
+
* @platform Android: Not supported
|
|
78
|
+
*/
|
|
79
|
+
lineJoin?: PolylineProps['lineJoin'];
|
|
80
|
+
/**
|
|
81
|
+
* Component to render in place of the default marker when the overlay type is a `point`
|
|
82
|
+
*
|
|
83
|
+
* @platform iOS: Supported
|
|
84
|
+
* @platform Android: Supported
|
|
85
|
+
*/
|
|
86
|
+
markerComponent?: MarkerProps['children'];
|
|
87
|
+
/**
|
|
88
|
+
* The limiting value that helps avoid spikes at junctions between connected line segments.
|
|
89
|
+
* The miter limit helps you avoid spikes in paths that use the `miter` `lineJoin` style. If
|
|
90
|
+
* the ratio of the miter length—that is, the diagonal length of the miter join—to the line
|
|
91
|
+
* thickness exceeds the miter limit, the joint is converted to a bevel join. The default
|
|
92
|
+
* miter limit is 10, which results in the conversion of miters whose angle at the joint
|
|
93
|
+
* is less than 11 degrees.
|
|
94
|
+
*
|
|
95
|
+
* @platform iOS: Apple Maps only
|
|
96
|
+
* @platform Android: Not supported
|
|
97
|
+
*/
|
|
98
|
+
miterLimit?: PolylineProps['miterLimit'];
|
|
99
|
+
/**
|
|
100
|
+
* Callback that is called when the user presses any of the overlays
|
|
101
|
+
*/
|
|
102
|
+
onPress?: (event: OverlayPressEvent) => void;
|
|
103
|
+
/**
|
|
104
|
+
* The stroke color to use for the path.
|
|
105
|
+
*
|
|
106
|
+
* @platform — iOS: Supported
|
|
107
|
+
* @platform — Android: Supported
|
|
108
|
+
*/
|
|
109
|
+
strokeColor?: PolygonProps['strokeColor'] | PolylineProps['strokeColor'];
|
|
110
|
+
/**
|
|
111
|
+
* The stroke width to use for the path.
|
|
112
|
+
*
|
|
113
|
+
* @platform — iOS: Supported
|
|
114
|
+
* @platform — Android: Supported
|
|
115
|
+
*/
|
|
116
|
+
strokeWidth?: PolygonProps['strokeWidth'] | PolylineProps['strokeWidth'];
|
|
117
|
+
/**
|
|
118
|
+
* Make the `Polygon` or `Polyline` tappable
|
|
119
|
+
*
|
|
120
|
+
* @platform — iOS: Google Maps only
|
|
121
|
+
* @platform — Android: Supported
|
|
122
|
+
*/
|
|
123
|
+
tappable?: PolygonProps['tappable'] | PolylineProps['tappable'];
|
|
124
|
+
/**
|
|
125
|
+
* The title of the marker. This is only used if the <Marker /> component has no children that
|
|
126
|
+
* are a `<Callout />`, in which case the default callout behavior will be used, which
|
|
127
|
+
* will show both the `title` and the `description`, if provided.
|
|
128
|
+
*
|
|
129
|
+
* @platform — iOS: Supported
|
|
130
|
+
* @platform — Android: Supported
|
|
131
|
+
*/
|
|
132
|
+
title?: MarkerProps['title'];
|
|
133
|
+
/**
|
|
134
|
+
* The order in which this tile overlay is drawn with respect to other overlays. An overlay
|
|
135
|
+
* with a larger z-index is drawn over overlays with smaller z-indices. The order of overlays
|
|
136
|
+
* with the same z-index is arbitrary. The default zIndex is 0.
|
|
137
|
+
*
|
|
138
|
+
* @platform iOS: Apple Maps: [Marker], Google Maps: [Marker, Polygon, Polyline]
|
|
139
|
+
* @platform Android: Supported
|
|
140
|
+
*/
|
|
141
|
+
zIndex?: MarkerProps['zIndex'] | PolygonProps['zIndex'] | PolylineProps['zIndex'];
|
|
142
|
+
};
|
|
143
|
+
declare const Geojson: (props: Props) => JSX.Element;
|
|
144
|
+
export default Geojson;
|
|
145
|
+
declare type OverlayPressEvent = {
|
|
146
|
+
type: AnyPointOverlay['type'] | AnyLineStringOverlay['type'] | AnyPolygonOverlay['type'];
|
|
147
|
+
feature: AnyPointOverlay['feature'] | AnyLineStringOverlay['feature'] | AnyPolygonOverlay['feature'];
|
|
148
|
+
coordinates: AnyPointOverlay['coordinates'] | AnyLineStringOverlay['coordinates'] | AnyPolygonOverlay['coordinates'];
|
|
149
|
+
holes?: AnyPolygonOverlay['holes'];
|
|
150
|
+
};
|
|
151
|
+
declare type AnyPointOverlay = {
|
|
152
|
+
type: 'point';
|
|
153
|
+
feature: Feature<Point | MultiPoint>;
|
|
154
|
+
coordinates: LatLng;
|
|
155
|
+
};
|
|
156
|
+
declare type AnyLineStringOverlay = {
|
|
157
|
+
type: 'polyline';
|
|
158
|
+
feature: Feature<LineString | MultiLineString>;
|
|
159
|
+
coordinates: LatLng[];
|
|
160
|
+
};
|
|
161
|
+
declare type AnyPolygonOverlay = {
|
|
162
|
+
type: 'polygon';
|
|
163
|
+
feature: Feature<Polygon | MultiPolygon>;
|
|
164
|
+
coordinates: LatLng[];
|
|
165
|
+
holes?: LatLng[][];
|
|
166
|
+
};
|
package/lib/Geojson.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const React = __importStar(require("react"));
|
|
30
|
+
const MapMarker_1 = __importDefault(require("./MapMarker"));
|
|
31
|
+
const MapPolyline_1 = __importDefault(require("./MapPolyline"));
|
|
32
|
+
const MapPolygon_1 = __importDefault(require("./MapPolygon"));
|
|
33
|
+
const Geojson = (props) => {
|
|
34
|
+
const { geojson, strokeColor, fillColor, strokeWidth, color, title, image, zIndex, onPress, lineCap, lineJoin, tappable, miterLimit, lineDashPhase, lineDashPattern, markerComponent, } = props;
|
|
35
|
+
const pointOverlays = makePointOverlays(geojson.features);
|
|
36
|
+
const lineOverlays = makeLineOverlays(geojson.features);
|
|
37
|
+
const polygonOverlays = makePolygonOverlays(geojson.features);
|
|
38
|
+
return (<React.Fragment>
|
|
39
|
+
{pointOverlays.map((overlay, index) => {
|
|
40
|
+
const markerColor = getColor(color, overlay, 'marker-color');
|
|
41
|
+
return (<MapMarker_1.default key={index} coordinate={overlay.coordinates} image={image} title={title} pinColor={markerColor} zIndex={zIndex} onPress={() => onPress && onPress(overlay)}>
|
|
42
|
+
{markerComponent}
|
|
43
|
+
</MapMarker_1.default>);
|
|
44
|
+
})}
|
|
45
|
+
{lineOverlays.map((overlay, index) => {
|
|
46
|
+
const lineStrokeColor = getColor(strokeColor, overlay, 'stroke');
|
|
47
|
+
const lineStrokeWidth = getStrokeWidth(strokeWidth, overlay);
|
|
48
|
+
return (<MapPolyline_1.default key={index} coordinates={overlay.coordinates} strokeColor={lineStrokeColor} strokeWidth={lineStrokeWidth} lineDashPhase={lineDashPhase} lineDashPattern={lineDashPattern} lineCap={lineCap} lineJoin={lineJoin} miterLimit={miterLimit} zIndex={zIndex} tappable={tappable} onPress={() => onPress && onPress(overlay)}/>);
|
|
49
|
+
})}
|
|
50
|
+
{polygonOverlays.map((overlay, index) => {
|
|
51
|
+
const polygonFillColor = getColor(fillColor, overlay, 'fill');
|
|
52
|
+
const lineStrokeColor = getColor(strokeColor, overlay, 'stroke');
|
|
53
|
+
const lineStrokeWidth = getStrokeWidth(strokeWidth, overlay);
|
|
54
|
+
return (<MapPolygon_1.default key={index} coordinates={overlay.coordinates} holes={overlay.holes} strokeColor={lineStrokeColor} fillColor={polygonFillColor} strokeWidth={lineStrokeWidth} tappable={tappable} onPress={() => onPress && onPress(overlay)} zIndex={zIndex}/>);
|
|
55
|
+
})}
|
|
56
|
+
</React.Fragment>);
|
|
57
|
+
};
|
|
58
|
+
exports.default = Geojson;
|
|
59
|
+
const makePointOverlays = (features) => {
|
|
60
|
+
return features
|
|
61
|
+
.filter(isAnyPointFeature)
|
|
62
|
+
.map(feature => makeCoordinatesForAnyPoint(feature.geometry).map(coordinates => makeOverlayForAnyPoint(coordinates, feature)))
|
|
63
|
+
.reduce((prev, curr) => prev.concat(curr), [])
|
|
64
|
+
.map(overlay => ({ ...overlay, type: 'point' }));
|
|
65
|
+
};
|
|
66
|
+
const makeLineOverlays = (features) => {
|
|
67
|
+
return features
|
|
68
|
+
.filter(isAnyLineStringFeature)
|
|
69
|
+
.map(feature => makeCoordinatesForAnyLine(feature.geometry).map(coordinates => makeOverlayForAnyLine(coordinates, feature)))
|
|
70
|
+
.reduce((prev, curr) => prev.concat(curr), [])
|
|
71
|
+
.map(overlay => ({ ...overlay, type: 'polyline' }));
|
|
72
|
+
};
|
|
73
|
+
const makePolygonOverlays = (features) => {
|
|
74
|
+
const multipolygons = features
|
|
75
|
+
.filter(isMultiPolygonFeature)
|
|
76
|
+
.map(feature => makeCoordinatesForMultiPolygon(feature.geometry).map(coordinates => makeOverlayForAnyPolygon(coordinates, feature)))
|
|
77
|
+
.reduce((prev, curr) => prev.concat(curr), [])
|
|
78
|
+
.map(overlay => ({ ...overlay, type: 'polygon' }));
|
|
79
|
+
const polygons = features
|
|
80
|
+
.filter(isPolygonFeature)
|
|
81
|
+
.map(feature => makeOverlayForAnyPolygon(makeCoordinatesForPolygon(feature.geometry), feature))
|
|
82
|
+
.reduce((prev, curr) => prev.concat(curr), [])
|
|
83
|
+
.map(overlay => ({ ...overlay, type: 'polygon' }));
|
|
84
|
+
return polygons.concat(multipolygons);
|
|
85
|
+
};
|
|
86
|
+
const makeOverlayForAnyPoint = (coordinates, feature) => {
|
|
87
|
+
return { feature, coordinates };
|
|
88
|
+
};
|
|
89
|
+
const makeOverlayForAnyLine = (coordinates, feature) => {
|
|
90
|
+
return { feature, coordinates };
|
|
91
|
+
};
|
|
92
|
+
const makeOverlayForAnyPolygon = (coordinates, feature) => {
|
|
93
|
+
return {
|
|
94
|
+
feature,
|
|
95
|
+
coordinates: coordinates[0],
|
|
96
|
+
holes: coordinates.length > 1 ? coordinates.slice(1) : undefined,
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
const makePoint = (c) => ({
|
|
100
|
+
latitude: c[1],
|
|
101
|
+
longitude: c[0],
|
|
102
|
+
});
|
|
103
|
+
const makeLine = (l) => l.map(makePoint);
|
|
104
|
+
const makeCoordinatesForAnyPoint = (geometry) => {
|
|
105
|
+
if (geometry.type === 'Point') {
|
|
106
|
+
return [makePoint(geometry.coordinates)];
|
|
107
|
+
}
|
|
108
|
+
return geometry.coordinates.map(makePoint);
|
|
109
|
+
};
|
|
110
|
+
const makeCoordinatesForAnyLine = (geometry) => {
|
|
111
|
+
if (geometry.type === 'LineString') {
|
|
112
|
+
return [makeLine(geometry.coordinates)];
|
|
113
|
+
}
|
|
114
|
+
return geometry.coordinates.map(makeLine);
|
|
115
|
+
};
|
|
116
|
+
const makeCoordinatesForPolygon = (geometry) => {
|
|
117
|
+
return geometry.coordinates.map(makeLine);
|
|
118
|
+
};
|
|
119
|
+
const makeCoordinatesForMultiPolygon = (geometry) => {
|
|
120
|
+
return geometry.coordinates.map(p => p.map(makeLine));
|
|
121
|
+
};
|
|
122
|
+
const getRgbaFromHex = (hex, alpha = 1) => {
|
|
123
|
+
const matchArray = hex.match(/\w\w/g);
|
|
124
|
+
if (!matchArray || matchArray.length < 3) {
|
|
125
|
+
throw new Error('Invalid hex string');
|
|
126
|
+
}
|
|
127
|
+
const [r, g, b] = matchArray.map(x => {
|
|
128
|
+
const subColor = parseInt(x, 16);
|
|
129
|
+
if (Number.isNaN(subColor)) {
|
|
130
|
+
throw new Error('Invalid hex string');
|
|
131
|
+
}
|
|
132
|
+
return subColor;
|
|
133
|
+
});
|
|
134
|
+
return `rgba(${r},${g},${b},${alpha})`;
|
|
135
|
+
};
|
|
136
|
+
const getColor = (prop, overlay, colorType) => {
|
|
137
|
+
if (prop) {
|
|
138
|
+
return prop;
|
|
139
|
+
}
|
|
140
|
+
let color = overlay.feature.properties?.[colorType];
|
|
141
|
+
if (color) {
|
|
142
|
+
const opacityProperty = colorType + '-opacity';
|
|
143
|
+
const alpha = overlay.feature.properties?.[opacityProperty];
|
|
144
|
+
if (alpha && alpha !== '0' && color[0] === '#') {
|
|
145
|
+
color = getRgbaFromHex(color, alpha);
|
|
146
|
+
}
|
|
147
|
+
return color;
|
|
148
|
+
}
|
|
149
|
+
return undefined;
|
|
150
|
+
};
|
|
151
|
+
const getStrokeWidth = (prop, overlay) => {
|
|
152
|
+
if (prop) {
|
|
153
|
+
return prop;
|
|
154
|
+
}
|
|
155
|
+
return overlay.feature.properties?.['stroke-width'];
|
|
156
|
+
};
|
|
157
|
+
// GeoJSON.Feature type-guards
|
|
158
|
+
const isPointFeature = (feature) => feature.geometry.type === 'Point';
|
|
159
|
+
const isMultiPointFeature = (feature) => feature.geometry.type === 'MultiPoint';
|
|
160
|
+
const isAnyPointFeature = (feature) => isPointFeature(feature) || isMultiPointFeature(feature);
|
|
161
|
+
const isLineStringFeature = (feature) => feature.geometry.type === 'LineString';
|
|
162
|
+
const isMultiLineStringFeature = (feature) => feature.geometry.type === 'MultiLineString';
|
|
163
|
+
const isAnyLineStringFeature = (feature) => isLineStringFeature(feature) || isMultiLineStringFeature(feature);
|
|
164
|
+
const isPolygonFeature = (feature) => feature.geometry.type === 'Polygon';
|
|
165
|
+
const isMultiPolygonFeature = (feature) => feature.geometry.type === 'MultiPolygon';
|