@maplibre/maplibre-react-native 9.1.0 → 10.0.0-alpha.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/.eslintrc.js +10 -2
- package/.husky/pre-commit +5 -0
- package/.yarn/plugins/@yarnpkg/plugin-typescript.cjs +9 -0
- package/.yarn/sdks/eslint/bin/eslint.js +20 -0
- package/.yarn/sdks/eslint/lib/api.js +20 -0
- package/.yarn/sdks/eslint/package.json +6 -0
- package/.yarn/sdks/integrations.yml +5 -0
- package/.yarn/sdks/prettier/index.js +20 -0
- package/.yarn/sdks/prettier/package.json +6 -0
- package/.yarn/sdks/typescript/bin/tsc +20 -0
- package/.yarn/sdks/typescript/bin/tsserver +20 -0
- package/.yarn/sdks/typescript/lib/tsc.js +20 -0
- package/.yarn/sdks/typescript/lib/tsserver.js +225 -0
- package/.yarn/sdks/typescript/lib/tsserverlibrary.js +225 -0
- package/.yarn/sdks/typescript/lib/typescript.js +20 -0
- package/.yarn/sdks/typescript/package.json +6 -0
- package/CHANGELOG.md +18 -0
- package/android/rctmgl/build.gradle +7 -7
- package/android/rctmgl/src/main/java/com/mapbox/rctmgl/location/LocationManager.java +2 -2
- package/android/rctmgl/src/main/java/com/mapbox/rctmgl/modules/RCTMGLOfflineModule.java +21 -26
- package/docs/Annotation.md +8 -9
- package/docs/BackgroundLayer.md +2 -10
- package/docs/Callout.md +5 -5
- package/docs/Camera.md +18 -47
- package/docs/CircleLayer.md +2 -10
- package/docs/FillExtrusionLayer.md +2 -10
- package/docs/FillLayer.md +2 -10
- package/docs/HeatmapLayer.md +2 -10
- package/docs/ImageSource.md +3 -2
- package/docs/Images.md +5 -3
- package/docs/Light.md +1 -1
- package/docs/LineLayer.md +2 -10
- package/docs/MapView.md +53 -37
- package/docs/MarkerView.md +4 -2
- package/docs/NativeUserLocation.md +2 -2
- package/docs/PointAnnotation.md +5 -8
- package/docs/RasterLayer.md +2 -10
- package/docs/RasterSource.md +3 -2
- package/docs/ShapeSource.md +12 -7
- package/docs/Style.md +1 -1
- package/docs/SymbolLayer.md +3 -10
- package/docs/UserLocation.md +8 -10
- package/docs/VectorSource.md +6 -5
- package/docs/coordinates.md +6 -0
- package/docs/docs.json +518 -1272
- package/docs/location.md +6 -0
- package/docs/snapshotManager.md +3 -3
- package/javascript/@types/assets.d.ts +4 -0
- package/javascript/MGLModule.ts +37 -0
- package/javascript/Maplibre.ts +65 -0
- package/javascript/components/AbstractLayer.tsx +107 -0
- package/javascript/components/AbstractSource.tsx +27 -0
- package/javascript/components/BackgroundLayer.tsx +43 -0
- package/javascript/components/{Callout.js → Callout.tsx} +67 -65
- package/javascript/components/{Camera.js → Camera.tsx} +266 -251
- package/javascript/components/CircleLayer.tsx +46 -0
- package/javascript/components/FillExtrusionLayer.tsx +47 -0
- package/javascript/components/FillLayer.tsx +41 -0
- package/javascript/components/{HeadingIndicator.js → HeadingIndicator.tsx} +8 -8
- package/javascript/components/HeatmapLayer.tsx +44 -0
- package/javascript/components/ImageSource.tsx +78 -0
- package/javascript/components/Images.tsx +134 -0
- package/javascript/components/Light.tsx +67 -0
- package/javascript/components/LineLayer.tsx +42 -0
- package/javascript/components/{MapView.js → MapView.tsx} +365 -354
- package/javascript/components/MarkerView.tsx +104 -0
- package/javascript/components/{NativeBridgeComponent.js → NativeBridgeComponent.tsx} +44 -13
- package/javascript/components/NativeUserLocation.tsx +33 -0
- package/javascript/components/PointAnnotation.tsx +221 -0
- package/javascript/components/RasterLayer.tsx +41 -0
- package/javascript/components/RasterSource.tsx +117 -0
- package/javascript/components/ShapeSource.tsx +383 -0
- package/javascript/components/{Style.js → Style.tsx} +129 -38
- package/javascript/components/SymbolLayer.tsx +72 -0
- package/javascript/components/{UserLocation.js → UserLocation.tsx} +111 -110
- package/javascript/components/VectorSource.tsx +207 -0
- package/javascript/components/annotations/Annotation.tsx +134 -0
- package/javascript/index.ts +4 -0
- package/javascript/modules/location/{locationManager.js → locationManager.ts} +71 -10
- package/javascript/modules/offline/{OfflineCreatePackOptions.js → OfflineCreatePackOptions.ts} +20 -4
- package/javascript/modules/offline/{OfflinePack.js → OfflinePack.ts} +23 -7
- package/javascript/modules/offline/{offlineManager.js → offlineManager.ts} +81 -24
- package/javascript/modules/snapshot/{SnapshotOptions.js → SnapshotOptions.ts} +43 -6
- package/javascript/modules/snapshot/{snapshotManager.js → snapshotManager.ts} +5 -5
- package/javascript/requestAndroidLocationPermissions.ts +29 -0
- package/javascript/types/BaseProps.ts +5 -0
- package/javascript/types/OnPressEvent.ts +13 -0
- package/javascript/types/index.ts +7 -0
- package/javascript/utils/BridgeValue.ts +90 -0
- package/javascript/utils/{Logger.js → Logger.ts} +37 -18
- package/javascript/utils/MaplibreStyles.d.ts +1486 -0
- package/javascript/utils/StyleValue.ts +49 -0
- package/javascript/utils/animated/AbstractAnimatedCoordinates.ts +134 -0
- package/javascript/utils/animated/AnimatedCoordinatesArray.ts +112 -0
- package/javascript/utils/animated/{AnimatedExtractCoordinateFromArray.js → AnimatedExtractCoordinateFromArray.ts} +5 -5
- package/javascript/utils/animated/{AnimatedPoint.js → AnimatedPoint.ts} +20 -12
- package/javascript/utils/animated/{AnimatedRouteCoordinatesArray.js → AnimatedRouteCoordinatesArray.ts} +39 -14
- package/javascript/utils/animated/{AnimatedShape.js → AnimatedShape.ts} +31 -10
- package/javascript/utils/{deprecation.js → deprecation.ts} +9 -6
- package/javascript/utils/filterUtils.ts +9 -0
- package/javascript/utils/geoUtils.ts +79 -0
- package/javascript/utils/{index.js → index.ts} +44 -24
- package/javascript/utils/styleMap.ts +264 -0
- package/package.json +35 -27
- package/plugin/build/withMapLibre.js +18 -3
- package/scripts/autogenHelpers/globals.js +1 -1
- package/scripts/autogenerate.js +14 -6
- package/scripts/download-style-spec.sh +1 -1
- package/scripts/templates/MaplibreStyles.ts.ejs +99 -0
- package/scripts/templates/index.d.ts.ejs +71 -42
- package/scripts/templates/{styleMap.js.ejs → styleMap.ts.ejs} +3 -33
- package/setup-jest.js +1 -10
- package/tsconfig.json +20 -61
- package/index.d.ts +0 -955
- package/javascript/components/AbstractLayer.js +0 -75
- package/javascript/components/AbstractSource.js +0 -15
- package/javascript/components/BackgroundLayer.js +0 -97
- package/javascript/components/CircleLayer.js +0 -101
- package/javascript/components/FillExtrusionLayer.js +0 -98
- package/javascript/components/FillLayer.js +0 -94
- package/javascript/components/HeatmapLayer.js +0 -99
- package/javascript/components/ImageSource.js +0 -82
- package/javascript/components/Images.js +0 -119
- package/javascript/components/Light.js +0 -47
- package/javascript/components/LineLayer.js +0 -94
- package/javascript/components/MarkerView.js +0 -87
- package/javascript/components/NativeUserLocation.js +0 -41
- package/javascript/components/PointAnnotation.js +0 -216
- package/javascript/components/RasterLayer.js +0 -95
- package/javascript/components/RasterSource.js +0 -124
- package/javascript/components/ShapeSource.js +0 -372
- package/javascript/components/SymbolLayer.js +0 -120
- package/javascript/components/VectorSource.js +0 -200
- package/javascript/components/annotations/Annotation.js +0 -122
- package/javascript/index.js +0 -149
- package/javascript/utils/BridgeValue.js +0 -81
- package/javascript/utils/animated/AnimatedCoordinatesArray.js +0 -191
- package/javascript/utils/filterUtils.js +0 -7
- package/javascript/utils/geoUtils.js +0 -73
- package/javascript/utils/styleMap.js +0 -1932
- /package/javascript/utils/animated/{Animated.js → Animated.ts} +0 -0
|
@@ -1,210 +1,222 @@
|
|
|
1
|
-
import {toJSONString,
|
|
1
|
+
import {toJSONString, existenceChange} from '../utils';
|
|
2
2
|
import * as geoUtils from '../utils/geoUtils';
|
|
3
|
+
import {MaplibreGLEvent} from '../types';
|
|
3
4
|
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import {
|
|
6
|
+
NativeMethods,
|
|
7
|
+
NativeModules,
|
|
8
|
+
requireNativeComponent,
|
|
9
|
+
ViewProps,
|
|
10
|
+
} from 'react-native';
|
|
11
|
+
import React, {Component, MutableRefObject, ReactElement} from 'react';
|
|
7
12
|
|
|
8
13
|
const MapLibreGL = NativeModules.MGLModule;
|
|
9
14
|
|
|
10
15
|
export const NATIVE_MODULE_NAME = 'RCTMGLCamera';
|
|
11
16
|
|
|
12
|
-
|
|
17
|
+
export enum UserTrackingMode {
|
|
18
|
+
Follow = 'normal',
|
|
19
|
+
FollowWithHeading = 'compass',
|
|
20
|
+
FollowWithCourse = 'course',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type UserTrackingModeChangeCallback = (
|
|
24
|
+
event: MaplibreGLEvent<
|
|
25
|
+
'usertrackingmodechange',
|
|
26
|
+
{
|
|
27
|
+
followUserLocation: boolean;
|
|
28
|
+
followUserMode: UserTrackingMode | null;
|
|
29
|
+
}
|
|
30
|
+
>,
|
|
31
|
+
) => void;
|
|
32
|
+
|
|
33
|
+
export interface CameraRef {
|
|
34
|
+
setCamera: (config: CameraStop | CameraStops) => void;
|
|
35
|
+
fitBounds: (
|
|
36
|
+
ne: GeoJSON.Position,
|
|
37
|
+
sw: GeoJSON.Position,
|
|
38
|
+
paddingConfig?: number | number[],
|
|
39
|
+
animationDuration?: number,
|
|
40
|
+
) => void;
|
|
41
|
+
flyTo: (
|
|
42
|
+
centerCoordinate: GeoJSON.Position,
|
|
43
|
+
animationDuration?: number,
|
|
44
|
+
) => void;
|
|
45
|
+
moveTo: (
|
|
46
|
+
centerCoordinate: GeoJSON.Position,
|
|
47
|
+
animationDuration?: number,
|
|
48
|
+
) => void;
|
|
49
|
+
zoomTo: (zoomLevel: number, animationDuration?: number) => void;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface CameraPadding {
|
|
53
|
+
/**
|
|
54
|
+
* Left padding in points
|
|
55
|
+
*/
|
|
56
|
+
paddingLeft?: number;
|
|
13
57
|
/**
|
|
14
|
-
*
|
|
58
|
+
* Right padding in points
|
|
15
59
|
*/
|
|
16
|
-
|
|
60
|
+
paddingRight?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Top padding in points
|
|
63
|
+
*/
|
|
64
|
+
paddingTop?: number;
|
|
65
|
+
/**
|
|
66
|
+
* Bottom padding in points
|
|
67
|
+
*/
|
|
68
|
+
paddingBottom?: number;
|
|
69
|
+
}
|
|
17
70
|
|
|
71
|
+
export interface CameraBounds {
|
|
72
|
+
/**
|
|
73
|
+
* North east coordinate of bound
|
|
74
|
+
*/
|
|
75
|
+
ne: number[];
|
|
18
76
|
/**
|
|
19
|
-
*
|
|
77
|
+
* South west coordinate of bound
|
|
20
78
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
79
|
+
sw: number[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
interface CameraBoundsWithPadding
|
|
83
|
+
extends CameraBounds,
|
|
84
|
+
Partial<CameraPadding> {}
|
|
85
|
+
|
|
86
|
+
type NativeAnimationMode = 'flight' | 'ease' | 'linear' | 'none' | 'move';
|
|
87
|
+
export type CameraAnimationMode = 'flyTo' | 'easeTo' | 'linearTo' | 'moveTo';
|
|
88
|
+
|
|
89
|
+
export interface NativeCameraStop extends Required<CameraPadding> {
|
|
90
|
+
mode: NativeAnimationMode;
|
|
91
|
+
pitch?: number;
|
|
92
|
+
heading?: number;
|
|
93
|
+
duration: number;
|
|
94
|
+
zoom?: number;
|
|
95
|
+
centerCoordinate?: string;
|
|
96
|
+
bounds?: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface CameraStop {
|
|
100
|
+
/** The location on which the map should center. */
|
|
101
|
+
centerCoordinate?: GeoJSON.Position;
|
|
102
|
+
/** The corners of a box around which the map should bound. Contains padding props for backwards
|
|
103
|
+
* compatibility; the root `padding` prop should be used instead. */
|
|
104
|
+
bounds?: CameraBoundsWithPadding;
|
|
105
|
+
/** The heading (orientation) of the map. */
|
|
106
|
+
heading?: number;
|
|
107
|
+
/** The pitch of the map. */
|
|
108
|
+
pitch?: number;
|
|
109
|
+
/** The zoom level of the map. */
|
|
110
|
+
zoomLevel?: number;
|
|
111
|
+
/** The viewport padding in points. */
|
|
112
|
+
padding?: CameraPadding;
|
|
113
|
+
/** The duration the map takes to animate to a new configuration. */
|
|
114
|
+
animationDuration?: number;
|
|
115
|
+
/** The easing or path the camera uses to animate to a new configuration. */
|
|
116
|
+
animationMode?: CameraAnimationMode;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export type CameraStops = {
|
|
120
|
+
stops: CameraStop[];
|
|
121
|
+
};
|
|
42
122
|
|
|
123
|
+
interface CameraProps extends Omit<ViewProps, 'style'>, CameraStop {
|
|
43
124
|
/**
|
|
44
|
-
*
|
|
125
|
+
* If false, the camera will not send any props to the native module. Intended to be used to prevent unnecessary tile fetching and improve performance when the map is not visible. Defaults to true.
|
|
45
126
|
*/
|
|
46
|
-
|
|
127
|
+
allowUpdates?: boolean;
|
|
47
128
|
|
|
48
129
|
/**
|
|
49
|
-
*
|
|
130
|
+
* Default view settings applied on camera
|
|
50
131
|
*/
|
|
51
|
-
|
|
132
|
+
defaultSettings?: CameraStop;
|
|
52
133
|
|
|
53
134
|
/**
|
|
54
|
-
*
|
|
55
|
-
* The `bounds.padding*` properties are deprecated; use root `padding` property instead.
|
|
135
|
+
* The minimun zoom level of the map
|
|
56
136
|
*/
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* North east coordinate of bound
|
|
60
|
-
*/
|
|
61
|
-
ne: PropTypes.arrayOf(PropTypes.number).isRequired,
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* South west coordinate of bound
|
|
65
|
-
*/
|
|
66
|
-
sw: PropTypes.arrayOf(PropTypes.number).isRequired,
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Left padding in points (deprecated; use root `padding` property instead)
|
|
70
|
-
*/
|
|
71
|
-
paddingLeft: PropTypes.number,
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Right padding in points (deprecated; use root `padding` property instead)
|
|
75
|
-
*/
|
|
76
|
-
paddingRight: PropTypes.number,
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Top padding in points (deprecated; use root `padding` property instead)
|
|
80
|
-
*/
|
|
81
|
-
paddingTop: PropTypes.number,
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Bottom padding in points (deprecated; use root `padding` property instead)
|
|
85
|
-
*/
|
|
86
|
-
paddingBottom: PropTypes.number,
|
|
87
|
-
}),
|
|
137
|
+
minZoomLevel?: number;
|
|
88
138
|
|
|
89
139
|
/**
|
|
90
|
-
*
|
|
140
|
+
* The maximun zoom level of the map
|
|
91
141
|
*/
|
|
92
|
-
|
|
142
|
+
maxZoomLevel?: number;
|
|
93
143
|
|
|
94
144
|
/**
|
|
95
|
-
*
|
|
145
|
+
* Restrict map panning so that the center is within these bounds
|
|
96
146
|
*/
|
|
97
|
-
|
|
98
|
-
};
|
|
147
|
+
maxBounds?: CameraBounds;
|
|
99
148
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* If false, the camera will not send any props to the native module. Intended to be used to prevent unnecessary tile fetching and improve performance when the map is not visible. Defaults to true.
|
|
106
|
-
*/
|
|
107
|
-
allowUpdates: PropTypes.bool,
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* The duration a camera update takes (in ms)
|
|
111
|
-
*/
|
|
112
|
-
animationDuration: PropTypes.number,
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* The animationstyle when the camara updates. One of: `flyTo`, `easeTo`, `linearTo`, `moveTo`
|
|
116
|
-
*/
|
|
117
|
-
animationMode: PropTypes.oneOf(['flyTo', 'easeTo', 'linearTo', 'moveTo']),
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Default view settings applied on camera
|
|
121
|
-
*/
|
|
122
|
-
defaultSettings: PropTypes.shape(SettingsPropTypes),
|
|
123
|
-
|
|
124
|
-
// normal - view settings
|
|
125
|
-
...SettingsPropTypes,
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* The minimun zoom level of the map
|
|
129
|
-
*/
|
|
130
|
-
minZoomLevel: PropTypes.number,
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* The maximun zoom level of the map
|
|
134
|
-
*/
|
|
135
|
-
maxZoomLevel: PropTypes.number,
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Restrict map panning so that the center is within these bounds
|
|
139
|
-
*/
|
|
140
|
-
maxBounds: PropTypes.shape({
|
|
141
|
-
/**
|
|
142
|
-
* northEastCoordinates - North east coordinate of bound
|
|
143
|
-
*/
|
|
144
|
-
ne: PropTypes.arrayOf(PropTypes.number).isRequired,
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* southWestCoordinates - South west coordinate of bound
|
|
148
|
-
*/
|
|
149
|
-
sw: PropTypes.arrayOf(PropTypes.number).isRequired,
|
|
150
|
-
}),
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Should the map orientation follow the user's.
|
|
154
|
-
*/
|
|
155
|
-
followUserLocation: PropTypes.bool,
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* The mode used to track the user location on the map. One of; "normal", "compass", "course". Each mode string is also available as a member on the `MapLibreGL.UserTrackingModes` object. `Follow` (normal), `FollowWithHeading` (compass), `FollowWithCourse` (course). NOTE: `followUserLocation` must be set to `true` for any of the modes to take effect. [Example](../example/src/examples/Camera/SetUserTrackingModes.js)
|
|
159
|
-
*/
|
|
160
|
-
followUserMode: PropTypes.oneOf(['normal', 'compass', 'course']),
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* The zoomLevel on map while followUserLocation is set to `true`
|
|
164
|
-
*/
|
|
165
|
-
followZoomLevel: PropTypes.number,
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* The pitch on map while followUserLocation is set to `true`
|
|
169
|
-
*/
|
|
170
|
-
followPitch: PropTypes.number,
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* The heading on map while followUserLocation is set to `true`
|
|
174
|
-
*/
|
|
175
|
-
followHeading: PropTypes.number,
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Manually update the camera - helpful for when props did not update, however you still want the camera to move
|
|
179
|
-
*/
|
|
180
|
-
triggerKey: PropTypes.any,
|
|
181
|
-
|
|
182
|
-
// Triggered when the
|
|
183
|
-
onUserTrackingModeChange: PropTypes.func,
|
|
184
|
-
};
|
|
149
|
+
/**
|
|
150
|
+
* Should the map orientation follow the user's.
|
|
151
|
+
*/
|
|
152
|
+
followUserLocation?: boolean;
|
|
185
153
|
|
|
154
|
+
/**
|
|
155
|
+
* The mode used to track the user location on the map. One of; "normal", "compass", "course". Each mode string is also available as a member on the `MapLibreGL.UserTrackingModes` object. `Follow` (normal), `FollowWithHeading` (compass), `FollowWithCourse` (course). NOTE: `followUserLocation` must be set to `true` for any of the modes to take effect. [Example](../example/src/examples/Camera/SetUserTrackingModes.js)
|
|
156
|
+
*/
|
|
157
|
+
followUserMode?: UserTrackingMode;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The zoomLevel on map while followUserLocation is set to `true`
|
|
161
|
+
*/
|
|
162
|
+
followZoomLevel?: number;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The pitch on map while followUserLocation is set to `true`
|
|
166
|
+
*/
|
|
167
|
+
followPitch?: number;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* The heading on map while followUserLocation is set to `true`
|
|
171
|
+
*/
|
|
172
|
+
followHeading?: number;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Manually update the camera - helpful for when props did not update, however you still want the camera to move
|
|
176
|
+
*/
|
|
177
|
+
triggerKey?: string | number;
|
|
178
|
+
|
|
179
|
+
// Triggered when the
|
|
180
|
+
onUserTrackingModeChange?: UserTrackingModeChangeCallback;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
interface NativeProps extends Omit<CameraProps, 'maxBounds'> {
|
|
184
|
+
maxBounds: string | null;
|
|
185
|
+
stop: NativeCameraStop | null;
|
|
186
|
+
defaultStop: NativeCameraStop | null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
class Camera extends React.Component<CameraProps> {
|
|
186
190
|
static defaultProps = {
|
|
187
191
|
allowUpdates: true,
|
|
188
192
|
animationMode: 'easeTo',
|
|
189
193
|
animationDuration: 2000,
|
|
190
194
|
};
|
|
191
195
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
196
|
+
defaultCamera: NativeCameraStop | null = null;
|
|
197
|
+
cameraRef: MutableRefObject<
|
|
198
|
+
(Component<NativeProps> & Readonly<NativeMethods>) | null
|
|
199
|
+
>;
|
|
200
|
+
|
|
201
|
+
constructor(props: CameraProps) {
|
|
202
|
+
super(props);
|
|
203
|
+
this.cameraRef = React.createRef<
|
|
204
|
+
Component<NativeProps> & Readonly<NativeMethods>
|
|
205
|
+
>();
|
|
206
|
+
}
|
|
198
207
|
|
|
199
|
-
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
208
|
+
UNSAFE_componentWillReceiveProps(nextProps: CameraProps): void {
|
|
200
209
|
this._handleCameraChange(this.props, nextProps);
|
|
201
210
|
}
|
|
202
211
|
|
|
203
|
-
shouldComponentUpdate() {
|
|
212
|
+
shouldComponentUpdate(): boolean {
|
|
204
213
|
return false;
|
|
205
214
|
}
|
|
206
215
|
|
|
207
|
-
_handleCameraChange(
|
|
216
|
+
_handleCameraChange(
|
|
217
|
+
currentCamera: CameraProps,
|
|
218
|
+
nextCamera: CameraProps,
|
|
219
|
+
): void {
|
|
208
220
|
const c = currentCamera;
|
|
209
221
|
const n = nextCamera;
|
|
210
222
|
|
|
@@ -218,15 +230,15 @@ class Camera extends React.Component {
|
|
|
218
230
|
}
|
|
219
231
|
|
|
220
232
|
if (c.followUserLocation && !n.followUserLocation) {
|
|
221
|
-
this.
|
|
233
|
+
this.cameraRef.current?.setNativeProps({followUserLocation: false});
|
|
222
234
|
return;
|
|
223
235
|
}
|
|
224
236
|
if (!c.followUserLocation && n.followUserLocation) {
|
|
225
|
-
this.
|
|
237
|
+
this.cameraRef.current?.setNativeProps({followUserLocation: true});
|
|
226
238
|
}
|
|
227
239
|
|
|
228
240
|
if (n.followUserLocation) {
|
|
229
|
-
this.
|
|
241
|
+
this.cameraRef.current?.setNativeProps({
|
|
230
242
|
followUserMode: n.followUserMode,
|
|
231
243
|
followPitch: n.followPitch || n.pitch,
|
|
232
244
|
followHeading: n.followHeading || n.heading,
|
|
@@ -236,22 +248,22 @@ class Camera extends React.Component {
|
|
|
236
248
|
}
|
|
237
249
|
|
|
238
250
|
if (n.maxBounds) {
|
|
239
|
-
this.
|
|
251
|
+
this.cameraRef.current?.setNativeProps({
|
|
240
252
|
maxBounds: this._getMaxBounds(),
|
|
241
253
|
});
|
|
242
254
|
}
|
|
243
255
|
if (n.minZoomLevel) {
|
|
244
|
-
this.
|
|
256
|
+
this.cameraRef.current?.setNativeProps({
|
|
245
257
|
minZoomLevel: this.props.minZoomLevel,
|
|
246
258
|
});
|
|
247
259
|
}
|
|
248
260
|
if (n.maxZoomLevel) {
|
|
249
|
-
this.
|
|
261
|
+
this.cameraRef.current?.setNativeProps({
|
|
250
262
|
maxZoomLevel: this.props.maxZoomLevel,
|
|
251
263
|
});
|
|
252
264
|
}
|
|
253
265
|
|
|
254
|
-
const cameraConfig = {
|
|
266
|
+
const cameraConfig: CameraStop = {
|
|
255
267
|
bounds: undefined,
|
|
256
268
|
centerCoordinate: undefined,
|
|
257
269
|
padding: n.padding,
|
|
@@ -291,15 +303,18 @@ class Camera extends React.Component {
|
|
|
291
303
|
}
|
|
292
304
|
}
|
|
293
305
|
|
|
294
|
-
_hasCameraChanged(
|
|
306
|
+
_hasCameraChanged(
|
|
307
|
+
currentCamera: CameraProps,
|
|
308
|
+
nextCamera: CameraProps,
|
|
309
|
+
): boolean {
|
|
295
310
|
const c = currentCamera;
|
|
296
311
|
const n = nextCamera;
|
|
297
312
|
|
|
298
313
|
const hasDefaultPropsChanged =
|
|
299
314
|
c.heading !== n.heading ||
|
|
300
315
|
this._hasCenterCoordinateChanged(
|
|
301
|
-
c
|
|
302
|
-
n
|
|
316
|
+
c?.centerCoordinate,
|
|
317
|
+
n?.centerCoordinate,
|
|
303
318
|
) ||
|
|
304
319
|
this._hasBoundsChanged(c.bounds, n.bounds) ||
|
|
305
320
|
this._hasPaddingChanged(c.padding, n.padding) ||
|
|
@@ -331,60 +346,66 @@ class Camera extends React.Component {
|
|
|
331
346
|
);
|
|
332
347
|
}
|
|
333
348
|
|
|
334
|
-
_hasCenterCoordinateChanged(
|
|
349
|
+
_hasCenterCoordinateChanged(
|
|
350
|
+
cC?: GeoJSON.Position,
|
|
351
|
+
nC?: GeoJSON.Position,
|
|
352
|
+
): boolean {
|
|
335
353
|
if (!cC && !nC) {
|
|
336
354
|
return false;
|
|
337
355
|
}
|
|
338
356
|
|
|
339
|
-
if (existenceChange(cC, nC)) {
|
|
357
|
+
if (existenceChange(!!cC, !!nC)) {
|
|
340
358
|
return true;
|
|
341
359
|
}
|
|
342
360
|
|
|
343
|
-
const isLngDiff = cC[0] !== nC[0];
|
|
344
|
-
const isLatDiff = cC[1] !== nC[1];
|
|
361
|
+
const isLngDiff = cC?.[0] !== nC?.[0];
|
|
362
|
+
const isLatDiff = cC?.[1] !== nC?.[1];
|
|
345
363
|
return isLngDiff || isLatDiff;
|
|
346
364
|
}
|
|
347
365
|
|
|
348
|
-
_hasBoundsChanged(
|
|
366
|
+
_hasBoundsChanged(
|
|
367
|
+
cB?: CameraBoundsWithPadding,
|
|
368
|
+
nB?: CameraBoundsWithPadding,
|
|
369
|
+
): boolean {
|
|
349
370
|
if (!cB && !nB) {
|
|
350
371
|
return false;
|
|
351
372
|
}
|
|
352
373
|
|
|
353
|
-
if (existenceChange(cB, nB)) {
|
|
374
|
+
if (existenceChange(!!cB, !!nB)) {
|
|
354
375
|
return true;
|
|
355
376
|
}
|
|
356
377
|
|
|
357
378
|
return (
|
|
358
|
-
cB
|
|
359
|
-
cB
|
|
360
|
-
cB
|
|
361
|
-
cB
|
|
362
|
-
cB
|
|
363
|
-
cB
|
|
364
|
-
cB
|
|
365
|
-
cB
|
|
379
|
+
cB?.ne[0] !== nB?.ne[0] ||
|
|
380
|
+
cB?.ne[1] !== nB?.ne[1] ||
|
|
381
|
+
cB?.sw[0] !== nB?.sw[0] ||
|
|
382
|
+
cB?.sw[1] !== nB?.sw[1] ||
|
|
383
|
+
cB?.paddingTop !== nB?.paddingTop ||
|
|
384
|
+
cB?.paddingLeft !== nB?.paddingLeft ||
|
|
385
|
+
cB?.paddingRight !== nB?.paddingRight ||
|
|
386
|
+
cB?.paddingBottom !== nB?.paddingBottom
|
|
366
387
|
);
|
|
367
388
|
}
|
|
368
389
|
|
|
369
|
-
_hasPaddingChanged(cP, nP) {
|
|
390
|
+
_hasPaddingChanged(cP?: CameraPadding, nP?: CameraPadding): boolean {
|
|
370
391
|
if (!cP && !nP) {
|
|
371
392
|
return false;
|
|
372
393
|
}
|
|
373
394
|
|
|
374
|
-
if (existenceChange(cP, nP)) {
|
|
395
|
+
if (existenceChange(!!cP, !!nP)) {
|
|
375
396
|
return true;
|
|
376
397
|
}
|
|
377
398
|
|
|
378
399
|
return (
|
|
379
|
-
cP
|
|
380
|
-
cP
|
|
381
|
-
cP
|
|
382
|
-
cP
|
|
400
|
+
cP?.paddingTop !== nP?.paddingTop ||
|
|
401
|
+
cP?.paddingLeft !== nP?.paddingLeft ||
|
|
402
|
+
cP?.paddingRight !== nP?.paddingRight ||
|
|
403
|
+
cP?.paddingBottom !== nP?.paddingBottom
|
|
383
404
|
);
|
|
384
405
|
}
|
|
385
406
|
|
|
386
|
-
_hasNumberChanged(prev, next) {
|
|
387
|
-
if (existenceChange(prev, next)) {
|
|
407
|
+
_hasNumberChanged(prev?: number, next?: number): boolean {
|
|
408
|
+
if (existenceChange(!!prev, !!next)) {
|
|
388
409
|
return true;
|
|
389
410
|
}
|
|
390
411
|
|
|
@@ -411,11 +432,11 @@ class Camera extends React.Component {
|
|
|
411
432
|
* @return {void}
|
|
412
433
|
*/
|
|
413
434
|
fitBounds(
|
|
414
|
-
northEastCoordinates,
|
|
415
|
-
southWestCoordinates,
|
|
435
|
+
northEastCoordinates: number[],
|
|
436
|
+
southWestCoordinates: number[],
|
|
416
437
|
padding = 0,
|
|
417
438
|
animationDuration = 0.0,
|
|
418
|
-
) {
|
|
439
|
+
): void {
|
|
419
440
|
const pad = {
|
|
420
441
|
paddingLeft: 0,
|
|
421
442
|
paddingRight: 0,
|
|
@@ -442,14 +463,14 @@ class Camera extends React.Component {
|
|
|
442
463
|
pad.paddingBottom = padding;
|
|
443
464
|
}
|
|
444
465
|
|
|
445
|
-
|
|
466
|
+
this.setCamera({
|
|
446
467
|
bounds: {
|
|
447
468
|
ne: northEastCoordinates,
|
|
448
469
|
sw: southWestCoordinates,
|
|
449
470
|
},
|
|
450
471
|
padding: pad,
|
|
451
472
|
animationDuration,
|
|
452
|
-
animationMode:
|
|
473
|
+
animationMode: 'easeTo',
|
|
453
474
|
});
|
|
454
475
|
}
|
|
455
476
|
|
|
@@ -464,11 +485,11 @@ class Camera extends React.Component {
|
|
|
464
485
|
* @param {Number=} animationDuration - Duration of camera animation
|
|
465
486
|
* @return {void}
|
|
466
487
|
*/
|
|
467
|
-
flyTo(coordinates, animationDuration = 2000) {
|
|
468
|
-
|
|
488
|
+
flyTo(coordinates: GeoJSON.Position, animationDuration = 2000): void {
|
|
489
|
+
this.setCamera({
|
|
469
490
|
centerCoordinate: coordinates,
|
|
470
491
|
animationDuration,
|
|
471
|
-
animationMode:
|
|
492
|
+
animationMode: 'flyTo',
|
|
472
493
|
});
|
|
473
494
|
}
|
|
474
495
|
|
|
@@ -483,8 +504,8 @@ class Camera extends React.Component {
|
|
|
483
504
|
* @param {Number=} animationDuration - Duration of camera animation
|
|
484
505
|
* @return {void}
|
|
485
506
|
*/
|
|
486
|
-
moveTo(coordinates, animationDuration = 0) {
|
|
487
|
-
|
|
507
|
+
moveTo(coordinates: GeoJSON.Position, animationDuration = 0): void {
|
|
508
|
+
this.setCamera({
|
|
488
509
|
centerCoordinate: coordinates,
|
|
489
510
|
animationDuration,
|
|
490
511
|
});
|
|
@@ -501,11 +522,11 @@ class Camera extends React.Component {
|
|
|
501
522
|
* @param {Number=} animationDuration - Duration of camera animation
|
|
502
523
|
* @return {void}
|
|
503
524
|
*/
|
|
504
|
-
zoomTo(zoomLevel, animationDuration = 2000) {
|
|
505
|
-
|
|
525
|
+
zoomTo(zoomLevel: number, animationDuration = 2000): void {
|
|
526
|
+
this.setCamera({
|
|
506
527
|
zoomLevel,
|
|
507
528
|
animationDuration,
|
|
508
|
-
animationMode:
|
|
529
|
+
animationMode: 'flyTo',
|
|
509
530
|
});
|
|
510
531
|
}
|
|
511
532
|
|
|
@@ -528,27 +549,30 @@ class Camera extends React.Component {
|
|
|
528
549
|
*
|
|
529
550
|
* @param {Object} config - Camera configuration
|
|
530
551
|
*/
|
|
531
|
-
setCamera(config = {}) {
|
|
552
|
+
setCamera(config: CameraStop | CameraStops = {}): void {
|
|
532
553
|
this._setCamera(config);
|
|
533
554
|
}
|
|
534
555
|
|
|
535
|
-
_setCamera(config = {}) {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
if (config.stops) {
|
|
539
|
-
cameraConfig.stops = [];
|
|
556
|
+
_setCamera(config: CameraStop | CameraStops = {}): void {
|
|
557
|
+
if ('stops' in config) {
|
|
558
|
+
let nativeStops: NativeCameraStop[] = [];
|
|
540
559
|
|
|
541
560
|
for (const stop of config.stops) {
|
|
542
|
-
|
|
561
|
+
const nativeStop = this._createStopConfig(stop);
|
|
562
|
+
if (nativeStop) {
|
|
563
|
+
nativeStops = [...nativeStops, nativeStop];
|
|
564
|
+
}
|
|
543
565
|
}
|
|
566
|
+
this.cameraRef.current?.setNativeProps({stop: {stops: nativeStops}});
|
|
544
567
|
} else {
|
|
545
|
-
|
|
568
|
+
const nativeStop = this._createStopConfig(config);
|
|
569
|
+
if (nativeStop) {
|
|
570
|
+
this.cameraRef.current?.setNativeProps({stop: nativeStop});
|
|
571
|
+
}
|
|
546
572
|
}
|
|
547
|
-
|
|
548
|
-
this.refs.camera.setNativeProps({stop: cameraConfig});
|
|
549
573
|
}
|
|
550
574
|
|
|
551
|
-
_createDefaultCamera() {
|
|
575
|
+
_createDefaultCamera(): NativeCameraStop | null {
|
|
552
576
|
if (this.defaultCamera) {
|
|
553
577
|
return this.defaultCamera;
|
|
554
578
|
}
|
|
@@ -559,24 +583,34 @@ class Camera extends React.Component {
|
|
|
559
583
|
this.defaultCamera = this._createStopConfig(
|
|
560
584
|
{
|
|
561
585
|
...this.props.defaultSettings,
|
|
562
|
-
animationMode:
|
|
586
|
+
animationMode: 'moveTo',
|
|
563
587
|
},
|
|
564
588
|
true,
|
|
565
589
|
);
|
|
566
590
|
return this.defaultCamera;
|
|
567
591
|
}
|
|
568
592
|
|
|
569
|
-
_createStopConfig(
|
|
593
|
+
_createStopConfig(
|
|
594
|
+
config: CameraStop = {},
|
|
595
|
+
ignoreFollowUserLocation = false,
|
|
596
|
+
): NativeCameraStop | null {
|
|
570
597
|
if (this.props.followUserLocation && !ignoreFollowUserLocation) {
|
|
571
598
|
return null;
|
|
572
599
|
}
|
|
573
600
|
|
|
574
|
-
const stopConfig = {
|
|
601
|
+
const stopConfig: NativeCameraStop = {
|
|
575
602
|
mode: this._getNativeCameraMode(config),
|
|
576
603
|
pitch: config.pitch,
|
|
577
604
|
heading: config.heading,
|
|
578
605
|
duration: config.animationDuration || 0,
|
|
579
606
|
zoom: config.zoomLevel,
|
|
607
|
+
paddingTop: config.padding?.paddingTop || config.bounds?.paddingTop || 0,
|
|
608
|
+
paddingRight:
|
|
609
|
+
config.padding?.paddingRight || config.bounds?.paddingRight || 0,
|
|
610
|
+
paddingBottom:
|
|
611
|
+
config.padding?.paddingBottom || config.bounds?.paddingBottom || 0,
|
|
612
|
+
paddingLeft:
|
|
613
|
+
config.padding?.paddingLeft || config.bounds?.paddingLeft || 0,
|
|
580
614
|
};
|
|
581
615
|
|
|
582
616
|
if (config.centerCoordinate) {
|
|
@@ -590,32 +624,23 @@ class Camera extends React.Component {
|
|
|
590
624
|
stopConfig.bounds = toJSONString(geoUtils.makeLatLngBounds(ne, sw));
|
|
591
625
|
}
|
|
592
626
|
|
|
593
|
-
stopConfig.paddingTop =
|
|
594
|
-
config.padding?.paddingTop || config.bounds?.paddingTop || 0;
|
|
595
|
-
stopConfig.paddingRight =
|
|
596
|
-
config.padding?.paddingRight || config.bounds?.paddingRight || 0;
|
|
597
|
-
stopConfig.paddingBottom =
|
|
598
|
-
config.padding?.paddingBottom || config.bounds?.paddingBottom || 0;
|
|
599
|
-
stopConfig.paddingLeft =
|
|
600
|
-
config.padding?.paddingLeft || config.bounds?.paddingLeft || 0;
|
|
601
|
-
|
|
602
627
|
return stopConfig;
|
|
603
628
|
}
|
|
604
629
|
|
|
605
|
-
_getNativeCameraMode(config) {
|
|
630
|
+
_getNativeCameraMode(config: CameraStop): NativeAnimationMode {
|
|
606
631
|
switch (config.animationMode) {
|
|
607
|
-
case
|
|
632
|
+
case 'flyTo':
|
|
608
633
|
return MapLibreGL.CameraModes.Flight;
|
|
609
|
-
case
|
|
634
|
+
case 'moveTo':
|
|
610
635
|
return MapLibreGL.CameraModes.None;
|
|
611
|
-
case
|
|
636
|
+
case 'linearTo':
|
|
612
637
|
return MapLibreGL.CameraModes.Linear;
|
|
613
638
|
default:
|
|
614
639
|
return MapLibreGL.CameraModes.Ease;
|
|
615
640
|
}
|
|
616
641
|
}
|
|
617
642
|
|
|
618
|
-
_getMaxBounds() {
|
|
643
|
+
_getMaxBounds(): string | null {
|
|
619
644
|
const bounds = this.props.maxBounds;
|
|
620
645
|
if (!bounds || !bounds.ne || !bounds.sw) {
|
|
621
646
|
return null;
|
|
@@ -623,7 +648,7 @@ class Camera extends React.Component {
|
|
|
623
648
|
return toJSONString(geoUtils.makeLatLngBounds(bounds.ne, bounds.sw));
|
|
624
649
|
}
|
|
625
650
|
|
|
626
|
-
render() {
|
|
651
|
+
render(): ReactElement {
|
|
627
652
|
const props = Object.assign({}, this.props);
|
|
628
653
|
|
|
629
654
|
const callbacks = {
|
|
@@ -633,7 +658,7 @@ class Camera extends React.Component {
|
|
|
633
658
|
return (
|
|
634
659
|
<RCTMGLCamera
|
|
635
660
|
testID="Camera"
|
|
636
|
-
ref=
|
|
661
|
+
ref={this.cameraRef}
|
|
637
662
|
followUserLocation={this.props.followUserLocation}
|
|
638
663
|
followUserMode={this.props.followUserMode}
|
|
639
664
|
followPitch={this.props.followPitch}
|
|
@@ -650,16 +675,6 @@ class Camera extends React.Component {
|
|
|
650
675
|
}
|
|
651
676
|
}
|
|
652
677
|
|
|
653
|
-
const RCTMGLCamera = requireNativeComponent(NATIVE_MODULE_NAME
|
|
654
|
-
nativeOnly: {
|
|
655
|
-
stop: true,
|
|
656
|
-
},
|
|
657
|
-
});
|
|
658
|
-
|
|
659
|
-
Camera.UserTrackingModes = {
|
|
660
|
-
Follow: 'normal',
|
|
661
|
-
FollowWithHeading: 'compass',
|
|
662
|
-
FollowWithCourse: 'course',
|
|
663
|
-
};
|
|
678
|
+
const RCTMGLCamera = requireNativeComponent<NativeProps>(NATIVE_MODULE_NAME);
|
|
664
679
|
|
|
665
680
|
export default Camera;
|