@maplibre/maplibre-react-native 11.0.0-beta.13 → 11.0.0-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/android/src/main/java/org/maplibre/reactnative/components/annotations/markerview/MLRNMarkerView.kt +2 -29
  2. package/android/src/main/java/org/maplibre/reactnative/modules/MLRNOfflineModule.kt +27 -4
  3. package/lib/commonjs/components/camera/Camera.js +4 -3
  4. package/lib/commonjs/components/camera/Camera.js.map +1 -1
  5. package/lib/commonjs/components/map/Map.js +4 -3
  6. package/lib/commonjs/components/map/Map.js.map +1 -1
  7. package/lib/commonjs/components/sources/geojson-source/GeoJSONSource.js +4 -3
  8. package/lib/commonjs/components/sources/geojson-source/GeoJSONSource.js.map +1 -1
  9. package/lib/commonjs/components/sources/vector-source/VectorSource.js +4 -3
  10. package/lib/commonjs/components/sources/vector-source/VectorSource.js.map +1 -1
  11. package/lib/module/components/camera/Camera.js +5 -4
  12. package/lib/module/components/camera/Camera.js.map +1 -1
  13. package/lib/module/components/map/Map.js +5 -4
  14. package/lib/module/components/map/Map.js.map +1 -1
  15. package/lib/module/components/sources/geojson-source/GeoJSONSource.js +5 -4
  16. package/lib/module/components/sources/geojson-source/GeoJSONSource.js.map +1 -1
  17. package/lib/module/components/sources/vector-source/VectorSource.js +5 -4
  18. package/lib/module/components/sources/vector-source/VectorSource.js.map +1 -1
  19. package/lib/typescript/commonjs/components/camera/Camera.d.ts +6 -1
  20. package/lib/typescript/commonjs/components/camera/Camera.d.ts.map +1 -1
  21. package/lib/typescript/commonjs/components/map/Map.d.ts +6 -1
  22. package/lib/typescript/commonjs/components/map/Map.d.ts.map +1 -1
  23. package/lib/typescript/commonjs/components/sources/geojson-source/GeoJSONSource.d.ts +6 -2
  24. package/lib/typescript/commonjs/components/sources/geojson-source/GeoJSONSource.d.ts.map +1 -1
  25. package/lib/typescript/commonjs/components/sources/vector-source/VectorSource.d.ts +6 -2
  26. package/lib/typescript/commonjs/components/sources/vector-source/VectorSource.d.ts.map +1 -1
  27. package/lib/typescript/commonjs/utils/animated/Animated.d.ts +1 -1
  28. package/lib/typescript/module/components/camera/Camera.d.ts +6 -1
  29. package/lib/typescript/module/components/camera/Camera.d.ts.map +1 -1
  30. package/lib/typescript/module/components/map/Map.d.ts +6 -1
  31. package/lib/typescript/module/components/map/Map.d.ts.map +1 -1
  32. package/lib/typescript/module/components/sources/geojson-source/GeoJSONSource.d.ts +6 -2
  33. package/lib/typescript/module/components/sources/geojson-source/GeoJSONSource.d.ts.map +1 -1
  34. package/lib/typescript/module/components/sources/vector-source/VectorSource.d.ts +6 -2
  35. package/lib/typescript/module/components/sources/vector-source/VectorSource.d.ts.map +1 -1
  36. package/lib/typescript/module/utils/animated/Animated.d.ts +1 -1
  37. package/package.json +1 -1
  38. package/src/components/camera/Camera.tsx +69 -68
  39. package/src/components/map/Map.tsx +147 -154
  40. package/src/components/sources/geojson-source/GeoJSONSource.tsx +64 -61
  41. package/src/components/sources/vector-source/VectorSource.tsx +39 -36
