@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.
Files changed (196) hide show
  1. package/README.md +3 -3
  2. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/CameraStop.kt +61 -46
  3. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImagesManager.kt +5 -5
  4. package/ios/RCTMGL-v10/RCMTGLImage.swift +2 -1
  5. package/ios/RCTMGL-v10/RCTMGLImages.swift +57 -17
  6. package/ios/RCTMGL-v10/RCTMGLMapView.swift +11 -1
  7. package/ios/RCTMGL-v10/RCTMGLUtils.swift +14 -5
  8. package/javascript/MGLModule.ts +54 -0
  9. package/javascript/Mapbox.ts +97 -0
  10. package/javascript/classes/index.d.ts +20 -1
  11. package/javascript/components/Annotation.tsx +141 -0
  12. package/javascript/components/Callout.d.ts +35 -0
  13. package/javascript/components/ImageSource.tsx +81 -0
  14. package/javascript/components/Images.tsx +58 -6
  15. package/javascript/components/{MapView.js → MapView.tsx} +456 -383
  16. package/javascript/components/MarkerView.tsx +3 -2
  17. package/javascript/components/NativeBridgeComponent.tsx +1 -1
  18. package/javascript/components/PointAnnotation.tsx +4 -3
  19. package/javascript/components/RasterDemSource.tsx +105 -0
  20. package/javascript/components/RasterSource.tsx +124 -0
  21. package/javascript/components/ShapeSource.tsx +1 -1
  22. package/javascript/components/{Style.js → Style.tsx} +117 -35
  23. package/javascript/components/Terrain.tsx +8 -7
  24. package/javascript/components/{UserLocation.js → UserLocation.tsx} +105 -94
  25. package/javascript/components/VectorSource.tsx +1 -1
  26. package/javascript/index.ts +4 -0
  27. package/javascript/modules/offline/{OfflineCreatePackOptions.js → OfflineCreatePackOptions.ts} +21 -6
  28. package/javascript/modules/offline/{OfflinePack.js → OfflinePack.ts} +19 -4
  29. package/javascript/modules/offline/{offlineManager.js → offlineManager.ts} +81 -21
  30. package/javascript/modules/snapshot/{SnapshotOptions.js → SnapshotOptions.ts} +27 -3
  31. package/javascript/modules/snapshot/{snapshotManager.js → snapshotManager.ts} +2 -1
  32. package/javascript/types/Position.ts +1 -0
  33. package/javascript/utils/Logger.ts +1 -1
  34. package/javascript/utils/geoUtils.ts +56 -0
  35. package/javascript/utils/{index.js → index.ts} +41 -19
  36. package/lib/commonjs/MGLModule.js +37 -0
  37. package/lib/commonjs/MGLModule.js.map +1 -0
  38. package/lib/commonjs/Mapbox.js +372 -0
  39. package/lib/commonjs/Mapbox.js.map +1 -0
  40. package/lib/commonjs/classes/index.d.js +2 -0
  41. package/lib/commonjs/classes/index.d.js.map +1 -1
  42. package/lib/commonjs/components/{annotations/Annotation.js → Annotation.js} +26 -27
  43. package/lib/commonjs/components/Annotation.js.map +1 -0
  44. package/lib/commonjs/components/Callout.d.js +9 -0
  45. package/lib/commonjs/components/Callout.d.js.map +1 -0
  46. package/lib/commonjs/components/ImageSource.js +8 -25
  47. package/lib/commonjs/components/ImageSource.js.map +1 -1
  48. package/lib/commonjs/components/Images.js +17 -1
  49. package/lib/commonjs/components/Images.js.map +1 -1
  50. package/lib/commonjs/components/MapView.js +30 -289
  51. package/lib/commonjs/components/MapView.js.map +1 -1
  52. package/lib/commonjs/components/MarkerView.js.map +1 -1
  53. package/lib/commonjs/components/NativeBridgeComponent.js.map +1 -1
  54. package/lib/commonjs/components/PointAnnotation.js.map +1 -1
  55. package/lib/commonjs/components/RasterDemSource.js +3 -37
  56. package/lib/commonjs/components/RasterDemSource.js.map +1 -1
  57. package/lib/commonjs/components/RasterSource.js +2 -46
  58. package/lib/commonjs/components/RasterSource.js.map +1 -1
  59. package/lib/commonjs/components/Style.js +11 -15
  60. package/lib/commonjs/components/Style.js.map +1 -1
  61. package/lib/commonjs/components/Terrain.js.map +1 -1
  62. package/lib/commonjs/components/UserLocation.js +26 -77
  63. package/lib/commonjs/components/UserLocation.js.map +1 -1
  64. package/lib/commonjs/index.js +16 -339
  65. package/lib/commonjs/index.js.map +1 -1
  66. package/lib/commonjs/modules/offline/OfflineCreatePackOptions.js +2 -4
  67. package/lib/commonjs/modules/offline/OfflineCreatePackOptions.js.map +1 -1
  68. package/lib/commonjs/modules/offline/OfflinePack.js.map +1 -1
  69. package/lib/commonjs/modules/offline/offlineManager.js +7 -2
  70. package/lib/commonjs/modules/offline/offlineManager.js.map +1 -1
  71. package/lib/commonjs/modules/snapshot/SnapshotOptions.js.map +1 -1
  72. package/lib/commonjs/modules/snapshot/snapshotManager.js.map +1 -1
  73. package/lib/commonjs/types/Position.js +2 -0
  74. package/lib/commonjs/{utils/index.d.js.map → types/Position.js.map} +1 -1
  75. package/lib/commonjs/utils/animated/Animated.js.map +1 -1
  76. package/lib/commonjs/utils/geoUtils.js +12 -38
  77. package/lib/commonjs/utils/geoUtils.js.map +1 -1
  78. package/lib/commonjs/utils/index.js +3 -6
  79. package/lib/commonjs/utils/index.js.map +1 -1
  80. package/lib/module/MGLModule.js +19 -0
  81. package/lib/module/MGLModule.js.map +1 -0
  82. package/lib/module/Mapbox.js +59 -0
  83. package/lib/module/Mapbox.js.map +1 -0
  84. package/lib/module/classes/index.d.js +2 -0
  85. package/lib/module/classes/index.d.js.map +1 -1
  86. package/lib/module/components/{annotations/Annotation.js → Annotation.js} +26 -27
  87. package/lib/module/components/Annotation.js.map +1 -0
  88. package/lib/module/components/Callout.d.js +2 -0
  89. package/lib/module/components/Callout.d.js.map +1 -0
  90. package/lib/module/components/ImageSource.js +8 -25
  91. package/lib/module/components/ImageSource.js.map +1 -1
  92. package/lib/module/components/Images.js +17 -1
  93. package/lib/module/components/Images.js.map +1 -1
  94. package/lib/module/components/MapView.js +31 -290
  95. package/lib/module/components/MapView.js.map +1 -1
  96. package/lib/module/components/MarkerView.js.map +1 -1
  97. package/lib/module/components/NativeBridgeComponent.js.map +1 -1
  98. package/lib/module/components/PointAnnotation.js.map +1 -1
  99. package/lib/module/components/RasterDemSource.js +4 -38
  100. package/lib/module/components/RasterDemSource.js.map +1 -1
  101. package/lib/module/components/RasterSource.js +3 -47
  102. package/lib/module/components/RasterSource.js.map +1 -1
  103. package/lib/module/components/Style.js +11 -15
  104. package/lib/module/components/Style.js.map +1 -1
  105. package/lib/module/components/Terrain.js.map +1 -1
  106. package/lib/module/components/UserLocation.js +25 -76
  107. package/lib/module/components/UserLocation.js.map +1 -1
  108. package/lib/module/index.js +3 -108
  109. package/lib/module/index.js.map +1 -1
  110. package/lib/module/modules/offline/OfflineCreatePackOptions.js +2 -4
  111. package/lib/module/modules/offline/OfflineCreatePackOptions.js.map +1 -1
  112. package/lib/module/modules/offline/OfflinePack.js.map +1 -1
  113. package/lib/module/modules/offline/offlineManager.js +1 -1
  114. package/lib/module/modules/offline/offlineManager.js.map +1 -1
  115. package/lib/module/modules/snapshot/SnapshotOptions.js.map +1 -1
  116. package/lib/module/modules/snapshot/snapshotManager.js.map +1 -1
  117. package/lib/module/types/Position.js +2 -0
  118. package/lib/module/{utils/index.d.js.map → types/Position.js.map} +1 -1
  119. package/lib/module/utils/animated/Animated.js.map +1 -1
  120. package/lib/module/utils/geoUtils.js +5 -32
  121. package/lib/module/utils/geoUtils.js.map +1 -1
  122. package/lib/module/utils/index.js +3 -5
  123. package/lib/module/utils/index.js.map +1 -1
  124. package/lib/typescript/MGLModule.d.ts +22 -0
  125. package/lib/typescript/MGLModule.d.ts.map +1 -0
  126. package/lib/typescript/Mapbox.d.ts +54 -0
  127. package/lib/typescript/Mapbox.d.ts.map +1 -0
  128. package/lib/typescript/components/Annotation.d.ts +34 -0
  129. package/lib/typescript/components/Annotation.d.ts.map +1 -0
  130. package/lib/typescript/components/ImageSource.d.ts +32 -0
  131. package/lib/typescript/components/ImageSource.d.ts.map +1 -0
  132. package/lib/typescript/components/Images.d.ts +24 -2
  133. package/lib/typescript/components/Images.d.ts.map +1 -1
  134. package/lib/typescript/components/MapView.d.ts +469 -0
  135. package/lib/typescript/components/MapView.d.ts.map +1 -0
  136. package/lib/typescript/components/MarkerView.d.ts +3 -2
  137. package/lib/typescript/components/MarkerView.d.ts.map +1 -1
  138. package/lib/typescript/components/NativeBridgeComponent.d.ts +1 -1
  139. package/lib/typescript/components/NativeBridgeComponent.d.ts.map +1 -1
  140. package/lib/typescript/components/PointAnnotation.d.ts +10 -4
  141. package/lib/typescript/components/PointAnnotation.d.ts.map +1 -1
  142. package/lib/typescript/components/RasterDemSource.d.ts +46 -0
  143. package/lib/typescript/components/RasterDemSource.d.ts.map +1 -0
  144. package/lib/typescript/components/RasterSource.d.ts +59 -0
  145. package/lib/typescript/components/RasterSource.d.ts.map +1 -0
  146. package/lib/typescript/components/ShapeSource.d.ts +2 -2
  147. package/lib/typescript/components/ShapeSource.d.ts.map +1 -1
  148. package/lib/typescript/components/Style.d.ts +74 -0
  149. package/lib/typescript/components/Style.d.ts.map +1 -0
  150. package/lib/typescript/components/Terrain.d.ts +2 -2
  151. package/lib/typescript/components/Terrain.d.ts.map +1 -1
  152. package/lib/typescript/components/UserLocation.d.ts +102 -0
  153. package/lib/typescript/components/UserLocation.d.ts.map +1 -0
  154. package/lib/typescript/components/VectorSource.d.ts +2 -2
  155. package/lib/typescript/components/VectorSource.d.ts.map +1 -1
  156. package/lib/typescript/index.d.ts +4 -0
  157. package/lib/typescript/index.d.ts.map +1 -0
  158. package/lib/typescript/modules/offline/OfflineCreatePackOptions.d.ts +22 -0
  159. package/lib/typescript/modules/offline/OfflineCreatePackOptions.d.ts.map +1 -0
  160. package/lib/typescript/modules/offline/OfflinePack.d.ts +24 -0
  161. package/lib/typescript/modules/offline/OfflinePack.d.ts.map +1 -0
  162. package/lib/typescript/modules/offline/offlineManager.d.ts +220 -0
  163. package/lib/typescript/modules/offline/offlineManager.d.ts.map +1 -0
  164. package/lib/typescript/modules/snapshot/SnapshotOptions.d.ts +41 -0
  165. package/lib/typescript/modules/snapshot/SnapshotOptions.d.ts.map +1 -0
  166. package/lib/typescript/modules/snapshot/snapshotManager.d.ts +52 -0
  167. package/lib/typescript/modules/snapshot/snapshotManager.d.ts.map +1 -0
  168. package/lib/typescript/types/Position.d.ts +2 -0
  169. package/lib/typescript/types/Position.d.ts.map +1 -0
  170. package/lib/typescript/utils/Logger.d.ts +1 -1
  171. package/lib/typescript/utils/Logger.d.ts.map +1 -1
  172. package/lib/typescript/utils/animated/Animated.d.ts +23 -0
  173. package/lib/typescript/utils/animated/Animated.d.ts.map +1 -0
  174. package/lib/typescript/utils/geoUtils.d.ts +15 -0
  175. package/lib/typescript/utils/geoUtils.d.ts.map +1 -0
  176. package/lib/typescript/utils/index.d.ts +48 -0
  177. package/lib/typescript/utils/index.d.ts.map +1 -0
  178. package/package.json +4 -4
  179. package/index.d.ts +0 -745
  180. package/javascript/components/ImageSource.js +0 -82
  181. package/javascript/components/RasterDemSource.js +0 -106
  182. package/javascript/components/RasterSource.js +0 -124
  183. package/javascript/components/annotations/Annotation.js +0 -122
  184. package/javascript/index.js +0 -162
  185. package/javascript/utils/geoUtils.d.ts +0 -10
  186. package/javascript/utils/geoUtils.js +0 -73
  187. package/javascript/utils/index.d.ts +0 -27
  188. package/lib/commonjs/components/annotations/Annotation.js.map +0 -1
  189. package/lib/commonjs/utils/geoUtils.d.js +0 -2
  190. package/lib/commonjs/utils/geoUtils.d.js.map +0 -1
  191. package/lib/commonjs/utils/index.d.js +0 -2
  192. package/lib/module/components/annotations/Annotation.js.map +0 -1
  193. package/lib/module/utils/geoUtils.d.js +0 -2
  194. package/lib/module/utils/geoUtils.d.js.map +0 -1
  195. package/lib/module/utils/index.d.js +0 -2
  196. /package/javascript/utils/animated/{Animated.js → Animated.ts} +0 -0
