@rnmapbox/maps 10.0.0-beta.74 → 10.0.0-beta.75

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 (96) hide show
  1. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/CameraStop.kt +61 -46
  2. package/index.d.ts +28 -257
  3. package/javascript/components/ImageSource.tsx +81 -0
  4. package/javascript/components/{MapView.js → MapView.tsx} +456 -383
  5. package/javascript/components/NativeBridgeComponent.tsx +1 -1
  6. package/javascript/components/RasterDemSource.tsx +105 -0
  7. package/javascript/components/RasterSource.tsx +124 -0
  8. package/javascript/modules/offline/{OfflineCreatePackOptions.js → OfflineCreatePackOptions.ts} +21 -6
  9. package/javascript/modules/offline/{OfflinePack.js → OfflinePack.ts} +19 -4
  10. package/javascript/modules/offline/{offlineManager.js → offlineManager.ts} +77 -21
  11. package/javascript/modules/snapshot/{SnapshotOptions.js → SnapshotOptions.ts} +27 -3
  12. package/javascript/modules/snapshot/{snapshotManager.js → snapshotManager.ts} +1 -1
  13. package/javascript/utils/geoUtils.ts +91 -0
  14. package/javascript/utils/{index.js → index.ts} +41 -19
  15. package/lib/commonjs/components/ImageSource.js +8 -25
  16. package/lib/commonjs/components/ImageSource.js.map +1 -1
  17. package/lib/commonjs/components/MapView.js +30 -289
  18. package/lib/commonjs/components/MapView.js.map +1 -1
  19. package/lib/commonjs/components/NativeBridgeComponent.js.map +1 -1
  20. package/lib/commonjs/components/RasterDemSource.js +3 -37
  21. package/lib/commonjs/components/RasterDemSource.js.map +1 -1
  22. package/lib/commonjs/components/RasterSource.js +2 -46
  23. package/lib/commonjs/components/RasterSource.js.map +1 -1
  24. package/lib/commonjs/modules/offline/OfflineCreatePackOptions.js +2 -4
  25. package/lib/commonjs/modules/offline/OfflineCreatePackOptions.js.map +1 -1
  26. package/lib/commonjs/modules/offline/OfflinePack.js.map +1 -1
  27. package/lib/commonjs/modules/offline/offlineManager.js +1 -2
  28. package/lib/commonjs/modules/offline/offlineManager.js.map +1 -1
  29. package/lib/commonjs/modules/snapshot/SnapshotOptions.js.map +1 -1
  30. package/lib/commonjs/modules/snapshot/snapshotManager.js.map +1 -1
  31. package/lib/commonjs/utils/geoUtils.js +15 -23
  32. package/lib/commonjs/utils/geoUtils.js.map +1 -1
  33. package/lib/commonjs/utils/index.js +3 -6
  34. package/lib/commonjs/utils/index.js.map +1 -1
  35. package/lib/module/components/ImageSource.js +8 -25
  36. package/lib/module/components/ImageSource.js.map +1 -1
  37. package/lib/module/components/MapView.js +31 -290
  38. package/lib/module/components/MapView.js.map +1 -1
  39. package/lib/module/components/NativeBridgeComponent.js.map +1 -1
  40. package/lib/module/components/RasterDemSource.js +4 -38
  41. package/lib/module/components/RasterDemSource.js.map +1 -1
  42. package/lib/module/components/RasterSource.js +3 -47
  43. package/lib/module/components/RasterSource.js.map +1 -1
  44. package/lib/module/modules/offline/OfflineCreatePackOptions.js +2 -4
  45. package/lib/module/modules/offline/OfflineCreatePackOptions.js.map +1 -1
  46. package/lib/module/modules/offline/OfflinePack.js.map +1 -1
  47. package/lib/module/modules/offline/offlineManager.js +0 -1
  48. package/lib/module/modules/offline/offlineManager.js.map +1 -1
  49. package/lib/module/modules/snapshot/SnapshotOptions.js.map +1 -1
  50. package/lib/module/modules/snapshot/snapshotManager.js.map +1 -1
  51. package/lib/module/utils/geoUtils.js +7 -18
  52. package/lib/module/utils/geoUtils.js.map +1 -1
  53. package/lib/module/utils/index.js +3 -5
  54. package/lib/module/utils/index.js.map +1 -1
  55. package/lib/typescript/components/ImageSource.d.ts +32 -0
  56. package/lib/typescript/components/ImageSource.d.ts.map +1 -0
  57. package/lib/typescript/components/MapView.d.ts +472 -0
  58. package/lib/typescript/components/MapView.d.ts.map +1 -0
  59. package/lib/typescript/components/NativeBridgeComponent.d.ts +1 -1
  60. package/lib/typescript/components/NativeBridgeComponent.d.ts.map +1 -1
  61. package/lib/typescript/components/PointAnnotation.d.ts +1 -1
  62. package/lib/typescript/components/RasterDemSource.d.ts +46 -0
  63. package/lib/typescript/components/RasterDemSource.d.ts.map +1 -0
  64. package/lib/typescript/components/RasterSource.d.ts +59 -0
  65. package/lib/typescript/components/RasterSource.d.ts.map +1 -0
  66. package/lib/typescript/components/ShapeSource.d.ts +1 -1
  67. package/lib/typescript/components/VectorSource.d.ts +1 -1
  68. package/lib/typescript/modules/offline/OfflineCreatePackOptions.d.ts +22 -0
  69. package/lib/typescript/modules/offline/OfflineCreatePackOptions.d.ts.map +1 -0
  70. package/lib/typescript/modules/offline/OfflinePack.d.ts +24 -0
  71. package/lib/typescript/modules/offline/OfflinePack.d.ts.map +1 -0
  72. package/lib/typescript/modules/offline/offlineManager.d.ts +219 -0
  73. package/lib/typescript/modules/offline/offlineManager.d.ts.map +1 -0
  74. package/lib/typescript/modules/snapshot/SnapshotOptions.d.ts +41 -0
  75. package/lib/typescript/modules/snapshot/SnapshotOptions.d.ts.map +1 -0
  76. package/lib/typescript/modules/snapshot/snapshotManager.d.ts +51 -0
  77. package/lib/typescript/modules/snapshot/snapshotManager.d.ts.map +1 -0
  78. package/lib/typescript/utils/geoUtils.d.ts +23 -0
  79. package/lib/typescript/utils/geoUtils.d.ts.map +1 -0
  80. package/lib/typescript/utils/index.d.ts +48 -0
  81. package/lib/typescript/utils/index.d.ts.map +1 -0
  82. package/package.json +3 -1
  83. package/javascript/components/ImageSource.js +0 -82
  84. package/javascript/components/RasterDemSource.js +0 -106
  85. package/javascript/components/RasterSource.js +0 -124
  86. package/javascript/utils/geoUtils.d.ts +0 -10
  87. package/javascript/utils/geoUtils.js +0 -73
  88. package/javascript/utils/index.d.ts +0 -27
  89. package/lib/commonjs/utils/geoUtils.d.js +0 -2
  90. package/lib/commonjs/utils/geoUtils.d.js.map +0 -1
  91. package/lib/commonjs/utils/index.d.js +0 -2
  92. package/lib/commonjs/utils/index.d.js.map +0 -1
  93. package/lib/module/utils/geoUtils.d.js +0 -2
  94. package/lib/module/utils/geoUtils.d.js.map +0 -1
  95. package/lib/module/utils/index.d.js +0 -2
  96. package/lib/module/utils/index.d.js.map +0 -1
