@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
@@ -9,6 +9,7 @@ import {
9
9
 
10
10
  import { toJSONString } from '../utils';
11
11
  import { makePoint } from '../utils/geoUtils';
12
+ import { type Position } from '../types/Position';
12
13
 
13
14
  import PointAnnotation from './PointAnnotation';
14
15
 
@@ -20,7 +21,7 @@ type Props = ViewProps & {
20
21
  /**
21
22
  * The center point (specified as a map coordinate) of the marker.
22
23
  */
23
- coordinate: [number, number];
24
+ coordinate: Position;
24
25
 
25
26
  /**
26
27
  * Any coordinate between (0, 0) and (1, 1), where (0, 0) is the top-left corner of
@@ -78,7 +79,7 @@ class MarkerView extends React.PureComponent<Props> {
78
79
  return this.__idForPointAnnotation;
79
80
  }
80
81
 
81
- _getCoordinate(coordinate: [number, number]): string | undefined {
82
+ _getCoordinate(coordinate: Position): string | undefined {
82
83
  if (!coordinate) {
83
84
  return undefined;
84
85
  }
@@ -82,7 +82,7 @@ const NativeBridgeComponent = <
82
82
 
83
83
  _runNativeCommand<RefType, ReturnType = NativeArg>(
84
84
  methodName: string,
85
- nativeRef: RefType,
85
+ nativeRef: RefType | undefined,
86
86
  args: NativeArg[] = [],
87
87
  ): Promise<ReturnType> {
88
88
  if (!nativeRef) {
@@ -10,6 +10,7 @@ import { type Feature } from 'geojson';
10
10
  import { toJSONString, isFunction } from '../utils';
11
11
  import { makePoint } from '../utils/geoUtils';
12
12
  import { type BaseProps } from '../types/BaseProps';
13
+ import { Position } from '../types/Position';
13
14
 
14
15
  import NativeBridgeComponent, { type RNMBEvent } from './NativeBridgeComponent';
15
16
 
@@ -24,7 +25,7 @@ const styles = StyleSheet.create({
24
25
  });
25
26
 
26
27
  type FeaturePayload = {
27
- feature: Feature;
28
+ feature: Feature<GeoJSON.Point, { id: string }>;
28
29
  };
29
30
 
30
31
  type Props = BaseProps & {
@@ -56,7 +57,7 @@ type Props = BaseProps & {
56
57
  /**
57
58
  * The center point (specified as a map coordinate) of the annotation.
58
59
  */
59
- coordinate: [number, number];
60
+ coordinate: Position;
60
61
 
61
62
  /**
62
63
  * Specifies the anchor being set on a particular point of the annotation.
@@ -104,7 +105,7 @@ type Props = BaseProps & {
104
105
  /**
105
106
  * Expects one child, and an optional callout can be added as well
106
107
  */
107
- children: React.ReactElement;
108
+ children: React.ReactElement | [React.ReactElement, React.ReactElement];
108
109
 
109
110
  style?: ViewProps['style'];
110
111
  };
@@ -0,0 +1,105 @@
1
+ import React from 'react';
2
+ import { NativeModules, requireNativeComponent } from 'react-native';
3
+
4
+ import { cloneReactChildrenWithProps } from '../utils';
5
+
6
+ import AbstractSource from './AbstractSource';
7
+
8
+ const isTileTemplateUrl = (url?: string): url is string =>
9
+ !!url &&
10
+ (url.includes('{z}') || url.includes('{bbox-') || url.includes('{quadkey}'));
11
+
12
+ const MapboxGL = NativeModules.MGLModule;
13
+
14
+ export const NATIVE_MODULE_NAME = 'RCTMGLRasterDemSource';
15
+
16
+ type Props = {
17
+ /**
18
+ * A string that uniquely identifies the source.
19
+ */
20
+ id: string;
21
+
22
+ /**
23
+ * A URL to a TileJSON configuration file describing the source’s contents and other metadata.
24
+ */
25
+ url?: string;
26
+
27
+ /**
28
+ * An array of tile URL templates. If multiple endpoints are specified, clients may use any combination of endpoints.
29
+ * Example: https://example.com/raster-tiles/{z}/{x}/{y}.png
30
+ */
31
+ tileUrlTemplates?: string[];
32
+
33
+ /**
34
+ * An unsigned integer that specifies the minimum zoom level at which to display tiles from the source.
35
+ * The value should be between 0 and 22, inclusive, and less than
36
+ * maxZoomLevel, if specified. The default value for this option is 0.
37
+ */
38
+ minZoomLevel?: number;
39
+
40
+ /**
41
+ * An unsigned integer that specifies the maximum zoom level at which to display tiles from the source.
42
+ * The value should be between 0 and 22, inclusive, and less than
43
+ * minZoomLevel, if specified. The default value for this option is 22.
44
+ */
45
+ maxZoomLevel?: number;
46
+
47
+ /**
48
+ * Size of the map tiles.
49
+ * Mapbox urls default to 256, all others default to 512.
50
+ */
51
+ tileSize?: number;
52
+
53
+ children?: React.ReactElement | React.ReactElement[];
54
+ };
55
+
56
+ type NativeProps = Props;
57
+
58
+ class RasterDemSource extends AbstractSource<Props, NativeProps> {
59
+ static defaultProps = {
60
+ id: MapboxGL.StyleSource.DefaultSourceID,
61
+ };
62
+
63
+ constructor(props: Props) {
64
+ super(props);
65
+ if (isTileTemplateUrl(props.url)) {
66
+ console.warn(
67
+ `RasterDemSource 'url' property contains a Tile URL Template, but is intended for a StyleJSON URL. Please migrate your VectorSource to use: \`tileUrlTemplates=["${props.url}"]\` instead.`,
68
+ );
69
+ }
70
+ }
71
+
72
+ render() {
73
+ let { url } = this.props;
74
+ let { tileUrlTemplates } = this.props;
75
+
76
+ // Swapping url for tileUrlTemplates to provide backward compatibility
77
+ // when RasterSource supported only tile url as url prop
78
+ if (isTileTemplateUrl(url)) {
79
+ tileUrlTemplates = [url];
80
+ url = undefined;
81
+ }
82
+
83
+ const props = {
84
+ ...this.props,
85
+ id: this.props.id,
86
+ url,
87
+ tileUrlTemplates,
88
+ minZoomLevel: this.props.minZoomLevel,
89
+ maxZoomLevel: this.props.maxZoomLevel,
90
+ tileSize: this.props.tileSize,
91
+ };
92
+ return (
93
+ <RCTMGLRasterDemSource ref={this.setNativeRef} {...props}>
94
+ {cloneReactChildrenWithProps(this.props.children, {
95
+ sourceID: this.props.id,
96
+ })}
97
+ </RCTMGLRasterDemSource>
98
+ );
99
+ }
100
+ }
101
+
102
+ const RCTMGLRasterDemSource =
103
+ requireNativeComponent<NativeProps>(NATIVE_MODULE_NAME);
104
+
105
+ export default RasterDemSource;
@@ -0,0 +1,124 @@
1
+ import React from 'react';
2
+ import { NativeModules, requireNativeComponent } from 'react-native';
3
+
4
+ import { cloneReactChildrenWithProps } from '../utils';
5
+ import { BaseProps } from '../types/BaseProps';
6
+
7
+ import AbstractSource from './AbstractSource';
8
+
9
+ const MapboxGL = NativeModules.MGLModule;
10
+
11
+ export const NATIVE_MODULE_NAME = 'RCTMGLRasterSource';
12
+
13
+ const isTileTemplateUrl = (url?: string): url is string =>
14
+ !!url &&
15
+ (url.includes('{z}') || url.includes('{bbox-') || url.includes('{quadkey}'));
16
+
17
+ type Props = BaseProps & {
18
+ /**
19
+ * A string that uniquely identifies the source.
20
+ */
21
+ id: string;
22
+
23
+ /**
24
+ * A URL to a TileJSON configuration file describing the source’s contents and other metadata.
25
+ */
26
+ url?: string;
27
+
28
+ /**
29
+ * An array of tile URL templates. If multiple endpoints are specified, clients may use any combination of endpoints.
30
+ * Example: https://example.com/raster-tiles/{z}/{x}/{y}.png
31
+ */
32
+ tileUrlTemplates?: string[];
33
+
34
+ /**
35
+ * An unsigned integer that specifies the minimum zoom level at which to display tiles from the source.
36
+ * The value should be between 0 and 22, inclusive, and less than
37
+ * maxZoomLevel, if specified. The default value for this option is 0.
38
+ */
39
+ minZoomLevel?: number;
40
+
41
+ /**
42
+ * An unsigned integer that specifies the maximum zoom level at which to display tiles from the source.
43
+ * The value should be between 0 and 22, inclusive, and less than
44
+ * minZoomLevel, if specified. The default value for this option is 22.
45
+ */
46
+ maxZoomLevel?: number;
47
+
48
+ /**
49
+ * Size of the map tiles.
50
+ * Mapbox urls default to 256, all others default to 512.
51
+ */
52
+ tileSize?: number;
53
+
54
+ /**
55
+ * Influences the y direction of the tile coordinates. (tms inverts y axis)
56
+ */
57
+ tms?: boolean;
58
+
59
+ /**
60
+ * An HTML or literal text string defining the buttons to be displayed in an action sheet when the
61
+ * source is part of a map view’s style and the map view’s attribution button is pressed.
62
+ */
63
+ attribution?: string;
64
+
65
+ children?: React.ReactElement | React.ReactElement[];
66
+ };
67
+
68
+ type NativeProps = Props;
69
+
70
+ /**
71
+ * RasterSource is a map content source that supplies raster image tiles to be shown on the map.
72
+ * The location of and metadata about the tiles are defined either by an option dictionary
73
+ * or by an external file that conforms to the TileJSON specification.
74
+ */
75
+ class RasterSource extends AbstractSource<Props, NativeProps> {
76
+ static defaultProps: Props = {
77
+ id: MapboxGL.StyleSource.DefaultSourceID,
78
+ };
79
+
80
+ constructor(props: Props) {
81
+ super(props);
82
+ if (isTileTemplateUrl(props.url)) {
83
+ console.warn(
84
+ `RasterSource 'url' property contains a Tile URL Template, but is intended for a StyleJSON URL. Please migrate your VectorSource to use: \`tileUrlTemplates=["${props.url}"]\` instead.`,
85
+ );
86
+ }
87
+ }
88
+
89
+ render() {
90
+ let { url } = this.props;
91
+ let { tileUrlTemplates } = this.props;
92
+
93
+ // Swapping url for tileUrlTemplates to provide backward compatibility
94
+ // when RasterSource supported only tile url as url prop
95
+ if (isTileTemplateUrl(url)) {
96
+ tileUrlTemplates = [url];
97
+ url = undefined;
98
+ }
99
+
100
+ const props = {
101
+ ...this.props,
102
+ id: this.props.id,
103
+ url,
104
+ tileUrlTemplates,
105
+ minZoomLevel: this.props.minZoomLevel,
106
+ maxZoomLevel: this.props.maxZoomLevel,
107
+ tileSize: this.props.tileSize,
108
+ tms: this.props.tms,
109
+ attribution: this.props.attribution,
110
+ };
111
+ return (
112
+ <RCTMGLRasterSource ref={this.setNativeRef} {...props}>
113
+ {cloneReactChildrenWithProps(this.props.children, {
114
+ sourceID: this.props.id,
115
+ })}
116
+ </RCTMGLRasterSource>
117
+ );
118
+ }
119
+ }
120
+
121
+ const RCTMGLRasterSource =
122
+ requireNativeComponent<NativeProps>(NATIVE_MODULE_NAME);
123
+
124
+ export default RasterSource;
@@ -136,7 +136,7 @@ export type Props = {
136
136
  height: number;
137
137
  };
138
138
 
139
- children: React.ReactElement | React.ReactElement[];
139
+ children?: React.ReactElement | React.ReactElement[];
140
140
  };