@@ -1,24 +1,27 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
1
+ import React, { Component } from 'react';
3
2
  import {
4
3
  View,
5
4
  StyleSheet,
6
5
  NativeModules,
7
6
  requireNativeComponent,
7
+ ViewProps,
8
+ NativeSyntheticEvent,
9
+ NativeMethods,
10
+ HostComponent,
11
+ LayoutChangeEvent,
8
12
  } from 'react-native';
9
13
  import { debounce } from 'debounce';
10
14
 
11
- import { makePoint, makeLatLngBounds } from '../utils/geoUtils';
12
15
  import {
13
16
  isFunction,
14
- isNumber,
15
- toJSONString,
16
17
  isAndroid,
17
- viewPropTypes,
18
- ornamentPositionPropType,
18
+ type NativeArg,
19
+ type OrnamentPositonProp,
19
20
  } from '../utils';
20
21
  import { getFilter } from '../utils/filterUtils';
21
22
  import Logger from '../utils/Logger';
23
+ import { FilterExpression } from '../utils/MapboxStyles';
24
+ import { type Position } from '../types/Position';
22
25
 
23
26
  import NativeBridgeComponent from './NativeBridgeComponent';
24
27
 
@@ -39,276 +42,334 @@ const styles = StyleSheet.create({
39
42
 
40
43
  const defaultStyleURL = MapboxGL.StyleURL.Street;
41
44
 
45
+ export type Point = {
46
+ x: number;
47
+ y: number;
48
+ };
49
+
50
+ type BBox = [number, number, number, number];
51
+
52
+ export type RegionPayload = {
53
+ zoomLevel: number;
54
+ heading: number;
55
+ animated: boolean;
56
+ isUserInteraction: boolean;
57
+ visibleBounds: GeoJSON.Position[];
58
+ pitch: number;
59
+ };
60
+
61
+ /**
62
+ * v10 only - experimental
63
+ */
64
+ export type MapState = {
65
+ properties: {
66
+ center: GeoJSON.Position;
67
+ bounds: {
68
+ ne: GeoJSON.Position;
69
+ sw: GeoJSON.Position;
70
+ };
71
+ zoom: number;
72
+ heading: number;
73
+ pitch: number;
74
+ };
75
+ gestures: {
76
+ isGestureActive: boolean;
77
+ isAnimatingFromGesture: boolean;
78
+ };
79
+ };
80
+
81
+ type Props = ViewProps & {
82
+ /**
83
+ * The distance from the edges of the map view’s frame to the edges of the map view’s logical viewport.
84
+ */
85
+ contentInset?: number | number[];
86
+
87
+ /**
88
+ * The projection used when rendering the map
89
+ */
90
+ projection?: 'mercator' | 'globe';
91
+
92
+ /**
93
+ * Style URL for map - notice, if non is set it _will_ default to `MapboxGL.StyleURL.Street`
94
+ */
95
+ styleURL?: string;
96
+
97
+ /**
98
+ * StyleJSON for map - according to TileJSON specs: https://github.com/mapbox/tilejson-spec
99
+ */
100
+ styleJSON?: string;
101
+
102
+ /**
103
+ * iOS: The preferred frame rate at which the map view is rendered.
104
+ * The default value for this property is MGLMapViewPreferredFramesPerSecondDefault,
105
+ * which will adaptively set the preferred frame rate based on the capability of
106
+ * the user’s device to maintain a smooth experience. This property can be set to arbitrary integer values.
107
+ *
108
+ * Android: The maximum frame rate at which the map view is rendered, but it can't exceed the ability of device hardware.
109
+ * This property can be set to arbitrary integer values.
110
+ */
111
+ preferredFramesPerSecond?: number;
112
+
113
+ /**
114
+ * Automatically change the language of the map labels to the system’s preferred language,
115
+ * this is not something that can be toggled on/off
116
+ */
117
+ localizeLabels?: boolean;
118
+
119
+ /**
120
+ * Enable/Disable zoom on the map
121
+ */
122
+ zoomEnabled?: boolean;
123
+
124
+ /**
125
+ * Enable/Disable scroll on the map
126
+ */
127
+ scrollEnabled?: boolean;
128
+
129
+ /**
130
+ * Enable/Disable pitch on map
131
+ */
132
+ pitchEnabled?: boolean;
133
+
134
+ /**
135
+ * Enable/Disable rotation on map
136
+ */
137
+ rotateEnabled?: boolean;
138
+
139
+ /**
140
+ * The Mapbox terms of service, which governs the use of Mapbox-hosted vector tiles and styles,
141
+ * [requires](https://www.mapbox.com/help/how-attribution-works/) these copyright notices to accompany any map that features Mapbox-designed styles, OpenStreetMap data, or other Mapbox data such as satellite or terrain data.
142
+ * If that applies to this map view, do not hide this view or remove any notices from it.
143
+ *
144
+ * You are additionally [required](https://www.mapbox.com/help/how-mobile-apps-work/#telemetry) to provide users with the option to disable anonymous usage and location sharing (telemetry).
145
+ * If this view is hidden, you must implement this setting elsewhere in your app. See our website for [Android](https://www.mapbox.com/android-docs/map-sdk/overview/#telemetry-opt-out) and [iOS](https://www.mapbox.com/ios-sdk/#telemetry_opt_out) for implementation details.
146
+ *
147
+ * Enable/Disable attribution on map. For iOS you need to add MGLMapboxMetricsEnabledSettingShownInApp=YES
148
+ * to your Info.plist
149
+ */
150
+ attributionEnabled?: boolean;
151
+
152
+ /**
153
+ * Adds attribution offset, e.g. `{top: 8, left: 8}` will put attribution button in top-left corner of the map. By default on Android, the attribution with information icon (i) will be on the bottom left, while on iOS the mapbox logo will be on bottom left with information icon (i) on bottom right. Read more about mapbox attribution [here](https://docs.mapbox.com/help/getting-started/attribution/)
154
+ */
155
+ attributionPosition?: OrnamentPositonProp;
156
+
157
+ /**
158
+ * MapView's tintColor
159
+ */
160
+ tintColor?: string | number[];
161
+
162
+ /**
163
+ * Enable/Disable the logo on the map.
164
+ */
165
+ logoEnabled?: boolean;
166
+
167
+ /**
168
+ * Adds logo offset, e.g. `{top: 8, left: 8}` will put the logo in top-left corner of the map
169
+ */
170
+ logoPosition?: OrnamentPositonProp;
171
+
172
+ /**
173
+ * Enable/Disable the compass from appearing on the map
174
+ */
175
+ compassEnabled: boolean;
176
+
177
+ /**
178
+ * [`mapbox` (v10) implementation only] Enable/Disable if the compass should fade out when the map is pointing north
179
+ */
180
+ compassFadeWhenNorth?: boolean;
181
+
182
+ /**
183
+ * [`mapbox` (v10) implementation only] Adds compass offset, e.g. `{top: 8, left: 8}` will put the compass in top-left corner of the map
184
+ */
185
+ compassPosition?: OrnamentPositonProp;
186
+
187
+ /**
188
+ * Change corner of map the compass starts at. 0: TopLeft, 1: TopRight, 2: BottomLeft, 3: BottomRight
189
+ */
190
+ compassViewPosition?: number;
191
+
192
+ /**
193
+ * Add margins to the compass with x and y values
194
+ */
195
+ compassViewMargins?: Point;
196
+
197
+ /**
198
+ * [iOS, `mapbox` (v10) implementation only] A string referencing an image key. Requires an `Images` component.
199
+ */
200
+ compassImage?: string;
201
+
202
+ /**
203
+ * [`mapbox` (v10) implementation only] Enable/Disable the scale bar from appearing on the map
204
+ */
205
+ scaleBarEnabled?: boolean;
206
+
207
+ /**
208
+ * [`mapbox` (v10) implementation only] Adds scale bar offset, e.g. `{top: 8, left: 8}` will put the scale bar in top-left corner of the map
209
+ */
210
+ scaleBarPosition?: OrnamentPositonProp;
211
+
212
+ /**
213
+ * [Android only] Enable/Disable use of GLSurfaceView instead of TextureView.
214
+ */
215
+ surfaceView?: boolean;
216
+
217
+ /**
218
+ * Map press listener, gets called when a user presses the map
219
+ */
220
+ onPress?: (feature: GeoJSON.Feature) => void;
221
+
222
+ /**
223
+ * Map long press listener, gets called when a user long presses the map
224
+ */
225
+ onLongPress?: (feature: GeoJSON.Feature) => void;
226
+
227
+ /**
228
+ * <v10 only
229
+ *
230
+ * This event is triggered whenever the currently displayed map region is about to change.
231
+ *
232
+ * @param {PointFeature} feature - The geojson point feature at the camera center, properties contains zoomLevel, visibleBounds
233
+ */
234
+ onRegionWillChange?: (
235
+ feature: GeoJSON.Feature<GeoJSON.Point, RegionPayload>,
236
+ ) => void;
237
+
238
+ /**
239
+ *
240
+ * This event is triggered whenever the currently displayed map region is changing.
241
+ *
242
+ * @param {PointFeature} feature - The geojson point feature at the camera center, properties contains zoomLevel, visibleBounds
243
+ */
244
+ onRegionIsChanging?: (
245
+ feature: GeoJSON.Feature<GeoJSON.Point, RegionPayload>,
246
+ ) => void;
247
+
248
+ /**
249
+ *
250
+ * This event is triggered whenever the currently displayed map region finished changing.
251
+ *
252
+ * @param {PointFeature} feature - The geojson point feature at the camera center, properties contains zoomLevel, visibleBounds
253
+ */
254
+ onRegionDidChange?: (
255
+ feature: GeoJSON.Feature<GeoJSON.Point, RegionPayload>,
256
+ ) => void;
257
+
258
+ /**
259
+ * iOS, v10 only, deprecated will be removed in next version - please use onRegionIsChanging.
260
+ */
261
+ onCameraChanged?: (state: MapState) => void;
262
+
263
+ /**
264
+ * iOS, v10 only, deprecated will be removed in next version - please use onRegionDidChange
265
+ */
266
+ onMapIdle?: (state: MapState) => void;
267
+
268
+ /**
269
+ * This event is triggered when the map is about to start loading a new map style.
270
+ */
271
+ onWillStartLoadingMap?: () => void;
272
+
273
+ /**
274
+ * This is triggered when the map has successfully loaded a new map style.
275
+ */
276
+ onDidFinishLoadingMap?: () => void;
277
+
278
+ /**
279
+ * This event is triggered when the map has failed to load a new map style. On v10 it's deprecated and replaced by onMapLoadingError
280
+ * @deprecated use onMapLoadingError
281
+ */
282
+ onDidFailLoadingMap?: () => void;
283
+
284
+ /**
285
+ * This event is tiggered when there is an error during map load. V10 only, replaces onDidFailLoadingMap, might be called multiple times and not exclusive with onDidFinishLoadingMap.
286
+ */
287
+ onMapLoadingError?: () => void;
288
+
289
+ /**
290
+ * This event is triggered when the map will start rendering a frame.
291
+ */
292
+ onWillStartRenderingFrame?: () => void;
293
+
294
+ /**
295
+ * This event is triggered when the map finished rendering a frame.
296
+ */
297
+ onDidFinishRenderingFrame?: () => void;
298
+
299
+ /**
300
+ * This event is triggered when the map fully finished rendering a frame.
301
+ */
302
+ onDidFinishRenderingFrameFully?: () => void;
303
+
304
+ /**
305
+ * This event is triggered when the map will start rendering the map.
306
+ */
307
+ onWillStartRenderingMap?: () => void;
308
+
309
+ /**
310
+ * This event is triggered when the map finished rendering the map.
311
+ */
312
+ onDidFinishRenderingMap?: () => void;
313
+
314
+ /**
315
+ * This event is triggered when the map fully finished rendering the map.
316
+ */
317
+ onDidFinishRenderingMapFully?: () => void;
318
+
319
+ /**
320
+ * This event is triggered when the user location is updated.
321
+ */
322
+ onUserLocationUpdate?: (feature: Location) => void;
323
+
324
+ /**
325
+ * This event is triggered when a style has finished loading.
326
+ */
327
+ onDidFinishLoadingStyle?: () => void;
328
+
329
+ /**
330
+ * The emitted frequency of regionwillchange events
331
+ */
332
+ regionWillChangeDebounceTime?: number;
333
+
334
+ /**
335
+ * The emitted frequency of regiondidchange events
336
+ */
337
+ regionDidChangeDebounceTime?: number;
338
+ };
339
+
340
+ type CallbablePropKeys =
341
+ | 'onRegionWillChange'
342
+ | 'onRegionIsChanging'
343
+ | 'onRegionDidChange'
344
+ | 'onUserLocationUpdate'
345
+ | 'onWillStartLoadingMap'
346
+ | 'onMapLoadingError'
347
+ | 'onDidFinishLoadingMap'
348
+ | 'onDidFailLoadingMap'
349
+ | 'onWillStartRenderingFrame'
350
+ | 'onDidFinishRenderingFrame'
351
+ | 'onDidFinishRenderingFrameFully'
352
+ | 'onWillStartRenderingMap'
353
+ | 'onDidFinishRenderingMap'
354
+ | 'onDidFinishRenderingMapFully'
355
+ | 'onDidFinishLoadingStyle'
356
+ | 'onMapIdle'
357
+ | 'onCameraChanged';
358
+
359
+ type CallbablePropKeysWithoutOn = CallbablePropKeys extends `on${infer C}`
360
+ ? C
361
+ : never;
362
+
363
+ type Debounced<F> = F & { clear(): void; flush(): void };
364
+
42
365
  /**
43
366
  * MapView backed by Mapbox Native GL
44
367
  */
45
368
  class MapView extends NativeBridgeComponent(
46
- React.Component,
369
+ React.PureComponent<Props>,
47
370
  NATIVE_MODULE_NAME,
48
371
  ) {
49
- static propTypes = {
50
- ...viewPropTypes,
51
-
52
- /**
53
- * The distance from the edges of the map view’s frame to the edges of the map view’s logical viewport.
54
- */
55
- contentInset: PropTypes.oneOfType([
56
- PropTypes.arrayOf(PropTypes.number),
57
- PropTypes.number,
58
- ]),
59
-
60
- /**
61
- * The projection used when rendering the map
62
- */
63
- projection: PropTypes.oneOf(['mercator', 'globe']),
64
-
65
- /**
66
- * Style for wrapping React Native View
67
- */
68
- style: PropTypes.any,
69
-
70
- /**
71
- * Style URL for map - notice, if non is set it _will_ default to `MapboxGL.StyleURL.Street`
72
- */
73
- styleURL: PropTypes.string,
74
-
75
- /**
76
- * StyleJSON for map - according to TileJSON specs: https://github.com/mapbox/tilejson-spec
77
- */
78
- styleJSON: PropTypes.string,
79
-
80
- /**
81
- * iOS: The preferred frame rate at which the map view is rendered.
82
- * The default value for this property is MGLMapViewPreferredFramesPerSecondDefault,
83
- * which will adaptively set the preferred frame rate based on the capability of
84
- * the user’s device to maintain a smooth experience. This property can be set to arbitrary integer values.
85
- *
86
- * Android: The maximum frame rate at which the map view is rendered, but it can't exceed the ability of device hardware.
87
- * This property can be set to arbitrary integer values.
88
- */
89
- preferredFramesPerSecond: PropTypes.number,
90
-
91
- /**
92
- * Automatically change the language of the map labels to the system’s preferred language,
93
- * this is not something that can be toggled on/off
94
- */
95
- localizeLabels: PropTypes.bool,
96
-
97
- /**
98
- * Enable/Disable zoom on the map
99
- */
100
- zoomEnabled: PropTypes.bool,
101
-
102
- /**
103
- * Enable/Disable scroll on the map
104
- */
105
- scrollEnabled: PropTypes.bool,
106
-
107
- /**
108
- * Enable/Disable pitch on map
109
- */
110
- pitchEnabled: PropTypes.bool,
111
-
112
- /**
113
- * Enable/Disable rotation on map
114
- */
115
- rotateEnabled: PropTypes.bool,
116
-
117
- /**
118
- * The Mapbox terms of service, which governs the use of Mapbox-hosted vector tiles and styles,
119
- * [requires](https://www.mapbox.com/help/how-attribution-works/) these copyright notices to accompany any map that features Mapbox-designed styles, OpenStreetMap data, or other Mapbox data such as satellite or terrain data.
120
- * If that applies to this map view, do not hide this view or remove any notices from it.
121
- *
122
- * You are additionally [required](https://www.mapbox.com/help/how-mobile-apps-work/#telemetry) to provide users with the option to disable anonymous usage and location sharing (telemetry).
123
- * If this view is hidden, you must implement this setting elsewhere in your app. See our website for [Android](https://www.mapbox.com/android-docs/map-sdk/overview/#telemetry-opt-out) and [iOS](https://www.mapbox.com/ios-sdk/#telemetry_opt_out) for implementation details.
124
- *
125
- * Enable/Disable attribution on map. For iOS you need to add MGLMapboxMetricsEnabledSettingShownInApp=YES
126
- * to your Info.plist
127
- */
128
- attributionEnabled: PropTypes.bool,
129
-
130
- /**
131
- * Adds attribution offset, e.g. `{top: 8, left: 8}` will put attribution button in top-left corner of the map. By default on Android, the attribution with information icon (i) will be on the bottom left, while on iOS the mapbox logo will be on bottom left with information icon (i) on bottom right. Read more about mapbox attribution [here](https://docs.mapbox.com/help/getting-started/attribution/)
132
- */
133
- attributionPosition: ornamentPositionPropType,
134
-
135
- /**
136
- * MapView's tintColor
137
- */
138
- tintColor: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
139
-
140
- /**
141
- * Enable/Disable the logo on the map.
142
- */
143
- logoEnabled: PropTypes.bool,
144
-
145
- /**
146
- * Adds logo offset, e.g. `{top: 8, left: 8}` will put the logo in top-left corner of the map
147
- */
148
- logoPosition: ornamentPositionPropType,
149
-
150
- /**
151
- * Enable/Disable the compass from appearing on the map
152
- */
153
- compassEnabled: PropTypes.bool,
154
-
155
- /**
156
- * [`mapbox` (v10) implementation only] Enable/Disable if the compass should fade out when the map is pointing north
157
- */
158
- compassFadeWhenNorth: PropTypes.bool,
159
-
160
- /**
161
- * [`mapbox` (v10) implementation only] Adds compass offset, e.g. `{top: 8, left: 8}` will put the compass in top-left corner of the map
162
- */
163
- compassPosition: ornamentPositionPropType,
164
-
165
- /**
166
- * Change corner of map the compass starts at. 0: TopLeft, 1: TopRight, 2: BottomLeft, 3: BottomRight
167
- */
168
- compassViewPosition: PropTypes.number,
169
-
170
- /**
171
- * Add margins to the compass with x and y values
172
- */
173
- compassViewMargins: PropTypes.object,
174
-
175
- /**
176
- * [iOS, `mapbox` (v10) implementation only] A string referencing an image key. Requires an `Images` component.
177
- */
178
- compassImage: PropTypes.string,
179
-
180
- /**
181
- * [`mapbox` (v10) implementation only] Enable/Disable the scale bar from appearing on the map
182
- */
183
- scaleBarEnabled: PropTypes.bool,
184
-
185
- /**
186
- * [`mapbox` (v10) implementation only] Adds scale bar offset, e.g. `{top: 8, left: 8}` will put the scale bar in top-left corner of the map
187
- */
188
- scaleBarPosition: ornamentPositionPropType,
189
-
190
- /**
191
- * [Android only] Enable/Disable use of GLSurfaceView instead of TextureView.
192
- */
193
- surfaceView: PropTypes.bool,
194
-
195
- /**
196
- * Map press listener, gets called when a user presses the map
197
- */
198
- onPress: PropTypes.func,
199
-
200
- /**
201
- * Map long press listener, gets called when a user long presses the map
202
- */
203
- onLongPress: PropTypes.func,
204
-
205
- /**
206
- * <v10 only
207
- *
208
- * This event is triggered whenever the currently displayed map region is about to change.
209
- *
210
- * @param {PointFeature} feature - The geojson point feature at the camera center, properties contains zoomLevel, visibleBounds
211
- */
212
- onRegionWillChange: PropTypes.func,
213
-
214
- /**
215
- *
216
- * This event is triggered whenever the currently displayed map region is changing.
217
- *
218
- * @param {PointFeature} feature - The geojson point feature at the camera center, properties contains zoomLevel, visibleBounds
219
- */
220
- onRegionIsChanging: PropTypes.func,
221
-
222
- /**
223
- *
224
- * This event is triggered whenever the currently displayed map region finished changing.
225
- *
226
- * @param {PointFeature} feature - The geojson point feature at the camera center, properties contains zoomLevel, visibleBounds
227
- */
228
- onRegionDidChange: PropTypes.func,
229
-
230
- /**
231
- * iOS, v10 only, deprecated will be removed in next version - please use onRegionIsChanging.
232
- */
233
- onCameraChanged: PropTypes.func,
234
-
235
- /**
236
- * iOS, v10 only, deprecated will be removed in next version - please use onRegionDidChange
237
- */
238
- onMapIdle: PropTypes.func,
239
-
240
- /**
241
- * This event is triggered when the map is about to start loading a new map style.
242
- */
243
- onWillStartLoadingMap: PropTypes.func,
244
-
245
- /**
246
- * This is triggered when the map has successfully loaded a new map style.
247
- */
248
- onDidFinishLoadingMap: PropTypes.func,
249
-
250
- /**
251
- * This event is triggered when the map has failed to load a new map style. On v10 it's deprecated and replaced by onMapLoadingError
252
- */
253
- onDidFailLoadingMap: PropTypes.func,
254
-
255
- /**
256
- * This event is tiggered when there is an error during map load. V10 only, replaces onDidFailLoadingMap, might be called multiple times and not exclusive with onDidFinishLoadingMap.
257
- */
258
- onMapLoadingError: PropTypes.func,
259
-
260
- /**
261
- * This event is triggered when the map will start rendering a frame.
262
- */
263
- onWillStartRenderingFrame: PropTypes.func,
264
-
265
- /**
266
- * This event is triggered when the map finished rendering a frame.
267
- */
268
- onDidFinishRenderingFrame: PropTypes.func,
269
-
270
- /**
271
- * This event is triggered when the map fully finished rendering a frame.
272
- */
273
- onDidFinishRenderingFrameFully: PropTypes.func,
274
-
275
- /**
276
- * This event is triggered when the map will start rendering the map.
277
- */
278
- onWillStartRenderingMap: PropTypes.func,
279
-
280
- /**
281
- * This event is triggered when the map finished rendering the map.
282
- */
283
- onDidFinishRenderingMap: PropTypes.func,
284
-
285
- /**
286
- * This event is triggered when the map fully finished rendering the map.
287
- */
288
- onDidFinishRenderingMapFully: PropTypes.func,
289
-
290
- /**
291
- * This event is triggered when the user location is updated.
292
- */
293
- onUserLocationUpdate: PropTypes.func,
294
-
295
- /**
296
- * This event is triggered when a style has finished loading.
297
- */
298
- onDidFinishLoadingStyle: PropTypes.func,
299
-
300
- /**
301
- * The emitted frequency of regionwillchange events
302
- */
303
- regionWillChangeDebounceTime: PropTypes.number,
304
-
305
- /**
306
- * The emitted frequency of regiondidchange events
307
- */
308
- regionDidChangeDebounceTime: PropTypes.number,
309
- };
310
-
311
- static defaultProps = {
372
+ static defaultProps: Props = {
312
373
  projection: 'mercator',
313
374
  localizeLabels: false,
314
375
  scrollEnabled: true,
@@ -324,7 +385,33 @@ class MapView extends NativeBridgeComponent(
324
385
  regionDidChangeDebounceTime: 500,
325
386
  };
326
387
 
327
- constructor(props) {
388
+ logger: Logger;
389
+ _onDebouncedRegionWillChange: Debounced<
390
+ (
391
+ payload: GeoJSON.Feature<
392
+ GeoJSON.Point,
393
+ RegionPayload & { isAnimatingFromUserInteraction: boolean }
394
+ >,
395
+ ) => void
396
+ >;
397
+ _onDebouncedRegionDidChange: Debounced<
398
+ (
399
+ payload: GeoJSON.Feature<
400
+ GeoJSON.Point,
401
+ RegionPayload & { isAnimatingFromUserInteraction: boolean }
402
+ >,
403
+ ) => void
404
+ >;
405
+ _nativeRef?: RCTMGLMapViewRefType;
406
+ state: {
407
+ isReady: boolean | null;
408
+ region: null;
409
+ width: number;
410
+ height: number;
411
+ isUserInteraction: boolean;
412
+ };
413
+
414
+ constructor(props: Props) {
328
415
  super(props);
329
416
 
330
417
  this.logger = Logger.sharedInstance();
@@ -366,15 +453,15 @@ class MapView extends NativeBridgeComponent(
366
453
  this.logger.stop();
367
454
  }
368
455
 
369
- UNSAFE_componentWillReceiveProps(nextProps) {
456
+ UNSAFE_componentWillReceiveProps(nextProps: Props) {
370
457
  this._setHandledMapChangedEvents(nextProps);
371
458
  }
372
459
 
373
- _setHandledMapChangedEvents(props) {
460
+ _setHandledMapChangedEvents(props: Props) {
374
461
  if (isAndroid() || MapboxGL.MapboxV10) {
375
- const events = [];
462
+ const events: string[] = [];
376
463
 
377
- function addIfHasHandler(name) {
464
+ function addIfHasHandler(name: CallbablePropKeysWithoutOn) {
378
465
  if (props[`on${name}`] != null) {
379
466
  if (MapboxGL.EventTypes[name] == null) {
380
467
  if (name === 'DidFailLoadingMap') {
@@ -447,13 +534,12 @@ class MapView extends NativeBridgeComponent(
447
534
  * @example
448
535
  * const pointInView = await this._map.getPointInView([-37.817070, 144.949901]);
449
536
  *
450
- * @param {Array<Number>} coordinate - A point expressed in the map view's coordinate system.
537
+ * @param {Array<number>} coordinate - A point expressed in the map view's coordinate system.
451
538
  * @return {Array}
452
539
  */
453
- async getPointInView(coordinate) {
454
- const res = await this._runNativeCommand(
540
+ async getPointInView(coordinate: Position): Promise<Position> {
541
+ const res = await this._runNative<{ pointInView: Position }>(
455
542
  'getPointInView',
456
- this._nativeRef,
457
543
  [coordinate],
458
544
  );
459
545
  return res.pointInView;
@@ -465,13 +551,12 @@ class MapView extends NativeBridgeComponent(
465
551
  * @example
466
552
  * const coordinate = await this._map.getCoordinateFromView([100, 100]);
467
553
  *
468
- * @param {Array<Number>} point - A point expressed in the given view’s coordinate system.
554
+ * @param {Array<number>} point - A point expressed in the given view’s coordinate system.
469
555
  * @return {Array}
470
556
  */
471
- async getCoordinateFromView(point) {
472
- const res = await this._runNativeCommand(
557
+ async getCoordinateFromView(point: Position): Promise<Position> {
558
+ const res = await this._runNative<{ coordinateFromView: Position }>(
473
559
  'getCoordinateFromView',
474
- this._nativeRef,
475
560
  [point],
476
561
  );
477
562
  return res.coordinateFromView;
@@ -485,10 +570,9 @@ class MapView extends NativeBridgeComponent(
485
570
  *
486
571
  * @return {Array}
487
572
  */
488
- async getVisibleBounds() {
489
- const res = await this._runNativeCommand(
573
+ async getVisibleBounds(): Promise<[Position, Position]> {
574
+ const res = await this._runNative<{ visibleBounds: [Position, Position] }>(
490
575
  'getVisibleBounds',
491
- this._nativeRef,
492
576
  );
493
577
  return res.visibleBounds;
494
578
  }
@@ -504,22 +588,26 @@ class MapView extends NativeBridgeComponent(
504
588
  * @param {Array=} layerIDs - A array of layer id's to filter the features by
505
589
  * @return {FeatureCollection}
506
590
  */
507
- async queryRenderedFeaturesAtPoint(coordinate, filter = [], layerIDs = []) {
591
+
592
+ async queryRenderedFeaturesAtPoint(
593
+ coordinate: Position,
594
+ filter: FilterExpression | [] = [],
595
+ layerIDs: string[] = [],
596
+ ): Promise<GeoJSON.FeatureCollection | undefined> {
508
597
  if (!coordinate || coordinate.length < 2) {
509
598
  throw new Error('Must pass in valid coordinate[lng, lat]');
510
599
  }
511
600
 
512
- const res = await this._runNativeCommand(
601
+ const res = await this._runNative<{ data: GeoJSON.FeatureCollection }>(
513
602
  'queryRenderedFeaturesAtPoint',
514
- this._nativeRef,
515
603
  [coordinate, getFilter(filter), layerIDs],
516
604
  );
517
605
 
518
606
  if (isAndroid()) {
519
- return JSON.parse(res.data);
607
+ return JSON.parse(res.data as unknown as string);
520
608
  }
521
609
 
522
- return res.data;
610
+ return res.data as GeoJSON.FeatureCollection;
523
611
  }
524
612
 
525
613
  /**
@@ -535,19 +623,22 @@ class MapView extends NativeBridgeComponent(
535
623
  * @param {Array=} layerIDs - A array of layer id's to filter the features by
536
624
  * @return {FeatureCollection}
537
625
  */
538
- async queryRenderedFeaturesInRect(bbox, filter = [], layerIDs = null) {
626
+ async queryRenderedFeaturesInRect(
627
+ bbox: BBox | [],
628
+ filter: FilterExpression | [] = [],
629
+ layerIDs: string[] | null = null,
630
+ ): Promise<GeoJSON.FeatureCollection | undefined> {
539
631
  if (
540
632
  bbox != null &&
541
633
  (bbox.length === 4 || (MapboxGL.MapboxV10 && bbox.length === 0))
542
634
  ) {
543
- const res = await this._runNativeCommand(
635
+ const res = await this._runNative<{ data: GeoJSON.FeatureCollection }>(
544
636
  'queryRenderedFeaturesInRect',
545
- this._nativeRef,
546
637
  [bbox, getFilter(filter), layerIDs],
547
638
  );
548
639
 
549
640
  if (isAndroid()) {
550
- return JSON.parse(res.data);
641
+ return JSON.parse(res.data as unknown as string);
551
642
  }
552
643
 
553
644
  return res.data;
@@ -560,6 +651,7 @@ class MapView extends NativeBridgeComponent(
560
651
 
561
652
  /**
562
653
  * Map camera will perform updates based on provided config. Deprecated use Camera#setCamera.
654
+ * @deprecated use Camera#setCamera
563
655
  */
564
656
  setCamera() {
565
657
  console.warn(
@@ -567,13 +659,24 @@ class MapView extends NativeBridgeComponent(
567
659
  );
568
660
  }
569
661
 
662
+ _runNative<ReturnType>(
663
+ methodName: string,
664
+ args: NativeArg[] = [],
665
+ ): Promise<ReturnType> {
666
+ return super._runNativeCommand<typeof RCTMGLMapView, ReturnType>(
667
+ methodName,
668
+ this._nativeRef as HostComponent<NativeProps> | undefined,
669
+ args,
670
+ );
671
+ }
672
+
570
673
  /**
571
674
  * Takes snapshot of map with current tiles and returns a URI to the image
572
675
  * @param {Boolean} writeToDisk If true will create a temp file, otherwise it is in base64
573
676
  * @return {String}
574
677
  */
575
- async takeSnap(writeToDisk = false) {
576
- const res = await this._runNativeCommand('takeSnap', this._nativeRef, [
678
+ async takeSnap(writeToDisk = false): Promise<string> {
679
+ const res = await this._runNative<{ uri: string }>('takeSnap', [
577
680
  writeToDisk,
578
681
  ]);
579
682
  return res.uri;
@@ -588,8 +691,8 @@ class MapView extends NativeBridgeComponent(
588
691
  * @return {Number}
589
692
  */
590
693
 
591
- async getZoom() {
592
- const res = await this._runNativeCommand('getZoom', this._nativeRef);
694
+ async getZoom(): Promise<number> {
695
+ const res = await this._runNative<{ zoom: number }>('getZoom');
593
696
  return res.zoom;
594
697
  }
595
698
 
@@ -601,8 +704,8 @@ class MapView extends NativeBridgeComponent(
601
704
  *
602
705
  * @return {Array<Number>} Coordinates
603
706
  */
604
- async getCenter() {
605
- const res = await this._runNativeCommand('getCenter', this._nativeRef);
707
+ async getCenter(): Promise<Position> {
708
+ const res = await this._runNative<{ center: Position }>('getCenter');
606
709
  return res.center;
607
710
  }
608
711
 
@@ -614,10 +717,9 @@ class MapView extends NativeBridgeComponent(
614
717
  * @param {Array<Number>} coordinate - the coordinates to query elevation at
615
718
  * @return {Number}
616
719
  */
617
- async queryTerrainElevation(coordinate) {
618
- const res = await this._runNativeCommand(
720
+ async queryTerrainElevation(coordinate: Position): Promise<number> {
721
+ const res = await this._runNative<{ data: number }>(
619
722
  'queryTerrainElevation',
620
- this._nativeRef,
621
723
  [coordinate],
622
724
  );
623
725
  return res.data;
@@ -633,8 +735,12 @@ class MapView extends NativeBridgeComponent(
633
735
  * @param {String} sourceId - Identifier of the target source (e.g. 'composite')
634
736
  * @param {String=} sourceLayerId - Identifier of the target source-layer (e.g. 'building')
635
737
  */
636
- setSourceVisibility(visible, sourceId, sourceLayerId = undefined) {
637
- this._runNativeCommand('setSourceVisibility', this._nativeRef, [
738
+ setSourceVisibility(
739
+ visible: boolean,
740
+ sourceId: string,
741
+ sourceLayerId: string | null = null,
742
+ ) {
743
+ this._runNative<void>('setSourceVisibility', [
638
744
  visible,
639
745
  sourceId,
640
746
  sourceLayerId,
@@ -649,47 +755,24 @@ class MapView extends NativeBridgeComponent(
649
755
  return this._runNativeCommand('showAttribution', this._nativeRef);
650
756
  }
651
757
 
652
- _createStopConfig(config = {}) {
653
- const stopConfig = {
654
- mode: isNumber(config.mode) ? config.mode : MapboxGL.CameraModes.Ease,
655
- pitch: config.pitch,
656
- heading: config.heading,
657
- duration: config.duration || 2000,
658
- zoom: config.zoom,
659
- };
660
-
661
- if (config.centerCoordinate) {
662
- stopConfig.centerCoordinate = toJSONString(
663
- makePoint(config.centerCoordinate),
664
- );
665
- }
666
-
667
- if (config.bounds && config.bounds.ne && config.bounds.sw) {
668
- const { ne, sw, paddingLeft, paddingRight, paddingTop, paddingBottom } =
669
- config.bounds;
670
- stopConfig.bounds = toJSONString(makeLatLngBounds(ne, sw));
671
- stopConfig.boundsPaddingTop = paddingTop || 0;
672
- stopConfig.boundsPaddingRight = paddingRight || 0;
673
- stopConfig.boundsPaddingBottom = paddingBottom || 0;
674
- stopConfig.boundsPaddingLeft = paddingLeft || 0;
675
- }
676
-
677
- return stopConfig;
678
- }
679
-
680
- _onPress(e) {
758
+ _onPress(e: NativeSyntheticEvent<{ payload: GeoJSON.Feature }>) {
681
759
  if (isFunction(this.props.onPress)) {
682
760
  this.props.onPress(e.nativeEvent.payload);
683
761
  }
684
762
  }
685
763
 
686
- _onLongPress(e) {
764
+ _onLongPress(e: NativeSyntheticEvent<{ payload: GeoJSON.Feature }>) {
687
765
  if (isFunction(this.props.onLongPress)) {
688
766
  this.props.onLongPress(e.nativeEvent.payload);
689
767
  }
690
768
  }
691
769
 
692
- _onRegionWillChange(payload) {
770
+ _onRegionWillChange(
771
+ payload: GeoJSON.Feature<
772
+ GeoJSON.Point,
773
+ RegionPayload & { isAnimatingFromUserInteraction: boolean }
774
+ >,
775
+ ) {
693
776
  if (isFunction(this.props.onRegionWillChange)) {
694
777
  this.props.onRegionWillChange(payload);
695
778
  }
@@ -700,23 +783,31 @@ class MapView extends NativeBridgeComponent(
700
783
  });
701
784
  }
702
785
 
703
- _onRegionDidChange(payload) {
786
+ _onRegionDidChange(payload: GeoJSON.Feature<GeoJSON.Point, RegionPayload>) {
704
787
  if (isFunction(this.props.onRegionDidChange)) {
705
788
  this.props.onRegionDidChange(payload);
706
789
  }
707
790
  this.setState({ region: payload });
708
791
  }
709
792
 
710
- _onChange(e) {
793
+ _onChange(
794
+ e: NativeSyntheticEvent<{
795
+ type: string;
796
+ payload: GeoJSON.Feature<
797
+ GeoJSON.Point,
798
+ RegionPayload & { isAnimatingFromUserInteraction: boolean }
799
+ >;
800
+ }>,
801
+ ) {
711
802
  const { regionWillChangeDebounceTime, regionDidChangeDebounceTime } =
712
803
  this.props;
713
804
  const { type, payload } = e.nativeEvent;
714
- let propName = '';
715
- let deprecatedPropName = '';
805
+ let propName: CallbablePropKeys | '' = '';
806
+ let deprecatedPropName: CallbablePropKeys | '' = '';
716
807
 
717
808
  switch (type) {
718
809
  case MapboxGL.EventTypes.RegionWillChange:
719
- if (regionWillChangeDebounceTime > 0) {
810
+ if (regionWillChangeDebounceTime && regionWillChangeDebounceTime > 0) {
720
811
  this._onDebouncedRegionWillChange(payload);
721
812
  } else {
722
813
  propName = 'onRegionWillChange';
@@ -726,7 +817,7 @@ class MapView extends NativeBridgeComponent(
726
817
  propName = 'onRegionIsChanging';
727
818
  break;
728
819
  case MapboxGL.EventTypes.RegionDidChange:
729
- if (regionDidChangeDebounceTime > 0) {
820
+ if (regionDidChangeDebounceTime && regionDidChangeDebounceTime > 0) {
730
821
  this._onDebouncedRegionDidChange(payload);
731
822
  } else {
732
823
  propName = 'onRegionDidChange';
@@ -779,15 +870,15 @@ class MapView extends NativeBridgeComponent(
779
870
  console.warn('Unhandled event callback type', type);
780
871
  }
781
872
 
782
- if (propName.length) {
873
+ if (propName !== '') {
783
874
  this._handleOnChange(propName, payload);
784
875
  }
785
- if (deprecatedPropName.length) {
876
+ if (deprecatedPropName !== '') {
786
877
  this._handleOnChange(deprecatedPropName, payload);
787
878
  }
788
879
  }
789
880
 
790
- _onLayout(e) {
881
+ _onLayout(e: LayoutChangeEvent) {
791
882
  this.setState({
792
883
  isReady: true,
793
884
  width: e.nativeEvent.layout.width,
@@ -795,31 +886,13 @@ class MapView extends NativeBridgeComponent(
795
886
  });
796
887
  }
797
888
 
798
- _handleOnChange(propName, payload) {
799
- if (isFunction(this.props[propName])) {
800
- this.props[propName](payload);
889
+ _handleOnChange<T>(propName: CallbablePropKeys, payload: object) {
890
+ const func = this.props[propName] as (payload: object) => void;
891
+ if (func && isFunction(func)) {
892
+ func(payload);
801
893
  }
802
894
  }
803
895
 
804
- _getCenterCoordinate() {
805
- if (!this.props.centerCoordinate) {
806
- return;
807
- }
808
- return toJSONString(makePoint(this.props.centerCoordinate));
809
- }
810
-
811
- _getVisibleCoordinateBounds() {
812
- if (!this.props.visibleCoordinateBounds) {
813
- return;
814
- }
815
- return toJSONString(
816
- makeLatLngBounds(
817
- this.props.visibleCoordinateBounds[0],
818
- this.props.visibleCoordinateBounds[1],
819
- ),
820
- );
821
- }
822
-
823
896
  _getContentInset() {
824
897
  if (!this.props.contentInset) {
825
898
  return;
@@ -832,18 +905,18 @@ class MapView extends NativeBridgeComponent(
832
905
  return this.props.contentInset;
833
906
  }
834
907
 
835
- _setNativeRef(nativeRef) {
908
+ _setNativeRef(nativeRef: RCTMGLMapViewRefType) {
836
909
  this._nativeRef = nativeRef;
837
910
  super._runPendingNativeCommands(nativeRef);
838
911
  }
839
912
 
840
- setNativeProps(props) {
913
+ setNativeProps(props: NativeProps) {
841
914
  if (this._nativeRef) {
842
915
  this._nativeRef.setNativeProps(props);
843
916
  }
844
917
  }
845
918
 
846
- _setStyleURL(props) {
919
+ _setStyleURL(props: Props) {
847
920
  // user set a styleURL, no need to alter props
848
921
  if (props.styleURL) {
849
922
  return;
@@ -871,7 +944,7 @@ class MapView extends NativeBridgeComponent(
871
944
  this._setStyleURL(props);
872
945
 
873
946
  const callbacks = {
874
- ref: (nativeRef) => this._setNativeRef(nativeRef),
947
+ ref: (nativeRef: RCTMGLMapViewRefType) => this._setNativeRef(nativeRef),
875
948
  onPress: this._onPress,
876
949
  onLongPress: this._onLongPress,
877
950
  onMapChange: this._onChange,
@@ -897,7 +970,7 @@ class MapView extends NativeBridgeComponent(
897
970
  <View
898
971
  onLayout={this._onLayout}
899
972
  style={this.props.style}
900
- testID={mapView ? null : this.props.testID}
973
+ testID={mapView ? undefined : this.props.testID}
901
974
  >
902
975
  {mapView}
903
976
  </View>
@@ -905,18 +978,18 @@ class MapView extends NativeBridgeComponent(
905
978
  }
906
979
  }
907
980
 
908
- const RCTMGLMapView = requireNativeComponent(NATIVE_MODULE_NAME, MapView, {
909
- nativeOnly: { onMapChange: true, onAndroidCallback: true },
910
- });
981
+ type NativeProps = Omit<Props, 'onPress' | 'onLongPress'> & {
982
+ onPress(event: NativeSyntheticEvent<{ payload: GeoJSON.Feature }>): void;
983
+ onLongPress(event: NativeSyntheticEvent<{ payload: GeoJSON.Feature }>): void;
984
+ };
985
+
986
+ type RCTMGLMapViewRefType = Component<NativeProps> & Readonly<NativeMethods>;
987
+ const RCTMGLMapView = requireNativeComponent<NativeProps>(NATIVE_MODULE_NAME);
911
988
 
912
- let RCTMGLAndroidTextureMapView;
989
+ let RCTMGLAndroidTextureMapView: typeof RCTMGLMapView;
913
990
  if (isAndroid()) {
914
- RCTMGLAndroidTextureMapView = requireNativeComponent(
991
+ RCTMGLAndroidTextureMapView = requireNativeComponent<NativeProps>(
915
992
  ANDROID_TEXTURE_NATIVE_MODULE_NAME,
916
- MapView,
917
- {
918
- nativeOnly: { onMapChange: true, onAndroidCallback: true },
919
- },
920
993
  );
921
994
  }
922
995