@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.
Files changed (141) hide show
  1. package/.eslintrc.js +10 -2
  2. package/.husky/pre-commit +5 -0
  3. package/.yarn/plugins/@yarnpkg/plugin-typescript.cjs +9 -0
  4. package/.yarn/sdks/eslint/bin/eslint.js +20 -0
  5. package/.yarn/sdks/eslint/lib/api.js +20 -0
  6. package/.yarn/sdks/eslint/package.json +6 -0
  7. package/.yarn/sdks/integrations.yml +5 -0
  8. package/.yarn/sdks/prettier/index.js +20 -0
  9. package/.yarn/sdks/prettier/package.json +6 -0
  10. package/.yarn/sdks/typescript/bin/tsc +20 -0
  11. package/.yarn/sdks/typescript/bin/tsserver +20 -0
  12. package/.yarn/sdks/typescript/lib/tsc.js +20 -0
  13. package/.yarn/sdks/typescript/lib/tsserver.js +225 -0
  14. package/.yarn/sdks/typescript/lib/tsserverlibrary.js +225 -0
  15. package/.yarn/sdks/typescript/lib/typescript.js +20 -0
  16. package/.yarn/sdks/typescript/package.json +6 -0
  17. package/CHANGELOG.md +18 -0
  18. package/android/rctmgl/build.gradle +7 -7
  19. package/android/rctmgl/src/main/java/com/mapbox/rctmgl/location/LocationManager.java +2 -2
  20. package/android/rctmgl/src/main/java/com/mapbox/rctmgl/modules/RCTMGLOfflineModule.java +21 -26
  21. package/docs/Annotation.md +8 -9
  22. package/docs/BackgroundLayer.md +2 -10
  23. package/docs/Callout.md +5 -5
  24. package/docs/Camera.md +18 -47
  25. package/docs/CircleLayer.md +2 -10
  26. package/docs/FillExtrusionLayer.md +2 -10
  27. package/docs/FillLayer.md +2 -10
  28. package/docs/HeatmapLayer.md +2 -10
  29. package/docs/ImageSource.md +3 -2
  30. package/docs/Images.md +5 -3
  31. package/docs/Light.md +1 -1
  32. package/docs/LineLayer.md +2 -10
  33. package/docs/MapView.md +53 -37
  34. package/docs/MarkerView.md +4 -2
  35. package/docs/NativeUserLocation.md +2 -2
  36. package/docs/PointAnnotation.md +5 -8
  37. package/docs/RasterLayer.md +2 -10
  38. package/docs/RasterSource.md +3 -2
  39. package/docs/ShapeSource.md +12 -7
  40. package/docs/Style.md +1 -1
  41. package/docs/SymbolLayer.md +3 -10
  42. package/docs/UserLocation.md +8 -10
  43. package/docs/VectorSource.md +6 -5
  44. package/docs/coordinates.md +6 -0
  45. package/docs/docs.json +518 -1272
  46. package/docs/location.md +6 -0
  47. package/docs/snapshotManager.md +3 -3
  48. package/javascript/@types/assets.d.ts +4 -0
  49. package/javascript/MGLModule.ts +37 -0
  50. package/javascript/Maplibre.ts +65 -0
  51. package/javascript/components/AbstractLayer.tsx +107 -0
  52. package/javascript/components/AbstractSource.tsx +27 -0
  53. package/javascript/components/BackgroundLayer.tsx +43 -0
  54. package/javascript/components/{Callout.js → Callout.tsx} +67 -65
  55. package/javascript/components/{Camera.js → Camera.tsx} +266 -251
  56. package/javascript/components/CircleLayer.tsx +46 -0
  57. package/javascript/components/FillExtrusionLayer.tsx +47 -0
  58. package/javascript/components/FillLayer.tsx +41 -0
  59. package/javascript/components/{HeadingIndicator.js → HeadingIndicator.tsx} +8 -8
  60. package/javascript/components/HeatmapLayer.tsx +44 -0
  61. package/javascript/components/ImageSource.tsx +78 -0
  62. package/javascript/components/Images.tsx +134 -0
  63. package/javascript/components/Light.tsx +67 -0
  64. package/javascript/components/LineLayer.tsx +42 -0
  65. package/javascript/components/{MapView.js → MapView.tsx} +365 -354
  66. package/javascript/components/MarkerView.tsx +104 -0
  67. package/javascript/components/{NativeBridgeComponent.js → NativeBridgeComponent.tsx} +44 -13
  68. package/javascript/components/NativeUserLocation.tsx +33 -0
  69. package/javascript/components/PointAnnotation.tsx +221 -0
  70. package/javascript/components/RasterLayer.tsx +41 -0
  71. package/javascript/components/RasterSource.tsx +117 -0
  72. package/javascript/components/ShapeSource.tsx +383 -0
  73. package/javascript/components/{Style.js → Style.tsx} +129 -38
  74. package/javascript/components/SymbolLayer.tsx +72 -0
  75. package/javascript/components/{UserLocation.js → UserLocation.tsx} +111 -110
  76. package/javascript/components/VectorSource.tsx +207 -0
  77. package/javascript/components/annotations/Annotation.tsx +134 -0
  78. package/javascript/index.ts +4 -0
  79. package/javascript/modules/location/{locationManager.js → locationManager.ts} +71 -10
  80. package/javascript/modules/offline/{OfflineCreatePackOptions.js → OfflineCreatePackOptions.ts} +20 -4
  81. package/javascript/modules/offline/{OfflinePack.js → OfflinePack.ts} +23 -7
  82. package/javascript/modules/offline/{offlineManager.js → offlineManager.ts} +81 -24
  83. package/javascript/modules/snapshot/{SnapshotOptions.js → SnapshotOptions.ts} +43 -6
  84. package/javascript/modules/snapshot/{snapshotManager.js → snapshotManager.ts} +5 -5
  85. package/javascript/requestAndroidLocationPermissions.ts +29 -0
  86. package/javascript/types/BaseProps.ts +5 -0
  87. package/javascript/types/OnPressEvent.ts +13 -0
  88. package/javascript/types/index.ts +7 -0
  89. package/javascript/utils/BridgeValue.ts +90 -0
  90. package/javascript/utils/{Logger.js → Logger.ts} +37 -18
  91. package/javascript/utils/MaplibreStyles.d.ts +1486 -0
  92. package/javascript/utils/StyleValue.ts +49 -0
  93. package/javascript/utils/animated/AbstractAnimatedCoordinates.ts +134 -0
  94. package/javascript/utils/animated/AnimatedCoordinatesArray.ts +112 -0
  95. package/javascript/utils/animated/{AnimatedExtractCoordinateFromArray.js → AnimatedExtractCoordinateFromArray.ts} +5 -5
  96. package/javascript/utils/animated/{AnimatedPoint.js → AnimatedPoint.ts} +20 -12
  97. package/javascript/utils/animated/{AnimatedRouteCoordinatesArray.js → AnimatedRouteCoordinatesArray.ts} +39 -14
  98. package/javascript/utils/animated/{AnimatedShape.js → AnimatedShape.ts} +31 -10
  99. package/javascript/utils/{deprecation.js → deprecation.ts} +9 -6
  100. package/javascript/utils/filterUtils.ts +9 -0
  101. package/javascript/utils/geoUtils.ts +79 -0
  102. package/javascript/utils/{index.js → index.ts} +44 -24
  103. package/javascript/utils/styleMap.ts +264 -0
  104. package/package.json +35 -27
  105. package/plugin/build/withMapLibre.js +18 -3
  106. package/scripts/autogenHelpers/globals.js +1 -1
  107. package/scripts/autogenerate.js +14 -6
  108. package/scripts/download-style-spec.sh +1 -1
  109. package/scripts/templates/MaplibreStyles.ts.ejs +99 -0
  110. package/scripts/templates/index.d.ts.ejs +71 -42
  111. package/scripts/templates/{styleMap.js.ejs → styleMap.ts.ejs} +3 -33
  112. package/setup-jest.js +1 -10
  113. package/tsconfig.json +20 -61
  114. package/index.d.ts +0 -955
  115. package/javascript/components/AbstractLayer.js +0 -75
  116. package/javascript/components/AbstractSource.js +0 -15
  117. package/javascript/components/BackgroundLayer.js +0 -97
  118. package/javascript/components/CircleLayer.js +0 -101
  119. package/javascript/components/FillExtrusionLayer.js +0 -98
  120. package/javascript/components/FillLayer.js +0 -94
  121. package/javascript/components/HeatmapLayer.js +0 -99
  122. package/javascript/components/ImageSource.js +0 -82
  123. package/javascript/components/Images.js +0 -119
  124. package/javascript/components/Light.js +0 -47
  125. package/javascript/components/LineLayer.js +0 -94
  126. package/javascript/components/MarkerView.js +0 -87
  127. package/javascript/components/NativeUserLocation.js +0 -41
  128. package/javascript/components/PointAnnotation.js +0 -216
  129. package/javascript/components/RasterLayer.js +0 -95
  130. package/javascript/components/RasterSource.js +0 -124
  131. package/javascript/components/ShapeSource.js +0 -372
  132. package/javascript/components/SymbolLayer.js +0 -120
  133. package/javascript/components/VectorSource.js +0 -200
  134. package/javascript/components/annotations/Annotation.js +0 -122
  135. package/javascript/index.js +0 -149
  136. package/javascript/utils/BridgeValue.js +0 -81
  137. package/javascript/utils/animated/AnimatedCoordinatesArray.js +0 -191
  138. package/javascript/utils/filterUtils.js +0 -7
  139. package/javascript/utils/geoUtils.js +0 -73
  140. package/javascript/utils/styleMap.js +0 -1932
  141. /package/javascript/utils/animated/{Animated.js → Animated.ts} +0 -0