141
141
 
142
142
  /**
@@ -1,5 +1,6 @@
1
1
  import React, { useMemo, useState, useEffect } from 'react';
2
- import PropTypes from 'prop-types';
2
+
3
+ import { FilterExpression } from '../utils/MapboxStyles';
3
4
 
4
5
  import CircleLayer from './CircleLayer';
5
6
  import RasterLayer from './RasterLayer';
@@ -14,7 +15,7 @@ import RasterSource from './RasterSource';
14
15
  import ImageSource from './ImageSource';
15
16
  import { ShapeSource } from './ShapeSource';
16
17
 
17
- function toCamelCase(s) {
18
+ function toCamelCase(s: string): string {
18
19
  return s.replace(/([-_][a-z])/gi, ($1) => {
19
20
  return $1.toUpperCase().replace('-', '').replace('_', '');
20
21
  });
@@ -22,11 +23,13 @@ function toCamelCase(s) {
22
23
 
23
24
  // Patches the Mapbox Style Specification keys into the style props attributes:
24
25
  // icon-allow-overlap -> iconAllowOverlap
25
- function toCamelCaseKeys(oldObj) {
26
+ function toCamelCaseKeys(oldObj?: { [key: string]: unknown }): {
27
+ [key: string]: unknown;
28
+ } {
26
29
  if (!oldObj) {
27
30
  return {};
28
31
  }
29
- const newObj = {};
32
+ const newObj: { [key: string]: unknown } = {};
30
33
  Object.keys(oldObj).forEach((key) => {
31
34
  const value = oldObj[key];
32
35
  if (key.includes('-')) {
@@ -38,7 +41,7 @@ function toCamelCaseKeys(oldObj) {
38
41
  return newObj;
39
42
  }
40
43
 
41
- function getLayerComponentType(layer) {
44
+ function getLayerComponentType(layer: { type: string }) {
42
45
  const { type } = layer;
43
46
 
44
47
  switch (type) {
@@ -65,8 +68,10 @@ function getLayerComponentType(layer) {
65
68
  return null;
66
69
  }
67
70
 
68
- function asLayerComponent(layer) {
69
- const LayerComponent = getLayerComponentType(layer);
71
+ function asLayerComponent(layer: MapboxJSONLayer) {
72
+ type GenericProps = { key?: string; id: string };
73
+ const LayerComponent: typeof React.PureComponent<GenericProps> | null =
74
+ getLayerComponentType(layer) as typeof React.PureComponent<GenericProps>;
70
75
  if (!LayerComponent) {
71
76
  return null;
72
77
  }
@@ -76,7 +81,14 @@ function asLayerComponent(layer) {
76
81
  ...toCamelCaseKeys(layer.layout),
77
82
  };
78
83
 
79
- const layerProps = {};
84
+ const layerProps: {
85
+ sourceID?: string;
86
+ sourceLayerID?: string;
87
+ minZoomLevel?: number;
88
+ maxZoomLevel?: number;
89
+ filter?: FilterExpression;
90
+ style?: object;
91
+ } = {};
80
92
 
81
93
  if (layer.source) {
82
94
  layerProps.sourceID = layer.source;
@@ -100,8 +112,17 @@ function asLayerComponent(layer) {
100
112
  return <LayerComponent key={layer.id} id={layer.id} {...layerProps} />;
101
113
  }
102
114
 
103
- function getTileSourceProps(source) {
104
- const sourceProps = {};
115
+ type SourceProps = {
116
+ url?: string;
117
+ tileUrlTemplates?: string[];
118
+ minZoomLevel?: number;
119
+ maxZoomLevel?: number;
120
+ attribution?: string;
121
+ tms?: boolean;
122
+ };
123
+
124
+ function getTileSourceProps(source: MapboxJSONSource): SourceProps {
125
+ const sourceProps: SourceProps = {};
105
126
  if (source.url) {
106
127
  sourceProps.url = source.url;
107
128
  }
@@ -123,20 +144,22 @@ function getTileSourceProps(source) {
123
144
  return sourceProps;
124
145
  }
125
146
 
126
- function getVectorSource(id, source) {
147
+ function getVectorSource(id: string, source: MapboxJSONSource) {
127
148
  const sourceProps = { ...getTileSourceProps(source) };
128
149
  return <VectorSource key={id} id={id} {...sourceProps} />;
129
150
  }
130
151
 
131
- function getRasterSource(id, source) {
132
- const sourceProps = { ...getTileSourceProps(source) };
152
+ function getRasterSource(id: string, source: MapboxJSONSource) {
153
+ const sourceProps: { tileSize?: number } & SourceProps = {
154
+ ...getTileSourceProps(source),
155
+ };
133
156
  if (source.tileSize) {
134
157
  sourceProps.tileSize = source.tileSize;
135
158
  }
136
159
  return <RasterSource key={id} id={id} {...sourceProps} />;
137
160
  }
138
161
 
139
- function getImageSource(id, source) {
162
+ function getImageSource(id: string, source: MapboxJSONSource) {
140
163
  const sourceProps = {
141
164
  url: source.url,
142
165
  coordinates: source.coordinates,
@@ -144,12 +167,24 @@ function getImageSource(id, source) {
144
167
  return <ImageSource key={id} id={id} {...sourceProps} />;
145
168
  }
146
169
 
147
- function getShapeSource(id, source) {
148
- const sourceProps = {};
170
+ type ShapeShourceShape = typeof ShapeSource.prototype.props['shape'];
171
+
172
+ function getShapeSource(id: string, source: MapboxJSONSource) {
173
+ const sourceProps: {
174
+ url?: string;
175
+ shape?: ShapeShourceShape;
176
+ cluster?: boolean;
177
+ clusterRadius?: number;
178
+ clusterMaxZoomLevel?: number;
179
+ clusterProperties?: object;
180
+ buffer?: number;
181
+ tolerance?: number;
182
+ lineMetrics?: boolean;
183
+ } & SourceProps = {};
149
184
  if (source.data && typeof source.data === 'string') {
150
185
  sourceProps.url = source.data;
151
186
  } else if (source.data && typeof source.data === 'object') {
152
- sourceProps.shape = source.data;
187
+ sourceProps.shape = source.data as ShapeShourceShape;
153
188
  }
154
189
  if (source.cluster !== undefined) {
155
190
  sourceProps.cluster = source.cluster;
@@ -178,7 +213,7 @@ function getShapeSource(id, source) {
178
213
  return <ShapeSource key={id} id={id} {...sourceProps} />;
179
214
  }
180
215
 
181
- function asSourceComponent(id, source) {
216
+ function asSourceComponent(id: string, source: MapboxJSONSource) {
182
217
  switch (source.type) {
183
218
  case 'vector':
184
219
  return getVectorSource(id, source);
@@ -195,26 +230,79 @@ function asSourceComponent(id, source) {
195
230
  return null;
196
231
  }
197
232
 
233
+ type MapboxJSONLayer = {
234
+ type: string;
235
+ id: string;
236
+ paint?: { [k: string]: unknown };
237
+ layout?: { [k: string]: unknown };
238
+ source?: string;
239
+ minzoom?: number;
240
+ maxzoom?: number;
241
+ filter?: FilterExpression;
242
+ style?: object;
243
+ ['source-layer']: string;
244
+ };
245
+
246
+ type MapboxJSONSource = {
247
+ type: string;
248
+ url?: string;
249
+ tiles?: string[];
250
+ minzoom?: number;
251
+ maxzoom?: number;
252
+ attribution?: string;
253
+ scheme?: string;
254
+ tileSize?: number;
255
+ coordinates?: [
256
+ [number, number],
257
+ [number, number],
258
+ [number, number],
259
+ [number, number],
260
+ ];
261
+ data?: string | object;
262
+
263
+ buffer: number;
264
+ cluster?: boolean;
265
+ clusterRadius?: number;
266
+ clusterMaxZoom?: number;
267
+ clusterProperties?: object;
268
+ tolerance?: number;
269
+ lineMetrics?: boolean;
270
+ };
271
+
272
+ type MapboxJSON = {
273
+ layers?: MapboxJSONLayer[];
274
+ sources?: { [key: string]: MapboxJSONSource };
275
+ };
276
+
277
+ type Props = {
278
+ /**
279
+ * A JSON object conforming to the schema described in the Mapbox Style Specification , or a URL to such JSON.
280
+ */
281
+ json: MapboxJSON | URL;
282
+ };
283
+
198
284
  /**
199
285
  * Style is a component that automatically adds sources / layers to the map using Mapbox GL Style Spec.
200
286
  * Only [`sources`](https://docs.mapbox.com/mapbox-gl-js/style-spec/sources) & [`layers`](https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/) are supported.
201
287
  * Other fields such as `sprites`, `glyphs` etc. will be ignored. Not all layer / source attributes from the style spec are supported, in general the supported attributes will be mentioned under https://github.com/rnmapbox/maps/tree/main/docs.
202
288
  */
