@maplibre/maplibre-react-native 11.0.0-alpha.26 → 11.0.0-alpha.27
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/android/src/main/java/org/maplibre/reactnative/MLRNPackage.kt +16 -1
- package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapView.kt +20 -32
- package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNRasterSource.java +1 -1
- package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNSource.kt +228 -0
- package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNTileSource.java +0 -1
- package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNVectorSourceManager.java +2 -2
- package/android/src/main/java/org/maplibre/reactnative/components/sources/shapesource/ClusterPropertyEntry.kt +5 -0
- package/android/src/main/java/org/maplibre/reactnative/components/sources/shapesource/MLRNShapeSource.kt +232 -0
- package/android/src/main/java/org/maplibre/reactnative/components/sources/shapesource/MLRNShapeSourceManager.kt +183 -0
- package/android/src/main/java/org/maplibre/reactnative/components/sources/shapesource/MLRNShapeSourceModule.kt +65 -0
- package/android/src/main/java/org/maplibre/reactnative/events/MapPressEvent.kt +1 -1
- package/android/src/main/java/org/maplibre/reactnative/events/MapPressEventWithFeatures.kt +24 -0
- package/android/src/main/java/org/maplibre/reactnative/utils/ConvertUtils.kt +203 -0
- package/android/src/main/java/org/maplibre/reactnative/utils/ExpressionParser.kt +70 -0
- package/android/src/main/java/org/maplibre/reactnative/utils/GeoJSONUtils.kt +37 -20
- package/ios/components/camera/MLRNCameraModule.mm +10 -20
- package/ios/components/map-view/MLRNMapViewModule.mm +10 -20
- package/ios/components/sources/MLRNSource.h +3 -0
- package/ios/components/sources/{MLRNShapeSource.h → shape-source/MLRNShapeSource.h} +3 -5
- package/ios/components/sources/{MLRNShapeSource.m → shape-source/MLRNShapeSource.m} +4 -12
- package/ios/components/sources/shape-source/MLRNShapeSourceComponentView.h +11 -0
- package/ios/components/sources/shape-source/MLRNShapeSourceComponentView.mm +163 -0
- package/ios/components/sources/shape-source/MLRNShapeSourceModule.h +5 -0
- package/ios/components/sources/shape-source/MLRNShapeSourceModule.mm +136 -0
- package/ios/utils/MLRNViewModuleUtils.h +35 -0
- package/ios/utils/MLRNViewModuleUtils.m +39 -0
- package/lib/commonjs/components/annotations/Annotation.js +1 -1
- package/lib/commonjs/components/annotations/Annotation.js.map +1 -1
- package/lib/commonjs/components/layers/BackgroundLayer.js.map +1 -1
- package/lib/commonjs/components/layers/CircleLayer.js.map +1 -1
- package/lib/commonjs/components/layers/FillExtrusionLayer.js.map +1 -1
- package/lib/commonjs/components/layers/HeatmapLayer.js.map +1 -1
- package/lib/commonjs/components/layers/RasterLayer.js.map +1 -1
- package/lib/commonjs/components/layers/SymbolLayer.js.map +1 -1
- package/lib/commonjs/components/map-view/MapView.js +16 -22
- package/lib/commonjs/components/map-view/MapView.js.map +1 -1
- package/lib/commonjs/components/sources/VectorSource.js +2 -2
- package/lib/commonjs/components/sources/VectorSource.js.map +1 -1
- package/lib/commonjs/components/sources/shape-source/NativeShapeSourceModule.js +9 -0
- package/lib/commonjs/components/sources/shape-source/NativeShapeSourceModule.js.map +1 -0
- package/lib/commonjs/components/sources/shape-source/ShapeSource.js +51 -0
- package/lib/commonjs/components/sources/shape-source/ShapeSource.js.map +1 -0
- package/lib/commonjs/components/sources/shape-source/ShapeSourceNativeComponent.ts +48 -0
- package/lib/commonjs/hooks/useAbstractLayer.js +2 -2
- package/lib/commonjs/hooks/useAbstractLayer.js.map +1 -1
- package/lib/commonjs/hooks/useFrozenId.js +16 -0
- package/lib/commonjs/hooks/useFrozenId.js.map +1 -0
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/modules/snapshot/SnapshotOptions.js.map +1 -1
- package/lib/commonjs/types/PressEventWithFeatures.js +6 -0
- package/lib/commonjs/types/PressEventWithFeatures.js.map +1 -0
- package/lib/commonjs/utils/animated/AbstractAnimatedCoordinates.js +0 -6
- package/lib/commonjs/utils/animated/AbstractAnimatedCoordinates.js.map +1 -1
- package/lib/commonjs/utils/animated/Animated.js +4 -4
- package/lib/commonjs/utils/animated/Animated.js.map +1 -1
- package/lib/commonjs/utils/animated/AnimatedExtractCoordinateFromArray.js +0 -6
- package/lib/commonjs/utils/animated/AnimatedExtractCoordinateFromArray.js.map +1 -1
- package/lib/commonjs/utils/animated/AnimatedPoint.js +0 -2
- package/lib/commonjs/utils/animated/AnimatedPoint.js.map +1 -1
- package/lib/commonjs/utils/animated/AnimatedShape.js +3 -16
- package/lib/commonjs/utils/animated/AnimatedShape.js.map +1 -1
- package/lib/commonjs/utils/findNodeHandle.js +16 -0
- package/lib/commonjs/utils/findNodeHandle.js.map +1 -0
- package/lib/commonjs/utils/{filterUtils.js → getFilter.js} +2 -2
- package/lib/commonjs/utils/getFilter.js.map +1 -0
- package/lib/commonjs/utils/index.js +3 -8
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/module/components/annotations/Annotation.js +1 -1
- package/lib/module/components/annotations/Annotation.js.map +1 -1
- package/lib/module/components/layers/BackgroundLayer.js.map +1 -1
- package/lib/module/components/layers/CircleLayer.js.map +1 -1
- package/lib/module/components/layers/FillExtrusionLayer.js.map +1 -1
- package/lib/module/components/layers/HeatmapLayer.js.map +1 -1
- package/lib/module/components/layers/RasterLayer.js.map +1 -1
- package/lib/module/components/layers/SymbolLayer.js.map +1 -1
- package/lib/module/components/map-view/MapView.js +3 -9
- package/lib/module/components/map-view/MapView.js.map +1 -1
- package/lib/module/components/sources/VectorSource.js +1 -1
- package/lib/module/components/sources/VectorSource.js.map +1 -1
- package/lib/module/components/sources/shape-source/NativeShapeSourceModule.js +5 -0
- package/lib/module/components/sources/shape-source/NativeShapeSourceModule.js.map +1 -0
- package/lib/module/components/sources/shape-source/ShapeSource.js +46 -0
- package/lib/module/components/sources/shape-source/ShapeSource.js.map +1 -0
- package/lib/module/components/sources/shape-source/ShapeSourceNativeComponent.ts +48 -0
- package/lib/module/hooks/useAbstractLayer.js +1 -1
- package/lib/module/hooks/useAbstractLayer.js.map +1 -1
- package/lib/module/hooks/useFrozenId.js +12 -0
- package/lib/module/hooks/useFrozenId.js.map +1 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/snapshot/SnapshotOptions.js.map +1 -1
- package/lib/module/types/PressEventWithFeatures.js +4 -0
- package/lib/module/types/PressEventWithFeatures.js.map +1 -0
- package/lib/module/utils/animated/AbstractAnimatedCoordinates.js +0 -7
- package/lib/module/utils/animated/AbstractAnimatedCoordinates.js.map +1 -1
- package/lib/module/utils/animated/Animated.js +4 -4
- package/lib/module/utils/animated/Animated.js.map +1 -1
- package/lib/module/utils/animated/AnimatedExtractCoordinateFromArray.js +0 -6
- package/lib/module/utils/animated/AnimatedExtractCoordinateFromArray.js.map +1 -1
- package/lib/module/utils/animated/AnimatedPoint.js +0 -3
- package/lib/module/utils/animated/AnimatedPoint.js.map +1 -1
- package/lib/module/utils/animated/AnimatedShape.js +3 -16
- package/lib/module/utils/animated/AnimatedShape.js.map +1 -1
- package/lib/module/utils/findNodeHandle.js +11 -0
- package/lib/module/utils/findNodeHandle.js.map +1 -0
- package/lib/module/utils/getFilter.js +9 -0
- package/lib/module/utils/getFilter.js.map +1 -0
- package/lib/module/utils/index.js +3 -8
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/commonjs/src/components/annotations/Annotation.d.ts +1 -1
- package/lib/typescript/commonjs/src/components/annotations/Annotation.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/layers/BackgroundLayer.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/layers/CircleLayer.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/layers/FillExtrusionLayer.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/layers/HeatmapLayer.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/layers/RasterLayer.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/layers/SymbolLayer.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/map-view/MapView.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/sources/VectorSource.d.ts +1 -1
- package/lib/typescript/commonjs/src/components/sources/VectorSource.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/sources/shape-source/NativeShapeSourceModule.d.ts +10 -0
- package/lib/typescript/commonjs/src/components/sources/shape-source/NativeShapeSourceModule.d.ts.map +1 -0
- package/lib/typescript/{module/src/components/sources → commonjs/src/components/sources/shape-source}/ShapeSource.d.ts +60 -41
- package/lib/typescript/commonjs/src/components/sources/shape-source/ShapeSource.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/sources/shape-source/ShapeSourceNativeComponent.d.ts +35 -0
- package/lib/typescript/commonjs/src/components/sources/shape-source/ShapeSourceNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/hooks/useFrozenId.d.ts +2 -0
- package/lib/typescript/commonjs/src/hooks/useFrozenId.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +4 -3
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/snapshot/SnapshotOptions.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/MapLibreRNStyles.d.ts +1 -1
- package/lib/typescript/commonjs/src/types/MapLibreRNStyles.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/PressEvent.d.ts +0 -3
- package/lib/typescript/commonjs/src/types/PressEvent.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/PressEventWithFeatures.d.ts +5 -0
- package/lib/typescript/commonjs/src/types/PressEventWithFeatures.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/utils/animated/AbstractAnimatedCoordinates.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/animated/Animated.d.ts +4 -1
- package/lib/typescript/commonjs/src/utils/animated/Animated.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/animated/AnimatedExtractCoordinateFromArray.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/animated/AnimatedPoint.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/animated/AnimatedRouteCoordinatesArray.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/animated/AnimatedShape.d.ts +2 -2
- package/lib/typescript/commonjs/src/utils/animated/AnimatedShape.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/findNodeHandle.d.ts +3 -0
- package/lib/typescript/commonjs/src/utils/findNodeHandle.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/utils/{filterUtils.d.ts → getFilter.d.ts} +2 -2
- package/lib/typescript/commonjs/src/utils/getFilter.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/utils/index.d.ts +3 -3
- package/lib/typescript/commonjs/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/module/src/components/annotations/Annotation.d.ts +1 -1
- package/lib/typescript/module/src/components/annotations/Annotation.d.ts.map +1 -1
- package/lib/typescript/module/src/components/layers/BackgroundLayer.d.ts.map +1 -1
- package/lib/typescript/module/src/components/layers/CircleLayer.d.ts.map +1 -1
- package/lib/typescript/module/src/components/layers/FillExtrusionLayer.d.ts.map +1 -1
- package/lib/typescript/module/src/components/layers/HeatmapLayer.d.ts.map +1 -1
- package/lib/typescript/module/src/components/layers/RasterLayer.d.ts.map +1 -1
- package/lib/typescript/module/src/components/layers/SymbolLayer.d.ts.map +1 -1
- package/lib/typescript/module/src/components/map-view/MapView.d.ts.map +1 -1
- package/lib/typescript/module/src/components/sources/VectorSource.d.ts +1 -1
- package/lib/typescript/module/src/components/sources/VectorSource.d.ts.map +1 -1
- package/lib/typescript/module/src/components/sources/shape-source/NativeShapeSourceModule.d.ts +10 -0
- package/lib/typescript/module/src/components/sources/shape-source/NativeShapeSourceModule.d.ts.map +1 -0
- package/lib/typescript/{commonjs/src/components/sources → module/src/components/sources/shape-source}/ShapeSource.d.ts +60 -41
- package/lib/typescript/module/src/components/sources/shape-source/ShapeSource.d.ts.map +1 -0
- package/lib/typescript/module/src/components/sources/shape-source/ShapeSourceNativeComponent.d.ts +35 -0
- package/lib/typescript/module/src/components/sources/shape-source/ShapeSourceNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/hooks/useFrozenId.d.ts +2 -0
- package/lib/typescript/module/src/hooks/useFrozenId.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +4 -3
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/snapshot/SnapshotOptions.d.ts.map +1 -1
- package/lib/typescript/module/src/types/MapLibreRNStyles.d.ts +1 -1
- package/lib/typescript/module/src/types/MapLibreRNStyles.d.ts.map +1 -1
- package/lib/typescript/module/src/types/PressEvent.d.ts +0 -3
- package/lib/typescript/module/src/types/PressEvent.d.ts.map +1 -1
- package/lib/typescript/module/src/types/PressEventWithFeatures.d.ts +5 -0
- package/lib/typescript/module/src/types/PressEventWithFeatures.d.ts.map +1 -0
- package/lib/typescript/module/src/utils/animated/AbstractAnimatedCoordinates.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/animated/Animated.d.ts +4 -1
- package/lib/typescript/module/src/utils/animated/Animated.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/animated/AnimatedExtractCoordinateFromArray.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/animated/AnimatedPoint.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/animated/AnimatedRouteCoordinatesArray.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/animated/AnimatedShape.d.ts +2 -2
- package/lib/typescript/module/src/utils/animated/AnimatedShape.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/findNodeHandle.d.ts +3 -0
- package/lib/typescript/module/src/utils/findNodeHandle.d.ts.map +1 -0
- package/lib/typescript/module/src/utils/{filterUtils.d.ts → getFilter.d.ts} +2 -2
- package/lib/typescript/module/src/utils/getFilter.d.ts.map +1 -0
- package/lib/typescript/module/src/utils/index.d.ts +3 -3
- package/lib/typescript/module/src/utils/index.d.ts.map +1 -1
- package/package.json +7 -6
- package/src/components/annotations/Annotation.tsx +2 -2
- package/src/components/layers/BackgroundLayer.tsx +1 -2
- package/src/components/layers/CircleLayer.tsx +1 -2
- package/src/components/layers/FillExtrusionLayer.tsx +1 -2
- package/src/components/layers/HeatmapLayer.tsx +1 -2
- package/src/components/layers/RasterLayer.tsx +1 -2
- package/src/components/layers/SymbolLayer.tsx +1 -2
- package/src/components/map-view/MapView.tsx +2 -14
- package/src/components/sources/VectorSource.tsx +2 -2
- package/src/components/sources/shape-source/NativeShapeSourceModule.ts +31 -0
- package/src/components/sources/shape-source/ShapeSource.tsx +235 -0
- package/src/components/sources/shape-source/ShapeSourceNativeComponent.ts +48 -0
- package/src/hooks/useAbstractLayer.ts +1 -1
- package/src/hooks/useFrozenId.ts +13 -0
- package/src/index.ts +4 -3
- package/src/modules/snapshot/SnapshotOptions.ts +3 -2
- package/src/types/MapLibreRNStyles.ts +1 -1
- package/src/types/PressEvent.ts +0 -4
- package/src/types/PressEventWithFeatures.ts +5 -0
- package/src/utils/animated/AbstractAnimatedCoordinates.ts +0 -9
- package/src/utils/animated/Animated.ts +12 -5
- package/src/utils/animated/AnimatedExtractCoordinateFromArray.ts +0 -9
- package/src/utils/animated/AnimatedPoint.ts +0 -2
- package/src/utils/animated/AnimatedRouteCoordinatesArray.ts +3 -3
- package/src/utils/animated/AnimatedShape.ts +7 -18
- package/src/utils/findNodeHandle.ts +14 -0
- package/src/utils/{filterUtils.ts → getFilter.ts} +2 -2
- package/src/utils/index.ts +12 -12
- package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNShapeSource.java +0 -248
- package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNShapeSourceManager.java +0 -216
- package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNSource.java +0 -240
- package/android/src/main/java/org/maplibre/reactnative/utils/ClusterPropertyEntry.java +0 -13
- package/android/src/main/java/org/maplibre/reactnative/utils/ConvertUtils.java +0 -246
- package/android/src/main/java/org/maplibre/reactnative/utils/ExpressionParser.java +0 -74
- package/ios/components/sources/MLRNShapeSourceManager.h +0 -6
- package/ios/components/sources/MLRNShapeSourceManager.m +0 -128
- package/lib/commonjs/components/sources/ShapeSource.js +0 -153
- package/lib/commonjs/components/sources/ShapeSource.js.map +0 -1
- package/lib/commonjs/utils/filterUtils.js.map +0 -1
- package/lib/module/components/sources/ShapeSource.js +0 -149
- package/lib/module/components/sources/ShapeSource.js.map +0 -1
- package/lib/module/utils/filterUtils.js +0 -9
- package/lib/module/utils/filterUtils.js.map +0 -1
- package/lib/typescript/commonjs/src/components/sources/ShapeSource.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/utils/filterUtils.d.ts.map +0 -1
- package/lib/typescript/module/src/components/sources/ShapeSource.d.ts.map +0 -1
- package/lib/typescript/module/src/utils/filterUtils.d.ts.map +0 -1
- package/src/components/sources/ShapeSource.tsx +0 -366
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Component,
|
|
3
|
+
type ComponentProps,
|
|
4
|
+
forwardRef,
|
|
5
|
+
memo,
|
|
6
|
+
type ReactNode,
|
|
7
|
+
useImperativeHandle,
|
|
8
|
+
useRef,
|
|
9
|
+
} from "react";
|
|
10
|
+
import { type NativeMethods, type NativeSyntheticEvent } from "react-native";
|
|
11
|
+
|
|
12
|
+
import NativeShapeSourceModule from "./NativeShapeSourceModule";
|
|
13
|
+
import ShapeSourceNativeComponent from "./ShapeSourceNativeComponent";
|
|
14
|
+
import { useFrozenId } from "../../../hooks/useFrozenId";
|
|
15
|
+
import { type BaseProps } from "../../../types/BaseProps";
|
|
16
|
+
import {
|
|
17
|
+
type ExpressionField,
|
|
18
|
+
type FilterExpression,
|
|
19
|
+
} from "../../../types/MapLibreRNStyles";
|
|
20
|
+
import type { PressEventWithFeatures } from "../../../types/PressEventWithFeatures";
|
|
21
|
+
import type { ViewPadding } from "../../../types/ViewPadding";
|
|
22
|
+
import { cloneReactChildrenWithProps } from "../../../utils";
|
|
23
|
+
import { findNodeHandle } from "../../../utils/findNodeHandle";
|
|
24
|
+
|
|
25
|
+
export interface ShapeSourceProps extends BaseProps {
|
|
26
|
+
/**
|
|
27
|
+
* A string that uniquely identifies the source.
|
|
28
|
+
*/
|
|
29
|
+
id?: string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* An HTTP(S) URL, absolute file URL, or local file URL relative to the current application’s resource bundle.
|
|
33
|
+
*
|
|
34
|
+
* The contents of the source. A shape can represent a GeoJSON geometry, a feature, or a feature collection.
|
|
35
|
+
*/
|
|
36
|
+
data: string | GeoJSON.GeoJSON;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Enables clustering on the source for point shapes.
|
|
40
|
+
*/
|
|
41
|
+
cluster?: boolean;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Specifies the radius of each cluster if clustering is enabled.
|
|
45
|
+
* A value of 512 produces a radius equal to the width of a tile.
|
|
46
|
+
* The default value is 50.
|
|
47
|
+
*/
|
|
48
|
+
clusterRadius?: number;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Specifies minimum number of points to form a cluster if clustering is enabled.
|
|
52
|
+
* The default value is 2.
|
|
53
|
+
*/
|
|
54
|
+
clusterMinPoints?: number;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Specifies the maximum zoom level at which to cluster points if clustering is enabled.
|
|
58
|
+
* Defaults to one zoom level less than the value of maxzoom so that, at the maximum zoom level,
|
|
59
|
+
* the shapes are not clustered.
|
|
60
|
+
*/
|
|
61
|
+
clusterMaxZoom?: number;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Specifies custom properties on the generated clusters if clustering
|
|
65
|
+
* is enabled, aggregating values from clustered points.
|
|
66
|
+
*
|
|
67
|
+
* Has the form `{ "property_name": [operator, map_expression]}`, where
|
|
68
|
+
* `operator` is a custom reduce expression that references a special `["accumulated"]` value -
|
|
69
|
+
* it accumulates the property value from clusters/points the cluster contains
|
|
70
|
+
* `map_expression` produces the value of a single point
|
|
71
|
+
*
|
|
72
|
+
* @example `{ "resultingSum": [["+", ["accumulated"], ["get", "resultingSum"]], ["get", "scalerank"]] }`
|
|
73
|
+
*
|
|
74
|
+
*/
|
|
75
|
+
clusterProperties?: { [propertyName: string]: ExpressionField };
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Specifies the maximum zoom level at which to create vector tiles.
|
|
79
|
+
* A greater value produces greater detail at high zoom levels.
|
|
80
|
+
* The default value is 18.
|
|
81
|
+
*/
|
|
82
|
+
maxzoom?: number;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Specifies the size of the tile buffer on each side.
|
|
86
|
+
* A value of 0 produces no buffer. A value of 512 produces a buffer as wide as the tile itself.
|
|
87
|
+
* Larger values produce fewer rendering artifacts near tile edges and slower performance.
|
|
88
|
+
* The default value is 128.
|
|
89
|
+
*/
|
|
90
|
+
buffer?: number;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Douglas-Peucker simplification tolerance applied to geometries
|
|
94
|
+
*
|
|
95
|
+
* Higher means simpler geometries and faster performance.
|
|
96
|
+
*
|
|
97
|
+
* @default 0.375
|
|
98
|
+
*/
|
|
99
|
+
tolerance?: number;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Whether to calculate line distance metrics.
|
|
103
|
+
* This is required for line layers that specify lineGradient values.
|
|
104
|
+
* The default value is false.
|
|
105
|
+
*/
|
|
106
|
+
lineMetrics?: boolean;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Source press listener, gets called when a user presses one of the children layers only if that layer has a higher z-index than another source layers.
|
|
110
|
+
*/
|
|
111
|
+
onPress?: (event: NativeSyntheticEvent<PressEventWithFeatures>) => void;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Overrides the default touch hitbox (44 x 44 pixels) for the source layers
|
|
115
|
+
*/
|
|
116
|
+
hitbox?: ViewPadding;
|
|
117
|
+
|
|
118
|
+
children?: ReactNode;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface ShapeSourceRef {
|
|
122
|
+
/**
|
|
123
|
+
* Get all features from the source that match the filter, regardless of visibility
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* shapeSource.features()
|
|
127
|
+
*
|
|
128
|
+
* @param filter Optional filter statement to filter the returned features
|
|
129
|
+
*/
|
|
130
|
+
getData(filter?: FilterExpression): Promise<GeoJSON.FeatureCollection>;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Returns the zoom needed to expand the cluster.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* const zoom = await shapeSource.getClusterExpansionZoom(clusterId);
|
|
137
|
+
*
|
|
138
|
+
* @param clusterId The feature cluster to expand.
|
|
139
|
+
* @return Zoom level at which the cluster expands
|
|
140
|
+
*/
|
|
141
|
+
getClusterExpansionZoom(clusterId: number): Promise<number>;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Returns the FeatureCollection from the cluster.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* const collection = await shapeSource.getClusterLeaves(clusterId, limit, offset);
|
|
148
|
+
*
|
|
149
|
+
* @param clusterId The feature cluster to expand.
|
|
150
|
+
* @param limit - The number of points to return.
|
|
151
|
+
* @param offset - The amount of points to skip (for pagination).
|
|
152
|
+
*/
|
|
153
|
+
getClusterLeaves(
|
|
154
|
+
clusterId: number,
|
|
155
|
+
limit: number,
|
|
156
|
+
offset: number,
|
|
157
|
+
): Promise<GeoJSON.Feature[]>;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Returns the FeatureCollection from the cluster (on the next zoom level).
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* const collection = await shapeSource.getClusterChildren(clusterId);
|
|
164
|
+
*
|
|
165
|
+
* @param clusterId - The feature cluster to expand.
|
|
166
|
+
*/
|
|
167
|
+
getClusterChildren(clusterId: number): Promise<GeoJSON.Feature[]>;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* ShapeSource is a map content source that supplies vector shapes to be shown on the map.
|
|
172
|
+
* The shape may be a url or a GeoJSON object
|
|
173
|
+
*/
|
|
174
|
+
export const ShapeSource = memo(
|
|
175
|
+
forwardRef<ShapeSourceRef, ShapeSourceProps>(
|
|
176
|
+
({ id, data, ...props }, ref) => {
|
|
177
|
+
const nativeRef = useRef<
|
|
178
|
+
Component<ComponentProps<typeof ShapeSourceNativeComponent>> &
|
|
179
|
+
Readonly<NativeMethods>
|
|
180
|
+
>(null);
|
|
181
|
+
|
|
182
|
+
const frozenId = useFrozenId(id);
|
|
183
|
+
|
|
184
|
+
useImperativeHandle(ref, () => ({
|
|
185
|
+
getData: async (filter) => {
|
|
186
|
+
return NativeShapeSourceModule.getData(
|
|
187
|
+
findNodeHandle(nativeRef.current),
|
|
188
|
+
filter,
|
|
189
|
+
);
|
|
190
|
+
},
|
|
191
|
+
|
|
192
|
+
getClusterExpansionZoom: async (clusterId) => {
|
|
193
|
+
return NativeShapeSourceModule.getClusterExpansionZoom(
|
|
194
|
+
findNodeHandle(nativeRef.current),
|
|
195
|
+
clusterId,
|
|
196
|
+
);
|
|
197
|
+
},
|
|
198
|
+
|
|
199
|
+
getClusterLeaves: async (
|
|
200
|
+
clusterId: number,
|
|
201
|
+
limit: number,
|
|
202
|
+
offset: number,
|
|
203
|
+
) => {
|
|
204
|
+
return NativeShapeSourceModule.getClusterLeaves(
|
|
205
|
+
findNodeHandle(nativeRef.current),
|
|
206
|
+
clusterId,
|
|
207
|
+
limit,
|
|
208
|
+
offset,
|
|
209
|
+
);
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
getClusterChildren: async (clusterId: number) => {
|
|
213
|
+
return NativeShapeSourceModule.getClusterChildren(
|
|
214
|
+
findNodeHandle(nativeRef.current),
|
|
215
|
+
clusterId,
|
|
216
|
+
);
|
|
217
|
+
},
|
|
218
|
+
}));
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<ShapeSourceNativeComponent
|
|
222
|
+
ref={nativeRef}
|
|
223
|
+
id={frozenId}
|
|
224
|
+
data={typeof data === "string" ? data : JSON.stringify(data)}
|
|
225
|
+
hasOnPress={!!props.onPress}
|
|
226
|
+
{...props}
|
|
227
|
+
>
|
|
228
|
+
{cloneReactChildrenWithProps(props.children, {
|
|
229
|
+
sourceID: frozenId,
|
|
230
|
+
})}
|
|
231
|
+
</ShapeSourceNativeComponent>
|
|
232
|
+
);
|
|
233
|
+
},
|
|
234
|
+
),
|
|
235
|
+
);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
codegenNativeComponent,
|
|
3
|
+
type CodegenTypes,
|
|
4
|
+
type HostComponent,
|
|
5
|
+
type ViewProps,
|
|
6
|
+
} from "react-native";
|
|
7
|
+
|
|
8
|
+
import type { UnsafeMixed } from "../../../types/codegen/UnsafeMixed";
|
|
9
|
+
|
|
10
|
+
type NativeHitbox = {
|
|
11
|
+
top?: CodegenTypes.WithDefault<CodegenTypes.Int32, 0>;
|
|
12
|
+
right?: CodegenTypes.WithDefault<CodegenTypes.Int32, 0>;
|
|
13
|
+
bottom?: CodegenTypes.WithDefault<CodegenTypes.Int32, 0>;
|
|
14
|
+
left?: CodegenTypes.WithDefault<CodegenTypes.Int32, 0>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type NativePressEvent = {
|
|
18
|
+
lngLat: UnsafeMixed<
|
|
19
|
+
[longitude: CodegenTypes.Double, latitude: CodegenTypes.Double]
|
|
20
|
+
>;
|
|
21
|
+
point: UnsafeMixed<[x: CodegenTypes.Double, y: CodegenTypes.Double]>;
|
|
22
|
+
features: UnsafeMixed<GeoJSON.Feature[]>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export interface NativeProps extends ViewProps {
|
|
26
|
+
id: string;
|
|
27
|
+
data: string;
|
|
28
|
+
|
|
29
|
+
maxzoom?: CodegenTypes.WithDefault<CodegenTypes.Int32, -1>;
|
|
30
|
+
buffer?: CodegenTypes.WithDefault<CodegenTypes.Int32, -1>;
|
|
31
|
+
tolerance?: CodegenTypes.WithDefault<CodegenTypes.Double, -1>;
|
|
32
|
+
lineMetrics?: CodegenTypes.WithDefault<boolean, false>;
|
|
33
|
+
|
|
34
|
+
cluster?: CodegenTypes.WithDefault<boolean, false>;
|
|
35
|
+
clusterRadius?: CodegenTypes.WithDefault<CodegenTypes.Int32, -1>;
|
|
36
|
+
clusterMaxZoom?: CodegenTypes.WithDefault<CodegenTypes.Int32, -1>;
|
|
37
|
+
clusterMinPoints?: CodegenTypes.WithDefault<CodegenTypes.Int32, -1>;
|
|
38
|
+
clusterProperties?: UnsafeMixed<object>;
|
|
39
|
+
|
|
40
|
+
hitbox?: NativeHitbox;
|
|
41
|
+
hasOnPress: boolean;
|
|
42
|
+
|
|
43
|
+
onPress?: CodegenTypes.BubblingEventHandler<NativePressEvent>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default codegenNativeComponent<NativeProps>(
|
|
47
|
+
"MLRNShapeSource",
|
|
48
|
+
) as HostComponent<NativeProps>;
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
type FilterExpression,
|
|
10
10
|
} from "../types/MapLibreRNStyles";
|
|
11
11
|
import { type StyleValue, transformStyle } from "../utils/StyleValue";
|
|
12
|
-
import { getFilter } from "../utils/
|
|
12
|
+
import { getFilter } from "../utils/getFilter";
|
|
13
13
|
|
|
14
14
|
export interface BaseLayerProps {
|
|
15
15
|
/**
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
|
|
3
|
+
let generatedIdCounter = 0;
|
|
4
|
+
|
|
5
|
+
export function useFrozenId(id?: string) {
|
|
6
|
+
const [frozenId] = useState(id ? id : `shape-source-${generatedIdCounter++}`);
|
|
7
|
+
|
|
8
|
+
if (id && id !== frozenId) {
|
|
9
|
+
throw new Error("Source id cannot be changed");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return frozenId;
|
|
13
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -35,8 +35,8 @@ export { NativeUserLocation } from "./components/user-location/NativeUserLocatio
|
|
|
35
35
|
export { useCurrentPosition } from "./hooks/useCurrentPosition";
|
|
36
36
|
|
|
37
37
|
export { VectorSource } from "./components/sources/VectorSource";
|
|
38
|
-
export { ShapeSource } from "./components/sources/ShapeSource";
|
|
39
|
-
export type { ShapeSourceRef } from "./components/sources/ShapeSource";
|
|
38
|
+
export { ShapeSource } from "./components/sources/shape-source/ShapeSource";
|
|
39
|
+
export type { ShapeSourceRef } from "./components/sources/shape-source/ShapeSource";
|
|
40
40
|
export { RasterSource } from "./components/sources/RasterSource";
|
|
41
41
|
export { ImageSource } from "./components/sources/ImageSource";
|
|
42
42
|
export { Images } from "./components/Images";
|
|
@@ -80,7 +80,8 @@ export type {
|
|
|
80
80
|
} from "./types/MapLibreRNStyles";
|
|
81
81
|
export type { PixelPoint } from "./types/PixelPoint";
|
|
82
82
|
export type { PixelPointBounds } from "./types/PixelPointBounds";
|
|
83
|
-
export type { PressEvent
|
|
83
|
+
export type { PressEvent } from "./types/PressEvent";
|
|
84
|
+
export type { PressEventWithFeatures } from "./types/PressEventWithFeatures";
|
|
84
85
|
export type { ViewPadding } from "./types/ViewPadding";
|
|
85
86
|
|
|
86
87
|
export { Animated } from "./utils/animated/Animated";
|
|
@@ -6,8 +6,9 @@ import { toJSONString } from "../../utils";
|
|
|
6
6
|
|
|
7
7
|
const MLRNModule = NativeModules.MLRNModule;
|
|
8
8
|
|
|
9
|
-
export interface SnapshotInputOptions
|
|
10
|
-
|
|
9
|
+
export interface SnapshotInputOptions extends Partial<
|
|
10
|
+
Omit<SnapshotJsonOptions, "centerCoordinate" | "bounds">
|
|
11
|
+
> {
|
|
11
12
|
centerCoordinate?: GeoJSON.Position;
|
|
12
13
|
bounds?: GeoJSON.Position[];
|
|
13
14
|
}
|
|
@@ -115,7 +115,7 @@ export type ExpressionField =
|
|
|
115
115
|
| ExpressionField[]
|
|
116
116
|
| { [key: string]: ExpressionField };
|
|
117
117
|
|
|
118
|
-
export type Expression =
|
|
118
|
+
export type Expression = [ExpressionName, ...ExpressionField[]];
|
|
119
119
|
|
|
120
120
|
export type FilterExpression = Expression;
|
|
121
121
|
|
package/src/types/PressEvent.ts
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
import { Animated } from "react-native";
|
|
2
2
|
|
|
3
|
-
// https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Animated/nodes/AnimatedWithChildren.js
|
|
4
3
|
const AnimatedWithChildren = Object.getPrototypeOf(Animated.ValueXY);
|
|
5
4
|
|
|
6
|
-
if (__DEV__) {
|
|
7
|
-
if (AnimatedWithChildren.name !== "AnimatedWithChildren") {
|
|
8
|
-
console.error(
|
|
9
|
-
"AnimatedCoordinatesArray could not obtain AnimatedWithChildren base class",
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
5
|
export type AnimatedCoordinates = [number, number];
|
|
15
6
|
|
|
16
7
|
const defaultConfig = {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ComponentProps, ComponentType } from "react";
|
|
1
2
|
import { Animated as RNAnimated } from "react-native";
|
|
2
3
|
|
|
3
4
|
import { AnimatedCoordinatesArray } from "./AnimatedCoordinatesArray";
|
|
@@ -12,14 +13,20 @@ import { LineLayer } from "../../components/layers/LineLayer";
|
|
|
12
13
|
import { RasterLayer } from "../../components/layers/RasterLayer";
|
|
13
14
|
import { SymbolLayer } from "../../components/layers/SymbolLayer";
|
|
14
15
|
import { ImageSource } from "../../components/sources/ImageSource";
|
|
15
|
-
import { ShapeSource } from "../../components/sources/ShapeSource";
|
|
16
|
+
import { ShapeSource } from "../../components/sources/shape-source/ShapeSource";
|
|
16
17
|
|
|
17
18
|
export const Animated = {
|
|
18
|
-
//
|
|
19
|
-
ShapeSource: RNAnimated.createAnimatedComponent(
|
|
19
|
+
// Sources
|
|
20
|
+
ShapeSource: RNAnimated.createAnimatedComponent(
|
|
21
|
+
ShapeSource as unknown as ComponentType<
|
|
22
|
+
Omit<ComponentProps<typeof ShapeSource>, "data"> & {
|
|
23
|
+
data: string | GeoJSON.GeoJSON | AnimatedShape;
|
|
24
|
+
}
|
|
25
|
+
>,
|
|
26
|
+
),
|
|
20
27
|
ImageSource: RNAnimated.createAnimatedComponent(ImageSource),
|
|
21
28
|
|
|
22
|
-
//
|
|
29
|
+
// Layers
|
|
23
30
|
FillLayer: RNAnimated.createAnimatedComponent(FillLayer),
|
|
24
31
|
FillExtrusionLayer: RNAnimated.createAnimatedComponent(FillExtrusionLayer),
|
|
25
32
|
LineLayer: RNAnimated.createAnimatedComponent(LineLayer),
|
|
@@ -28,7 +35,7 @@ export const Animated = {
|
|
|
28
35
|
RasterLayer: RNAnimated.createAnimatedComponent(RasterLayer),
|
|
29
36
|
BackgroundLayer: RNAnimated.createAnimatedComponent(BackgroundLayer),
|
|
30
37
|
|
|
31
|
-
//
|
|
38
|
+
// Values
|
|
32
39
|
CoordinatesArray: AnimatedCoordinatesArray,
|
|
33
40
|
RouteCoordinatesArray: AnimatedRouteCoordinatesArray,
|
|
34
41
|
Shape: AnimatedShape,
|
|
@@ -3,17 +3,8 @@ import { Animated } from "react-native";
|
|
|
3
3
|
import type { AnimatedCoordinates } from "./AbstractAnimatedCoordinates";
|
|
4
4
|
import { AnimatedRouteCoordinatesArray } from "./AnimatedRouteCoordinatesArray";
|
|
5
5
|
|
|
6
|
-
// https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Animated/nodes/AnimatedWithChildren.js
|
|
7
6
|
const AnimatedWithChildren = Object.getPrototypeOf(Animated.ValueXY);
|
|
8
7
|
|
|
9
|
-
if (__DEV__) {
|
|
10
|
-
if (AnimatedWithChildren.name !== "AnimatedWithChildren") {
|
|
11
|
-
console.error(
|
|
12
|
-
"AnimatedCoordinatesArray could not obtain AnimatedWithChildren base class",
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
8
|
export class AnimatedExtractCoordinateFromArray extends AnimatedWithChildren {
|
|
18
9
|
_array: AnimatedRouteCoordinatesArray;
|
|
19
10
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Animated } from "react-native";
|
|
2
2
|
|
|
3
|
-
// Used react-native-maps as a reference
|
|
4
|
-
// https://github.com/react-community/react-native-maps/blob/master/lib/components/AnimatedRegion.js
|
|
5
3
|
const AnimatedWithChildren = Object.getPrototypeOf(Animated.ValueXY);
|
|
6
4
|
|
|
7
5
|
const DEFAULT_COORD = [0, 0];
|
|
@@ -16,9 +16,9 @@ import {
|
|
|
16
16
|
|
|
17
17
|
interface AnimatedRouteToValue {
|
|
18
18
|
end: /**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
* Animate to this point on the coordinates array
|
|
20
|
+
*/
|
|
21
|
+
| { point: Coord | AnimatedCoordinates }
|
|
22
22
|
/**
|
|
23
23
|
* Animate to this length of the coordinates array
|
|
24
24
|
*/
|
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
2
|
-
|
|
3
1
|
import { Animated } from "react-native";
|
|
4
2
|
|
|
5
3
|
import type { AnimatedCoordinatesArray } from "./AnimatedCoordinatesArray";
|
|
6
4
|
import { AnimatedExtractCoordinateFromArray } from "./AnimatedExtractCoordinateFromArray";
|
|
7
5
|
import { AnimatedRouteCoordinatesArray } from "./AnimatedRouteCoordinatesArray";
|
|
8
6
|
|
|
9
|
-
// https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Animated/nodes/AnimatedWithChildren.js
|
|
10
7
|
const AnimatedWithChildren = Object.getPrototypeOf(Animated.ValueXY);
|
|
11
8
|
|
|
12
|
-
if (__DEV__) {
|
|
13
|
-
if (AnimatedWithChildren.name !== "AnimatedWithChildren") {
|
|
14
|
-
console.error(
|
|
15
|
-
"AnimatedShape could not obtain AnimatedWithChildren base class",
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
9
|
type Shape =
|
|
21
10
|
| {
|
|
22
11
|
type: "Point";
|
|
@@ -34,7 +23,7 @@ type Shape =
|
|
|
34
23
|
* https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Animated/nodes/AnimatedStyle.js
|
|
35
24
|
*
|
|
36
25
|
* @example
|
|
37
|
-
* <AnimatedShapeSource ...
|
|
26
|
+
* <AnimatedShapeSource ... data={new AnimatedShape({type:'LineString', coordinates: animatedCoords})} />
|
|
38
27
|
*/
|
|
39
28
|
export class AnimatedShape extends AnimatedWithChildren {
|
|
40
29
|
constructor(shape: Shape) {
|
|
@@ -47,8 +36,7 @@ export class AnimatedShape extends AnimatedWithChildren {
|
|
|
47
36
|
return value.map((i) => this._walkShapeAndGetValues(i));
|
|
48
37
|
}
|
|
49
38
|
|
|
50
|
-
|
|
51
|
-
if (value instanceof Animated.Node) {
|
|
39
|
+
if (value instanceof AnimatedWithChildren) {
|
|
52
40
|
return (value as any).__getValue();
|
|
53
41
|
}
|
|
54
42
|
|
|
@@ -75,12 +63,13 @@ export class AnimatedShape extends AnimatedWithChildren {
|
|
|
75
63
|
return shape;
|
|
76
64
|
}
|
|
77
65
|
|
|
78
|
-
|
|
79
|
-
|
|
66
|
+
_walkAndProcess(
|
|
67
|
+
value: any,
|
|
68
|
+
cb: (value: Animated.AnimatedNode) => void,
|
|
69
|
+
): void {
|
|
80
70
|
if (Array.isArray(value)) {
|
|
81
71
|
value.forEach((i) => this._walkAndProcess(i, cb));
|
|
82
|
-
|
|
83
|
-
} else if (value instanceof Animated.Node) {
|
|
72
|
+
} else if (value instanceof AnimatedWithChildren) {
|
|
84
73
|
cb(value);
|
|
85
74
|
} else if (typeof value === "object") {
|
|
86
75
|
for (const key in value) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Component } from "react";
|
|
2
|
+
import { findNodeHandle as rnFindNodeHandle } from "react-native";
|
|
3
|
+
|
|
4
|
+
export const findNodeHandle = (ref: Component | null) => {
|
|
5
|
+
const nodeHandle = rnFindNodeHandle(ref);
|
|
6
|
+
|
|
7
|
+
if (nodeHandle === null) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
"NativeComponent ref is null, wait for the map being initialized",
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return nodeHandle;
|
|
14
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type FilterExpression } from "../types/MapLibreRNStyles";
|
|
2
2
|
|
|
3
|
-
export function getFilter(filter: FilterExpression | undefined):
|
|
4
|
-
if (!Array.isArray(filter)
|
|
3
|
+
export function getFilter(filter: FilterExpression | undefined): any[] {
|
|
4
|
+
if (!Array.isArray(filter)) {
|
|
5
5
|
return [];
|
|
6
6
|
}
|
|
7
7
|
|
package/src/utils/index.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
cloneElement,
|
|
4
|
+
Component,
|
|
5
|
+
type ReactElement,
|
|
6
|
+
type ReactNode,
|
|
7
|
+
} from "react";
|
|
2
8
|
import {
|
|
3
9
|
Image,
|
|
4
10
|
NativeModules,
|
|
@@ -74,22 +80,16 @@ export function runNativeCommand<ReturnType = NativeArg>(
|
|
|
74
80
|
}
|
|
75
81
|
|
|
76
82
|
export function cloneReactChildrenWithProps(
|
|
77
|
-
children:
|
|
83
|
+
children: ReactNode,
|
|
78
84
|
propsToAdd: { [key: string]: string } = {},
|
|
79
|
-
): ReactElement[] |
|
|
85
|
+
): ReactElement[] | null {
|
|
80
86
|
if (!children) {
|
|
81
|
-
return
|
|
87
|
+
return null;
|
|
82
88
|
}
|
|
83
89
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (!Array.isArray(children)) {
|
|
87
|
-
foundChildren = [children];
|
|
88
|
-
} else {
|
|
89
|
-
foundChildren = children;
|
|
90
|
-
}
|
|
90
|
+
const foundChildren = Array.isArray(children) ? children : [children];
|
|
91
|
+
const filteredChildren = foundChildren.filter((child) => !!child);
|
|
91
92
|
|
|
92
|
-
const filteredChildren = foundChildren.filter((child) => !!child); // filter out falsy children, since some can be null
|
|
93
93
|
return Children.map(filteredChildren, (child) =>
|
|
94
94
|
cloneElement(child, propsToAdd),
|
|
95
95
|
);
|