@@ -1,23 +1,22 @@
1
- import {makePoint, makeLatLngBounds} from '../utils/geoUtils';
2
- import {
3
- isFunction,
4
- isNumber,
5
- toJSONString,
6
- isAndroid,
7
- viewPropTypes,
8
- } from '../utils';
1
+ import {FilterExpression} from '../utils/MaplibreStyles';
2
+ import {Location} from '../modules/location/locationManager';
3
+ import {isFunction, isAndroid} from '../utils';
9
4
  import {getFilter} from '../utils/filterUtils';
10
5
  import Logger from '../utils/Logger';
6
+ import BaseProps from '../types/BaseProps';
11
7
 
12
8
  import NativeBridgeComponent from './NativeBridgeComponent';
13
9
 
14
- import PropTypes from 'prop-types';
15
- import React from 'react';
10
+ import React, {Component, ReactElement, ReactNode} from 'react';
16
11
  import {
17
12
  View,
18
13
  StyleSheet,
19
14
  NativeModules,
20
15
  requireNativeComponent,
16
+ ViewProps,
17
+ NativeMethods,
18
+ LayoutChangeEvent,
19
+ NativeSyntheticEvent,
21
20
  } from 'react-native';
22
21
  import {debounce} from 'debounce';
23
22
 
@@ -38,228 +37,254 @@ const styles = StyleSheet.create({
38
37
 
39
38
  const defaultStyleURL = MapLibreGL.StyleURL.Street;
40
39
 
40
+ export interface RegionPayload {
41
+ zoomLevel: number;
42
+ heading: number;
43
+ animated: boolean;
44
+ isUserInteraction: boolean;
45
+ visibleBounds: GeoJSON.Position[];
46
+ pitch: number;
47
+ }
48
+
49
+ interface Bounds {
50
+ ne: GeoJSON.Position;
51
+ sw: GeoJSON.Position;
52
+ }
53
+
54
+ interface MapViewProps extends BaseProps {
55
+ /**
56
+ * The distance from the edges of the map view’s frame to the edges of the map view’s logical viewport.
57
+ */
58
+ contentInset?: number[] | number;
59
+ /**
60
+ * Style for wrapping React Native View
61
+ */
62
+ style?: ViewProps['style'];
63
+ /**
64
+ * Style URL for map - notice, if non is set it _will_ default to `MapLibreGL.StyleURL.Default`
65
+ */
66
+ styleURL?: string;
67
+ /**
68
+ * StyleJSON for map - according to TileJSON specs: https://github.com/mapbox/tilejson-spec
69
+ */
70
+ styleJSON?: string;
71
+ /**
72
+ * iOS: The preferred frame rate at which the map view is rendered.
73
+ * The default value for this property is MGLMapViewPreferredFramesPerSecondDefault,
74
+ * which will adaptively set the preferred frame rate based on the capability of
75
+ * the user’s device to maintain a smooth experience. This property can be set to arbitrary integer values.
76
+ *
77
+ * Android: The maximum frame rate at which the map view is rendered, but it can't excess the ability of device hardware.
78
+ * This property can be set to arbitrary integer values.
79
+ */
80
+ preferredFramesPerSecond?: number;
81
+ /**
82
+ * Automatically change the language of the map labels to the system’s preferred language,
83
+ * this is not something that can be toggled on/off
84
+ */
85
+ localizeLabels?: boolean;
86
+ /**
87
+ * Enable/Disable zoom on the map
88
+ */
89
+ zoomEnabled?: boolean;
90
+ /**
91
+ * Enable/Disable scroll on the map
92
+ */
93
+ scrollEnabled?: boolean;
94
+ /**
95
+ * Enable/Disable pitch on map
96
+ */
97
+ pitchEnabled?: boolean;
98
+ /**
99
+ * Enable/Disable rotation on map
100
+ */
101
+ rotateEnabled?: boolean;
102
+ /**
103
+ * Enable/Disable attribution on map.
104
+ *
105
+ * This must be enabled for Mapbox-hosted tiles and styles. Please refer to the Mapbox Terms of Service.
106
+ * Other providers do not require this.
107
+ */
108
+ attributionEnabled?: boolean;
109
+ /**
110
+ * Adds attribution offset, e.g. `{top: 8, left: 8}` will put attribution button in top-left corner of the map
111
+ */
112
+ attributionPosition?:
113
+ | {
114
+ top?: number;
115
+ left?: number;
116
+ }
117
+ | {
118
+ top?: number;
119
+ right?: number;
120
+ }
121
+ | {
122
+ bottom?: number;
123
+ left?: number;
124
+ }
125
+ | {
126
+ bottom?: number;
127
+ right?: number;
128
+ };
129
+ /**
130
+ * MapView's tintColor
131
+ */
132
+ tintColor?: string | unknown[];
133
+ /**
134
+ * Enable/Disable the logo on the map.
135
+ */
136
+ logoEnabled?: boolean;
137
+ /**
138
+ * Adds logo offset, e.g. `{top: 8, left: 8}` will put the logo in top-left corner of the map
139
+ */
140
+ logoPosition?:
141
+ | {
142
+ top?: number;
143
+ left?: number;
144
+ }
145
+ | {
146
+ top?: number;
147
+ right?: number;
148
+ }
149
+ | {
150
+ bottom?: number;
151
+ left?: number;
152
+ }
153
+ | {
154
+ bottom?: number;
155
+ right?: number;
156
+ };
157
+ /**
158
+ * Enable/Disable the compass from appearing on the map
159
+ */
160
+ compassEnabled?: boolean;
161
+ /**
162
+ * Change corner of map the compass starts at. 0: TopLeft, 1: TopRight, 2: BottomLeft, 3: BottomRight
163
+ */
164
+ compassViewPosition?: number;
165
+ /**
166
+ * Add margins to the compass with x and y values
167
+ */
168
+ compassViewMargins?: object;
169
+ /**
170
+ * [Android only] Enable/Disable use of GLSurfaceView insted of TextureView.
171
+ */
172
+ surfaceView?: boolean;
173
+ /**
174
+ * Map press listener, gets called when a user presses the map
175
+ */
176
+ onPress?(feature: GeoJSON.Feature): void;
177
+ /**
178
+ * Map long press listener, gets called when a user long presses the map
179
+ */
180
+ onLongPress?(feature: GeoJSON.Feature): void;
181
+ /**
182
+ * This event is triggered whenever the currently displayed map region is about to change.
183
+ *
184
+ * @param {PointFeature} feature - The geojson point feature at the camera center, properties contains zoomLevel, visibleBounds
185
+ */
186
+ onRegionWillChange?(
187
+ feature: GeoJSON.Feature<GeoJSON.Point, RegionPayload>,
188
+ ): void;
189
+ /**
190
+ * This event is triggered whenever the currently displayed map region is changing.
191
+ *
192
+ * @param {PointFeature} feature - The geojson point feature at the camera center, properties contains zoomLevel, visibleBounds
193
+ */
194
+ onRegionIsChanging?(
195
+ feature: GeoJSON.Feature<GeoJSON.Point, RegionPayload>,
196
+ ): void;
197
+ /**
198
+ * This event is triggered whenever the currently displayed map region finished changing
199
+ *
200
+ * @param {PointFeature} feature - The geojson point feature at the camera center, properties contains zoomLevel, visibleBounds
201
+ */
202
+ onRegionDidChange?(
203
+ feature: GeoJSON.Feature<GeoJSON.Point, RegionPayload>,
204
+ ): void;
205
+ /**
206
+ * This event is triggered when the map is about to start loading a new map style.
207
+ */
208
+ onWillStartLoadingMap?(): void;
209
+ /**
210
+ * This is triggered when the map has successfully loaded a new map style.
211
+ */
212
+ onDidFinishLoadingMap?(): void;
213
+ /**
214
+ * This event is triggered when the map has failed to load a new map style.
215
+ */
216
+ onDidFailLoadingMap?(): void;
217
+ /**
218
+ * This event is triggered when the map will start rendering a frame.
219
+ */
220
+ onWillStartRenderingFrame?(): void;
221
+ /**
222
+ * This event is triggered when the map finished rendering a frame.
223
+ */
224
+ onDidFinishRenderingFrame?(): void;
225
+ /**
226
+ * This event is triggered when the map fully finished rendering a frame.
227
+ */
228
+ onDidFinishRenderingFrameFully?(): void;
229
+ /**
230
+ * This event is triggered when the map will start rendering the map.
231
+ */
232
+ onWillStartRenderingMap?(): void;
233
+ /**
234
+ * This event is triggered when the map finished rendering the map.
235
+ */
236
+ onDidFinishRenderingMap?(): void;
237
+ /**
238
+ * This event is triggered when the map fully finished rendering the map.
239
+ */
240
+ onDidFinishRenderingMapFully?(): void;
241
+ /**
242
+ * This event is triggered when the user location is updated.
243
+ */
244
+ onUserLocationUpdate?: (location: Location) => void;
245
+ /**
246
+ * This event is triggered when a style has finished loading.
247
+ */
248
+ onDidFinishLoadingStyle?(): void;
249
+ /**
250
+ * The emitted frequency of regionwillchange events
251
+ */
252
+ regionWillChangeDebounceTime?: number;
253
+ /**
254
+ * The emitted frequency of regiondidchange events
255
+ */
256
+ regionDidChangeDebounceTime?: number;
257
+
258
+ children: ReactNode;
259
+ }
260
+
261
+ type Fn = (...args: any) => any;
262
+ type CallableProps = {
263
+ [Prop in keyof MapViewProps]-?: MapViewProps[Prop] extends Fn | undefined
264
+ ? Prop
265
+ : never;
266
+ }[keyof MapViewProps];
267
+
268
+ interface NativeProps extends Omit<MapViewProps, 'onPress' | 'onLongPress'> {
269
+ onPress(event: NativeSyntheticEvent<{payload: GeoJSON.Feature}>): void;
270
+ onLongPress(event: NativeSyntheticEvent<{payload: GeoJSON.Feature}>): void;
271
+ }
272
+
273
+ export interface MapViewState {
274
+ isReady: boolean;
275
+ width: number;
276
+ height: number;
277
+ region: RegionPayload | null;
278
+ isUserInteraction: boolean;
279
+ }
280
+
41
281
  /**
42
282
  * MapView backed by MapLibre GL Native
43
283
  */
44
- class MapView extends NativeBridgeComponent(React.Component) {
45
- static propTypes = {
46
- ...viewPropTypes,
47
-
48
- /**
49
- * The distance from the edges of the map view’s frame to the edges of the map view’s logical viewport.
50
- */
51
- contentInset: PropTypes.oneOfType([
52
- PropTypes.arrayOf(PropTypes.number),
53
- PropTypes.number,
54
- ]),
55
-
56
- /**
57
- * Style for wrapping React Native View
58
- */
59
- style: PropTypes.any,
60
-
61
- /**
62
- * Style URL for map - notice, if non is set it _will_ default to `MapLibreGL.StyleURL.Street`
63
- */
64
- styleURL: PropTypes.string,
65
-
66
- /**
67
- * StyleJSON for map - according to TileJSON specs: https://github.com/mapbox/tilejson-spec
68
- */
69
- styleJSON: PropTypes.string,
70
-
71
- /**
72
- * iOS: The preferred frame rate at which the map view is rendered.
73
- * The default value for this property is MGLMapViewPreferredFramesPerSecondDefault,
74
- * which will adaptively set the preferred frame rate based on the capability of
75
- * the user’s device to maintain a smooth experience. This property can be set to arbitrary integer values.
76
- *
77
- * Android: The maximum frame rate at which the map view is rendered, but it can't excess the ability of device hardware.
78
- * This property can be set to arbitrary integer values.
79
- */
80
- preferredFramesPerSecond: PropTypes.number,
81
-
82
- /**
83
- * Automatically change the language of the map labels to the system’s preferred language,
84
- * this is not something that can be toggled on/off
85
- */
86
- localizeLabels: PropTypes.bool,
87
-
88
- /**
89
- * Enable/Disable zoom on the map
90
- */
91
- zoomEnabled: PropTypes.bool,
92
-
93
- /**
94
- * Enable/Disable scroll on the map
95
- */
96
- scrollEnabled: PropTypes.bool,
97
-
98
- /**
99
- * Enable/Disable pitch on map
100
- */
101
- pitchEnabled: PropTypes.bool,
102
-
103
- /**
104
- * Enable/Disable rotation on map
105
- */
106
- rotateEnabled: PropTypes.bool,
107
-
108
- /**
109
- * Enable/Disable attribution on map.
110
- *
111
- * This must be enabled for Mapbox-hosted tiles and styles. Please refer to the Mapbox Terms of Service.
112
- * Other providers do not require this.
113
- */
114
- attributionEnabled: PropTypes.bool,
115
-
116
- /**
117
- * Adds attribution offset, e.g. `{top: 8, left: 8}` will put attribution button in top-left corner of the map
118
- */
119
- attributionPosition: PropTypes.oneOfType([
120
- PropTypes.shape({top: PropTypes.number, left: PropTypes.number}),
121
- PropTypes.shape({top: PropTypes.number, right: PropTypes.number}),
122
- PropTypes.shape({bottom: PropTypes.number, left: PropTypes.number}),
123
- PropTypes.shape({bottom: PropTypes.number, right: PropTypes.number}),
124
- ]),
125
-
126
- /**
127
- * MapView's tintColor
128
- */
129
- tintColor: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
130
-
131
- /**
132
- * Enable/Disable the logo on the map.
133
- */
134
- logoEnabled: PropTypes.bool,
135
-
136
- /**
137
- * Adds logo offset, e.g. `{top: 8, left: 8}` will put the logo in top-left corner of the map
138
- */
139
- logoPosition: PropTypes.oneOfType([
140
- PropTypes.shape({top: PropTypes.number, left: PropTypes.number}),
141
- PropTypes.shape({top: PropTypes.number, right: PropTypes.number}),
142
- PropTypes.shape({bottom: PropTypes.number, left: PropTypes.number}),
143
- PropTypes.shape({bottom: PropTypes.number, right: PropTypes.number}),
144
- ]),
145
-
146
- /**
147
- * Enable/Disable the compass from appearing on the map
148
- */
149
- compassEnabled: PropTypes.bool,
150
-
151
- /**
152
- * Change corner of map the compass starts at. 0: TopLeft, 1: TopRight, 2: BottomLeft, 3: BottomRight
153
- */
154
- compassViewPosition: PropTypes.number,
155
-
156
- /**
157
- * Add margins to the compass with x and y values
158
- */
159
- compassViewMargins: PropTypes.object,
160
-
161
- /**
162
- * [Android only] Enable/Disable use of GLSurfaceView insted of TextureView.
163
- */
164
- surfaceView: PropTypes.bool,
165
-
166
- /**
167
- * Map press listener, gets called when a user presses the map
168
- */
169
- onPress: PropTypes.func,
170
-
171
- /**
172
- * Map long press listener, gets called when a user long presses the map
173
- */
174
- onLongPress: PropTypes.func,
175
-
176
- /**
177
- * This event is triggered whenever the currently displayed map region is about to change.
178
- *
179
- * @param {PointFeature} feature - The geojson point feature at the camera center, properties contains zoomLevel, visibleBounds
180
- */
181
- onRegionWillChange: PropTypes.func,
182
-
183
- /**
184
- * This event is triggered whenever the currently displayed map region is changing.
185
- *
186
- * @param {PointFeature} feature - The geojson point feature at the camera center, properties contains zoomLevel, visibleBounds
187
- */
188
- onRegionIsChanging: PropTypes.func,
189
-
190
- /**
191
- * This event is triggered whenever the currently displayed map region finished changing
192
- *
193
- * @param {PointFeature} feature - The geojson point feature at the camera center, properties contains zoomLevel, visibleBounds
194
- */
195
- onRegionDidChange: PropTypes.func,
196
-
197
- /**
198
- * This event is triggered when the map is about to start loading a new map style.
199
- */
200
- onWillStartLoadingMap: PropTypes.func,
201
-
202
- /**
203
- * This is triggered when the map has successfully loaded a new map style.
204
- */
205
- onDidFinishLoadingMap: PropTypes.func,
206
-
207
- /**
208
- * This event is triggered when the map has failed to load a new map style.
209
- */
210
- onDidFailLoadingMap: PropTypes.func,
211
-
212
- /**
213
- * This event is triggered when the map will start rendering a frame.
214
- */
215
- onWillStartRenderingFrame: PropTypes.func,
216
-
217
- /**
218
- * This event is triggered when the map finished rendering a frame.
219
- */
220
- onDidFinishRenderingFrame: PropTypes.func,
221
-
222
- /**
223
- * This event is triggered when the map fully finished rendering a frame.
224
- */
225
- onDidFinishRenderingFrameFully: PropTypes.func,
226
-
227
- /**
228
- * This event is triggered when the map will start rendering the map.
229
- */
230
- onWillStartRenderingMap: PropTypes.func,
231
-
232
- /**
233
- * This event is triggered when the map finished rendering the map.
234
- */
235
- onDidFinishRenderingMap: PropTypes.func,
236
-
237
- /**
238
- * This event is triggered when the map fully finished rendering the map.
239
- */
240
- onDidFinishRenderingMapFully: PropTypes.func,
241
-
242
- /**
243
- * This event is triggered when the user location is updated.
244
- */
245
- onUserLocationUpdate: PropTypes.func,
246
-
247
- /**
248
- * This event is triggered when a style has finished loading.
249
- */
250
- onDidFinishLoadingStyle: PropTypes.func,
251
-
252
- /**
253
- * The emitted frequency of regionwillchange events
254
- */
255
- regionWillChangeDebounceTime: PropTypes.number,
256
-
257
- /**
258
- * The emitted frequency of regiondidchange events
259
- */
260
- regionDidChangeDebounceTime: PropTypes.number,
261
- };
262
-
284
+ class MapView extends NativeBridgeComponent(
285
+ React.Component<MapViewProps, MapViewState>,
286
+ NATIVE_MODULE_NAME,
287
+ ) {
263
288
  static defaultProps = {
264
289
  localizeLabels: false,
265
290
  scrollEnabled: true,
@@ -272,14 +297,19 @@ class MapView extends NativeBridgeComponent(React.Component) {
272
297
  regionDidChangeDebounceTime: 500,
273
298
  };
274
299
 
275
- constructor(props) {
276
- super(props, NATIVE_MODULE_NAME);
300
+ logger: Logger;
301
+ _nativeRef?: RCTMGLMapViewRefType;
302
+ _onDebouncedRegionWillChange: ReturnType<typeof debounce>;
303
+ _onDebouncedRegionDidChange: ReturnType<typeof debounce>;
304
+
305
+ constructor(props: MapViewProps) {
306
+ super(props);
277
307
 
278
308
  this.logger = Logger.sharedInstance();
279
309
  this.logger.start();
280
310
 
281
311
  this.state = {
282
- isReady: null,
312
+ isReady: false,
283
313
  region: null,
284
314
  width: 0,
285
315
  height: 0,
@@ -304,21 +334,21 @@ class MapView extends NativeBridgeComponent(React.Component) {
304
334
  );
305
335
  }
306
336
 
307
- componentDidMount() {
337
+ componentDidMount(): void {
308
338
  this._setHandledMapChangedEvents(this.props);
309
339
  }
310
340
 
311
- componentWillUnmount() {
341
+ componentWillUnmount(): void {
312
342
  this._onDebouncedRegionWillChange.clear();
313
343
  this._onDebouncedRegionDidChange.clear();
314
344
  this.logger.stop();
315
345
  }
316
346
 
317
- UNSAFE_componentWillReceiveProps(nextProps) {
347
+ UNSAFE_componentWillReceiveProps(nextProps: MapViewProps): void {
318
348
  this._setHandledMapChangedEvents(nextProps);
319
349
  }
320
350
 
321
- _setHandledMapChangedEvents(props) {
351
+ _setHandledMapChangedEvents(props: MapViewProps): void {
322
352
  if (isAndroid()) {
323
353
  const events = [];
324
354
 
@@ -382,8 +412,8 @@ class MapView extends NativeBridgeComponent(React.Component) {
382
412
  * @param {Array<Number>} coordinate - A point expressed in the map view's coordinate system.
383
413
  * @return {Array}
384
414
  */
385
- async getPointInView(coordinate) {
386
- const res = await this._runNativeCommand(
415
+ async getPointInView(coordinate: GeoJSON.Position): Promise<GeoJSON.Point> {
416
+ const res: {pointInView: GeoJSON.Point} = await this._runNativeCommand(
387
417
  'getPointInView',
388
418
  this._nativeRef,
389
419
  [coordinate],
@@ -400,12 +430,11 @@ class MapView extends NativeBridgeComponent(React.Component) {
400
430
  * @param {Array<Number>} point - A point expressed in the given view’s coordinate system.
401
431
  * @return {Array}
402
432
  */
403
- async getCoordinateFromView(point) {
404
- const res = await this._runNativeCommand(
405
- 'getCoordinateFromView',
406
- this._nativeRef,
407
- [point],
408
- );
433
+ async getCoordinateFromView(point: number[]): Promise<GeoJSON.Position> {
434
+ const res: {coordinateFromView: GeoJSON.Position} =
435
+ await this._runNativeCommand('getCoordinateFromView', this._nativeRef, [
436
+ point,
437
+ ]);
409
438
  return res.coordinateFromView;
410
439
  }
411
440
 
@@ -417,8 +446,8 @@ class MapView extends NativeBridgeComponent(React.Component) {
417
446
  *
418
447
  * @return {Array}
419
448
  */
420
- async getVisibleBounds() {
421
- const res = await this._runNativeCommand(
449
+ async getVisibleBounds(): Promise<Bounds> {
450
+ const res: {visibleBounds: Bounds} = await this._runNativeCommand(
422
451
  'getVisibleBounds',
423
452
  this._nativeRef,
424
453
  );
@@ -434,24 +463,29 @@ class MapView extends NativeBridgeComponent(React.Component) {
434
463
  * @param {Array<Number>} coordinate - A point expressed in the map view’s coordinate system.
435
464
  * @param {Array=} filter - A set of strings that correspond to the names of layers defined in the current style. Only the features contained in these layers are included in the returned array.
436
465
  * @param {Array=} layerIDs - A array of layer id's to filter the features by
437
- * @return {FeatureCollection}
466
+ * @return {GeoJSON.FeatureCollection}
438
467
  */
439
- async queryRenderedFeaturesAtPoint(coordinate, filter = [], layerIDs = []) {
468
+ async queryRenderedFeaturesAtPoint(
469
+ coordinate: GeoJSON.Position,
470
+ filter?: FilterExpression,
471
+ layerIDs = [],
472
+ ): Promise<GeoJSON.FeatureCollection> {
440
473
  if (!coordinate || coordinate.length < 2) {
441
474
  throw new Error('Must pass in valid coordinate[lng, lat]');
442
475
  }
443
476
 
444
- const res = await this._runNativeCommand(
445
- 'queryRenderedFeaturesAtPoint',
446
- this._nativeRef,
447
- [coordinate, getFilter(filter), layerIDs],
448
- );
477
+ const res: {data: string | GeoJSON.FeatureCollection} =
478
+ await this._runNativeCommand(
479
+ 'queryRenderedFeaturesAtPoint',
480
+ this._nativeRef,
481
+ [coordinate, getFilter(filter), layerIDs],
482
+ );
449
483
 
450
484
  if (isAndroid()) {
451
- return JSON.parse(res.data);
485
+ return JSON.parse(res.data as string);
452
486
  }
453
487
 
454
- return res.data;
488
+ return res.data as GeoJSON.FeatureCollection;
455
489
  }
456
490
 
457
491
  /**
@@ -464,31 +498,36 @@ class MapView extends NativeBridgeComponent(React.Component) {
464
498
  * @param {Array<Number>} bbox - A rectangle expressed in the map view’s coordinate system.
465
499
  * @param {Array=} filter - A set of strings that correspond to the names of layers defined in the current style. Only the features contained in these layers are included in the returned array.
466
500
  * @param {Array=} layerIDs - A array of layer id's to filter the features by
467
- * @return {FeatureCollection}
501
+ * @return {GeoJSON.FeatureCollection}
468
502
  */
469
- async queryRenderedFeaturesInRect(bbox, filter = [], layerIDs = []) {
503
+ async queryRenderedFeaturesInRect(
504
+ bbox: GeoJSON.BBox,
505
+ filter?: FilterExpression,
506
+ layerIDs = [],
507
+ ): Promise<GeoJSON.FeatureCollection> {
470
508
  if (!bbox || bbox.length !== 4) {
471
509
  throw new Error(
472
510
  'Must pass in a valid bounding box[top, right, bottom, left]',
473
511
  );
474
512
  }
475
- const res = await this._runNativeCommand(
476
- 'queryRenderedFeaturesInRect',
477
- this._nativeRef,
478
- [bbox, getFilter(filter), layerIDs],
479
- );
513
+ const res: {data: string | GeoJSON.FeatureCollection} =
514
+ await this._runNativeCommand(
515
+ 'queryRenderedFeaturesInRect',
516
+ this._nativeRef,
517
+ [bbox, getFilter(filter), layerIDs],
518
+ );
480
519
 
481
520
  if (isAndroid()) {
482
- return JSON.parse(res.data);
521
+ return JSON.parse(res.data as string);
483
522
  }
484
523
 
485
- return res.data;
524
+ return res.data as GeoJSON.FeatureCollection;
486
525
  }
487
526
 
488
527
  /**
489
528
  * Map camera will perform updates based on provided config. Deprecated use Camera#setCamera.
490
529
  */
491
- setCamera() {
530
+ setCamera(): void {
492
531
  console.warn(
493
532
  'MapView.setCamera is deprecated - please use Camera#setCamera',
494
533
  );
@@ -499,10 +538,12 @@ class MapView extends NativeBridgeComponent(React.Component) {
499
538
  * @param {Boolean} writeToDisk If true will create a temp file, otherwise it is in base64
500
539
  * @return {String}
501
540
  */
502
- async takeSnap(writeToDisk = false) {
503
- const res = await this._runNativeCommand('takeSnap', this._nativeRef, [
504
- writeToDisk,
505
- ]);
541
+ async takeSnap(writeToDisk = false): Promise<string> {
542
+ const res: {uri: string} = await this._runNativeCommand(
543
+ 'takeSnap',
544
+ this._nativeRef,
545
+ [writeToDisk],
546
+ );
506
547
  return res.uri;
507
548
  }
508
549
 
@@ -515,8 +556,11 @@ class MapView extends NativeBridgeComponent(React.Component) {
515
556
  * @return {Number}
516
557
  */
517
558
 
518
- async getZoom() {
519
- const res = await this._runNativeCommand('getZoom', this._nativeRef);
559
+ async getZoom(): Promise<number> {
560
+ const res: {zoom: number} = await this._runNativeCommand(
561
+ 'getZoom',
562
+ this._nativeRef,
563
+ );
520
564
  return res.zoom;
521
565
  }
522
566
 
@@ -528,8 +572,11 @@ class MapView extends NativeBridgeComponent(React.Component) {
528
572
  *
529
573
  * @return {Array<Number>} Coordinates
530
574
  */
531
- async getCenter() {
532
- const res = await this._runNativeCommand('getCenter', this._nativeRef);
575
+ async getCenter(): Promise<GeoJSON.Position> {
576
+ const res: {center: GeoJSON.Position} = await this._runNativeCommand(
577
+ 'getCenter',
578
+ this._nativeRef,
579
+ );
533
580
  return res.center;
534
581
  }
535
582
 
@@ -543,7 +590,11 @@ class MapView extends NativeBridgeComponent(React.Component) {
543
590
  * @param {String} sourceId - Identifier of the target source (e.g. 'composite')
544
591
  * @param {String=} sourceLayerId - Identifier of the target source-layer (e.g. 'building')
545
592
  */
546
- setSourceVisibility(visible, sourceId, sourceLayerId = undefined) {
593
+ setSourceVisibility(
594
+ visible: boolean,
595
+ sourceId: string,
596
+ sourceLayerId: string | null = null,
597
+ ): void {
547
598
  this._runNativeCommand('setSourceVisibility', this._nativeRef, [
548
599
  visible,
549
600
  sourceId,
@@ -555,73 +606,54 @@ class MapView extends NativeBridgeComponent(React.Component) {
555
606
  * Show the attribution and telemetry action sheet.
556
607
  * If you implement a custom attribution button, you should add this action to the button.
557
608
  */
558
- showAttribution() {
559
- return this._runNativeCommand('showAttribution', this._nativeRef);
560
- }
561
-
562
- _createStopConfig(config = {}) {
563
- const stopConfig = {
564
- mode: isNumber(config.mode) ? config.mode : MapLibreGL.CameraModes.Ease,
565
- pitch: config.pitch,
566
- heading: config.heading,
567
- duration: config.duration || 2000,
568
- zoom: config.zoom,
569
- };
570
-
571
- if (config.centerCoordinate) {
572
- stopConfig.centerCoordinate = toJSONString(
573
- makePoint(config.centerCoordinate),
574
- );
575
- }
576
-
577
- if (config.bounds && config.bounds.ne && config.bounds.sw) {
578
- const {ne, sw, paddingLeft, paddingRight, paddingTop, paddingBottom} =
579
- config.bounds;
580
- stopConfig.bounds = toJSONString(makeLatLngBounds(ne, sw));
581
- stopConfig.boundsPaddingTop = paddingTop || 0;
582
- stopConfig.boundsPaddingRight = paddingRight || 0;
583
- stopConfig.boundsPaddingBottom = paddingBottom || 0;
584
- stopConfig.boundsPaddingLeft = paddingLeft || 0;
585
- }
586
-
587
- return stopConfig;
609
+ async showAttribution(): Promise<void> {
610
+ this._runNativeCommand('showAttribution', this._nativeRef);
588
611
  }
589
612
 
590
- _onPress(e) {
613
+ _onPress(e: NativeSyntheticEvent<{payload: GeoJSON.Feature}>): void {
591
614
  if (isFunction(this.props.onPress)) {
592
615
  this.props.onPress(e.nativeEvent.payload);
593
616
  }
594
617
  }
595
618
 
596
- _onLongPress(e) {
619
+ _onLongPress(e: NativeSyntheticEvent<{payload: GeoJSON.Feature}>): void {
597
620
  if (isFunction(this.props.onLongPress)) {
598
621
  this.props.onLongPress(e.nativeEvent.payload);
599
622
  }
600
623
  }
601
624
 
602
- _onRegionWillChange(payload) {
625
+ _onRegionWillChange(
626
+ payload: GeoJSON.Feature<GeoJSON.Point, RegionPayload>,
627
+ ): void {
603
628
  if (isFunction(this.props.onRegionWillChange)) {
604
629
  this.props.onRegionWillChange(payload);
605
630
  }
606
631
  this.setState({isUserInteraction: payload.properties.isUserInteraction});
607
632
  }
608
633
 
609
- _onRegionDidChange(payload) {
634
+ _onRegionDidChange(
635
+ payload: GeoJSON.Feature<GeoJSON.Point, RegionPayload>,
636
+ ): void {
610
637
  if (isFunction(this.props.onRegionDidChange)) {
611
638
  this.props.onRegionDidChange(payload);
612
639
  }
613
640
  this.setState({region: payload});
614
641
  }
615
642
 
616
- _onChange(e) {
643
+ _onChange(
644
+ e: NativeSyntheticEvent<{
645
+ type: string;
646
+ payload?: GeoJSON.Feature | Location;
647
+ }>,
648
+ ): void {
617
649
  const {regionWillChangeDebounceTime, regionDidChangeDebounceTime} =
618
650
  this.props;
619
651
  const {type, payload} = e.nativeEvent;
620
- let propName = '';
652
+ let propName: CallableProps | undefined;
621
653
 
622
654
  switch (type) {
623
655
  case MapLibreGL.EventTypes.RegionWillChange:
624
- if (regionWillChangeDebounceTime > 0) {
656
+ if (regionWillChangeDebounceTime && regionWillChangeDebounceTime > 0) {
625
657
  this._onDebouncedRegionWillChange(payload);
626
658
  } else {
627
659
  propName = 'onRegionWillChange';
@@ -631,7 +663,7 @@ class MapView extends NativeBridgeComponent(React.Component) {
631
663
  propName = 'onRegionIsChanging';
632
664
  break;
633
665
  case MapLibreGL.EventTypes.RegionDidChange:
634
- if (regionDidChangeDebounceTime > 0) {
666
+ if (regionDidChangeDebounceTime && regionDidChangeDebounceTime > 0) {
635
667
  this._onDebouncedRegionDidChange(payload);
636
668
  } else {
637
669
  propName = 'onRegionDidChange';
@@ -674,12 +706,12 @@ class MapView extends NativeBridgeComponent(React.Component) {
674
706
  console.warn('Unhandled event callback type', type);
675
707
  }
676
708
 
677
- if (propName.length) {
709
+ if (propName) {
678
710
  this._handleOnChange(propName, payload);
679
711
  }
680
712
  }
681
713
 
682
- _onLayout(e) {
714
+ _onLayout(e: LayoutChangeEvent): void {
683
715
  this.setState({
684
716
  isReady: true,
685
717
  width: e.nativeEvent.layout.width,
@@ -687,32 +719,17 @@ class MapView extends NativeBridgeComponent(React.Component) {
687
719
  });
688
720
  }
689
721
 
690
- _handleOnChange(propName, payload) {
691
- if (isFunction(this.props[propName])) {
692
- this.props[propName](payload);
722
+ _handleOnChange<T extends CallableProps>(
723
+ propName: T,
724
+ payload?: object,
725
+ ): void {
726
+ const callable = this.props[propName] as (payload?: object) => void;
727
+ if (callable && isFunction(callable)) {
728
+ callable(payload);
693
729
  }
694
730
  }
695
731
 
696
- _getCenterCoordinate() {
697
- if (!this.props.centerCoordinate) {
698
- return;
699
- }
700
- return toJSONString(makePoint(this.props.centerCoordinate));
701
- }
702
-
703
- _getVisibleCoordinateBounds() {
704
- if (!this.props.visibleCoordinateBounds) {
705
- return;
706
- }
707
- return toJSONString(
708
- makeLatLngBounds(
709
- this.props.visibleCoordinateBounds[0],
710
- this.props.visibleCoordinateBounds[1],
711
- ),
712
- );
713
- }
714
-
715
- _getContentInset() {
732
+ _getContentInset(): number[] | undefined {
716
733
  if (!this.props.contentInset) {
717
734
  return;
718
735
  }
@@ -724,18 +741,18 @@ class MapView extends NativeBridgeComponent(React.Component) {
724
741
  return this.props.contentInset;
725
742
  }
726
743
 
727
- _setNativeRef(nativeRef) {
744
+ _setNativeRef(nativeRef: RCTMGLMapViewRefType): void {
728
745
  this._nativeRef = nativeRef;
729
746
  super._runPendingNativeCommands(nativeRef);
730
747
  }
731
748
 
732
- setNativeProps(props) {
749
+ setNativeProps(props: NativeProps): void {
733
750
  if (this._nativeRef) {
734
751
  this._nativeRef.setNativeProps(props);
735
752
  }
736
753
  }
737
754
 
738
- _setStyleURL(props) {
755
+ _setStyleURL(props: MapViewProps): void {
739
756
  // user set a styleURL, no need to alter props
740
757
  if (props.styleURL) {
741
758
  return;
@@ -753,7 +770,7 @@ class MapView extends NativeBridgeComponent(React.Component) {
753
770
  }
754
771
  }
755
772
 
756
- render() {
773
+ render(): ReactElement {
757
774
  const props = {
758
775
  ...this.props,
759
776
  contentInset: this._getContentInset(),
@@ -763,14 +780,14 @@ class MapView extends NativeBridgeComponent(React.Component) {
763
780
  this._setStyleURL(props);
764
781
 
765
782
  const callbacks = {
766
- ref: nativeRef => this._setNativeRef(nativeRef),
783
+ ref: (ref: RCTMGLMapViewRefType) => this._setNativeRef(ref),
767
784
  onPress: this._onPress,
768
785
  onLongPress: this._onLongPress,
769
786
  onMapChange: this._onChange,
770
787
  onAndroidCallback: isAndroid() ? this._onAndroidCallback : undefined,
771
788
  };
772
789
 
773
- let mapView = null;
790
+ let mapView: ReactElement | null = null;
774
791
  if (isAndroid() && !this.props.surfaceView && this.state.isReady) {
775
792
  mapView = (
776
793
  <RCTMGLAndroidTextureMapView {...props} {...callbacks}>
@@ -789,26 +806,20 @@ class MapView extends NativeBridgeComponent(React.Component) {
789
806
  <View
790
807
  onLayout={this._onLayout}
791
808
  style={this.props.style}
792
- testID={mapView ? null : this.props.testID}>
809
+ testID={mapView ? undefined : this.props.testID}>
793
810
  {mapView}
794
811
  </View>
795
812
  );
796
813
  }
797
814
  }
798
815
 
799
- const RCTMGLMapView = requireNativeComponent(NATIVE_MODULE_NAME, MapView, {
800
- nativeOnly: {onMapChange: true, onAndroidCallback: true},
801
- });
816
+ type RCTMGLMapViewRefType = Component<NativeProps> & Readonly<NativeMethods>;
817
+ const RCTMGLMapView = requireNativeComponent<NativeProps>(NATIVE_MODULE_NAME);
802
818
 
803
- let RCTMGLAndroidTextureMapView;
819
+ let RCTMGLAndroidTextureMapView: typeof RCTMGLMapView;
804
820
  if (isAndroid()) {
805
- RCTMGLAndroidTextureMapView = requireNativeComponent(
821
+ RCTMGLAndroidTextureMapView = requireNativeComponent<NativeProps>(
806
822
  ANDROID_TEXTURE_NATIVE_MODULE_NAME,
807
- MapView,
808
- {
809
- nativeOnly: {onMapChange: true, onAndroidCallback: true},
810
- },
811
823
  );
812
824
  }
813
-
814
825
  export default MapView;