@maplibre/maplibre-react-native 10.0.0-alpha.8 → 10.0.0-alpha.9
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/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/docs/Camera.md +1 -1
- package/docs/MapView.md +9 -9
- package/docs/MarkerView.md +1 -1
- package/docs/NativeUserLocation.md +1 -1
- package/docs/PointAnnotation.md +2 -2
- package/docs/UserLocation.md +2 -2
- package/docs/docs.json +12 -12
- package/javascript/@types/assets.d.ts +1 -1
- package/javascript/MLNModule.ts +2 -2
- package/javascript/Maplibre.ts +37 -42
- package/javascript/components/BackgroundLayer.tsx +9 -9
- package/javascript/components/Callout.tsx +19 -19
- package/javascript/components/Camera.tsx +29 -29
- package/javascript/components/CircleLayer.tsx +9 -9
- package/javascript/components/FillExtrusionLayer.tsx +9 -9
- package/javascript/components/FillLayer.tsx +9 -9
- package/javascript/components/HeadingIndicator.tsx +7 -8
- package/javascript/components/HeatmapLayer.tsx +10 -10
- package/javascript/components/ImageSource.tsx +8 -8
- package/javascript/components/Images.tsx +19 -20
- package/javascript/components/Light.tsx +15 -15
- package/javascript/components/LineLayer.tsx +9 -9
- package/javascript/components/MapView.tsx +74 -70
- package/javascript/components/MarkerView.tsx +9 -10
- package/javascript/components/NativeUserLocation.tsx +4 -4
- package/javascript/components/PointAnnotation.tsx +17 -17
- package/javascript/components/RasterLayer.tsx +9 -9
- package/javascript/components/RasterSource.tsx +10 -10
- package/javascript/components/ShapeSource.tsx +63 -61
- package/javascript/components/Style.tsx +69 -59
- package/javascript/components/SymbolLayer.tsx +10 -10
- package/javascript/components/UserLocation.tsx +23 -23
- package/javascript/components/VectorSource.tsx +19 -19
- package/javascript/components/annotations/Annotation.tsx +16 -15
- package/javascript/hooks/useAbstractLayer.ts +15 -12
- package/javascript/hooks/useAbstractSource.ts +2 -2
- package/javascript/hooks/useNativeBridge.ts +7 -7
- package/javascript/hooks/useNativeRef.ts +2 -2
- package/javascript/hooks/useOnce.ts +1 -1
- package/javascript/index.ts +2 -2
- package/javascript/modules/location/locationManager.ts +4 -4
- package/javascript/modules/offline/OfflineCreatePackOptions.ts +5 -5
- package/javascript/modules/offline/OfflinePack.ts +3 -3
- package/javascript/modules/offline/offlineManager.ts +11 -12
- package/javascript/modules/snapshot/SnapshotOptions.ts +4 -4
- package/javascript/modules/snapshot/snapshotManager.ts +2 -2
- package/javascript/requestAndroidLocationPermissions.ts +3 -3
- package/javascript/types/OnPressEvent.ts +1 -1
- package/javascript/types/index.ts +6 -2
- package/javascript/utils/BridgeValue.ts +20 -20
- package/javascript/utils/Logger.ts +14 -14
- package/javascript/utils/MaplibreStyles.d.ts +359 -359
- package/javascript/utils/StyleValue.ts +12 -12
- package/javascript/utils/animated/AbstractAnimatedCoordinates.ts +6 -6
- package/javascript/utils/animated/Animated.ts +38 -16
- package/javascript/utils/animated/AnimatedCoordinatesArray.ts +7 -11
- package/javascript/utils/animated/AnimatedExtractCoordinateFromArray.ts +3 -3
- package/javascript/utils/animated/AnimatedPoint.ts +7 -7
- package/javascript/utils/animated/AnimatedRouteCoordinatesArray.ts +16 -20
- package/javascript/utils/animated/AnimatedShape.ts +15 -15
- package/javascript/utils/deprecation.ts +6 -3
- package/javascript/utils/filterUtils.ts +1 -1
- package/javascript/utils/geoUtils.ts +8 -8
- package/javascript/utils/index.ts +14 -14
- package/javascript/utils/styleMap.ts +18 -18
- package/package.json +28 -15
- package/plugin/build/withMapLibre.d.ts +2 -2
- package/plugin/build/withMapLibre.js +24 -24
- package/scripts/autogenerate.js +1 -1
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -169
- package/.prettierrc.js +0 -7
- package/.yarn/sdks/eslint/bin/eslint.js +0 -27
- package/.yarn/sdks/eslint/lib/api.js +0 -27
- package/.yarn/sdks/eslint/lib/unsupported-api.js +0 -27
- package/.yarn/sdks/eslint/package.json +0 -14
- package/.yarn/sdks/integrations.yml +0 -5
- package/.yarn/sdks/prettier/bin/prettier.cjs +0 -27
- package/.yarn/sdks/prettier/index.cjs +0 -27
- package/.yarn/sdks/prettier/package.json +0 -7
- package/.yarn/sdks/typescript/bin/tsc +0 -27
- package/.yarn/sdks/typescript/bin/tsserver +0 -27
- package/.yarn/sdks/typescript/lib/tsc.js +0 -27
- package/.yarn/sdks/typescript/lib/tsserver.js +0 -239
- package/.yarn/sdks/typescript/lib/tsserverlibrary.js +0 -239
- package/.yarn/sdks/typescript/lib/typescript.js +0 -27
- package/.yarn/sdks/typescript/package.json +0 -10
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {CircleLayerStyleProps} from '../utils/MaplibreStyles';
|
|
1
|
+
import React, { ReactElement, useEffect, useImperativeHandle } from "react";
|
|
3
2
|
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
3
|
+
import CircleLayer from "./CircleLayer";
|
|
4
|
+
import HeadingIndicator from "./HeadingIndicator";
|
|
5
|
+
import NativeUserLocation from "./NativeUserLocation";
|
|
6
|
+
import Annotation from "./annotations/Annotation";
|
|
7
|
+
import locationManager, { Location } from "../modules/location/locationManager";
|
|
8
|
+
import { CircleLayerStyleProps } from "../utils/MaplibreStyles";
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const mapboxBlue = 'rgba(51, 181, 229, 100)';
|
|
10
|
+
const mapboxBlue = "rgba(51, 181, 229, 100)";
|
|
12
11
|
|
|
13
12
|
const layerStyles: Record<string, CircleLayerStyleProps> = {
|
|
14
13
|
pluse: {
|
|
15
14
|
circleRadius: 15,
|
|
16
15
|
circleColor: mapboxBlue,
|
|
17
16
|
circleOpacity: 0.2,
|
|
18
|
-
circlePitchAlignment:
|
|
17
|
+
circlePitchAlignment: "map",
|
|
19
18
|
},
|
|
20
19
|
background: {
|
|
21
20
|
circleRadius: 9,
|
|
22
|
-
circleColor:
|
|
23
|
-
circlePitchAlignment:
|
|
21
|
+
circleColor: "#fff",
|
|
22
|
+
circlePitchAlignment: "map",
|
|
24
23
|
},
|
|
25
24
|
foreground: {
|
|
26
25
|
circleRadius: 6,
|
|
27
26
|
circleColor: mapboxBlue,
|
|
28
|
-
circlePitchAlignment:
|
|
27
|
+
circlePitchAlignment: "map",
|
|
29
28
|
},
|
|
30
29
|
};
|
|
31
30
|
|
|
@@ -50,7 +49,7 @@ export const normalIcon = (
|
|
|
50
49
|
style={layerStyles.foreground}
|
|
51
50
|
/>,
|
|
52
51
|
...(showsUserHeadingIndicator && heading
|
|
53
|
-
? [HeadingIndicator({heading})]
|
|
52
|
+
? [HeadingIndicator({ heading })]
|
|
54
53
|
: []),
|
|
55
54
|
];
|
|
56
55
|
|
|
@@ -63,7 +62,7 @@ interface UserLocationProps {
|
|
|
63
62
|
* Which render mode to use.
|
|
64
63
|
* Can either be `normal` or `native`
|
|
65
64
|
*/
|
|
66
|
-
renderMode?:
|
|
65
|
+
renderMode?: "normal" | "native";
|
|
67
66
|
/**
|
|
68
67
|
* native/android only render mode
|
|
69
68
|
*
|
|
@@ -73,7 +72,7 @@ interface UserLocationProps {
|
|
|
73
72
|
*
|
|
74
73
|
* @platform android
|
|
75
74
|
*/
|
|
76
|
-
androidRenderMode?:
|
|
75
|
+
androidRenderMode?: "normal" | "compass" | "gps";
|
|
77
76
|
/**
|
|
78
77
|
* Whether location icon is visible
|
|
79
78
|
*/
|
|
@@ -109,12 +108,12 @@ interface UserLocationState {
|
|
|
109
108
|
}
|
|
110
109
|
|
|
111
110
|
export enum UserLocationRenderMode {
|
|
112
|
-
Native =
|
|
113
|
-
Normal =
|
|
111
|
+
Native = "native",
|
|
112
|
+
Normal = "normal",
|
|
114
113
|
}
|
|
115
114
|
|
|
116
115
|
export interface UserLocationRef {
|
|
117
|
-
setLocationManager: (props: {running: boolean}) => Promise<void>;
|
|
116
|
+
setLocationManager: (props: { running: boolean }) => Promise<void>;
|
|
118
117
|
needsLocationManagerRunning: () => boolean;
|
|
119
118
|
_onLocationUpdate: (location: Location | null) => void;
|
|
120
119
|
}
|
|
@@ -127,7 +126,7 @@ const UserLocation = React.memo(
|
|
|
127
126
|
visible = true,
|
|
128
127
|
showsUserHeadingIndicator = false,
|
|
129
128
|
minDisplacement = 0,
|
|
130
|
-
renderMode =
|
|
129
|
+
renderMode = "normal",
|
|
131
130
|
androidRenderMode,
|
|
132
131
|
children,
|
|
133
132
|
onUpdate,
|
|
@@ -183,7 +182,7 @@ const UserLocation = React.memo(
|
|
|
183
182
|
|
|
184
183
|
return (): void => {
|
|
185
184
|
_isMounted.current = false;
|
|
186
|
-
setLocationManager({running: false});
|
|
185
|
+
setLocationManager({ running: false });
|
|
187
186
|
};
|
|
188
187
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
189
188
|
}, []);
|
|
@@ -236,7 +235,7 @@ const UserLocation = React.memo(
|
|
|
236
235
|
let heading;
|
|
237
236
|
|
|
238
237
|
if (location && location.coords) {
|
|
239
|
-
const {longitude, latitude} = location.coords;
|
|
238
|
+
const { longitude, latitude } = location.coords;
|
|
240
239
|
heading = location.coords.heading;
|
|
241
240
|
coordinates = [longitude, latitude];
|
|
242
241
|
}
|
|
@@ -277,7 +276,8 @@ const UserLocation = React.memo(
|
|
|
277
276
|
coordinates={userLocationState.coordinates}
|
|
278
277
|
style={{
|
|
279
278
|
iconRotate: userLocationState.heading,
|
|
280
|
-
}}
|
|
279
|
+
}}
|
|
280
|
+
>
|
|
281
281
|
{children ||
|
|
282
282
|
normalIcon(showsUserHeadingIndicator, userLocationState.heading)}
|
|
283
283
|
</Annotation>
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {getFilter} from '../utils/filterUtils';
|
|
4
|
-
import {copyPropertiesAsDeprecated} from '../utils/deprecation';
|
|
5
|
-
import BaseProps from '../types/BaseProps';
|
|
6
|
-
import OnPressEvent from '../types/OnPressEvent';
|
|
7
|
-
import useAbstractSource from '../hooks/useAbstractSource';
|
|
8
|
-
import useNativeBridge from '../hooks/useNativeBridge';
|
|
9
|
-
|
|
10
|
-
import React, {memo, useImperativeHandle} from 'react';
|
|
1
|
+
import { featureCollection } from "@turf/helpers";
|
|
2
|
+
import React, { memo, useImperativeHandle } from "react";
|
|
11
3
|
import {
|
|
12
4
|
NativeModules,
|
|
13
5
|
NativeSyntheticEvent,
|
|
14
6
|
requireNativeComponent,
|
|
15
|
-
} from
|
|
16
|
-
|
|
7
|
+
} from "react-native";
|
|
8
|
+
|
|
9
|
+
import useAbstractSource from "../hooks/useAbstractSource";
|
|
10
|
+
import useNativeBridge from "../hooks/useNativeBridge";
|
|
11
|
+
import BaseProps from "../types/BaseProps";
|
|
12
|
+
import OnPressEvent from "../types/OnPressEvent";
|
|
13
|
+
import { cloneReactChildrenWithProps, isFunction, isAndroid } from "../utils";
|
|
14
|
+
import { FilterExpression } from "../utils/MaplibreStyles";
|
|
15
|
+
import { copyPropertiesAsDeprecated } from "../utils/deprecation";
|
|
16
|
+
import { getFilter } from "../utils/filterUtils";
|
|
17
17
|
|
|
18
18
|
const MapLibreGL = NativeModules.MLNModule;
|
|
19
19
|
|
|
20
|
-
export const NATIVE_MODULE_NAME =
|
|
20
|
+
export const NATIVE_MODULE_NAME = "RCTMLNVectorSource";
|
|
21
21
|
|
|
22
22
|
interface VectorSourceProps extends BaseProps {
|
|
23
23
|
/**
|
|
@@ -122,7 +122,7 @@ const VectorSource = memo(
|
|
|
122
122
|
// _runPendingNativeCommands,
|
|
123
123
|
_onAndroidCallback,
|
|
124
124
|
} = useNativeBridge(NATIVE_MODULE_NAME);
|
|
125
|
-
const {setNativeRef, _nativeRef} = useAbstractSource<NativeProps>();
|
|
125
|
+
const { setNativeRef, _nativeRef } = useAbstractSource<NativeProps>();
|
|
126
126
|
|
|
127
127
|
// const _setNativeRef = (
|
|
128
128
|
// nativeRef: (Component<NativeProps> & Readonly<NativeMethods>) | null,
|
|
@@ -140,8 +140,8 @@ const VectorSource = memo(
|
|
|
140
140
|
if (!_nativeRef) {
|
|
141
141
|
return featureCollection([]);
|
|
142
142
|
}
|
|
143
|
-
const res: {data: string | GeoJSON.FeatureCollection} =
|
|
144
|
-
await _runNativeCommand(
|
|
143
|
+
const res: { data: string | GeoJSON.FeatureCollection } =
|
|
144
|
+
await _runNativeCommand("features", _nativeRef, [
|
|
145
145
|
[[layerIDs, getFilter(filter)]],
|
|
146
146
|
]);
|
|
147
147
|
|
|
@@ -153,16 +153,16 @@ const VectorSource = memo(
|
|
|
153
153
|
};
|
|
154
154
|
|
|
155
155
|
const onPress = (
|
|
156
|
-
event: NativeSyntheticEvent<{payload: OnPressEvent}>,
|
|
156
|
+
event: NativeSyntheticEvent<{ payload: OnPressEvent }>,
|
|
157
157
|
): void => {
|
|
158
|
-
const {onPress} = props;
|
|
158
|
+
const { onPress } = props;
|
|
159
159
|
|
|
160
160
|
if (!onPress) {
|
|
161
161
|
return;
|
|
162
162
|
}
|
|
163
163
|
const {
|
|
164
164
|
nativeEvent: {
|
|
165
|
-
payload: {features, coordinates, point},
|
|
165
|
+
payload: { features, coordinates, point },
|
|
166
166
|
},
|
|
167
167
|
} = event;
|
|
168
168
|
let newEvent = {
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import SymbolLayer from '../SymbolLayer';
|
|
2
|
-
import Animated from '../../utils/animated/Animated';
|
|
3
|
-
import AnimatedMapPoint from '../../utils/animated/AnimatedPoint';
|
|
4
|
-
import OnPressEvent from '../../types/OnPressEvent';
|
|
5
|
-
import {SymbolLayerStyleProps} from '../../utils/MaplibreStyles';
|
|
6
|
-
|
|
7
1
|
import React, {
|
|
8
2
|
ReactElement,
|
|
9
3
|
useCallback,
|
|
10
4
|
useEffect,
|
|
11
5
|
useImperativeHandle,
|
|
12
|
-
} from
|
|
13
|
-
import {Animated as RNAnimated, Easing} from
|
|
6
|
+
} from "react";
|
|
7
|
+
import { Animated as RNAnimated, Easing } from "react-native";
|
|
8
|
+
|
|
9
|
+
import OnPressEvent from "../../types/OnPressEvent";
|
|
10
|
+
import { SymbolLayerStyleProps } from "../../utils/MaplibreStyles";
|
|
11
|
+
import { AnimatedShapeSource } from "../../utils/animated/Animated";
|
|
12
|
+
import AnimatedMapPoint from "../../utils/animated/AnimatedPoint";
|
|
13
|
+
import SymbolLayer from "../SymbolLayer";
|
|
14
14
|
|
|
15
15
|
interface AnnotationProps {
|
|
16
16
|
id: string;
|
|
@@ -29,7 +29,7 @@ type Shape = AnimatedMapPoint | GeoJSON.Point;
|
|
|
29
29
|
function getShapeFromProps(props: Partial<AnnotationProps> = {}): Shape {
|
|
30
30
|
const lng = props.coordinates?.[0] || 0;
|
|
31
31
|
const lat = props.coordinates?.[1] || 0;
|
|
32
|
-
const point: GeoJSON.Point = {type:
|
|
32
|
+
const point: GeoJSON.Point = { type: "Point", coordinates: [lng, lat] };
|
|
33
33
|
|
|
34
34
|
if (props.animated) {
|
|
35
35
|
return new AnimatedMapPoint(point);
|
|
@@ -77,7 +77,7 @@ const Annotation = React.forwardRef<AnnotationRef, AnnotationProps>(
|
|
|
77
77
|
);
|
|
78
78
|
|
|
79
79
|
// this will run useEffect only when actual coordinates values change
|
|
80
|
-
const coordinateDeps = props.coordinates?.join(
|
|
80
|
+
const coordinateDeps = props.coordinates?.join(",");
|
|
81
81
|
|
|
82
82
|
useEffect(() => {
|
|
83
83
|
if (!Array.isArray(props.coordinates)) {
|
|
@@ -127,7 +127,7 @@ const Annotation = React.forwardRef<AnnotationRef, AnnotationProps>(
|
|
|
127
127
|
|
|
128
128
|
const children = [];
|
|
129
129
|
const symbolStyle: SymbolLayerStyleProps | undefined = props.icon
|
|
130
|
-
? {...props.style, iconImage: props.icon}
|
|
130
|
+
? { ...props.style, iconImage: props.icon }
|
|
131
131
|
: undefined;
|
|
132
132
|
|
|
133
133
|
if (symbolStyle) {
|
|
@@ -145,16 +145,17 @@ const Annotation = React.forwardRef<AnnotationRef, AnnotationProps>(
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
return (
|
|
148
|
-
<
|
|
148
|
+
<AnimatedShapeSource
|
|
149
149
|
id={props.id}
|
|
150
150
|
onPress={_onPress}
|
|
151
|
-
shape={shape as RNAnimated.WithAnimatedObject<GeoJSON.Point>}
|
|
151
|
+
shape={shape as RNAnimated.WithAnimatedObject<GeoJSON.Point>}
|
|
152
|
+
>
|
|
152
153
|
{children}
|
|
153
|
-
</
|
|
154
|
+
</AnimatedShapeSource>
|
|
154
155
|
);
|
|
155
156
|
},
|
|
156
157
|
);
|
|
157
158
|
|
|
158
|
-
Annotation.displayName =
|
|
159
|
+
Annotation.displayName = "Annotation";
|
|
159
160
|
|
|
160
161
|
export default Annotation;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import React, { useMemo, useRef } from "react";
|
|
2
|
+
import { processColor, NativeMethods } from "react-native";
|
|
3
|
+
|
|
4
|
+
import BaseProps from "../types/BaseProps";
|
|
3
5
|
import {
|
|
4
6
|
AllLayerStyleProps,
|
|
5
7
|
ExpressionField,
|
|
6
8
|
ExpressionName,
|
|
7
9
|
FilterExpression,
|
|
8
|
-
} from
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
import React, {useMemo, useRef} from 'react';
|
|
12
|
-
import {processColor, NativeMethods} from 'react-native';
|
|
10
|
+
} from "../utils/MaplibreStyles";
|
|
11
|
+
import { StyleValue, transformStyle } from "../utils/StyleValue";
|
|
12
|
+
import { getFilter } from "../utils/filterUtils";
|
|
13
13
|
|
|
14
14
|
export interface BaseLayerProps {
|
|
15
15
|
/**
|
|
@@ -57,7 +57,7 @@ export interface BaseLayerProps {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
export interface NativeBaseProps {
|
|
60
|
-
reactStyle?: {[key: string]: StyleValue};
|
|
60
|
+
reactStyle?: { [key: string]: StyleValue };
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
export default function useAbstractLayer<
|
|
@@ -71,7 +71,7 @@ export default function useAbstractLayer<
|
|
|
71
71
|
instance: (React.Component<NativeProps> & Readonly<NativeMethods>) | null,
|
|
72
72
|
) => void;
|
|
73
73
|
getStyleTypeFormatter: (styleType: string) => typeof processColor | undefined;
|
|
74
|
-
setNativeProps: (nativeProps: {[key: string]: unknown}) => void;
|
|
74
|
+
setNativeProps: (nativeProps: { [key: string]: unknown }) => void;
|
|
75
75
|
} {
|
|
76
76
|
const nativeLayer = useRef<
|
|
77
77
|
(React.Component<NativeProps> & Readonly<NativeMethods>) | null
|
|
@@ -102,14 +102,17 @@ export default function useAbstractLayer<
|
|
|
102
102
|
const getStyleTypeFormatter = (
|
|
103
103
|
styleType: string,
|
|
104
104
|
): typeof processColor | undefined => {
|
|
105
|
-
return styleType ===
|
|
105
|
+
return styleType === "color" ? processColor : undefined;
|
|
106
106
|
};
|
|
107
107
|
|
|
108
|
-
const setNativeProps = (nativeProps: {[key: string]: unknown}): void => {
|
|
108
|
+
const setNativeProps = (nativeProps: { [key: string]: unknown }): void => {
|
|
109
109
|
if (nativeLayer.current) {
|
|
110
110
|
let propsToPass = nativeProps;
|
|
111
111
|
if (nativeProps.style) {
|
|
112
|
-
propsToPass = {
|
|
112
|
+
propsToPass = {
|
|
113
|
+
...nativeProps,
|
|
114
|
+
reactStyle: transformStyle(props.style),
|
|
115
|
+
};
|
|
113
116
|
}
|
|
114
117
|
nativeLayer.current.setNativeProps(propsToPass);
|
|
115
118
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, {useRef} from
|
|
2
|
-
import {NativeMethods} from
|
|
1
|
+
import React, { useRef } from "react";
|
|
2
|
+
import { NativeMethods } from "react-native";
|
|
3
3
|
|
|
4
4
|
export default function useAbstractSource<NativePropsType extends object>(): {
|
|
5
5
|
_nativeRef:
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import React, { Component, SyntheticEvent, useRef } from "react";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { runNativeCommand, isAndroid, NativeArg } from "../utils";
|
|
4
4
|
|
|
5
|
-
export type RNMLEvent<PayloadType = {[key: string]: string}> = {
|
|
5
|
+
export type RNMLEvent<PayloadType = { [key: string]: string }> = {
|
|
6
6
|
payload: PayloadType;
|
|
7
7
|
type: string;
|
|
8
8
|
};
|
|
@@ -41,7 +41,7 @@ const useNativeBridge: (moduleName: string) => UseNativeBridge = (
|
|
|
41
41
|
resolve: (value: ReturnType) => void,
|
|
42
42
|
reject: (error: Error) => void,
|
|
43
43
|
): void => {
|
|
44
|
-
_callbackMap.current.set(id, {resolve, reject});
|
|
44
|
+
_callbackMap.current.set(id, { resolve, reject });
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
const _removeAndroidCallback = (id: string): void => {
|
|
@@ -57,7 +57,7 @@ const useNativeBridge: (moduleName: string) => UseNativeBridge = (
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
_callbackMap.current.delete(callbackID);
|
|
60
|
-
const {payload} = e.nativeEvent;
|
|
60
|
+
const { payload } = e.nativeEvent;
|
|
61
61
|
if (payload.error) {
|
|
62
62
|
callback.reject.call(null, new Error(payload.error));
|
|
63
63
|
} else {
|
|
@@ -90,9 +90,9 @@ const useNativeBridge: (moduleName: string) => UseNativeBridge = (
|
|
|
90
90
|
args: NativeArg[] = [],
|
|
91
91
|
): Promise<ReturnType> => {
|
|
92
92
|
if (!nativeRef) {
|
|
93
|
-
return new Promise(resolve => {
|
|
93
|
+
return new Promise((resolve) => {
|
|
94
94
|
_preRefMapMethodQueue.current.push({
|
|
95
|
-
method: {name: methodName, args},
|
|
95
|
+
method: { name: methodName, args },
|
|
96
96
|
resolver: resolve,
|
|
97
97
|
});
|
|
98
98
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, {Component, useRef} from
|
|
2
|
-
import {NativeMethods} from
|
|
1
|
+
import React, { Component, useRef } from "react";
|
|
2
|
+
import { NativeMethods } from "react-native";
|
|
3
3
|
|
|
4
4
|
type NativeRef<NativeProps> = Component<NativeProps> & Readonly<NativeMethods>;
|
|
5
5
|
|
package/javascript/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
NativeModules,
|
|
3
3
|
NativeEventEmitter,
|
|
4
4
|
EmitterSubscription,
|
|
5
|
-
} from
|
|
5
|
+
} from "react-native";
|
|
6
6
|
|
|
7
7
|
const MapLibreGL = NativeModules.MLNModule;
|
|
8
8
|
const MapLibreGLLocationManager = NativeModules.MLNLocationModule;
|
|
@@ -89,7 +89,7 @@ class LocationManager {
|
|
|
89
89
|
lastKnownLocation =
|
|
90
90
|
await MapLibreGLLocationManager.getLastKnownLocation();
|
|
91
91
|
} catch (error) {
|
|
92
|
-
console.log(
|
|
92
|
+
console.log("locationManager Error: ", error);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
if (!this._lastKnownLocation && lastKnownLocation) {
|
|
@@ -114,7 +114,7 @@ class LocationManager {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
removeListener(listener: (location: Location) => void): void {
|
|
117
|
-
this._listeners = this._listeners.filter(l => l !== listener);
|
|
117
|
+
this._listeners = this._listeners.filter((l) => l !== listener);
|
|
118
118
|
if (this._listeners.length === 0) {
|
|
119
119
|
this.stop();
|
|
120
120
|
}
|
|
@@ -155,7 +155,7 @@ class LocationManager {
|
|
|
155
155
|
onUpdate(location: Location): void {
|
|
156
156
|
this._lastKnownLocation = location;
|
|
157
157
|
|
|
158
|
-
this._listeners.forEach(l => l(location));
|
|
158
|
+
this._listeners.forEach((l) => l(location));
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { toJSONString } from "../../utils";
|
|
2
|
+
import { makeLatLngBounds } from "../../utils/geoUtils";
|
|
3
3
|
|
|
4
4
|
export interface OfflineCreatePackInputOptions {
|
|
5
5
|
name: string;
|
|
@@ -32,16 +32,16 @@ class OfflineCreatePackOptions {
|
|
|
32
32
|
_assert(options: OfflineCreatePackInputOptions): void {
|
|
33
33
|
if (!options.styleURL) {
|
|
34
34
|
throw new Error(
|
|
35
|
-
|
|
35
|
+
"Style URL must be provided for creating an offline pack",
|
|
36
36
|
);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
if (!options.name) {
|
|
40
|
-
throw new Error(
|
|
40
|
+
throw new Error("Name must be provided for creating an offline pack");
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
if (!options.bounds) {
|
|
44
|
-
throw new Error(
|
|
44
|
+
throw new Error("Bounds must be provided for creating an offline pack");
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { NativeModules } from "react-native";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import OfflineCreatePackOptions from "./OfflineCreatePackOptions";
|
|
4
4
|
|
|
5
5
|
const MapLibreGLOfflineManager = NativeModules.MLNOfflineModule;
|
|
6
6
|
|
|
@@ -25,7 +25,7 @@ class OfflinePack {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
get name(): string | null {
|
|
28
|
-
const {metadata} = this;
|
|
28
|
+
const { metadata } = this;
|
|
29
29
|
return metadata && metadata.name;
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {isUndefined, isFunction, isAndroid} from '../../utils';
|
|
2
|
-
|
|
3
|
-
import OfflineCreatePackOptions, {
|
|
4
|
-
OfflineCreatePackInputOptions,
|
|
5
|
-
} from './OfflineCreatePackOptions';
|
|
6
|
-
import OfflinePack from './OfflinePack';
|
|
7
|
-
|
|
8
1
|
import {
|
|
9
2
|
NativeModules,
|
|
10
3
|
NativeEventEmitter,
|
|
11
4
|
EventSubscription,
|
|
12
|
-
} from
|
|
5
|
+
} from "react-native";
|
|
6
|
+
|
|
7
|
+
import OfflineCreatePackOptions, {
|
|
8
|
+
OfflineCreatePackInputOptions,
|
|
9
|
+
} from "./OfflineCreatePackOptions";
|
|
10
|
+
import OfflinePack from "./OfflinePack";
|
|
11
|
+
import { isUndefined, isFunction, isAndroid } from "../../utils";
|
|
13
12
|
|
|
14
13
|
const MapLibreGL = NativeModules.MLNModule;
|
|
15
14
|
const MapLibreGLOfflineManager = NativeModules.MLNOfflineModule;
|
|
@@ -232,7 +231,7 @@ class OfflineManager {
|
|
|
232
231
|
async getPacks(): Promise<OfflinePack[]> {
|
|
233
232
|
await this._initialize();
|
|
234
233
|
return Object.keys(this._offlinePacks).map(
|
|
235
|
-
name => this._offlinePacks[name],
|
|
234
|
+
(name) => this._offlinePacks[name],
|
|
236
235
|
);
|
|
237
236
|
}
|
|
238
237
|
|
|
@@ -340,7 +339,7 @@ class OfflineManager {
|
|
|
340
339
|
// manually set a listener, since listeners are only set on create flow
|
|
341
340
|
await MapLibreGLOfflineManager.setPackObserver(packName);
|
|
342
341
|
} catch (e) {
|
|
343
|
-
console.log(
|
|
342
|
+
console.log("Unable to set pack observer", e);
|
|
344
343
|
}
|
|
345
344
|
}
|
|
346
345
|
}
|
|
@@ -393,7 +392,7 @@ class OfflineManager {
|
|
|
393
392
|
}
|
|
394
393
|
|
|
395
394
|
_onProgress(e: ProgressEvent): void {
|
|
396
|
-
const {name, state} = e.payload;
|
|
395
|
+
const { name, state } = e.payload;
|
|
397
396
|
|
|
398
397
|
if (!this._hasListeners(name, this._progressListeners)) {
|
|
399
398
|
return;
|
|
@@ -409,7 +408,7 @@ class OfflineManager {
|
|
|
409
408
|
}
|
|
410
409
|
|
|
411
410
|
_onError(e: ErrorEvent): void {
|
|
412
|
-
const {name} = e.payload;
|
|
411
|
+
const { name } = e.payload;
|
|
413
412
|
|
|
414
413
|
if (!this._hasListeners(name, this._errorListeners)) {
|
|
415
414
|
return;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {makePoint, makeFeatureCollection} from '../../utils/geoUtils';
|
|
1
|
+
import { NativeModules } from "react-native";
|
|
3
2
|
|
|
4
|
-
import {
|
|
3
|
+
import { toJSONString } from "../../utils";
|
|
4
|
+
import { makePoint, makeFeatureCollection } from "../../utils/geoUtils";
|
|
5
5
|
|
|
6
6
|
const MapLibreGL = NativeModules.MLNModule;
|
|
7
7
|
|
|
@@ -46,7 +46,7 @@ export class SnapshotOptions {
|
|
|
46
46
|
constructor(options: SnapshotInputOptions) {
|
|
47
47
|
if (!options.centerCoordinate && !options.bounds) {
|
|
48
48
|
throw new Error(
|
|
49
|
-
|
|
49
|
+
"Center coordinate or bounds must be supplied in order to take a snapshot",
|
|
50
50
|
);
|
|
51
51
|
}
|
|
52
52
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { NativeModules } from "react-native";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import SnapshotOptions, { SnapshotInputOptions } from "./SnapshotOptions";
|
|
4
4
|
|
|
5
5
|
const MapLibreGLSnapshotManger = NativeModules.MLNSnapshotModule;
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Permission, PermissionsAndroid } from "react-native";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { isAndroid } from "./utils";
|
|
4
4
|
|
|
5
5
|
export async function requestAndroidLocationPermissions(): Promise<boolean> {
|
|
6
6
|
if (isAndroid()) {
|
|
@@ -25,5 +25,5 @@ export async function requestAndroidLocationPermissions(): Promise<boolean> {
|
|
|
25
25
|
return false;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
throw new Error(
|
|
28
|
+
throw new Error("You should only call this method on Android!");
|
|
29
29
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {SyntheticEvent} from
|
|
1
|
+
import { SyntheticEvent } from "react";
|
|
2
2
|
|
|
3
3
|
export type MaplibreGLEvent<
|
|
4
4
|
T extends string,
|
|
5
5
|
P = GeoJSON.Feature,
|
|
6
6
|
V = Element,
|
|
7
|
-
> = SyntheticEvent<V, {type: T; payload: P}>;
|
|
7
|
+
> = SyntheticEvent<V, { type: T; payload: P }>;
|
|
8
|
+
|
|
9
|
+
export enum StyleURL {
|
|
10
|
+
Default = "https://demotiles.maplibre.org/style.json",
|
|
11
|
+
}
|