@maplibre/maplibre-react-native 9.1.0 → 10.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +10 -2
- package/.husky/pre-commit +5 -0
- package/.yarn/plugins/@yarnpkg/plugin-typescript.cjs +9 -0
- package/.yarn/sdks/eslint/bin/eslint.js +20 -0
- package/.yarn/sdks/eslint/lib/api.js +20 -0
- package/.yarn/sdks/eslint/package.json +6 -0
- package/.yarn/sdks/integrations.yml +5 -0
- package/.yarn/sdks/prettier/index.js +20 -0
- package/.yarn/sdks/prettier/package.json +6 -0
- package/.yarn/sdks/typescript/bin/tsc +20 -0
- package/.yarn/sdks/typescript/bin/tsserver +20 -0
- package/.yarn/sdks/typescript/lib/tsc.js +20 -0
- package/.yarn/sdks/typescript/lib/tsserver.js +225 -0
- package/.yarn/sdks/typescript/lib/tsserverlibrary.js +225 -0
- package/.yarn/sdks/typescript/lib/typescript.js +20 -0
- package/.yarn/sdks/typescript/package.json +6 -0
- package/CHANGELOG.md +18 -0
- package/android/rctmgl/build.gradle +7 -7
- package/android/rctmgl/src/main/java/com/mapbox/rctmgl/location/LocationManager.java +2 -2
- package/android/rctmgl/src/main/java/com/mapbox/rctmgl/modules/RCTMGLOfflineModule.java +21 -26
- package/docs/Annotation.md +8 -9
- package/docs/BackgroundLayer.md +2 -10
- package/docs/Callout.md +5 -5
- package/docs/Camera.md +18 -47
- package/docs/CircleLayer.md +2 -10
- package/docs/FillExtrusionLayer.md +2 -10
- package/docs/FillLayer.md +2 -10
- package/docs/HeatmapLayer.md +2 -10
- package/docs/ImageSource.md +3 -2
- package/docs/Images.md +5 -3
- package/docs/Light.md +1 -1
- package/docs/LineLayer.md +2 -10
- package/docs/MapView.md +53 -37
- package/docs/MarkerView.md +4 -2
- package/docs/NativeUserLocation.md +2 -2
- package/docs/PointAnnotation.md +5 -8
- package/docs/RasterLayer.md +2 -10
- package/docs/RasterSource.md +3 -2
- package/docs/ShapeSource.md +12 -7
- package/docs/Style.md +1 -1
- package/docs/SymbolLayer.md +3 -10
- package/docs/UserLocation.md +8 -10
- package/docs/VectorSource.md +6 -5
- package/docs/coordinates.md +6 -0
- package/docs/docs.json +518 -1272
- package/docs/location.md +6 -0
- package/docs/snapshotManager.md +3 -3
- package/javascript/@types/assets.d.ts +4 -0
- package/javascript/MGLModule.ts +37 -0
- package/javascript/Maplibre.ts +65 -0
- package/javascript/components/AbstractLayer.tsx +107 -0
- package/javascript/components/AbstractSource.tsx +27 -0
- package/javascript/components/BackgroundLayer.tsx +43 -0
- package/javascript/components/{Callout.js → Callout.tsx} +67 -65
- package/javascript/components/{Camera.js → Camera.tsx} +266 -251
- package/javascript/components/CircleLayer.tsx +46 -0
- package/javascript/components/FillExtrusionLayer.tsx +47 -0
- package/javascript/components/FillLayer.tsx +41 -0
- package/javascript/components/{HeadingIndicator.js → HeadingIndicator.tsx} +8 -8
- package/javascript/components/HeatmapLayer.tsx +44 -0
- package/javascript/components/ImageSource.tsx +78 -0
- package/javascript/components/Images.tsx +134 -0
- package/javascript/components/Light.tsx +67 -0
- package/javascript/components/LineLayer.tsx +42 -0
- package/javascript/components/{MapView.js → MapView.tsx} +365 -354
- package/javascript/components/MarkerView.tsx +104 -0
- package/javascript/components/{NativeBridgeComponent.js → NativeBridgeComponent.tsx} +44 -13
- package/javascript/components/NativeUserLocation.tsx +33 -0
- package/javascript/components/PointAnnotation.tsx +221 -0
- package/javascript/components/RasterLayer.tsx +41 -0
- package/javascript/components/RasterSource.tsx +117 -0
- package/javascript/components/ShapeSource.tsx +383 -0
- package/javascript/components/{Style.js → Style.tsx} +129 -38
- package/javascript/components/SymbolLayer.tsx +72 -0
- package/javascript/components/{UserLocation.js → UserLocation.tsx} +111 -110
- package/javascript/components/VectorSource.tsx +207 -0
- package/javascript/components/annotations/Annotation.tsx +134 -0
- package/javascript/index.ts +4 -0
- package/javascript/modules/location/{locationManager.js → locationManager.ts} +71 -10
- package/javascript/modules/offline/{OfflineCreatePackOptions.js → OfflineCreatePackOptions.ts} +20 -4
- package/javascript/modules/offline/{OfflinePack.js → OfflinePack.ts} +23 -7
- package/javascript/modules/offline/{offlineManager.js → offlineManager.ts} +81 -24
- package/javascript/modules/snapshot/{SnapshotOptions.js → SnapshotOptions.ts} +43 -6
- package/javascript/modules/snapshot/{snapshotManager.js → snapshotManager.ts} +5 -5
- package/javascript/requestAndroidLocationPermissions.ts +29 -0
- package/javascript/types/BaseProps.ts +5 -0
- package/javascript/types/OnPressEvent.ts +13 -0
- package/javascript/types/index.ts +7 -0
- package/javascript/utils/BridgeValue.ts +90 -0
- package/javascript/utils/{Logger.js → Logger.ts} +37 -18
- package/javascript/utils/MaplibreStyles.d.ts +1486 -0
- package/javascript/utils/StyleValue.ts +49 -0
- package/javascript/utils/animated/AbstractAnimatedCoordinates.ts +134 -0
- package/javascript/utils/animated/AnimatedCoordinatesArray.ts +112 -0
- package/javascript/utils/animated/{AnimatedExtractCoordinateFromArray.js → AnimatedExtractCoordinateFromArray.ts} +5 -5
- package/javascript/utils/animated/{AnimatedPoint.js → AnimatedPoint.ts} +20 -12
- package/javascript/utils/animated/{AnimatedRouteCoordinatesArray.js → AnimatedRouteCoordinatesArray.ts} +39 -14
- package/javascript/utils/animated/{AnimatedShape.js → AnimatedShape.ts} +31 -10
- package/javascript/utils/{deprecation.js → deprecation.ts} +9 -6
- package/javascript/utils/filterUtils.ts +9 -0
- package/javascript/utils/geoUtils.ts +79 -0
- package/javascript/utils/{index.js → index.ts} +44 -24
- package/javascript/utils/styleMap.ts +264 -0
- package/package.json +35 -27
- package/plugin/build/withMapLibre.js +18 -3
- package/scripts/autogenHelpers/globals.js +1 -1
- package/scripts/autogenerate.js +14 -6
- package/scripts/download-style-spec.sh +1 -1
- package/scripts/templates/MaplibreStyles.ts.ejs +99 -0
- package/scripts/templates/index.d.ts.ejs +71 -42
- package/scripts/templates/{styleMap.js.ejs → styleMap.ts.ejs} +3 -33
- package/setup-jest.js +1 -10
- package/tsconfig.json +20 -61
- package/index.d.ts +0 -955
- package/javascript/components/AbstractLayer.js +0 -75
- package/javascript/components/AbstractSource.js +0 -15
- package/javascript/components/BackgroundLayer.js +0 -97
- package/javascript/components/CircleLayer.js +0 -101
- package/javascript/components/FillExtrusionLayer.js +0 -98
- package/javascript/components/FillLayer.js +0 -94
- package/javascript/components/HeatmapLayer.js +0 -99
- package/javascript/components/ImageSource.js +0 -82
- package/javascript/components/Images.js +0 -119
- package/javascript/components/Light.js +0 -47
- package/javascript/components/LineLayer.js +0 -94
- package/javascript/components/MarkerView.js +0 -87
- package/javascript/components/NativeUserLocation.js +0 -41
- package/javascript/components/PointAnnotation.js +0 -216
- package/javascript/components/RasterLayer.js +0 -95
- package/javascript/components/RasterSource.js +0 -124
- package/javascript/components/ShapeSource.js +0 -372
- package/javascript/components/SymbolLayer.js +0 -120
- package/javascript/components/VectorSource.js +0 -200
- package/javascript/components/annotations/Annotation.js +0 -122
- package/javascript/index.js +0 -149
- package/javascript/utils/BridgeValue.js +0 -81
- package/javascript/utils/animated/AnimatedCoordinatesArray.js +0 -191
- package/javascript/utils/filterUtils.js +0 -7
- package/javascript/utils/geoUtils.js +0 -73
- package/javascript/utils/styleMap.js +0 -1932
- /package/javascript/utils/animated/{Animated.js → Animated.ts} +0 -0
|
@@ -5,15 +5,52 @@ import {NativeModules} from 'react-native';
|
|
|
5
5
|
|
|
6
6
|
const MapLibreGL = NativeModules.MGLModule;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
export interface SnapshotInputOptions {
|
|
9
|
+
centerCoordinate?: GeoJSON.Position;
|
|
10
|
+
bounds?: GeoJSON.Position[];
|
|
11
|
+
styleURL?: string;
|
|
12
|
+
heading?: number;
|
|
13
|
+
pitch?: number;
|
|
14
|
+
zoomLevel?: number;
|
|
15
|
+
width?: number;
|
|
16
|
+
height?: number;
|
|
17
|
+
writeToDisk?: boolean;
|
|
18
|
+
withLogo?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface SnapshotJsonOptions {
|
|
22
|
+
centerCoordinate?: string;
|
|
23
|
+
bounds?: string;
|
|
24
|
+
styleURL: string;
|
|
25
|
+
heading: number;
|
|
26
|
+
pitch: number;
|
|
27
|
+
zoomLevel: number;
|
|
28
|
+
width: number;
|
|
29
|
+
height: number;
|
|
30
|
+
writeToDisk: boolean;
|
|
31
|
+
withLogo: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class SnapshotOptions {
|
|
35
|
+
centerCoordinate?: string;
|
|
36
|
+
bounds?: string;
|
|
37
|
+
styleURL: string;
|
|
38
|
+
heading: number;
|
|
39
|
+
pitch: number;
|
|
40
|
+
zoomLevel: number;
|
|
41
|
+
width: number;
|
|
42
|
+
height: number;
|
|
43
|
+
writeToDisk: boolean;
|
|
44
|
+
withLogo: boolean;
|
|
45
|
+
|
|
46
|
+
constructor(options: SnapshotInputOptions) {
|
|
10
47
|
if (!options.centerCoordinate && !options.bounds) {
|
|
11
48
|
throw new Error(
|
|
12
49
|
'Center coordinate or bounds must be supplied in order to take a snapshot',
|
|
13
50
|
);
|
|
14
51
|
}
|
|
15
52
|
|
|
16
|
-
this.styleURL = options.styleURL || MapLibreGL.StyleURL.
|
|
53
|
+
this.styleURL = options.styleURL || MapLibreGL.StyleURL.Default;
|
|
17
54
|
this.heading = options.heading || 0.0;
|
|
18
55
|
this.pitch = options.pitch || 0.0;
|
|
19
56
|
this.zoomLevel = options.zoomLevel || 16.0;
|
|
@@ -33,7 +70,7 @@ class SnapshotOptions {
|
|
|
33
70
|
}
|
|
34
71
|
}
|
|
35
72
|
|
|
36
|
-
toJSON() {
|
|
73
|
+
toJSON(): SnapshotJsonOptions {
|
|
37
74
|
return {
|
|
38
75
|
styleURL: this.styleURL,
|
|
39
76
|
heading: this.heading,
|
|
@@ -48,12 +85,12 @@ class SnapshotOptions {
|
|
|
48
85
|
};
|
|
49
86
|
}
|
|
50
87
|
|
|
51
|
-
_createCenterCoordPoint(centerCoordinate) {
|
|
88
|
+
_createCenterCoordPoint(centerCoordinate: GeoJSON.Position): string {
|
|
52
89
|
const point = makePoint(centerCoordinate);
|
|
53
90
|
return toJSONString(point);
|
|
54
91
|
}
|
|
55
92
|
|
|
56
|
-
_createBoundsCollection(bounds) {
|
|
93
|
+
_createBoundsCollection(bounds: GeoJSON.Position[]): string {
|
|
57
94
|
const features = [];
|
|
58
95
|
|
|
59
96
|
for (const bound of bounds) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import SnapshotOptions from './SnapshotOptions';
|
|
1
|
+
import SnapshotOptions, {SnapshotInputOptions} from './SnapshotOptions';
|
|
2
2
|
|
|
3
3
|
import {NativeModules} from 'react-native';
|
|
4
4
|
|
|
@@ -23,7 +23,7 @@ class SnapshotManager {
|
|
|
23
23
|
* zoomLevel: 12,
|
|
24
24
|
* pitch: 30,
|
|
25
25
|
* heading: 20,
|
|
26
|
-
* styleURL: MapLibreGL.StyleURL.
|
|
26
|
+
* styleURL: MapLibreGL.StyleURL.Default,
|
|
27
27
|
* writeToDisk: true, // Create a temporary file
|
|
28
28
|
* });
|
|
29
29
|
*
|
|
@@ -35,7 +35,7 @@ class SnapshotManager {
|
|
|
35
35
|
* zoomLevel: 12,
|
|
36
36
|
* pitch: 30,
|
|
37
37
|
* heading: 20,
|
|
38
|
-
* styleURL: MapLibreGL.StyleURL.
|
|
38
|
+
* styleURL: MapLibreGL.StyleURL.Default,
|
|
39
39
|
* withLogo: false, // Disable Mapbox logo (Android only)
|
|
40
40
|
* });
|
|
41
41
|
*
|
|
@@ -44,13 +44,13 @@ class SnapshotManager {
|
|
|
44
44
|
* bounds: [[-74.126410, 40.797968], [-74.143727, 40.772177]],
|
|
45
45
|
* width: width,
|
|
46
46
|
* height: height,
|
|
47
|
-
* styleURL: MapLibreGL.StyleURL.
|
|
47
|
+
* styleURL: MapLibreGL.StyleURL.Default,
|
|
48
48
|
* });
|
|
49
49
|
*
|
|
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: SnapshotInputOptions = {}): Promise<string> {
|
|
54
54
|
const snapshotOptions = new SnapshotOptions(options);
|
|
55
55
|
|
|
56
56
|
const uri = await MapLibreGLSnapshotManger.takeSnap(snapshotOptions);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {isAndroid} from './utils';
|
|
2
|
+
|
|
3
|
+
import {Permission, PermissionsAndroid} from 'react-native';
|
|
4
|
+
|
|
5
|
+
export async function requestAndroidLocationPermissions(): Promise<boolean> {
|
|
6
|
+
if (isAndroid()) {
|
|
7
|
+
const res = await PermissionsAndroid.requestMultiple([
|
|
8
|
+
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
|
|
9
|
+
PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
if (!res) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const permissions: string[] = Object.keys(res);
|
|
17
|
+
for (const permission of permissions) {
|
|
18
|
+
if (
|
|
19
|
+
res[permission as Permission] === PermissionsAndroid.RESULTS.GRANTED
|
|
20
|
+
) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
throw new Error('You should only call this method on Android!');
|
|
29
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {isBoolean, isNumber, isString} from './index';
|
|
2
|
+
|
|
3
|
+
export type RawValueType =
|
|
4
|
+
| string
|
|
5
|
+
| number
|
|
6
|
+
| boolean
|
|
7
|
+
| RawValueType[]
|
|
8
|
+
| {[key: string]: RawValueType};
|
|
9
|
+
|
|
10
|
+
export type StyleValueJSON =
|
|
11
|
+
| {type: 'boolean'; value: boolean}
|
|
12
|
+
| {type: 'number'; value: number}
|
|
13
|
+
| {type: 'string'; value: string}
|
|
14
|
+
| {type: 'hashmap'; value: object}
|
|
15
|
+
| {type: 'array'; value: unknown[]};
|
|
16
|
+
|
|
17
|
+
type StyleValueTypes = 'boolean' | 'number' | 'string' | 'hashmap' | 'array';
|
|
18
|
+
|
|
19
|
+
export default class BridgeValue {
|
|
20
|
+
rawValue: RawValueType;
|
|
21
|
+
|
|
22
|
+
constructor(rawValue: RawValueType) {
|
|
23
|
+
this.rawValue = rawValue;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get type(): StyleValueTypes {
|
|
27
|
+
if (Array.isArray(this.rawValue)) {
|
|
28
|
+
return 'array';
|
|
29
|
+
}
|
|
30
|
+
if (isBoolean(this.rawValue)) {
|
|
31
|
+
return 'boolean';
|
|
32
|
+
}
|
|
33
|
+
if (isNumber(this.rawValue)) {
|
|
34
|
+
return 'number';
|
|
35
|
+
}
|
|
36
|
+
if (isString(this.rawValue)) {
|
|
37
|
+
return 'string';
|
|
38
|
+
}
|
|
39
|
+
if (this.rawValue && typeof this.rawValue === 'object') {
|
|
40
|
+
return 'hashmap';
|
|
41
|
+
}
|
|
42
|
+
throw new Error(
|
|
43
|
+
`[type - ${this.rawValue}] BridgeValue must be a primitive/array/object`,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get value():
|
|
48
|
+
| [StyleValueJSON, StyleValueJSON][]
|
|
49
|
+
| StyleValueJSON[]
|
|
50
|
+
| RawValueType {
|
|
51
|
+
const {type} = this;
|
|
52
|
+
|
|
53
|
+
let value;
|
|
54
|
+
|
|
55
|
+
if (type === 'array') {
|
|
56
|
+
value = [];
|
|
57
|
+
|
|
58
|
+
for (const innerRawValue of this.rawValue as RawValueType[]) {
|
|
59
|
+
const bridgeValue = new BridgeValue(innerRawValue);
|
|
60
|
+
value.push(bridgeValue.toJSON());
|
|
61
|
+
}
|
|
62
|
+
} else if (type === 'hashmap') {
|
|
63
|
+
value = [];
|
|
64
|
+
const rawValue = this.rawValue as {[key: string]: RawValueType};
|
|
65
|
+
const stringKeys = Object.keys(this.rawValue);
|
|
66
|
+
for (const stringKey of stringKeys) {
|
|
67
|
+
value.push([
|
|
68
|
+
new BridgeValue(stringKey).toJSON(),
|
|
69
|
+
new BridgeValue(rawValue[stringKey]).toJSON(),
|
|
70
|
+
] as [StyleValueJSON, StyleValueJSON]);
|
|
71
|
+
}
|
|
72
|
+
} else if (type === 'boolean' || type === 'number' || type === 'string') {
|
|
73
|
+
value = this.rawValue;
|
|
74
|
+
} else {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`[value - ${this.rawValue}] BridgeValue must be a primitive/array/object`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
toJSON(formatter?: <T>(arg0: T) => T): StyleValueJSON {
|
|
84
|
+
return {
|
|
85
|
+
type: this.type,
|
|
86
|
+
value:
|
|
87
|
+
typeof formatter === 'function' ? formatter(this.value) : this.value,
|
|
88
|
+
} as StyleValueJSON;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -1,20 +1,39 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
EmitterSubscription,
|
|
3
|
+
NativeEventEmitter,
|
|
4
|
+
NativeModules,
|
|
5
|
+
} from 'react-native';
|
|
2
6
|
const {MGLLogging} = NativeModules;
|
|
3
7
|
|
|
8
|
+
export type LogLevel = 'error' | 'warning' | 'info' | 'debug' | 'verbose';
|
|
9
|
+
interface Log {
|
|
10
|
+
message: string;
|
|
11
|
+
level: LogLevel;
|
|
12
|
+
tag?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type LogCallback = (log: Log) => boolean;
|
|
16
|
+
|
|
4
17
|
class Logger {
|
|
5
|
-
static instance = null;
|
|
18
|
+
static instance: Logger | null = null;
|
|
6
19
|
|
|
7
|
-
static sharedInstance() {
|
|
20
|
+
static sharedInstance(): Logger {
|
|
8
21
|
if (this.instance === null) {
|
|
9
22
|
this.instance = new Logger();
|
|
10
23
|
}
|
|
11
24
|
return this.instance;
|
|
12
25
|
}
|
|
13
26
|
|
|
27
|
+
private loggerEmitter: NativeEventEmitter;
|
|
28
|
+
private startedCount: number;
|
|
29
|
+
private logCallback: LogCallback | null;
|
|
30
|
+
private subscription: EmitterSubscription | null;
|
|
31
|
+
|
|
14
32
|
constructor() {
|
|
15
33
|
this.loggerEmitter = new NativeEventEmitter(MGLLogging);
|
|
16
34
|
this.startedCount = 0;
|
|
17
35
|
this.logCallback = null;
|
|
36
|
+
this.subscription = null;
|
|
18
37
|
}
|
|
19
38
|
|
|
20
39
|
/**
|
|
@@ -22,7 +41,7 @@ class Logger {
|
|
|
22
41
|
* @param {Logger~logCallback} logCallback - callback taking a log object as param. If callback return falsy value then
|
|
23
42
|
* default logging will take place.
|
|
24
43
|
*/
|
|
25
|
-
static setLogCallback(logCallback) {
|
|
44
|
+
static setLogCallback(logCallback: LogCallback): void {
|
|
26
45
|
this.sharedInstance().setLogCallback(logCallback);
|
|
27
46
|
}
|
|
28
47
|
|
|
@@ -31,7 +50,7 @@ class Logger {
|
|
|
31
50
|
* @param {Logger~logCallback} logCallback - callback taking a log object as param. If callback return falsy value then
|
|
32
51
|
* default logging will take place.
|
|
33
52
|
*/
|
|
34
|
-
setLogCallback(logCallback) {
|
|
53
|
+
setLogCallback(logCallback: LogCallback): void {
|
|
35
54
|
this.logCallback = logCallback;
|
|
36
55
|
}
|
|
37
56
|
|
|
@@ -48,7 +67,7 @@ class Logger {
|
|
|
48
67
|
* setLogLevel
|
|
49
68
|
* @param {LogLevel} level
|
|
50
69
|
*/
|
|
51
|
-
static setLogLevel(level) {
|
|
70
|
+
static setLogLevel(level: LogLevel): void {
|
|
52
71
|
MGLLogging.setLogLevel(level);
|
|
53
72
|
}
|
|
54
73
|
|
|
@@ -56,34 +75,34 @@ class Logger {
|
|
|
56
75
|
* @type {('error'|'warning'|'info'|'debug'|'verbose')} LogLevel - Supported log levels
|
|
57
76
|
*/
|
|
58
77
|
|
|
59
|
-
start() {
|
|
78
|
+
start(): void {
|
|
60
79
|
if (this.startedCount === 0) {
|
|
61
80
|
this.subscribe();
|
|
62
81
|
}
|
|
63
82
|
this.startedCount += 1;
|
|
64
83
|
}
|
|
65
84
|
|
|
66
|
-
stop() {
|
|
85
|
+
stop(): void {
|
|
67
86
|
this.startedCount -= 1;
|
|
68
87
|
if (this.startedCount === 0) {
|
|
69
88
|
this.unsubscribe();
|
|
70
89
|
}
|
|
71
90
|
}
|
|
72
91
|
|
|
73
|
-
subscribe() {
|
|
92
|
+
subscribe(): void {
|
|
74
93
|
this.subscription = this.loggerEmitter.addListener('LogEvent', log => {
|
|
75
94
|
this.onLog(log);
|
|
76
95
|
});
|
|
77
96
|
}
|
|
78
97
|
|
|
79
|
-
unsubscribe() {
|
|
80
|
-
this.subscription
|
|
81
|
-
|
|
98
|
+
unsubscribe(): void {
|
|
99
|
+
if (this.subscription) {
|
|
100
|
+
this.subscription.remove();
|
|
101
|
+
this.subscription = null;
|
|
102
|
+
}
|
|
82
103
|
}
|
|
83
104
|
|
|
84
|
-
effectiveLevel(
|
|
85
|
-
let {level, message, tag} = log;
|
|
86
|
-
|
|
105
|
+
effectiveLevel({level, message, tag}: Log): LogLevel {
|
|
87
106
|
if (level === 'warning') {
|
|
88
107
|
if (
|
|
89
108
|
tag === 'Mbgl-HttpRequest' &&
|
|
@@ -96,10 +115,10 @@ class Logger {
|
|
|
96
115
|
return level;
|
|
97
116
|
}
|
|
98
117
|
|
|
99
|
-
onLog(log) {
|
|
118
|
+
onLog(log: Log): void {
|
|
100
119
|
if (!this.logCallback || !this.logCallback(log)) {
|
|
101
|
-
|
|
102
|
-
|
|
120
|
+
const {message} = log;
|
|
121
|
+
const level = this.effectiveLevel(log);
|
|
103
122
|
if (level === 'error') {
|
|
104
123
|
console.error('Mapbox error', message, log);
|
|
105
124
|
} else if (level === 'warning') {
|