@@ -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) {
@@ -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;
@@ -1,8 +1,24 @@
1
1
  import { makeLatLngBounds } from '../../utils/geoUtils';
2
2
  import { toJSONString } from '../../utils';
3
3
 
4
+ export type OfflineCreatePackOptionsArgs = {
5
+ name: string;
6
+ styleURL: string;
7
+ bounds: [GeoJSON.Position, GeoJSON.Position];
8
+ minZoom?: number;
9
+ maxZoom?: number;
10
+ metadata?: Record<string, unknown>;
11
+ };
12
+
4
13
  class OfflineCreatePackOptions {
5
- constructor(options = {}) {
14
+ public readonly name: string;
15
+ public readonly styleURL: string;
16
+ public readonly bounds: string;
17
+ public readonly minZoom: number | undefined;
18
+ public readonly maxZoom: number | undefined;
19
+ public readonly metadata: string | undefined;
20
+
21
+ constructor(options: OfflineCreatePackOptionsArgs) {
6
22
  this._assert(options);
7
23
 
8
24
  this.name = options.name;
@@ -13,7 +29,7 @@ class OfflineCreatePackOptions {
13
29
  this.metadata = this._makeMetadata(options.metadata);
14
30
  }
15
31
 
16
- _assert(options) {
32
+ _assert(options: OfflineCreatePackOptionsArgs) {
17
33
  if (!options.styleURL) {
18
34
  throw new Error(
19
35
  'Style URL must be provided for creating an offline pack',
@@ -29,13 +45,12 @@ class OfflineCreatePackOptions {
29
45
  }
30
46
  }
31
47
 
32
- _makeLatLngBounds(bounds) {
33
- const ne = bounds[0];
34
- const sw = bounds[1];
48
+ _makeLatLngBounds(bounds: [GeoJSON.Position, GeoJSON.Position]): string {
49
+ const [ne, sw] = bounds;
35
50
  return toJSONString(makeLatLngBounds(ne, sw));
36
51
  }
37
52
 
38
- _makeMetadata(metadata) {
53
+ _makeMetadata(metadata: Record<string, unknown> | undefined) {
39
54
  return JSON.stringify({
40
55
  ...metadata,
41
56
  name: this.name,
@@ -1,9 +1,24 @@
1
1
  import { NativeModules } from 'react-native';
2
2
 
3
+ import OfflineCreatePackOptions from './OfflineCreatePackOptions';
4
+
3
5
  const MapboxGLOfflineManager = NativeModules.MGLOfflineModule;
4
6
 
7
+ type OfflinePackStatus = {
8
+ name: string;
9
+ state: number;
10
+ percentage: number;
11
+ completedResourceCount: number;
12
+ completedResourceSize: number;
13
+ completedTileSize: number;
14
+ completedTileCount: number;
15
+ requiredResourceCount: number;
16
+ };
17
+
5
18
  class OfflinePack {
6
- constructor(pack) {
19
+ private pack: OfflineCreatePackOptions;
20
+ private _metadata: any;
21
+ constructor(pack: OfflineCreatePackOptions) {
7
22
  this.pack = pack;
8
23
  this._metadata = null;
9
24
  }
@@ -24,15 +39,15 @@ class OfflinePack {
24
39
  return this._metadata;
25
40
  }
26
41
 
27
- status() {
42
+ status(): Promise<OfflinePackStatus> {
28
43
  return MapboxGLOfflineManager.getPackStatus(this.name);
29
44
  }
30
45
 
31
- resume() {
46
+ resume(): Promise<void> {
32
47
  return MapboxGLOfflineManager.resumePackDownload(this.name);
33
48
  }
34
49
 
35
- pause() {
50
+ pause(): Promise<void> {
36
51
  return MapboxGLOfflineManager.pausePackDownload(this.name);
37
52
  }
38
53
  }
@@ -1,8 +1,14 @@
1
- import { NativeModules, NativeEventEmitter } from 'react-native';
1
+ import {
2
+ NativeModules,
3
+ NativeEventEmitter,
4
+ EventSubscription,
5
+ } from 'react-native';
2
6
 
3
7
  import { isUndefined, isFunction, isAndroid } from '../../utils';
4
8
 
5
- import OfflineCreatePackOptions from './OfflineCreatePackOptions';
9
+ import OfflineCreatePackOptions, {
10
+ OfflineCreatePackOptionsArgs,
11
+ } from './OfflineCreatePackOptions';
6
12
  import OfflinePack from './OfflinePack';
7
13
 
8
14
  const MapboxGL = NativeModules.MGLModule;
@@ -11,12 +17,49 @@ export const OfflineModuleEventEmitter = new NativeEventEmitter(
11
17
  MapboxGLOfflineManager,
12
18
  );
13
19
 
20
+ export type OfflineProgressStatus = {
21
+ name: string;
22
+ state: number;
23
+ percentage: number;
24
+ completedResourceSize: number;
25
+ completedTileCount: number;
26
+ completedResourceCount: number;
27
+ requiredResourceCount: number;
28
+ completedTileSize: number;
29
+ };
30
+
31
+ export type OfflinePackError = {
32
+ name: string;
33
+ message: string;
34
+ };
35
+
36
+ type ErrorEvent = {
37
+ payload: OfflinePackError;
38
+ };
39
+
40
+ type ProgressEvent = {
41
+ payload: OfflineProgressStatus;
42
+ };
43
+
44
+ type ProgressListener = (
45
+ pack: OfflinePack,
46
+ status: OfflineProgressStatus,
47
+ ) => void;
48
+ type ErrorListener = (pack: OfflinePack, err: OfflinePackError) => void;
49
+
14
50
  /**
15
51
  * OfflineManager implements a singleton (shared object) that manages offline packs.
16
52
  * All of this class’s instance methods are asynchronous, reflecting the fact that offline resources are stored in a database.
17
53
  * The shared object maintains a canonical collection of offline packs.
18
54
  */
19
55
  class OfflineManager {
56
+ private _hasInitialized: boolean;
57
+ private _offlinePacks: Record<string, OfflinePack>;
58
+ private _progressListeners: Record<string, ProgressListener>;
59
+ private _errorListeners: Record<string, ErrorListener>;
60
+ public subscriptionProgress: EventSubscription | null;
61
+ public subscriptionError: EventSubscription | null;
62
+
20
63
  constructor() {
21
64
  this._hasInitialized = false;
22
65
  this._offlinePacks = {};
@@ -52,7 +95,11 @@ class OfflineManager {
52
95
  * @param {Callback=} errorListener Callback that listens for status events while downloading the offline resource.
53
96
  * @return {void}
54
97
  */
55
- async createPack(options, progressListener, errorListener) {
98
+ async createPack(
99
+ options: OfflineCreatePackOptionsArgs,
100
+ progressListener: ProgressListener,
101
+ errorListener?: ErrorListener,
102
+ ): Promise<void> {
56
103
  await this._initialize();
57
104
 
58
105
  const packOptions = new OfflineCreatePackOptions(options);
@@ -81,7 +128,7 @@ class OfflineManager {
81
128
  * @param {String} name Name of the offline pack.
82
129
  * @return {void}
83
130
  */
84
- async invalidatePack(name) {
131
+ async invalidatePack(name: string): Promise<void> {
85
132
  if (!name) {
86
133
  return;
87
134
  }
@@ -103,7 +150,7 @@ class OfflineManager {
103
150
  * @param {String} name Name of the offline pack.
104
151
  * @return {void}
105
152
  */
106
- async deletePack(name) {
153
+ async deletePack(name: string): Promise<void> {
107
154
  if (!name) {
108
155
  return;
109
156
  }
@@ -128,7 +175,7 @@ class OfflineManager {
128
175
  *
129
176
  * @return {void}
130
177
  */
131
- async invalidateAmbientCache() {
178
+ async invalidateAmbientCache(): Promise<void> {
132
179
  await this._initialize();
133
180
  await MapboxGLOfflineManager.invalidateAmbientCache();
134
181
  }
@@ -142,7 +189,7 @@ class OfflineManager {
142
189
  *
143
190
  * @return {void}
144
191
  */
145
- async clearAmbientCache() {
192
+ async clearAmbientCache(): Promise<void> {
146
193
  await this._initialize();
147
194
  await MapboxGLOfflineManager.clearAmbientCache();
148
195
  }
@@ -155,7 +202,7 @@ class OfflineManager {
155
202
  *
156
203
  * @return {void}
157
204
  */
158
- async migrateOfflineCache() {
205
+ async migrateOfflineCache(): Promise<void> {
159
206
  await this._initialize();
160
207
  await MapboxGLOfflineManager.migrateOfflineCache();
161
208
  }
@@ -170,7 +217,7 @@ class OfflineManager {
170
217
  * @param {Number} size Size of ambient cache.
171
218
  * @return {void}
172
219
  */
173
- async setMaximumAmbientCacheSize(size) {
220
+ async setMaximumAmbientCacheSize(size: number): Promise<void> {
174
221
  await this._initialize();
175
222
  await MapboxGLOfflineManager.setMaximumAmbientCacheSize(size);
176
223
  }
@@ -183,7 +230,7 @@ class OfflineManager {
183
230
  *
184
231
  * @return {void}
185
232
  */
186
- async resetDatabase() {
233
+ async resetDatabase(): Promise<void> {
187
234
  await this._initialize();
188
235
  await MapboxGLOfflineManager.resetDatabase();
189
236
  }
@@ -196,7 +243,7 @@ class OfflineManager {
196
243
  *
197
244
  * @return {Array<OfflinePack>}
198
245
  */
199
- async getPacks() {
246
+ async getPacks(): Promise<OfflinePack[]> {
200
247
  await this._initialize();
201
248
  return Object.keys(this._offlinePacks).map(
202
249
  (name) => this._offlinePacks[name],
@@ -212,7 +259,7 @@ class OfflineManager {
212
259
  * @param {String} name Name of the offline pack.
213
260
  * @return {OfflinePack}
214
261
  */
215
- async getPack(name) {
262
+ async getPack(name: string): Promise<OfflinePack | undefined> {
216
263
  await this._initialize();
217
264
  return this._offlinePacks[name];
218
265
  }
@@ -226,7 +273,7 @@ class OfflineManager {
226
273
  * @param {String} path Path to offline tile db on file system.
227
274
  * @return {void}
228
275
  */
229
- async mergeOfflineRegions(path) {
276
+ async mergeOfflineRegions(path: string): Promise<void> {
230
277
  await this._initialize();
231
278
  return MapboxGLOfflineManager.mergeOfflineRegions(path);
232
279
  }
@@ -241,7 +288,7 @@ class OfflineManager {
241
288
  * @param {Number} limit Map tile limit count.
242
289
  * @return {void}
243
290
  */
244
- setTileCountLimit(limit) {
291
+ setTileCountLimit(limit: number): void {
245
292
  MapboxGLOfflineManager.setTileCountLimit(limit);
246
293
  }
247
294
 
@@ -255,7 +302,7 @@ class OfflineManager {
255
302
  * @param {Number} throttleValue event throttle value in ms.
256
303
  * @return {void}
257
304
  */
258
- setProgressEventThrottle(throttleValue) {
305
+ setProgressEventThrottle(throttleValue: number): void {
259
306
  MapboxGLOfflineManager.setProgressEventThrottle(throttleValue);
260
307
  }
261
308
 
@@ -273,7 +320,11 @@ class OfflineManager {
273
320
  * @param {Callback} errorListener Callback that listens for status events while downloading the offline resource.
274
321
  * @return {void}
275
322
  */
276
- async subscribe(packName, progressListener, errorListener) {
323
+ async subscribe(
324
+ packName: string,
325
+ progressListener: ProgressListener,
326
+ errorListener?: ErrorListener,
327
+ ): Promise<void> {
277
328
  const totalProgressListeners = Object.keys(this._progressListeners).length;
278
329
  if (isFunction(progressListener)) {
279
330
  if (totalProgressListeners === 0) {
@@ -318,7 +369,7 @@ class OfflineManager {
318
369
  * @param {String} packName Name of the offline pack.
319
370
  * @return {void}
320
371
  */
321
- unsubscribe(packName) {
372
+ unsubscribe(packName: string): void {
322
373
  delete this._progressListeners[packName];
323
374
  delete this._errorListeners[packName];
324
375
 
@@ -337,7 +388,7 @@ class OfflineManager {
337
388
  }
338
389
  }
339
390
 
340
- async _initialize() {
391
+ async _initialize(): Promise<boolean> {
341
392
  if (this._hasInitialized) {
342
393
  return true;
343
394
  }
@@ -353,7 +404,7 @@ class OfflineManager {
353
404
  return true;
354
405
  }
355
406
 
356
- _onProgress(e) {
407
+ _onProgress(e: ProgressEvent): void {
357
408
  const { name, state } = e.payload;
358
409
 
359
410
  if (!this._hasListeners(name, this._progressListeners)) {
@@ -369,7 +420,7 @@ class OfflineManager {
369
420
  }
370
421
  }
371
422
 
372
- _onError(e) {
423
+ _onError(e: ErrorEvent): void {
373
424
  const { name } = e.payload;
374
425
 
375
426
  if (!this._hasListeners(name, this._errorListeners)) {
@@ -380,7 +431,12 @@ class OfflineManager {
380
431
  this._errorListeners[name](pack, e.payload);
381
432
  }
382
433
 
383
- _hasListeners(name, listenerMap) {
434
+ _hasListeners(
435
+ name: string,
436
+ listenerMap:
437
+ | Record<string, ProgressListener>
438
+ | Record<string, ErrorListener>,
439
+ ): boolean {
384
440
  return (
385
441
  !isUndefined(this._offlinePacks[name]) && isFunction(listenerMap[name])
386
442
  );
@@ -5,8 +5,32 @@ import { makePoint, makeFeatureCollection } from '../../utils/geoUtils';
5
5
 
6
6
  const MapboxGL = NativeModules.MGLModule;
7
7
 
8
+ export type SnapshotOptionsArgs = {
9
+ centerCoordinate?: GeoJSON.Position;
10
+ width?: number;
11
+ height?: number;
12
+ zoomLevel?: number;
13
+ pitch?: number;
14
+ heading?: number;
15
+ styleURL?: string;
16
+ writeToDisk?: boolean;
17
+ bounds?: number[][];
18
+ withLogo?: boolean;
19
+ };
20
+
8
21
  class SnapshotOptions {
9
- constructor(options = {}) {
22
+ public readonly styleURL: string;
23
+ public readonly heading: number;
24
+ public readonly pitch: number;
25
+ public readonly zoomLevel: number;
26
+ public readonly width: number;
27
+ public readonly height: number;
28
+ public readonly writeToDisk: boolean;
29
+ public readonly withLogo: boolean;
30
+ public readonly centerCoordinate: string | undefined;
31
+ public readonly bounds: string | undefined;
32
+
33
+ constructor(options: SnapshotOptionsArgs = {}) {
10
34
  if (!options.centerCoordinate && !options.bounds) {
11
35
  throw new Error(
12
36
  'Center coordinate or bounds must be supplied in order to take a snapshot',
@@ -48,12 +72,12 @@ class SnapshotOptions {
48
72
  };
49
73
  }
50
74
 
51
- _createCenterCoordPoint(centerCoordinate) {
75
+ _createCenterCoordPoint(centerCoordinate: number[]) {
52
76
  const point = makePoint(centerCoordinate);
53
77
  return toJSONString(point);
54
78
  }
55
79
 
56
- _createBoundsCollection(bounds) {
80
+ _createBoundsCollection(bounds: number[][]) {
57
81
  const features = [];
58
82
 
59
83
  for (const bound of bounds) {
@@ -50,7 +50,7 @@ class SnapshotManager {
50
50
  * @param {SnapshotOptions} options Snapshot options for create a static image of the base map
51
51
  * @return {Promise}
52
52
  */
53
- async takeSnap(options = {}) {
53
+ async takeSnap(options = {}): Promise<string> {
54
54
  const snapshotOptions = new SnapshotOptions(options);
55
55
 
56
56
  const uri = await MapboxGLSnapshotManger.takeSnap(snapshotOptions);