@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,34 +1,34 @@
|
|
|
1
|
-
import
|
|
2
|
-
import BaseProps from '../types/BaseProps';
|
|
3
|
-
import OnPressEvent from '../types/OnPressEvent';
|
|
4
|
-
import {
|
|
5
|
-
cloneReactChildrenWithProps,
|
|
6
|
-
isAndroid,
|
|
7
|
-
isFunction,
|
|
8
|
-
toJSONString,
|
|
9
|
-
} from '../utils';
|
|
10
|
-
import {ExpressionField, FilterExpression} from '../utils/MaplibreStyles';
|
|
11
|
-
import {copyPropertiesAsDeprecated} from '../utils/deprecation';
|
|
12
|
-
import {getFilter} from '../utils/filterUtils';
|
|
13
|
-
|
|
14
|
-
import {
|
|
15
|
-
NativeMethods,
|
|
16
|
-
NativeModules,
|
|
17
|
-
NativeSyntheticEvent,
|
|
18
|
-
requireNativeComponent,
|
|
19
|
-
} from 'react-native';
|
|
1
|
+
import { Feature, FeatureCollection } from "@turf/helpers";
|
|
20
2
|
import React, {
|
|
21
3
|
Component,
|
|
22
4
|
ReactElement,
|
|
23
5
|
memo,
|
|
24
6
|
useImperativeHandle,
|
|
25
7
|
useRef,
|
|
26
|
-
} from
|
|
27
|
-
import {
|
|
8
|
+
} from "react";
|
|
9
|
+
import {
|
|
10
|
+
NativeMethods,
|
|
11
|
+
NativeModules,
|
|
12
|
+
NativeSyntheticEvent,
|
|
13
|
+
requireNativeComponent,
|
|
14
|
+
} from "react-native";
|
|
15
|
+
|
|
16
|
+
import useNativeBridge from "../hooks/useNativeBridge";
|
|
17
|
+
import BaseProps from "../types/BaseProps";
|
|
18
|
+
import OnPressEvent from "../types/OnPressEvent";
|
|
19
|
+
import {
|
|
20
|
+
cloneReactChildrenWithProps,
|
|
21
|
+
isAndroid,
|
|
22
|
+
isFunction,
|
|
23
|
+
toJSONString,
|
|
24
|
+
} from "../utils";
|
|
25
|
+
import { ExpressionField, FilterExpression } from "../utils/MaplibreStyles";
|
|
26
|
+
import { copyPropertiesAsDeprecated } from "../utils/deprecation";
|
|
27
|
+
import { getFilter } from "../utils/filterUtils";
|
|
28
28
|
|
|
29
29
|
const MapLibreGL = NativeModules.MLNModule;
|
|
30
|
-
export const NATIVE_MODULE_NAME =
|
|
31
|
-
export const SHAPE_SOURCE_NATIVE_ASSETS_KEY =
|
|
30
|
+
export const NATIVE_MODULE_NAME = "RCTMLNShapeSource";
|
|
31
|
+
export const SHAPE_SOURCE_NATIVE_ASSETS_KEY = "assets";
|
|
32
32
|
|
|
33
33
|
interface NativeProps {
|
|
34
34
|
shape?: string;
|
|
@@ -82,7 +82,7 @@ export interface ShapeSourceProps extends BaseProps {
|
|
|
82
82
|
* Example: `{ "resultingSum": [["+", ["accumulated"], ["get", "resultingSum"]], ["get", "scalerank"]] }`
|
|
83
83
|
*
|
|
84
84
|
*/
|
|
85
|
-
clusterProperties?: {[propertyName: string]: ExpressionField};
|
|
85
|
+
clusterProperties?: { [propertyName: string]: ExpressionField };
|
|
86
86
|
/**
|
|
87
87
|
* Specifies the maximum zoom level at which to create vector tiles.
|
|
88
88
|
* A greater value produces greater detail at high zoom levels.
|
|
@@ -146,7 +146,7 @@ export interface ShapeSourceRef {
|
|
|
146
146
|
): Promise<FeatureCollection>;
|
|
147
147
|
getClusterChildren(feature: Feature): Promise<FeatureCollection>;
|
|
148
148
|
setNativeProps: (props: NativeProps) => void;
|
|
149
|
-
onPress: (event: NativeSyntheticEvent<{payload: OnPressEvent}>) => void;
|
|
149
|
+
onPress: (event: NativeSyntheticEvent<{ payload: OnPressEvent }>) => void;
|
|
150
150
|
|
|
151
151
|
// this was required by existing test __tests__/utils/animated/AnimatedCoordinatesArray.test.js
|
|
152
152
|
_nativeRef: RCTMLNShapeSourceRefType | undefined;
|
|
@@ -157,7 +157,7 @@ export interface ShapeSourceRef {
|
|
|
157
157
|
* The shape may be a url or a GeoJSON object
|
|
158
158
|
*/
|
|
159
159
|
const ShapeSource = memo(
|
|
160
|
-
React.forwardRef(
|
|
160
|
+
React.forwardRef<ShapeSourceRef, ShapeSourceProps>(
|
|
161
161
|
(
|
|
162
162
|
{
|
|
163
163
|
id: shapeId = MapLibreGL.StyleSource.DefaultSourceID,
|
|
@@ -219,8 +219,11 @@ const ShapeSource = memo(
|
|
|
219
219
|
|
|
220
220
|
const _nativeRef = useRef<RCTMLNShapeSourceRefType>();
|
|
221
221
|
|
|
222
|
-
const {
|
|
223
|
-
|
|
222
|
+
const {
|
|
223
|
+
_runNativeCommand,
|
|
224
|
+
_runPendingNativeCommands,
|
|
225
|
+
_onAndroidCallback,
|
|
226
|
+
} = useNativeBridge(NATIVE_MODULE_NAME);
|
|
224
227
|
|
|
225
228
|
const _setNativeRef = (nativeRef: RCTMLNShapeSourceRefType): void => {
|
|
226
229
|
_nativeRef.current = nativeRef;
|
|
@@ -230,11 +233,10 @@ const ShapeSource = memo(
|
|
|
230
233
|
async function features(
|
|
231
234
|
filter?: FilterExpression,
|
|
232
235
|
): Promise<FeatureCollection> {
|
|
233
|
-
const res: {data: string | FeatureCollection} =
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
);
|
|
236
|
+
const res: { data: string | FeatureCollection } =
|
|
237
|
+
await _runNativeCommand("features", _nativeRef.current, [
|
|
238
|
+
getFilter(filter),
|
|
239
|
+
]);
|
|
238
240
|
|
|
239
241
|
if (isAndroid()) {
|
|
240
242
|
return JSON.parse(res.data as string);
|
|
@@ -246,20 +248,20 @@ const ShapeSource = memo(
|
|
|
246
248
|
async function getClusterExpansionZoom(
|
|
247
249
|
feature: Feature,
|
|
248
250
|
): Promise<number> {
|
|
249
|
-
if (typeof feature ===
|
|
251
|
+
if (typeof feature === "number") {
|
|
250
252
|
console.warn(
|
|
251
|
-
|
|
253
|
+
"Using cluster_id is deprecated and will be removed from the future releases. Please use cluster as an argument instead.",
|
|
252
254
|
);
|
|
253
|
-
const res: {data: number} = await _runNativeCommand(
|
|
254
|
-
|
|
255
|
+
const res: { data: number } = await _runNativeCommand(
|
|
256
|
+
"getClusterExpansionZoomById",
|
|
255
257
|
_nativeRef.current,
|
|
256
258
|
[feature],
|
|
257
259
|
);
|
|
258
260
|
return res.data;
|
|
259
261
|
}
|
|
260
262
|
|
|
261
|
-
const res: {data: number} = await _runNativeCommand(
|
|
262
|
-
|
|
263
|
+
const res: { data: number } = await _runNativeCommand(
|
|
264
|
+
"getClusterExpansionZoom",
|
|
263
265
|
_nativeRef.current,
|
|
264
266
|
[JSON.stringify(feature)],
|
|
265
267
|
);
|
|
@@ -271,13 +273,13 @@ const ShapeSource = memo(
|
|
|
271
273
|
limit: number,
|
|
272
274
|
offset: number,
|
|
273
275
|
): Promise<FeatureCollection> {
|
|
274
|
-
if (typeof feature ===
|
|
276
|
+
if (typeof feature === "number") {
|
|
275
277
|
console.warn(
|
|
276
|
-
|
|
278
|
+
"Using cluster_id is deprecated and will be removed from the future releases. Please use cluster as an argument instead.",
|
|
277
279
|
);
|
|
278
|
-
const res: {data: string | FeatureCollection} =
|
|
280
|
+
const res: { data: string | FeatureCollection } =
|
|
279
281
|
await _runNativeCommand(
|
|
280
|
-
|
|
282
|
+
"getClusterLeavesById",
|
|
281
283
|
_nativeRef.current,
|
|
282
284
|
[feature, limit, offset],
|
|
283
285
|
);
|
|
@@ -289,11 +291,12 @@ const ShapeSource = memo(
|
|
|
289
291
|
return res.data as FeatureCollection;
|
|
290
292
|
}
|
|
291
293
|
|
|
292
|
-
const res: {data: string | FeatureCollection} =
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
294
|
+
const res: { data: string | FeatureCollection } =
|
|
295
|
+
await _runNativeCommand("getClusterLeaves", _nativeRef.current, [
|
|
296
|
+
JSON.stringify(feature),
|
|
297
|
+
limit,
|
|
298
|
+
offset,
|
|
299
|
+
]);
|
|
297
300
|
|
|
298
301
|
if (isAndroid()) {
|
|
299
302
|
return JSON.parse(res.data as string);
|
|
@@ -305,13 +308,13 @@ const ShapeSource = memo(
|
|
|
305
308
|
async function getClusterChildren(
|
|
306
309
|
feature: Feature,
|
|
307
310
|
): Promise<FeatureCollection> {
|
|
308
|
-
if (typeof feature ===
|
|
311
|
+
if (typeof feature === "number") {
|
|
309
312
|
console.warn(
|
|
310
|
-
|
|
313
|
+
"Using cluster_id is deprecated and will be removed from the future releases. Please use cluster as an argument instead.",
|
|
311
314
|
);
|
|
312
|
-
const res: {data: string | FeatureCollection} =
|
|
315
|
+
const res: { data: string | FeatureCollection } =
|
|
313
316
|
await _runNativeCommand(
|
|
314
|
-
|
|
317
|
+
"getClusterChildrenById",
|
|
315
318
|
_nativeRef.current,
|
|
316
319
|
[feature],
|
|
317
320
|
);
|
|
@@ -323,11 +326,10 @@ const ShapeSource = memo(
|
|
|
323
326
|
return res.data as FeatureCollection;
|
|
324
327
|
}
|
|
325
328
|
|
|
326
|
-
const res: {data: string | FeatureCollection} =
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
);
|
|
329
|
+
const res: { data: string | FeatureCollection } =
|
|
330
|
+
await _runNativeCommand("getClusterChildren", _nativeRef.current, [
|
|
331
|
+
JSON.stringify(feature),
|
|
332
|
+
]);
|
|
331
333
|
|
|
332
334
|
if (isAndroid()) {
|
|
333
335
|
return JSON.parse(res.data as string);
|
|
@@ -344,7 +346,7 @@ const ShapeSource = memo(
|
|
|
344
346
|
const shallowProps = Object.assign({}, nativeProps);
|
|
345
347
|
|
|
346
348
|
// Adds support for Animated
|
|
347
|
-
if (shallowProps.shape && typeof shallowProps !==
|
|
349
|
+
if (shallowProps.shape && typeof shallowProps !== "string") {
|
|
348
350
|
shallowProps.shape = JSON.stringify(shallowProps.shape);
|
|
349
351
|
}
|
|
350
352
|
|
|
@@ -359,11 +361,11 @@ const ShapeSource = memo(
|
|
|
359
361
|
}
|
|
360
362
|
|
|
361
363
|
function onPress(
|
|
362
|
-
event: NativeSyntheticEvent<{payload: OnPressEvent}>,
|
|
364
|
+
event: NativeSyntheticEvent<{ payload: OnPressEvent }>,
|
|
363
365
|
): void {
|
|
364
366
|
const {
|
|
365
367
|
nativeEvent: {
|
|
366
|
-
payload: {features, coordinates, point},
|
|
368
|
+
payload: { features, coordinates, point },
|
|
367
369
|
},
|
|
368
370
|
} = event;
|
|
369
371
|
let newEvent = {
|
|
@@ -381,7 +383,7 @@ const ShapeSource = memo(
|
|
|
381
383
|
},
|
|
382
384
|
{
|
|
383
385
|
nativeEvent: (
|
|
384
|
-
origNativeEvent: NativeSyntheticEvent<{payload: OnPressEvent}>,
|
|
386
|
+
origNativeEvent: NativeSyntheticEvent<{ payload: OnPressEvent }>,
|
|
385
387
|
) => ({
|
|
386
388
|
...origNativeEvent,
|
|
387
389
|
payload: features[0],
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import {ExpressionField, FilterExpression} from '../utils/MaplibreStyles';
|
|
2
|
-
import {BaseLayerProps} from '../hooks/useAbstractLayer';
|
|
3
|
-
|
|
4
|
-
import CircleLayer from './CircleLayer';
|
|
5
|
-
import RasterLayer from './RasterLayer';
|
|
6
|
-
import SymbolLayer from './SymbolLayer';
|
|
7
|
-
import LineLayer from './LineLayer';
|
|
8
|
-
import FillLayer from './FillLayer';
|
|
9
|
-
import FillExtrusionLayer from './FillExtrusionLayer';
|
|
10
|
-
import BackgroundLayer from './BackgroundLayer';
|
|
11
|
-
import HeatmapLayer from './HeatmapLayer';
|
|
12
|
-
import VectorSource from './VectorSource';
|
|
13
|
-
import RasterSource from './RasterSource';
|
|
14
|
-
import ImageSource from './ImageSource';
|
|
15
|
-
import ShapeSource from './ShapeSource';
|
|
16
|
-
|
|
17
1
|
import React, {
|
|
18
2
|
useMemo,
|
|
19
3
|
useState,
|
|
20
4
|
useEffect,
|
|
21
5
|
ReactElement,
|
|
22
6
|
ComponentType,
|
|
23
|
-
} from
|
|
7
|
+
} from "react";
|
|
8
|
+
|
|
9
|
+
import BackgroundLayer, { BackgroundLayerProps } from "./BackgroundLayer";
|
|
10
|
+
import CircleLayer, { CircleLayerProps } from "./CircleLayer";
|
|
11
|
+
import FillExtrusionLayer, {
|
|
12
|
+
FillExtrusionLayerProps,
|
|
13
|
+
} from "./FillExtrusionLayer";
|
|
14
|
+
import FillLayer, { FillLayerProps } from "./FillLayer";
|
|
15
|
+
import HeatmapLayer, { HeatmapLayerProps } from "./HeatmapLayer";
|
|
16
|
+
import ImageSource from "./ImageSource";
|
|
17
|
+
import LineLayer, { LineLayerProps } from "./LineLayer";
|
|
18
|
+
import RasterLayer, { RasterLayerProps } from "./RasterLayer";
|
|
19
|
+
import RasterSource from "./RasterSource";
|
|
20
|
+
import ShapeSource from "./ShapeSource";
|
|
21
|
+
import SymbolLayer, { SymbolLayerProps } from "./SymbolLayer";
|
|
22
|
+
import VectorSource from "./VectorSource";
|
|
23
|
+
import { ExpressionField, FilterExpression } from "../utils/MaplibreStyles";
|
|
24
24
|
|
|
25
25
|
function toCamelCase(s: string): string {
|
|
26
|
-
return s.replace(/([-_][a-z])/gi, $1 => {
|
|
27
|
-
return $1.toUpperCase().replace(
|
|
26
|
+
return s.replace(/([-_][a-z])/gi, ($1) => {
|
|
27
|
+
return $1.toUpperCase().replace("-", "").replace("_", "");
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -37,9 +37,9 @@ function toCamelCaseKeys(
|
|
|
37
37
|
return {};
|
|
38
38
|
}
|
|
39
39
|
const newObj: Record<string, unknown> = {};
|
|
40
|
-
Object.keys(oldObj).forEach(key => {
|
|
40
|
+
Object.keys(oldObj).forEach((key) => {
|
|
41
41
|
const value = oldObj[key];
|
|
42
|
-
if (key.includes(
|
|
42
|
+
if (key.includes("-")) {
|
|
43
43
|
newObj[toCamelCase(key)] = value;
|
|
44
44
|
} else {
|
|
45
45
|
newObj[key] = value;
|
|
@@ -48,27 +48,37 @@ function toCamelCaseKeys(
|
|
|
48
48
|
return newObj;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
type LayerProps =
|
|
52
|
+
| CircleLayerProps
|
|
53
|
+
| SymbolLayerProps
|
|
54
|
+
| RasterLayerProps
|
|
55
|
+
| LineLayerProps
|
|
56
|
+
| FillLayerProps
|
|
57
|
+
| FillExtrusionLayerProps
|
|
58
|
+
| BackgroundLayerProps
|
|
59
|
+
| HeatmapLayerProps;
|
|
60
|
+
|
|
51
61
|
function getLayerComponentType(
|
|
52
62
|
layer: MaplibreJSONLayer,
|
|
53
|
-
): ComponentType<
|
|
54
|
-
const {type} = layer;
|
|
63
|
+
): ComponentType<LayerProps> | null {
|
|
64
|
+
const { type } = layer;
|
|
55
65
|
|
|
56
66
|
switch (type) {
|
|
57
|
-
case
|
|
67
|
+
case "circle":
|
|
58
68
|
return CircleLayer;
|
|
59
|
-
case
|
|
69
|
+
case "symbol":
|
|
60
70
|
return SymbolLayer;
|
|
61
|
-
case
|
|
71
|
+
case "raster":
|
|
62
72
|
return RasterLayer;
|
|
63
|
-
case
|
|
73
|
+
case "line":
|
|
64
74
|
return LineLayer;
|
|
65
|
-
case
|
|
75
|
+
case "fill":
|
|
66
76
|
return FillLayer;
|
|
67
|
-
case
|
|
77
|
+
case "fill-extrusion":
|
|
68
78
|
return FillExtrusionLayer;
|
|
69
|
-
case
|
|
79
|
+
case "background":
|
|
70
80
|
return BackgroundLayer;
|
|
71
|
-
case
|
|
81
|
+
case "heatmap":
|
|
72
82
|
return HeatmapLayer;
|
|
73
83
|
}
|
|
74
84
|
|
|
@@ -79,10 +89,10 @@ function getLayerComponentType(
|
|
|
79
89
|
|
|
80
90
|
interface MaplibreJSONLayer {
|
|
81
91
|
type: string;
|
|
82
|
-
paint: {[k: string]: unknown};
|
|
83
|
-
layout: {[k: string]: unknown};
|
|
92
|
+
paint: { [k: string]: unknown };
|
|
93
|
+
layout: { [k: string]: unknown };
|
|
84
94
|
source?: string;
|
|
85
|
-
|
|
95
|
+
"source-layer"?: string;
|
|
86
96
|
minzoom?: number;
|
|
87
97
|
maxzoom?: number;
|
|
88
98
|
filter?: FilterExpression;
|
|
@@ -91,7 +101,7 @@ interface MaplibreJSONLayer {
|
|
|
91
101
|
|
|
92
102
|
function asLayerComponent(
|
|
93
103
|
layer: MaplibreJSONLayer,
|
|
94
|
-
): ReactElement<
|
|
104
|
+
): ReactElement<LayerProps> | null {
|
|
95
105
|
const LayerComponent = getLayerComponentType(layer);
|
|
96
106
|
|
|
97
107
|
if (!LayerComponent) {
|
|
@@ -103,13 +113,13 @@ function asLayerComponent(
|
|
|
103
113
|
...toCamelCaseKeys(layer.layout),
|
|
104
114
|
};
|
|
105
115
|
|
|
106
|
-
const layerProps: Partial<
|
|
116
|
+
const layerProps: Partial<LayerProps> = {};
|
|
107
117
|
|
|
108
118
|
if (layer.source) {
|
|
109
119
|
layerProps.sourceID = layer.source;
|
|
110
120
|
}
|
|
111
|
-
if (layer[
|
|
112
|
-
layerProps.sourceLayerID = layer[
|
|
121
|
+
if (layer["source-layer"]) {
|
|
122
|
+
layerProps.sourceLayerID = layer["source-layer"];
|
|
113
123
|
}
|
|
114
124
|
if (layer.minzoom) {
|
|
115
125
|
layerProps.minZoomLevel = layer.minzoom;
|
|
@@ -134,7 +144,7 @@ interface MaplibreJSONSource {
|
|
|
134
144
|
minzoom?: number;
|
|
135
145
|
maxzoom?: number;
|
|
136
146
|
attribution?: string;
|
|
137
|
-
scheme?:
|
|
147
|
+
scheme?: "xyz" | "tms";
|
|
138
148
|
bounds?: number[];
|
|
139
149
|
buffer?: number;
|
|
140
150
|
tileSize?: number;
|
|
@@ -148,7 +158,7 @@ interface MaplibreJSONSource {
|
|
|
148
158
|
clusterMaxZoom?: number;
|
|
149
159
|
clusterMinPoints?: number;
|
|
150
160
|
clusterRadius?: number;
|
|
151
|
-
clusterProperties?: {[propertyName: string]: ExpressionField};
|
|
161
|
+
clusterProperties?: { [propertyName: string]: ExpressionField };
|
|
152
162
|
data?: string | object;
|
|
153
163
|
filter?: FilterExpression;
|
|
154
164
|
generateId?: boolean;
|
|
@@ -182,19 +192,19 @@ function getTileSourceProps(source: MaplibreJSONSource): SourceProps {
|
|
|
182
192
|
if (source.attribution) {
|
|
183
193
|
sourceProps.attribution = source.attribution;
|
|
184
194
|
}
|
|
185
|
-
if (source.scheme && source.scheme ===
|
|
195
|
+
if (source.scheme && source.scheme === "tms") {
|
|
186
196
|
sourceProps.tms = true;
|
|
187
197
|
}
|
|
188
198
|
return sourceProps;
|
|
189
199
|
}
|
|
190
200
|
|
|
191
201
|
function getVectorSource(id: string, source: MaplibreJSONSource): ReactElement {
|
|
192
|
-
const sourceProps = {...getTileSourceProps(source)};
|
|
202
|
+
const sourceProps = { ...getTileSourceProps(source) };
|
|
193
203
|
return <VectorSource key={id} id={id} {...sourceProps} />;
|
|
194
204
|
}
|
|
195
205
|
|
|
196
206
|
function getRasterSource(id: string, source: MaplibreJSONSource): ReactElement {
|
|
197
|
-
const sourceProps: SourceProps & {tileSize?: number} = {
|
|
207
|
+
const sourceProps: SourceProps & { tileSize?: number } = {
|
|
198
208
|
...getTileSourceProps(source),
|
|
199
209
|
};
|
|
200
210
|
if (source.tileSize) {
|
|
@@ -211,7 +221,7 @@ function getImageSource(id: string, source: MaplibreJSONSource): ReactElement {
|
|
|
211
221
|
return <ImageSource key={id} id={id} {...sourceProps} />;
|
|
212
222
|
}
|
|
213
223
|
|
|
214
|
-
type ShapeSourceShape = (typeof ShapeSource.prototype.props)[
|
|
224
|
+
type ShapeSourceShape = (typeof ShapeSource.prototype.props)["shape"];
|
|
215
225
|
|
|
216
226
|
function getShapeSource(id: string, source: MaplibreJSONSource): ReactElement {
|
|
217
227
|
const sourceProps: SourceProps & {
|
|
@@ -219,14 +229,14 @@ function getShapeSource(id: string, source: MaplibreJSONSource): ReactElement {
|
|
|
219
229
|
cluster?: boolean;
|
|
220
230
|
clusterRadius?: number;
|
|
221
231
|
clusterMaxZoomLevel?: number;
|
|
222
|
-
clusterProperties?: {[propertyName: string]: ExpressionField};
|
|
232
|
+
clusterProperties?: { [propertyName: string]: ExpressionField };
|
|
223
233
|
buffer?: number;
|
|
224
234
|
tolerance?: number;
|
|
225
235
|
lineMetrics?: boolean;
|
|
226
236
|
} = {};
|
|
227
|
-
if (source.data && typeof source.data ===
|
|
237
|
+
if (source.data && typeof source.data === "string") {
|
|
228
238
|
sourceProps.url = source.data;
|
|
229
|
-
} else if (source.data && typeof source.data ===
|
|
239
|
+
} else if (source.data && typeof source.data === "object") {
|
|
230
240
|
sourceProps.shape = source.data as ShapeSourceShape;
|
|
231
241
|
}
|
|
232
242
|
if (source.cluster !== undefined) {
|
|
@@ -261,13 +271,13 @@ function asSourceComponent(
|
|
|
261
271
|
source: MaplibreJSONSource,
|
|
262
272
|
): ReactElement | null {
|
|
263
273
|
switch (source.type) {
|
|
264
|
-
case
|
|
274
|
+
case "vector":
|
|
265
275
|
return getVectorSource(id, source);
|
|
266
|
-
case
|
|
276
|
+
case "raster":
|
|
267
277
|
return getRasterSource(id, source);
|
|
268
|
-
case
|
|
278
|
+
case "image":
|
|
269
279
|
return getImageSource(id, source);
|
|
270
|
-
case
|
|
280
|
+
case "geojson":
|
|
271
281
|
return getShapeSource(id, source);
|
|
272
282
|
}
|
|
273
283
|
|
|
@@ -278,7 +288,7 @@ function asSourceComponent(
|
|
|
278
288
|
|
|
279
289
|
interface MaplibreJSON {
|
|
280
290
|
layers?: MaplibreJSONLayer[];
|
|
281
|
-
sources?: {[key: string]: MaplibreJSONSource};
|
|
291
|
+
sources?: { [key: string]: MaplibreJSONSource };
|
|
282
292
|
}
|
|
283
293
|
|
|
284
294
|
interface StyleProps {
|
|
@@ -298,7 +308,7 @@ interface StyleProps {
|
|
|
298
308
|
const Style = (props: StyleProps): ReactElement => {
|
|
299
309
|
const [fetchedJson, setFetchedJson] = useState({});
|
|
300
310
|
const json: MaplibreJSON =
|
|
301
|
-
typeof props.json ===
|
|
311
|
+
typeof props.json === "object" ? props.json : fetchedJson;
|
|
302
312
|
|
|
303
313
|
// Fetch style when props.json is a URL
|
|
304
314
|
useEffect(() => {
|
|
@@ -311,14 +321,14 @@ const Style = (props: StyleProps): ReactElement => {
|
|
|
311
321
|
const responseJson = await response.json();
|
|
312
322
|
setFetchedJson(responseJson);
|
|
313
323
|
} catch (error: unknown) {
|
|
314
|
-
const e = error as {name?: string};
|
|
315
|
-
if (e.name ===
|
|
324
|
+
const e = error as { name?: string };
|
|
325
|
+
if (e.name === "AbortError") {
|
|
316
326
|
return;
|
|
317
327
|
}
|
|
318
328
|
throw e;
|
|
319
329
|
}
|
|
320
330
|
};
|
|
321
|
-
if (typeof props.json ===
|
|
331
|
+
if (typeof props.json === "string") {
|
|
322
332
|
fetchStyleJson(props.json);
|
|
323
333
|
}
|
|
324
334
|
return function cleanup(): void {
|
|
@@ -338,13 +348,13 @@ const Style = (props: StyleProps): ReactElement => {
|
|
|
338
348
|
|
|
339
349
|
// Extract source components from json
|
|
340
350
|
const sourceComponents = useMemo(() => {
|
|
341
|
-
const {sources} = json;
|
|
351
|
+
const { sources } = json;
|
|
342
352
|
if (!sources || !Object.keys(sources)) {
|
|
343
353
|
return [];
|
|
344
354
|
}
|
|
345
355
|
return Object.keys(sources)
|
|
346
|
-
.map(id => asSourceComponent(id, sources[id]))
|
|
347
|
-
.filter(x => !!x);
|
|
356
|
+
.map((id) => asSourceComponent(id, sources[id]))
|
|
357
|
+
.filter((x) => !!x);
|
|
348
358
|
}, [json]);
|
|
349
359
|
|
|
350
360
|
return (
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import React, { ReactElement } from "react";
|
|
2
|
+
import { View, NativeModules, requireNativeComponent } from "react-native";
|
|
3
|
+
|
|
3
4
|
import useAbstractLayer, {
|
|
4
5
|
BaseLayerProps,
|
|
5
6
|
NativeBaseProps,
|
|
6
|
-
} from
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
import {View, NativeModules, requireNativeComponent} from 'react-native';
|
|
7
|
+
} from "../hooks/useAbstractLayer";
|
|
8
|
+
import BaseProps from "../types/BaseProps";
|
|
9
|
+
import { type SymbolLayerStyleProps } from "../utils/MaplibreStyles";
|
|
10
10
|
|
|
11
11
|
const MapLibreGL = NativeModules.MLNModule;
|
|
12
12
|
|
|
13
|
-
export const NATIVE_MODULE_NAME =
|
|
13
|
+
export const NATIVE_MODULE_NAME = "RCTMLNSymbolLayer";
|
|
14
14
|
|
|
15
15
|
export interface SymbolLayerProps extends BaseProps, BaseLayerProps {
|
|
16
16
|
/**
|
|
@@ -25,7 +25,7 @@ export interface SymbolLayerProps extends BaseProps, BaseLayerProps {
|
|
|
25
25
|
children?: ReactElement | ReactElement[];
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
interface NativeProps extends Omit<SymbolLayerProps,
|
|
28
|
+
interface NativeProps extends Omit<SymbolLayerProps, "style">, NativeBaseProps {
|
|
29
29
|
snapshot: boolean;
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -39,7 +39,7 @@ const SymbolLayer: React.FC<SymbolLayerProps> = ({
|
|
|
39
39
|
sourceID = MapLibreGL.StyleSource.DefaultSourceID,
|
|
40
40
|
...props
|
|
41
41
|
}: SymbolLayerProps) => {
|
|
42
|
-
const {baseProps, setNativeLayer} = useAbstractLayer<
|
|
42
|
+
const { baseProps, setNativeLayer } = useAbstractLayer<
|
|
43
43
|
SymbolLayerProps,
|
|
44
44
|
NativeBaseProps
|
|
45
45
|
>({
|
|
@@ -54,7 +54,7 @@ const SymbolLayer: React.FC<SymbolLayerProps> = ({
|
|
|
54
54
|
return isSnapshot;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
React.Children.forEach(props.children, child => {
|
|
57
|
+
React.Children.forEach(props.children, (child) => {
|
|
58
58
|
if (child?.type === View) {
|
|
59
59
|
isSnapshot = true;
|
|
60
60
|
}
|