@@ -6,9 +6,9 @@ import type {
6
6
  import {
7
7
  Component,
8
8
  type ComponentProps,
9
- forwardRef,
10
9
  memo,
11
10
  type ReactElement,
11
+ type Ref,
12
12
  useImperativeHandle,
13
13
  useLayoutEffect,
14
14
  useMemo,
@@ -461,166 +461,159 @@ export interface MapProps extends ViewProps {
461
461
  * Triggered when a style has finished loading
462
462
  */
463
463
  onDidFinishLoadingStyle?: (event: NativeSyntheticEvent<null>) => void;
464
+
465
+ /**
466
+ * Ref to access Map methods.
467
+ */
468
+ ref?: Ref<MapRef>;
464
469
  }
465
470
 
466
471
  /**
467
472
  * MapLibre Native Map
468
473
  */
469
474
  export const Map = memo(
470
- forwardRef<MapRef, MapProps>(
471
- ({ androidView = "surface", style, ...props }, ref) => {
472
- const [isReady, setIsReady] = useState(false);
473
-
474
- const nativeRef = useRef<
475
- Component<ComponentProps<typeof MapViewNativeComponent>> &
476
- ReactNativeElement
477
- >(null);
478
-
479
- useImperativeHandle(ref, () => ({
480
- getCenter: () =>
481
- NativeMapViewModule.getCenter(findNodeHandle(nativeRef.current)),
482
-
483
- getZoom: () =>
484
- NativeMapViewModule.getZoom(findNodeHandle(nativeRef.current)),
485
-
486
- getBearing: () =>
487
- NativeMapViewModule.getBearing(findNodeHandle(nativeRef.current)),
488
-
489
- getPitch: () =>
490
- NativeMapViewModule.getPitch(findNodeHandle(nativeRef.current)),
491
-
492
- getBounds: () =>
493
- NativeMapViewModule.getBounds(findNodeHandle(nativeRef.current)),
494
-
495
- getViewState: () =>
496
- NativeMapViewModule.getViewState(
497
- findNodeHandle(nativeRef.current),
498
- ) as Promise<ViewState>,
499
-
500
- project: (lngLat) =>
501
- NativeMapViewModule.project(
502
- findNodeHandle(nativeRef.current),
503
- lngLat,
504
- ),
505
-
506
- unproject: (point) =>
507
- NativeMapViewModule.unproject(
508
- findNodeHandle(nativeRef.current),
509
- point,
510
- ),
511
-
512
- queryRenderedFeatures: async (
513
- pixelPointOrPixelPointBoundsOrOptions?:
514
- | PixelPoint
515
- | PixelPointBounds
516
- | QueryRenderedFeaturesOptions,
517
- options?: QueryRenderedFeaturesOptions,
518
- ) => {
519
- if (
520
- pixelPointOrPixelPointBoundsOrOptions &&
521
- Array.isArray(pixelPointOrPixelPointBoundsOrOptions) &&
522
- ((value: PixelPoint | PixelPointBounds): value is PixelPoint =>
523
- typeof value[0] === "number" && typeof value[1] === "number")(
524
- pixelPointOrPixelPointBoundsOrOptions,
525
- )
526
- ) {
527
- return await NativeMapViewModule.queryRenderedFeaturesWithPoint(
528
- findNodeHandle(nativeRef.current),
529
- pixelPointOrPixelPointBoundsOrOptions,
530
- options?.layers ?? [],
531
- getNativeFilter(options?.filter) as string[],
532
- );
533
- } else if (
534
- pixelPointOrPixelPointBoundsOrOptions &&
535
- Array.isArray(pixelPointOrPixelPointBoundsOrOptions) &&
536
- ((
537
- value: PixelPoint | PixelPointBounds,
538
- ): value is PixelPointBounds =>
539
- Array.isArray(value[0]) && Array.isArray(value[1]))(
540
- pixelPointOrPixelPointBoundsOrOptions,
541
- )
542
- ) {
543
- return await NativeMapViewModule.queryRenderedFeaturesWithBounds(
544
- findNodeHandle(nativeRef.current),
545
- pixelPointOrPixelPointBoundsOrOptions,
546
- options?.layers ?? [],
547
- getNativeFilter(options?.filter) as string[],
548
- );
549
- } else {
550
- return await NativeMapViewModule.queryRenderedFeaturesWithBounds(
551
- findNodeHandle(nativeRef.current),
552
- null,
553
- pixelPointOrPixelPointBoundsOrOptions?.layers ?? [],
554
- getNativeFilter(
555
- pixelPointOrPixelPointBoundsOrOptions?.filter,
556
- ) as string[],
557
- );
558
- }
559
- },
560
-
561
- createStaticMapImage: (options) =>
562
- NativeMapViewModule.createStaticMapImage(
475
+ ({ androidView = "surface", style, ref, ...props }: MapProps) => {
476
+ const [isReady, setIsReady] = useState(false);
477
+
478
+ const nativeRef = useRef<
479
+ Component<ComponentProps<typeof MapViewNativeComponent>> &
480
+ ReactNativeElement
481
+ >(null);
482
+
483
+ useImperativeHandle(ref, () => ({
484
+ getCenter: () =>
485
+ NativeMapViewModule.getCenter(findNodeHandle(nativeRef.current)),
486
+
487
+ getZoom: () =>
488
+ NativeMapViewModule.getZoom(findNodeHandle(nativeRef.current)),
489
+
490
+ getBearing: () =>
491
+ NativeMapViewModule.getBearing(findNodeHandle(nativeRef.current)),
492
+
493
+ getPitch: () =>
494
+ NativeMapViewModule.getPitch(findNodeHandle(nativeRef.current)),
495
+
496
+ getBounds: () =>
497
+ NativeMapViewModule.getBounds(findNodeHandle(nativeRef.current)),
498
+
499
+ getViewState: () =>
500
+ NativeMapViewModule.getViewState(
501
+ findNodeHandle(nativeRef.current),
502
+ ) as Promise<ViewState>,
503
+
504
+ project: (lngLat) =>
505
+ NativeMapViewModule.project(findNodeHandle(nativeRef.current), lngLat),
506
+
507
+ unproject: (point) =>
508
+ NativeMapViewModule.unproject(findNodeHandle(nativeRef.current), point),
509
+
510
+ queryRenderedFeatures: async (
511
+ pixelPointOrPixelPointBoundsOrOptions?:
512
+ | PixelPoint
513
+ | PixelPointBounds
514
+ | QueryRenderedFeaturesOptions,
515
+ options?: QueryRenderedFeaturesOptions,
516
+ ) => {
517
+ if (
518
+ pixelPointOrPixelPointBoundsOrOptions &&
519
+ Array.isArray(pixelPointOrPixelPointBoundsOrOptions) &&
520
+ ((value: PixelPoint | PixelPointBounds): value is PixelPoint =>
521
+ typeof value[0] === "number" && typeof value[1] === "number")(
522
+ pixelPointOrPixelPointBoundsOrOptions,
523
+ )
524
+ ) {
525
+ return await NativeMapViewModule.queryRenderedFeaturesWithPoint(
563
526
  findNodeHandle(nativeRef.current),
564
- options.output,
565
- ),
566
-
567
- setSourceVisibility: (visible, source, sourceLayer) =>
568
- NativeMapViewModule.setSourceVisibility(
527
+ pixelPointOrPixelPointBoundsOrOptions,
528
+ options?.layers ?? [],
529
+ getNativeFilter(options?.filter) as string[],
530
+ );
531
+ } else if (
532
+ pixelPointOrPixelPointBoundsOrOptions &&
533
+ Array.isArray(pixelPointOrPixelPointBoundsOrOptions) &&
534
+ ((value: PixelPoint | PixelPointBounds): value is PixelPointBounds =>
535
+ Array.isArray(value[0]) && Array.isArray(value[1]))(
536
+ pixelPointOrPixelPointBoundsOrOptions,
537
+ )
538
+ ) {
539
+ return await NativeMapViewModule.queryRenderedFeaturesWithBounds(
569
540
  findNodeHandle(nativeRef.current),
570
- visible,
571
- source,
572
- sourceLayer ?? null,
573
- ),
574
-
575
- showAttribution: () =>
576
- NativeMapViewModule.showAttribution(
541
+ pixelPointOrPixelPointBoundsOrOptions,
542
+ options?.layers ?? [],
543
+ getNativeFilter(options?.filter) as string[],
544
+ );
545
+ } else {
546
+ return await NativeMapViewModule.queryRenderedFeaturesWithBounds(
577
547
  findNodeHandle(nativeRef.current),
578
- ),
579
- }));
580
-
581
- // Start before rendering
582
- useLayoutEffect(() => {
583
- LogManager.start();
584
-
585
- return () => {
586
- LogManager.stop();
587
- };
588
- }, []);
589
-
590
- const nativeProps = useMemo(() => {
591
- const { mapStyle, light, ...otherProps } = props;
592
-
593
- return {
594
- ...otherProps,
595
- ref: nativeRef,
596
- style: styles.flex1,
597
- mapStyle:
598
- typeof mapStyle === "object" ? JSON.stringify(mapStyle) : mapStyle,
599
- light: props.light
600
- ? transformStyle(convertToInternalStyle(props.light))
601
- : undefined,
602
- };
603
- }, [props]);
604
-
605
- let map: ReactElement | null = null;
606
- if (isReady) {
607
- const NativeMapView =
608
- Platform.OS === "android" && androidView === "texture"
609
- ? AndroidTextureMapViewNativeComponent
610
- : MapViewNativeComponent;
611
-
612
- map = <NativeMapView {...nativeProps} />;
613
- }
614
-
615
- return (
616
- <View
617
- onLayout={() => setIsReady(true)}
618
- style={style ?? styles.flex1}
619
- testID={nativeProps.testID ? `${nativeProps.testID}-view` : undefined}
620
- >
621
- {map}
622
- </View>
623
- );
624
- },
625
- ),
548
+ null,
549
+ pixelPointOrPixelPointBoundsOrOptions?.layers ?? [],
550
+ getNativeFilter(
551
+ pixelPointOrPixelPointBoundsOrOptions?.filter,
552
+ ) as string[],
553
+ );
554
+ }
555
+ },
556
+
557
+ createStaticMapImage: (options) =>
558
+ NativeMapViewModule.createStaticMapImage(
559
+ findNodeHandle(nativeRef.current),
560
+ options.output,
561
+ ),
562
+
563
+ setSourceVisibility: (visible, source, sourceLayer) =>
564
+ NativeMapViewModule.setSourceVisibility(
565
+ findNodeHandle(nativeRef.current),
566
+ visible,
567
+ source,
568
+ sourceLayer ?? null,
569
+ ),
570
+
571
+ showAttribution: () =>
572
+ NativeMapViewModule.showAttribution(findNodeHandle(nativeRef.current)),
573
+ }));
574
+
575
+ // Start before rendering
576
+ useLayoutEffect(() => {
577
+ LogManager.start();
578
+
579
+ return () => {
580
+ LogManager.stop();
581
+ };
582
+ }, []);
583
+
584
+ const nativeProps = useMemo(() => {
585
+ const { mapStyle, light, ...otherProps } = props;
586
+
587
+ return {
588
+ ...otherProps,
589
+ ref: nativeRef,
590
+ style: styles.flex1,
591
+ mapStyle:
592
+ typeof mapStyle === "object" ? JSON.stringify(mapStyle) : mapStyle,
593
+ light: props.light
594
+ ? transformStyle(convertToInternalStyle(props.light))
595
+ : undefined,
596
+ };
597
+ }, [props]);
598
+
599
+ let map: ReactElement | null = null;
600
+ if (isReady) {
601
+ const NativeMapView =
602
+ Platform.OS === "android" && androidView === "texture"
603
+ ? AndroidTextureMapViewNativeComponent
604
+ : MapViewNativeComponent;
605
+
606
+ map = <NativeMapView {...nativeProps} />;
607
+ }
608
+
609
+ return (
610
+ <View
611
+ onLayout={() => setIsReady(true)}
612
+ style={style ?? styles.flex1}
613
+ testID={nativeProps.testID ? `${nativeProps.testID}-view` : undefined}
614
+ >
615
+ {map}
616
+ </View>
617
+ );
618
+ },
626
619
  );
@@ -5,9 +5,9 @@ import type {
5
5
  import {
6
6
  Component,
7
7
  type ComponentProps,
8
- forwardRef,
9
8
  memo,
10
9
  type ReactNode,
10
+ type Ref,
11
11
  useImperativeHandle,
12
12
  useRef,
13
13
  } from "react";
@@ -155,6 +155,11 @@ export interface GeoJSONSourceProps extends BaseProps, PressableSourceProps {
155
155
  lineMetrics?: boolean;
156
156
 
157
157
  children?: ReactNode;
158
+
159
+ /**
160
+ * Ref to access GeoJSONSource methods.
161
+ */
162
+ ref?: Ref<GeoJSONSourceRef>;
158
163
  }
159
164
 
160
165
  /**
@@ -162,64 +167,62 @@ export interface GeoJSONSourceProps extends BaseProps, PressableSourceProps {
162
167
  * The data may be provided as an url or a GeoJSON object.
163
168
  */
164
169
  export const GeoJSONSource = memo(
165
- forwardRef<GeoJSONSourceRef, GeoJSONSourceProps>(
166
- ({ id, data, ...props }, ref) => {
167
- const nativeRef = useRef<
168
- Component<ComponentProps<typeof GeoJSONSourceNativeComponent>> &
169
- ReactNativeElement
170
- >(null);
171
-
172
- const frozenId = useFrozenId(id);
173
-
174
- useImperativeHandle(ref, () => ({
175
- getData: async (filter) => {
176
- return NativeGeoJSONSourceModule.getData(
177
- findNodeHandle(nativeRef.current),
178
- getNativeFilter(filter),
179
- );
180
- },
181
-
182
- getClusterExpansionZoom: async (clusterId) => {
183
- return NativeGeoJSONSourceModule.getClusterExpansionZoom(
184
- findNodeHandle(nativeRef.current),
185
- clusterId,
186
- );
187
- },
188
-
189
- getClusterLeaves: async (
190
- clusterId: number,
191
- limit: number,
192
- offset: number,
193
- ) => {
194
- return NativeGeoJSONSourceModule.getClusterLeaves(
195
- findNodeHandle(nativeRef.current),
196
- clusterId,
197
- limit,
198
- offset,
199
- );
200
- },
201
-
202
- getClusterChildren: async (clusterId: number) => {
203
- return NativeGeoJSONSourceModule.getClusterChildren(
204
- findNodeHandle(nativeRef.current),
205
- clusterId,
206
- );
207
- },
208
- }));
209
-
210
- return (
211
- <GeoJSONSourceNativeComponent
212
- ref={nativeRef}
213
- id={frozenId}
214
- data={typeof data === "string" ? data : JSON.stringify(data)}
215
- hasOnPress={!!props.onPress}
216
- {...props}
217
- >
218
- {cloneReactChildrenWithProps(props.children, {
219
- source: frozenId,
220
- })}
221
- </GeoJSONSourceNativeComponent>
222
- );
223
- },
224
- ),
170
+ ({ id, data, ref, ...props }: GeoJSONSourceProps) => {
171
+ const nativeRef = useRef<
172
+ Component<ComponentProps<typeof GeoJSONSourceNativeComponent>> &
173
+ ReactNativeElement
174
+ >(null);
175
+
176
+ const frozenId = useFrozenId(id);
177
+
178
+ useImperativeHandle(ref, () => ({
179
+ getData: async (filter) => {
180
+ return NativeGeoJSONSourceModule.getData(
181
+ findNodeHandle(nativeRef.current),
182
+ getNativeFilter(filter),
183
+ );
184
+ },
185
+
186
+ getClusterExpansionZoom: async (clusterId) => {
187
+ return NativeGeoJSONSourceModule.getClusterExpansionZoom(
188
+ findNodeHandle(nativeRef.current),
189
+ clusterId,
190
+ );
191
+ },
192
+
193
+ getClusterLeaves: async (
194
+ clusterId: number,
195
+ limit: number,
196
+ offset: number,
197
+ ) => {
198
+ return NativeGeoJSONSourceModule.getClusterLeaves(
199
+ findNodeHandle(nativeRef.current),
200
+ clusterId,
201
+ limit,
202
+ offset,
203
+ );
204
+ },
205
+
206
+ getClusterChildren: async (clusterId: number) => {
207
+ return NativeGeoJSONSourceModule.getClusterChildren(
208
+ findNodeHandle(nativeRef.current),
209
+ clusterId,
210
+ );
211
+ },
212
+ }));
213
+
214
+ return (
215
+ <GeoJSONSourceNativeComponent
216
+ ref={nativeRef}
217
+ id={frozenId}
218
+ data={typeof data === "string" ? data : JSON.stringify(data)}
219
+ hasOnPress={!!props.onPress}
220
+ {...props}
221
+ >
222
+ {cloneReactChildrenWithProps(props.children, {
223
+ source: frozenId,
224
+ })}
225
+ </GeoJSONSourceNativeComponent>
226
+ );
227
+ },
225
228
  );
@@ -2,9 +2,9 @@ import type { FilterSpecification } from "@maplibre/maplibre-gl-style-spec";
2
2
  import {
3
3
  Component,
4
4
  type ComponentProps,
5
- forwardRef,
6
5
  memo,
7
6
  type ReactNode,
7
+ type Ref,
8
8
  useImperativeHandle,
9
9
  useRef,
10
10
  } from "react";
@@ -82,48 +82,51 @@ export interface VectorSourceProps extends BaseProps, PressableSourceProps {
82
82
  attribution?: string;
83
83
 
84
84
  children?: ReactNode;
85
+
86
+ /**
87
+ * Ref to access VectorSource methods.
88
+ */
89
+ ref?: Ref<VectorSourceRef>;
85
90
  }
86
91
 
87
92
  /**
88
93
  * VectorSource is a map content source that supplies tiled vector data in Mapbox Vector Tile format to be shown on the map.
89
94
  * The location of and metadata about the tiles are defined either by an option dictionary or by an external file that conforms to the TileJSON specification.
90
95
  */
91
- export const VectorSource = memo(
92
- forwardRef<VectorSourceRef, VectorSourceProps>(({ id, ...props }, ref) => {
93
- const nativeRef = useRef<
94
- Component<ComponentProps<typeof VectorSourceNativeComponent>> &
95
- ReactNativeElement
96
- >(null);
96
+ export const VectorSource = memo(({ id, ref, ...props }: VectorSourceProps) => {
97
+ const nativeRef = useRef<
98
+ Component<ComponentProps<typeof VectorSourceNativeComponent>> &
99
+ ReactNativeElement
100
+ >(null);
97
101
 
98
- const frozenId = useFrozenId(id);
102
+ const frozenId = useFrozenId(id);
99
103
 
100
- useImperativeHandle(ref, () => ({
101
- querySourceFeatures: async ({
104
+ useImperativeHandle(ref, () => ({
105
+ querySourceFeatures: async ({
106
+ sourceLayer,
107
+ filter,
108
+ }: {
109
+ sourceLayer: string;
110
+ filter?: FilterSpecification;
111
+ }): Promise<GeoJSON.Feature[]> => {
112
+ return NativeVectorSourceModule.querySourceFeatures(
113
+ findNodeHandle(nativeRef.current),
102
114
  sourceLayer,
103
- filter,
104
- }: {
105
- sourceLayer: string;
106
- filter?: FilterSpecification;
107
- }): Promise<GeoJSON.Feature[]> => {
108
- return NativeVectorSourceModule.querySourceFeatures(
109
- findNodeHandle(nativeRef.current),
110
- sourceLayer,
111
- getNativeFilter(filter) as string[],
112
- );
113
- },
114
- }));
115
+ getNativeFilter(filter) as string[],
116
+ );
117
+ },
118
+ }));
115
119
 
116
- return (
117
- <VectorSourceNativeComponent
118
- ref={nativeRef}
119
- id={frozenId}
120
- hasOnPress={!!props.onPress}
121
- {...props}
122
- >
123
- {cloneReactChildrenWithProps(props.children, {
124
- source: frozenId,
125
- })}
126
- </VectorSourceNativeComponent>
127
- );
128
- }),
129
- );
120
+ return (
121
+ <VectorSourceNativeComponent
122
+ ref={nativeRef}
123
+ id={frozenId}
124
+ hasOnPress={!!props.onPress}
125
+ {...props}
126
+ >
127
+ {cloneReactChildrenWithProps(props.children, {
128
+ source: frozenId,
129
+ })}
130
+ </VectorSourceNativeComponent>
131
+ );
132
+ });