203
- const Style = (props) => {
289
+ const Style = (props: Props) => {
204
290
  const [fetchedJson, setFetchedJson] = useState({});
205
- const json = typeof props.json === 'object' ? props.json : fetchedJson;
291
+ const json: MapboxJSON =
292
+ typeof props.json === 'object' ? props.json : fetchedJson;
206
293
 
207
294
  // Fetch style when props.json is a URL
208
295
  useEffect(() => {
209
296
  const abortController = new AbortController();
210
- const fetchStyleJson = async () => {
297
+ const fetchStyleJson = async (json: string) => {
211
298
  try {
212
- const response = await fetch(props.json, {
299
+ const response = await fetch(json, {
213
300
  signal: abortController.signal,
214
301
  });
215
302
  const responseJson = await response.json();
216
303
  setFetchedJson(responseJson);
217
- } catch (e) {
304
+ } catch (error: unknown) {
305
+ const e = error as { name?: string };
218
306
  if (e.name === 'AbortError') {
219
307
  return;
220
308
  }
@@ -222,7 +310,7 @@ const Style = (props) => {
222
310
  }
223
311
  };
224
312
  if (typeof props.json === 'string') {
225
- fetchStyleJson();
313
+ fetchStyleJson(props.json);
226
314
  }
227
315
  return function cleanup() {
228
316
  abortController.abort();
@@ -238,14 +326,15 @@ const Style = (props) => {
238
326
  }, [json.layers]);
239
327
 
240
328
  // Extract source components from json
329
+ const { sources } = json;
241
330
  const sourceComponents = useMemo(() => {
242
- if (!json.sources || !Object.keys(json.sources)) {
331
+ if (!sources || !Object.keys(sources)) {
243
332
  return [];
244
333
  }
245
- return Object.keys(json.sources)
246
- .map((id) => asSourceComponent(id, json.sources[id]))
334
+ return Object.keys(sources)
335
+ .map((id) => asSourceComponent(id, sources[id]))
247
336
  .filter((x) => !!x);
248
- }, [json.sources]);
337
+ }, [sources]);
249
338
 
250
339
  return (
251
340
  <>
@@ -255,11 +344,4 @@ const Style = (props) => {
255
344
  );
256
345
  };
257
346
 
258
- Style.propTypes = {
259
- /**
260
- * A JSON object conforming to the schema described in the Mapbox Style Specification , or a URL to such JSON.
261
- */
262
- json: PropTypes.any,
263
- };
264
-
265
347
  export default Style;
@@ -11,7 +11,7 @@ type Props = BaseProps & {
11
11
  /**
12
12
  * Name of a source of raster_dem type to be used for terrain elevation.
13
13
  */
14
- sourceID: string;
14
+ sourceID?: string;
15
15
 
16
16
  /**
17
17
  * Deprecated, use exaggeration in style instead
@@ -21,7 +21,11 @@ type Props = BaseProps & {
21
21
  /**
22
22
  * Customizable style attributes
23
23
  */
24
- style: TerrainLayerStyleProps;
24
+ style?: TerrainLayerStyleProps;
25
+ };
26
+
27
+ type NativeProps = Omit<Props, 'style'> & {
28
+ reactStyle?: { [key: string]: StyleValue };
25
29
  };
26
30
 
27
31
  export const Terrain = memo((props: Props) => {
@@ -46,8 +50,5 @@ export const Terrain = memo((props: Props) => {
46
50
  return <RCTMGLTerrain {...baseProps} />;
47
51
  });
48
52
 
49
- const RCTMGLTerrain: HostComponent<{
50
- sourceID: string;
51
- reactStyle?: { [key: string]: StyleValue };
52
- style?: undefined;
53
- }> = requireNativeComponent(NATIVE_MODULE_NAME);
53
+ const RCTMGLTerrain: HostComponent<NativeProps> =
54
+ requireNativeComponent(NATIVE_MODULE_NAME);