@rnmapbox/maps 10.0.0-beta.74 → 10.0.0-beta.76
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 +3 -3
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/CameraStop.kt +61 -46
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImagesManager.kt +5 -5
- package/ios/RCTMGL-v10/RCMTGLImage.swift +2 -1
- package/ios/RCTMGL-v10/RCTMGLImages.swift +57 -17
- package/ios/RCTMGL-v10/RCTMGLMapView.swift +11 -1
- package/ios/RCTMGL-v10/RCTMGLUtils.swift +14 -5
- package/javascript/MGLModule.ts +54 -0
- package/javascript/Mapbox.ts +97 -0
- package/javascript/classes/index.d.ts +20 -1
- package/javascript/components/Annotation.tsx +141 -0
- package/javascript/components/Callout.d.ts +35 -0
- package/javascript/components/ImageSource.tsx +81 -0
- package/javascript/components/Images.tsx +58 -6
- package/javascript/components/{MapView.js → MapView.tsx} +456 -383
- package/javascript/components/MarkerView.tsx +3 -2
- package/javascript/components/NativeBridgeComponent.tsx +1 -1
- package/javascript/components/PointAnnotation.tsx +4 -3
- package/javascript/components/RasterDemSource.tsx +105 -0
- package/javascript/components/RasterSource.tsx +124 -0
- package/javascript/components/ShapeSource.tsx +1 -1
- package/javascript/components/{Style.js → Style.tsx} +117 -35
- package/javascript/components/Terrain.tsx +8 -7
- package/javascript/components/{UserLocation.js → UserLocation.tsx} +105 -94
- package/javascript/components/VectorSource.tsx +1 -1
- package/javascript/index.ts +4 -0
- package/javascript/modules/offline/{OfflineCreatePackOptions.js → OfflineCreatePackOptions.ts} +21 -6
- package/javascript/modules/offline/{OfflinePack.js → OfflinePack.ts} +19 -4
- package/javascript/modules/offline/{offlineManager.js → offlineManager.ts} +81 -21
- package/javascript/modules/snapshot/{SnapshotOptions.js → SnapshotOptions.ts} +27 -3
- package/javascript/modules/snapshot/{snapshotManager.js → snapshotManager.ts} +2 -1
- package/javascript/types/Position.ts +1 -0
- package/javascript/utils/Logger.ts +1 -1
- package/javascript/utils/geoUtils.ts +56 -0
- package/javascript/utils/{index.js → index.ts} +41 -19
- package/lib/commonjs/MGLModule.js +37 -0
- package/lib/commonjs/MGLModule.js.map +1 -0
- package/lib/commonjs/Mapbox.js +372 -0
- package/lib/commonjs/Mapbox.js.map +1 -0
- package/lib/commonjs/classes/index.d.js +2 -0
- package/lib/commonjs/classes/index.d.js.map +1 -1
- package/lib/commonjs/components/{annotations/Annotation.js → Annotation.js} +26 -27
- package/lib/commonjs/components/Annotation.js.map +1 -0
- package/lib/commonjs/components/Callout.d.js +9 -0
- package/lib/commonjs/components/Callout.d.js.map +1 -0
- package/lib/commonjs/components/ImageSource.js +8 -25
- package/lib/commonjs/components/ImageSource.js.map +1 -1
- package/lib/commonjs/components/Images.js +17 -1
- package/lib/commonjs/components/Images.js.map +1 -1
- package/lib/commonjs/components/MapView.js +30 -289
- package/lib/commonjs/components/MapView.js.map +1 -1
- package/lib/commonjs/components/MarkerView.js.map +1 -1
- package/lib/commonjs/components/NativeBridgeComponent.js.map +1 -1
- package/lib/commonjs/components/PointAnnotation.js.map +1 -1
- package/lib/commonjs/components/RasterDemSource.js +3 -37
- package/lib/commonjs/components/RasterDemSource.js.map +1 -1
- package/lib/commonjs/components/RasterSource.js +2 -46
- package/lib/commonjs/components/RasterSource.js.map +1 -1
- package/lib/commonjs/components/Style.js +11 -15
- package/lib/commonjs/components/Style.js.map +1 -1
- package/lib/commonjs/components/Terrain.js.map +1 -1
- package/lib/commonjs/components/UserLocation.js +26 -77
- package/lib/commonjs/components/UserLocation.js.map +1 -1
- package/lib/commonjs/index.js +16 -339
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/modules/offline/OfflineCreatePackOptions.js +2 -4
- package/lib/commonjs/modules/offline/OfflineCreatePackOptions.js.map +1 -1
- package/lib/commonjs/modules/offline/OfflinePack.js.map +1 -1
- package/lib/commonjs/modules/offline/offlineManager.js +7 -2
- package/lib/commonjs/modules/offline/offlineManager.js.map +1 -1
- package/lib/commonjs/modules/snapshot/SnapshotOptions.js.map +1 -1
- package/lib/commonjs/modules/snapshot/snapshotManager.js.map +1 -1
- package/lib/commonjs/types/Position.js +2 -0
- package/lib/commonjs/{utils/index.d.js.map → types/Position.js.map} +1 -1
- package/lib/commonjs/utils/animated/Animated.js.map +1 -1
- package/lib/commonjs/utils/geoUtils.js +12 -38
- package/lib/commonjs/utils/geoUtils.js.map +1 -1
- package/lib/commonjs/utils/index.js +3 -6
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/module/MGLModule.js +19 -0
- package/lib/module/MGLModule.js.map +1 -0
- package/lib/module/Mapbox.js +59 -0
- package/lib/module/Mapbox.js.map +1 -0
- package/lib/module/classes/index.d.js +2 -0
- package/lib/module/classes/index.d.js.map +1 -1
- package/lib/module/components/{annotations/Annotation.js → Annotation.js} +26 -27
- package/lib/module/components/Annotation.js.map +1 -0
- package/lib/module/components/Callout.d.js +2 -0
- package/lib/module/components/Callout.d.js.map +1 -0
- package/lib/module/components/ImageSource.js +8 -25
- package/lib/module/components/ImageSource.js.map +1 -1
- package/lib/module/components/Images.js +17 -1
- package/lib/module/components/Images.js.map +1 -1
- package/lib/module/components/MapView.js +31 -290
- package/lib/module/components/MapView.js.map +1 -1
- package/lib/module/components/MarkerView.js.map +1 -1
- package/lib/module/components/NativeBridgeComponent.js.map +1 -1
- package/lib/module/components/PointAnnotation.js.map +1 -1
- package/lib/module/components/RasterDemSource.js +4 -38
- package/lib/module/components/RasterDemSource.js.map +1 -1
- package/lib/module/components/RasterSource.js +3 -47
- package/lib/module/components/RasterSource.js.map +1 -1
- package/lib/module/components/Style.js +11 -15
- package/lib/module/components/Style.js.map +1 -1
- package/lib/module/components/Terrain.js.map +1 -1
- package/lib/module/components/UserLocation.js +25 -76
- package/lib/module/components/UserLocation.js.map +1 -1
- package/lib/module/index.js +3 -108
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/offline/OfflineCreatePackOptions.js +2 -4
- package/lib/module/modules/offline/OfflineCreatePackOptions.js.map +1 -1
- package/lib/module/modules/offline/OfflinePack.js.map +1 -1
- package/lib/module/modules/offline/offlineManager.js +1 -1
- package/lib/module/modules/offline/offlineManager.js.map +1 -1
- package/lib/module/modules/snapshot/SnapshotOptions.js.map +1 -1
- package/lib/module/modules/snapshot/snapshotManager.js.map +1 -1
- package/lib/module/types/Position.js +2 -0
- package/lib/module/{utils/index.d.js.map → types/Position.js.map} +1 -1
- package/lib/module/utils/animated/Animated.js.map +1 -1
- package/lib/module/utils/geoUtils.js +5 -32
- package/lib/module/utils/geoUtils.js.map +1 -1
- package/lib/module/utils/index.js +3 -5
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/MGLModule.d.ts +22 -0
- package/lib/typescript/MGLModule.d.ts.map +1 -0
- package/lib/typescript/Mapbox.d.ts +54 -0
- package/lib/typescript/Mapbox.d.ts.map +1 -0
- package/lib/typescript/components/Annotation.d.ts +34 -0
- package/lib/typescript/components/Annotation.d.ts.map +1 -0
- package/lib/typescript/components/ImageSource.d.ts +32 -0
- package/lib/typescript/components/ImageSource.d.ts.map +1 -0
- package/lib/typescript/components/Images.d.ts +24 -2
- package/lib/typescript/components/Images.d.ts.map +1 -1
- package/lib/typescript/components/MapView.d.ts +469 -0
- package/lib/typescript/components/MapView.d.ts.map +1 -0
- package/lib/typescript/components/MarkerView.d.ts +3 -2
- package/lib/typescript/components/MarkerView.d.ts.map +1 -1
- package/lib/typescript/components/NativeBridgeComponent.d.ts +1 -1
- package/lib/typescript/components/NativeBridgeComponent.d.ts.map +1 -1
- package/lib/typescript/components/PointAnnotation.d.ts +10 -4
- package/lib/typescript/components/PointAnnotation.d.ts.map +1 -1
- package/lib/typescript/components/RasterDemSource.d.ts +46 -0
- package/lib/typescript/components/RasterDemSource.d.ts.map +1 -0
- package/lib/typescript/components/RasterSource.d.ts +59 -0
- package/lib/typescript/components/RasterSource.d.ts.map +1 -0
- package/lib/typescript/components/ShapeSource.d.ts +2 -2
- package/lib/typescript/components/ShapeSource.d.ts.map +1 -1
- package/lib/typescript/components/Style.d.ts +74 -0
- package/lib/typescript/components/Style.d.ts.map +1 -0
- package/lib/typescript/components/Terrain.d.ts +2 -2
- package/lib/typescript/components/Terrain.d.ts.map +1 -1
- package/lib/typescript/components/UserLocation.d.ts +102 -0
- package/lib/typescript/components/UserLocation.d.ts.map +1 -0
- package/lib/typescript/components/VectorSource.d.ts +2 -2
- package/lib/typescript/components/VectorSource.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +4 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/modules/offline/OfflineCreatePackOptions.d.ts +22 -0
- package/lib/typescript/modules/offline/OfflineCreatePackOptions.d.ts.map +1 -0
- package/lib/typescript/modules/offline/OfflinePack.d.ts +24 -0
- package/lib/typescript/modules/offline/OfflinePack.d.ts.map +1 -0
- package/lib/typescript/modules/offline/offlineManager.d.ts +220 -0
- package/lib/typescript/modules/offline/offlineManager.d.ts.map +1 -0
- package/lib/typescript/modules/snapshot/SnapshotOptions.d.ts +41 -0
- package/lib/typescript/modules/snapshot/SnapshotOptions.d.ts.map +1 -0
- package/lib/typescript/modules/snapshot/snapshotManager.d.ts +52 -0
- package/lib/typescript/modules/snapshot/snapshotManager.d.ts.map +1 -0
- package/lib/typescript/types/Position.d.ts +2 -0
- package/lib/typescript/types/Position.d.ts.map +1 -0
- package/lib/typescript/utils/Logger.d.ts +1 -1
- package/lib/typescript/utils/Logger.d.ts.map +1 -1
- package/lib/typescript/utils/animated/Animated.d.ts +23 -0
- package/lib/typescript/utils/animated/Animated.d.ts.map +1 -0
- package/lib/typescript/utils/geoUtils.d.ts +15 -0
- package/lib/typescript/utils/geoUtils.d.ts.map +1 -0
- package/lib/typescript/utils/index.d.ts +48 -0
- package/lib/typescript/utils/index.d.ts.map +1 -0
- package/package.json +4 -4
- package/index.d.ts +0 -745
- package/javascript/components/ImageSource.js +0 -82
- package/javascript/components/RasterDemSource.js +0 -106
- package/javascript/components/RasterSource.js +0 -124
- package/javascript/components/annotations/Annotation.js +0 -122
- package/javascript/index.js +0 -162
- package/javascript/utils/geoUtils.d.ts +0 -10
- package/javascript/utils/geoUtils.js +0 -73
- package/javascript/utils/index.d.ts +0 -27
- package/lib/commonjs/components/annotations/Annotation.js.map +0 -1
- package/lib/commonjs/utils/geoUtils.d.js +0 -2
- package/lib/commonjs/utils/geoUtils.d.js.map +0 -1
- package/lib/commonjs/utils/index.d.js +0 -2
- package/lib/module/components/annotations/Annotation.js.map +0 -1
- package/lib/module/utils/geoUtils.d.js +0 -2
- package/lib/module/utils/geoUtils.d.js.map +0 -1
- package/lib/module/utils/index.d.js +0 -2
- /package/javascript/utils/animated/{Animated.js → Animated.ts} +0 -0
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
1
|
+
import React, { ReactElement } from 'react';
|
|
3
2
|
|
|
4
3
|
import locationManager from '../modules/location/locationManager';
|
|
4
|
+
import { type Location } from '../modules/location/locationManager';
|
|
5
|
+
import { CircleLayerStyle } from '../Mapbox';
|
|
5
6
|
|
|
6
|
-
import Annotation from './
|
|
7
|
+
import Annotation from './Annotation';
|
|
7
8
|
import CircleLayer from './CircleLayer';
|
|
8
9
|
import HeadingIndicator from './HeadingIndicator';
|
|
9
10
|
import NativeUserLocation from './NativeUserLocation';
|
|
10
11
|
|
|
11
12
|
const mapboxBlue = 'rgba(51, 181, 229, 100)';
|
|
12
13
|
|
|
13
|
-
const layerStyles = {
|
|
14
|
+
const layerStyles: Record<'normal', Record<string, CircleLayerStyle>> = {
|
|
14
15
|
normal: {
|
|
15
|
-
|
|
16
|
+
pulse: {
|
|
16
17
|
circleRadius: 15,
|
|
17
18
|
circleColor: mapboxBlue,
|
|
18
19
|
circleOpacity: 0.2,
|
|
@@ -31,11 +32,14 @@ const layerStyles = {
|
|
|
31
32
|
},
|
|
32
33
|
};
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
const normalIcon = (
|
|
36
|
+
showsUserHeadingIndicator?: boolean,
|
|
37
|
+
heading?: number | null,
|
|
38
|
+
): ReactElement[] => [
|
|
35
39
|
<CircleLayer
|
|
36
|
-
key="
|
|
37
|
-
id="
|
|
38
|
-
style={layerStyles.normal.
|
|
40
|
+
key="mapboxUserLocationPulseCircle"
|
|
41
|
+
id="mapboxUserLocationPulseCircle"
|
|
42
|
+
style={layerStyles.normal.pulse}
|
|
39
43
|
/>,
|
|
40
44
|
<CircleLayer
|
|
41
45
|
key="mapboxUserLocationWhiteCircle"
|
|
@@ -43,93 +47,98 @@ export const normalIcon = (showsUserHeadingIndicator, heading) => [
|
|
|
43
47
|
style={layerStyles.normal.background}
|
|
44
48
|
/>,
|
|
45
49
|
<CircleLayer
|
|
46
|
-
key="
|
|
47
|
-
id="
|
|
50
|
+
key="mapboxUserLocationBlueCircle"
|
|
51
|
+
id="mapboxUserLocationBlueCircle"
|
|
48
52
|
aboveLayerID="mapboxUserLocationWhiteCircle"
|
|
49
53
|
style={layerStyles.normal.foreground}
|
|
50
54
|
/>,
|
|
51
|
-
...(showsUserHeadingIndicator && heading
|
|
55
|
+
...(showsUserHeadingIndicator && typeof heading === 'number'
|
|
52
56
|
? [HeadingIndicator({ heading })]
|
|
53
57
|
: []),
|
|
54
58
|
];
|
|
55
59
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
*/
|
|
115
|
-
children: PropTypes.any,
|
|
116
|
-
};
|
|
60
|
+
export enum UserLocationRenderMode {
|
|
61
|
+
Native = 'native',
|
|
62
|
+
Normal = 'normal',
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
type Props = {
|
|
66
|
+
/**
|
|
67
|
+
* native/android only render mode
|
|
68
|
+
*
|
|
69
|
+
* - normal: just a circle
|
|
70
|
+
* - compass: triangle with heading
|
|
71
|
+
* - gps: large arrow
|
|
72
|
+
*
|
|
73
|
+
* @platform android
|
|
74
|
+
*/
|
|
75
|
+
androidRenderMode?: 'normal' | 'compass' | 'gps';
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Whether location icon is animated between updates
|
|
79
|
+
*/
|
|
80
|
+
animated?: boolean;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Custom location icon of type mapbox-gl-native components
|
|
84
|
+
*/
|
|
85
|
+
children?: ReactElement;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Minimum amount of movement before GPS location is updated in meters
|
|
89
|
+
*/
|
|
90
|
+
minDisplacement?: number;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Callback that is triggered on location icon press
|
|
94
|
+
*/
|
|
95
|
+
onPress?: () => void;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Callback that is triggered on location update
|
|
99
|
+
*/
|
|
100
|
+
onUpdate?: (location: Location) => void;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Which render mode to use.
|
|
104
|
+
*/
|
|
105
|
+
renderMode?: UserLocationRenderMode;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Request the always location permission, and listen to the location even when the app is in background
|
|
109
|
+
*
|
|
110
|
+
* @platform ios
|
|
111
|
+
*/
|
|
112
|
+
requestsAlwaysUse?: boolean;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Show or hide small arrow which indicates direction the device is pointing relative to north.
|
|
116
|
+
*/
|
|
117
|
+
showsUserHeadingIndicator?: boolean;
|
|
117
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Whether location icon is visible
|
|
121
|
+
*/
|
|
122
|
+
visible?: boolean;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
type UserLocationState = {
|
|
126
|
+
shouldShowUserLocation: false;
|
|
127
|
+
coordinates: number[] | null;
|
|
128
|
+
heading: number | null;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
class UserLocation extends React.Component<Props, UserLocationState> {
|
|
118
132
|
static defaultProps = {
|
|
119
133
|
animated: true,
|
|
120
134
|
visible: true,
|
|
121
135
|
showsUserHeadingIndicator: false,
|
|
122
136
|
requestsAlwaysUse: false,
|
|
123
137
|
minDisplacement: 0,
|
|
124
|
-
renderMode:
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
static RenderMode = {
|
|
128
|
-
Native: 'native',
|
|
129
|
-
Normal: 'normal',
|
|
138
|
+
renderMode: UserLocationRenderMode.Normal,
|
|
130
139
|
};
|
|
131
140
|
|
|
132
|
-
constructor(props) {
|
|
141
|
+
constructor(props: Props) {
|
|
133
142
|
super(props);
|
|
134
143
|
|
|
135
144
|
this.state = {
|
|
@@ -143,34 +152,36 @@ class UserLocation extends React.Component {
|
|
|
143
152
|
|
|
144
153
|
// required as #setLocationManager attempts to setState
|
|
145
154
|
// after component unmount
|
|
146
|
-
_isMounted =
|
|
155
|
+
_isMounted?: boolean = undefined;
|
|
147
156
|
|
|
148
|
-
locationManagerRunning = false;
|
|
157
|
+
locationManagerRunning?: boolean = false;
|
|
149
158
|
|
|
150
159
|
async componentDidMount() {
|
|
151
160
|
this._isMounted = true;
|
|
152
161
|
|
|
153
|
-
locationManager.setMinDisplacement(this.props.minDisplacement);
|
|
162
|
+
locationManager.setMinDisplacement(this.props.minDisplacement || 0);
|
|
154
163
|
|
|
155
164
|
await this.setLocationManager({
|
|
156
165
|
running: this.needsLocationManagerRunning(),
|
|
157
166
|
});
|
|
158
167
|
|
|
159
|
-
if (this.renderMode ===
|
|
168
|
+
if (this.props.renderMode === UserLocationRenderMode.Native) {
|
|
160
169
|
return;
|
|
161
170
|
}
|
|
162
171
|
}
|
|
163
172
|
|
|
164
|
-
async componentDidUpdate(prevProps) {
|
|
173
|
+
async componentDidUpdate(prevProps: Props) {
|
|
165
174
|
await this.setLocationManager({
|
|
166
175
|
running: this.needsLocationManagerRunning(),
|
|
167
176
|
});
|
|
168
177
|
|
|
169
178
|
if (this.props.minDisplacement !== prevProps.minDisplacement) {
|
|
170
|
-
locationManager.setMinDisplacement(this.props.minDisplacement);
|
|
179
|
+
locationManager.setMinDisplacement(this.props.minDisplacement || 0);
|
|
171
180
|
}
|
|
172
181
|
if (this.props.requestsAlwaysUse !== prevProps.requestsAlwaysUse) {
|
|
173
|
-
locationManager.setRequestsAlwaysUse(
|
|
182
|
+
locationManager.setRequestsAlwaysUse(
|
|
183
|
+
this.props.requestsAlwaysUse || false,
|
|
184
|
+
);
|
|
174
185
|
}
|
|
175
186
|
}
|
|
176
187
|
|
|
@@ -189,7 +200,7 @@ class UserLocation extends React.Component {
|
|
|
189
200
|
* @param {Object} running - Object with key `running` and `boolean` value
|
|
190
201
|
* @return {Promise<void>}
|
|
191
202
|
*/
|
|
192
|
-
async setLocationManager({ running }) {
|
|
203
|
+
async setLocationManager({ running }: { running?: boolean }) {
|
|
193
204
|
if (this.locationManagerRunning !== running) {
|
|
194
205
|
this.locationManagerRunning = running;
|
|
195
206
|
if (running) {
|
|
@@ -211,12 +222,12 @@ class UserLocation extends React.Component {
|
|
|
211
222
|
needsLocationManagerRunning() {
|
|
212
223
|
return (
|
|
213
224
|
!!this.props.onUpdate ||
|
|
214
|
-
(this.props.renderMode ===
|
|
225
|
+
(this.props.renderMode === UserLocationRenderMode.Normal &&
|
|
215
226
|
this.props.visible)
|
|
216
227
|
);
|
|
217
228
|
}
|
|
218
229
|
|
|
219
|
-
_onLocationUpdate(location) {
|
|
230
|
+
_onLocationUpdate(location: Location | null) {
|
|
220
231
|
if (!this._isMounted || !location) {
|
|
221
232
|
return;
|
|
222
233
|
}
|
|
@@ -231,7 +242,7 @@ class UserLocation extends React.Component {
|
|
|
231
242
|
|
|
232
243
|
this.setState({
|
|
233
244
|
coordinates,
|
|
234
|
-
heading,
|
|
245
|
+
heading: heading ?? null,
|
|
235
246
|
});
|
|
236
247
|
|
|
237
248
|
if (this.props.onUpdate) {
|
|
@@ -242,7 +253,7 @@ class UserLocation extends React.Component {
|
|
|
242
253
|
_renderNative() {
|
|
243
254
|
const { androidRenderMode, showsUserHeadingIndicator } = this.props;
|
|
244
255
|
|
|
245
|
-
|
|
256
|
+
const props = {
|
|
246
257
|
androidRenderMode,
|
|
247
258
|
iosShowsUserHeadingIndicator: showsUserHeadingIndicator,
|
|
248
259
|
};
|
|
@@ -258,7 +269,7 @@ class UserLocation extends React.Component {
|
|
|
258
269
|
return null;
|
|
259
270
|
}
|
|
260
271
|
|
|
261
|
-
if (this.props.renderMode ===
|
|
272
|
+
if (this.props.renderMode === UserLocationRenderMode.Native) {
|
|
262
273
|
return this._renderNative();
|
|
263
274
|
}
|
|
264
275
|
|
|
@@ -268,8 +279,8 @@ class UserLocation extends React.Component {
|
|
|
268
279
|
|
|
269
280
|
return (
|
|
270
281
|
<Annotation
|
|
271
|
-
animated={animated}
|
|
272
282
|
id="mapboxUserLocation"
|
|
283
|
+
animated={animated}
|
|
273
284
|
onPress={onPress}
|
|
274
285
|
coordinates={coordinates}
|
|
275
286
|
style={{
|
package/javascript/modules/offline/{OfflineCreatePackOptions.js → OfflineCreatePackOptions.ts}
RENAMED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
import { makeLatLngBounds } from '../../utils/geoUtils';
|
|
2
2
|
import { toJSONString } from '../../utils';
|
|
3
3
|
|
|
4
|
+
export type OfflineCreatePackOptionsArgs = {
|
|
5
|
+
name: string;
|
|
6
|
+
styleURL: string;
|
|
7
|
+
bounds: [GeoJSON.Position, GeoJSON.Position];
|
|
8
|
+
minZoom?: number;
|
|
9
|
+
maxZoom?: number;
|
|
10
|
+
metadata?: Record<string, unknown>;
|
|
11
|
+
};
|
|
12
|
+
|
|
4
13
|
class OfflineCreatePackOptions {
|
|
5
|
-
|
|
14
|
+
public readonly name: string;
|
|
15
|
+
public readonly styleURL: string;
|
|
16
|
+
public readonly bounds: string;
|
|
17
|
+
public readonly minZoom: number | undefined;
|
|
18
|
+
public readonly maxZoom: number | undefined;
|
|
19
|
+
public readonly metadata: string | undefined;
|
|
20
|
+
|
|
21
|
+
constructor(options: OfflineCreatePackOptionsArgs) {
|
|
6
22
|
this._assert(options);
|
|
7
23
|
|
|
8
24
|
this.name = options.name;
|
|
@@ -13,7 +29,7 @@ class OfflineCreatePackOptions {
|
|
|
13
29
|
this.metadata = this._makeMetadata(options.metadata);
|
|
14
30
|
}
|
|
15
31
|
|
|
16
|
-
_assert(options) {
|
|
32
|
+
_assert(options: OfflineCreatePackOptionsArgs) {
|
|
17
33
|
if (!options.styleURL) {
|
|
18
34
|
throw new Error(
|
|
19
35
|
'Style URL must be provided for creating an offline pack',
|
|
@@ -29,13 +45,12 @@ class OfflineCreatePackOptions {
|
|
|
29
45
|
}
|
|
30
46
|
}
|
|
31
47
|
|
|
32
|
-
_makeLatLngBounds(bounds) {
|
|
33
|
-
const ne = bounds
|
|
34
|
-
const sw = bounds[1];
|
|
48
|
+
_makeLatLngBounds(bounds: [GeoJSON.Position, GeoJSON.Position]): string {
|
|
49
|
+
const [ne, sw] = bounds;
|
|
35
50
|
return toJSONString(makeLatLngBounds(ne, sw));
|
|
36
51
|
}
|
|
37
52
|
|
|
38
|
-
_makeMetadata(metadata) {
|
|
53
|
+
_makeMetadata(metadata: Record<string, unknown> | undefined) {
|
|
39
54
|
return JSON.stringify({
|
|
40
55
|
...metadata,
|
|
41
56
|
name: this.name,
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import { NativeModules } from 'react-native';
|
|
2
2
|
|
|
3
|
+
import OfflineCreatePackOptions from './OfflineCreatePackOptions';
|
|
4
|
+
|
|
3
5
|
const MapboxGLOfflineManager = NativeModules.MGLOfflineModule;
|
|
4
6
|
|
|
7
|
+
type OfflinePackStatus = {
|
|
8
|
+
name: string;
|
|
9
|
+
state: number;
|
|
10
|
+
percentage: number;
|
|
11
|
+
completedResourceCount: number;
|
|
12
|
+
completedResourceSize: number;
|
|
13
|
+
completedTileSize: number;
|
|
14
|
+
completedTileCount: number;
|
|
15
|
+
requiredResourceCount: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
5
18
|
class OfflinePack {
|
|
6
|
-
|
|
19
|
+
private pack: OfflineCreatePackOptions;
|
|
20
|
+
private _metadata: any;
|
|
21
|
+
constructor(pack: OfflineCreatePackOptions) {
|
|
7
22
|
this.pack = pack;
|
|
8
23
|
this._metadata = null;
|
|
9
24
|
}
|
|
@@ -24,15 +39,15 @@ class OfflinePack {
|
|
|
24
39
|
return this._metadata;
|
|
25
40
|
}
|
|
26
41
|
|
|
27
|
-
status() {
|
|
42
|
+
status(): Promise<OfflinePackStatus> {
|
|
28
43
|
return MapboxGLOfflineManager.getPackStatus(this.name);
|
|
29
44
|
}
|
|
30
45
|
|
|
31
|
-
resume() {
|
|
46
|
+
resume(): Promise<void> {
|
|
32
47
|
return MapboxGLOfflineManager.resumePackDownload(this.name);
|
|
33
48
|
}
|
|
34
49
|
|
|
35
|
-
pause() {
|
|
50
|
+
pause(): Promise<void> {
|
|
36
51
|
return MapboxGLOfflineManager.pausePackDownload(this.name);
|
|
37
52
|
}
|
|
38
53
|
}
|
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
NativeModules,
|
|
3
|
+
NativeEventEmitter,
|
|
4
|
+
EventSubscription,
|
|
5
|
+
} from 'react-native';
|
|
2
6
|
|
|
3
7
|
import { isUndefined, isFunction, isAndroid } from '../../utils';
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
export {
|
|
10
|
+
default as OfflineCreatePackOptions,
|
|
11
|
+
type OfflineCreatePackOptionsArgs,
|
|
12
|
+
} from './OfflineCreatePackOptions';
|
|
13
|
+
import OfflineCreatePackOptions, {
|
|
14
|
+
type OfflineCreatePackOptionsArgs,
|
|
15
|
+
} from './OfflineCreatePackOptions';
|
|
6
16
|
import OfflinePack from './OfflinePack';
|
|
7
17
|
|
|
8
18
|
const MapboxGL = NativeModules.MGLModule;
|
|
@@ -11,12 +21,49 @@ export const OfflineModuleEventEmitter = new NativeEventEmitter(
|
|
|
11
21
|
MapboxGLOfflineManager,
|
|
12
22
|
);
|
|
13
23
|
|
|
24
|
+
export type OfflineProgressStatus = {
|
|
25
|
+
name: string;
|
|
26
|
+
state: number;
|
|
27
|
+
percentage: number;
|
|
28
|
+
completedResourceSize: number;
|
|
29
|
+
completedTileCount: number;
|
|
30
|
+
completedResourceCount: number;
|
|
31
|
+
requiredResourceCount: number;
|
|
32
|
+
completedTileSize: number;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type OfflinePackError = {
|
|
36
|
+
name: string;
|
|
37
|
+
message: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type ErrorEvent = {
|
|
41
|
+
payload: OfflinePackError;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type ProgressEvent = {
|
|
45
|
+
payload: OfflineProgressStatus;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
type ProgressListener = (
|
|
49
|
+
pack: OfflinePack,
|
|
50
|
+
status: OfflineProgressStatus,
|
|
51
|
+
) => void;
|
|
52
|
+
type ErrorListener = (pack: OfflinePack, err: OfflinePackError) => void;
|
|
53
|
+
|
|
14
54
|
/**
|
|
15
55
|
* OfflineManager implements a singleton (shared object) that manages offline packs.
|
|
16
56
|
* All of this class’s instance methods are asynchronous, reflecting the fact that offline resources are stored in a database.
|
|
17
57
|
* The shared object maintains a canonical collection of offline packs.
|
|
18
58
|
*/
|
|
19
59
|
class OfflineManager {
|
|
60
|
+
private _hasInitialized: boolean;
|
|
61
|
+
private _offlinePacks: Record<string, OfflinePack>;
|
|
62
|
+
private _progressListeners: Record<string, ProgressListener>;
|
|
63
|
+
private _errorListeners: Record<string, ErrorListener>;
|
|
64
|
+
public subscriptionProgress: EventSubscription | null;
|
|
65
|
+
public subscriptionError: EventSubscription | null;
|
|
66
|
+
|
|
20
67
|
constructor() {
|
|
21
68
|
this._hasInitialized = false;
|
|
22
69
|
this._offlinePacks = {};
|
|
@@ -52,7 +99,11 @@ class OfflineManager {
|
|
|
52
99
|
* @param {Callback=} errorListener Callback that listens for status events while downloading the offline resource.
|
|
53
100
|
* @return {void}
|
|
54
101
|
*/
|
|
55
|
-
async createPack(
|
|
102
|
+
async createPack(
|
|
103
|
+
options: OfflineCreatePackOptionsArgs,
|
|
104
|
+
progressListener: ProgressListener,
|
|
105
|
+
errorListener?: ErrorListener,
|
|
106
|
+
): Promise<void> {
|
|
56
107
|
await this._initialize();
|
|
57
108
|
|
|
58
109
|
const packOptions = new OfflineCreatePackOptions(options);
|
|
@@ -81,7 +132,7 @@ class OfflineManager {
|
|
|
81
132
|
* @param {String} name Name of the offline pack.
|
|
82
133
|
* @return {void}
|
|
83
134
|
*/
|
|
84
|
-
async invalidatePack(name) {
|
|
135
|
+
async invalidatePack(name: string): Promise<void> {
|
|
85
136
|
if (!name) {
|
|
86
137
|
return;
|
|
87
138
|
}
|
|
@@ -103,7 +154,7 @@ class OfflineManager {
|
|
|
103
154
|
* @param {String} name Name of the offline pack.
|
|
104
155
|
* @return {void}
|
|
105
156
|
*/
|
|
106
|
-
async deletePack(name) {
|
|
157
|
+
async deletePack(name: string): Promise<void> {
|
|
107
158
|
if (!name) {
|
|
108
159
|
return;
|
|
109
160
|
}
|
|
@@ -128,7 +179,7 @@ class OfflineManager {
|
|
|
128
179
|
*
|
|
129
180
|
* @return {void}
|
|
130
181
|
*/
|
|
131
|
-
async invalidateAmbientCache() {
|
|
182
|
+
async invalidateAmbientCache(): Promise<void> {
|
|
132
183
|
await this._initialize();
|
|
133
184
|
await MapboxGLOfflineManager.invalidateAmbientCache();
|
|
134
185
|
}
|
|
@@ -142,7 +193,7 @@ class OfflineManager {
|
|
|
142
193
|
*
|
|
143
194
|
* @return {void}
|
|
144
195
|
*/
|
|
145
|
-
async clearAmbientCache() {
|
|
196
|
+
async clearAmbientCache(): Promise<void> {
|
|
146
197
|
await this._initialize();
|
|
147
198
|
await MapboxGLOfflineManager.clearAmbientCache();
|
|
148
199
|
}
|
|
@@ -155,7 +206,7 @@ class OfflineManager {
|
|
|
155
206
|
*
|
|
156
207
|
* @return {void}
|
|
157
208
|
*/
|
|
158
|
-
async migrateOfflineCache() {
|
|
209
|
+
async migrateOfflineCache(): Promise<void> {
|
|
159
210
|
await this._initialize();
|
|
160
211
|
await MapboxGLOfflineManager.migrateOfflineCache();
|
|
161
212
|
}
|
|
@@ -170,7 +221,7 @@ class OfflineManager {
|
|
|
170
221
|
* @param {Number} size Size of ambient cache.
|
|
171
222
|
* @return {void}
|
|
172
223
|
*/
|
|
173
|
-
async setMaximumAmbientCacheSize(size) {
|
|
224
|
+
async setMaximumAmbientCacheSize(size: number): Promise<void> {
|
|
174
225
|
await this._initialize();
|
|
175
226
|
await MapboxGLOfflineManager.setMaximumAmbientCacheSize(size);
|
|
176
227
|
}
|
|
@@ -183,7 +234,7 @@ class OfflineManager {
|
|
|
183
234
|
*
|
|
184
235
|
* @return {void}
|
|
185
236
|
*/
|
|
186
|
-
async resetDatabase() {
|
|
237
|
+
async resetDatabase(): Promise<void> {
|
|
187
238
|
await this._initialize();
|
|
188
239
|
await MapboxGLOfflineManager.resetDatabase();
|
|
189
240
|
}
|
|
@@ -196,7 +247,7 @@ class OfflineManager {
|
|
|
196
247
|
*
|
|
197
248
|
* @return {Array<OfflinePack>}
|
|
198
249
|
*/
|
|
199
|
-
async getPacks() {
|
|
250
|
+
async getPacks(): Promise<OfflinePack[]> {
|
|
200
251
|
await this._initialize();
|
|
201
252
|
return Object.keys(this._offlinePacks).map(
|
|
202
253
|
(name) => this._offlinePacks[name],
|
|
@@ -212,7 +263,7 @@ class OfflineManager {
|
|
|
212
263
|
* @param {String} name Name of the offline pack.
|
|
213
264
|
* @return {OfflinePack}
|
|
214
265
|
*/
|
|
215
|
-
async getPack(name) {
|
|
266
|
+
async getPack(name: string): Promise<OfflinePack | undefined> {
|
|
216
267
|
await this._initialize();
|
|
217
268
|
return this._offlinePacks[name];
|
|
218
269
|
}
|
|
@@ -226,7 +277,7 @@ class OfflineManager {
|
|
|
226
277
|
* @param {String} path Path to offline tile db on file system.
|
|
227
278
|
* @return {void}
|
|
228
279
|
*/
|
|
229
|
-
async mergeOfflineRegions(path) {
|
|
280
|
+
async mergeOfflineRegions(path: string): Promise<void> {
|
|
230
281
|
await this._initialize();
|
|
231
282
|
return MapboxGLOfflineManager.mergeOfflineRegions(path);
|
|
232
283
|
}
|
|
@@ -241,7 +292,7 @@ class OfflineManager {
|
|
|
241
292
|
* @param {Number} limit Map tile limit count.
|
|
242
293
|
* @return {void}
|
|
243
294
|
*/
|
|
244
|
-
setTileCountLimit(limit) {
|
|
295
|
+
setTileCountLimit(limit: number): void {
|
|
245
296
|
MapboxGLOfflineManager.setTileCountLimit(limit);
|
|
246
297
|
}
|
|
247
298
|
|
|
@@ -255,7 +306,7 @@ class OfflineManager {
|
|
|
255
306
|
* @param {Number} throttleValue event throttle value in ms.
|
|
256
307
|
* @return {void}
|
|
257
308
|
*/
|
|
258
|
-
setProgressEventThrottle(throttleValue) {
|
|
309
|
+
setProgressEventThrottle(throttleValue: number): void {
|
|
259
310
|
MapboxGLOfflineManager.setProgressEventThrottle(throttleValue);
|
|
260
311
|
}
|
|
261
312
|
|
|
@@ -273,7 +324,11 @@ class OfflineManager {
|
|
|
273
324
|
* @param {Callback} errorListener Callback that listens for status events while downloading the offline resource.
|
|
274
325
|
* @return {void}
|
|
275
326
|
*/
|
|
276
|
-
async subscribe(
|
|
327
|
+
async subscribe(
|
|
328
|
+
packName: string,
|
|
329
|
+
progressListener: ProgressListener,
|
|
330
|
+
errorListener?: ErrorListener,
|
|
331
|
+
): Promise<void> {
|
|
277
332
|
const totalProgressListeners = Object.keys(this._progressListeners).length;
|
|
278
333
|
if (isFunction(progressListener)) {
|
|
279
334
|
if (totalProgressListeners === 0) {
|
|
@@ -318,7 +373,7 @@ class OfflineManager {
|
|
|
318
373
|
* @param {String} packName Name of the offline pack.
|
|
319
374
|
* @return {void}
|
|
320
375
|
*/
|
|
321
|
-
unsubscribe(packName) {
|
|
376
|
+
unsubscribe(packName: string): void {
|
|
322
377
|
delete this._progressListeners[packName];
|
|
323
378
|
delete this._errorListeners[packName];
|
|
324
379
|
|
|
@@ -337,7 +392,7 @@ class OfflineManager {
|
|
|
337
392
|
}
|
|
338
393
|
}
|
|
339
394
|
|
|
340
|
-
async _initialize() {
|
|
395
|
+
async _initialize(): Promise<boolean> {
|
|
341
396
|
if (this._hasInitialized) {
|
|
342
397
|
return true;
|
|
343
398
|
}
|
|
@@ -353,7 +408,7 @@ class OfflineManager {
|
|
|
353
408
|
return true;
|
|
354
409
|
}
|
|
355
410
|
|
|
356
|
-
_onProgress(e) {
|
|
411
|
+
_onProgress(e: ProgressEvent): void {
|
|
357
412
|
const { name, state } = e.payload;
|
|
358
413
|
|
|
359
414
|
if (!this._hasListeners(name, this._progressListeners)) {
|
|
@@ -369,7 +424,7 @@ class OfflineManager {
|
|
|
369
424
|
}
|
|
370
425
|
}
|
|
371
426
|
|
|
372
|
-
_onError(e) {
|
|
427
|
+
_onError(e: ErrorEvent): void {
|
|
373
428
|
const { name } = e.payload;
|
|
374
429
|
|
|
375
430
|
if (!this._hasListeners(name, this._errorListeners)) {
|
|
@@ -380,7 +435,12 @@ class OfflineManager {
|
|
|
380
435
|
this._errorListeners[name](pack, e.payload);
|
|
381
436
|
}
|
|
382
437
|
|
|
383
|
-
_hasListeners(
|
|
438
|
+
_hasListeners(
|
|
439
|
+
name: string,
|
|
440
|
+
listenerMap:
|
|
441
|
+
| Record<string, ProgressListener>
|
|
442
|
+
| Record<string, ErrorListener>,
|
|
443
|
+
): boolean {
|
|
384
444
|
return (
|
|
385
445
|
!isUndefined(this._offlinePacks[name]) && isFunction(listenerMap[name])
|
|
386
446
|
);
|