@rnmapbox/maps 10.0.0-beta.73 → 10.0.0-beta.74

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 (104) hide show
  1. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/location/LocationComponentManager.kt +4 -2
  2. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/layers/RCTLayer.kt +7 -2
  3. package/index.d.ts +19 -72
  4. package/javascript/components/AbstractLayer.tsx +2 -1
  5. package/javascript/components/AbstractSource.tsx +3 -1
  6. package/javascript/components/Atmosphere.tsx +2 -1
  7. package/javascript/components/Camera.tsx +6 -4
  8. package/javascript/components/Images.tsx +1 -1
  9. package/javascript/components/Light.tsx +60 -0
  10. package/javascript/components/PointAnnotation.tsx +2 -1
  11. package/javascript/components/ShapeSource.tsx +1 -11
  12. package/javascript/components/Terrain.tsx +2 -1
  13. package/javascript/components/VectorSource.tsx +209 -0
  14. package/javascript/modules/location/locationManager.ts +1 -1
  15. package/javascript/types/BaseProps.ts +3 -0
  16. package/javascript/types/OnPressEvent.ts +11 -0
  17. package/javascript/utils/{Logger.js → Logger.ts} +32 -14
  18. package/javascript/utils/MapboxStyles.d.ts +1 -1
  19. package/javascript/utils/deprecation.ts +3 -3
  20. package/javascript/utils/nativeRef.ts +28 -0
  21. package/lib/commonjs/components/AbstractLayer.js.map +1 -1
  22. package/lib/commonjs/components/AbstractSource.js.map +1 -1
  23. package/lib/commonjs/components/Atmosphere.js.map +1 -1
  24. package/lib/commonjs/components/Camera.js +4 -4
  25. package/lib/commonjs/components/Camera.js.map +1 -1
  26. package/lib/commonjs/components/Images.js +1 -1
  27. package/lib/commonjs/components/Images.js.map +1 -1
  28. package/lib/commonjs/components/Light.js +32 -33
  29. package/lib/commonjs/components/Light.js.map +1 -1
  30. package/lib/commonjs/components/PointAnnotation.js.map +1 -1
  31. package/lib/commonjs/components/ShapeSource.js.map +1 -1
  32. package/lib/commonjs/components/Terrain.js.map +1 -1
  33. package/lib/commonjs/components/VectorSource.js +15 -74
  34. package/lib/commonjs/components/VectorSource.js.map +1 -1
  35. package/lib/commonjs/modules/location/locationManager.js +2 -1
  36. package/lib/commonjs/modules/location/locationManager.js.map +1 -1
  37. package/lib/commonjs/types/BaseProps.js +2 -0
  38. package/lib/commonjs/types/BaseProps.js.map +1 -0
  39. package/lib/commonjs/types/OnPressEvent.js +2 -0
  40. package/lib/commonjs/types/OnPressEvent.js.map +1 -0
  41. package/lib/commonjs/utils/Logger.js +7 -7
  42. package/lib/commonjs/utils/Logger.js.map +1 -1
  43. package/lib/commonjs/utils/deprecation.js +2 -2
  44. package/lib/commonjs/utils/nativeRef.js +27 -0
  45. package/lib/commonjs/utils/nativeRef.js.map +1 -0
  46. package/lib/module/components/AbstractLayer.js.map +1 -1
  47. package/lib/module/components/AbstractSource.js.map +1 -1
  48. package/lib/module/components/Atmosphere.js.map +1 -1
  49. package/lib/module/components/Camera.js +4 -4
  50. package/lib/module/components/Camera.js.map +1 -1
  51. package/lib/module/components/Images.js +1 -1
  52. package/lib/module/components/Images.js.map +1 -1
  53. package/lib/module/components/Light.js +29 -32
  54. package/lib/module/components/Light.js.map +1 -1
  55. package/lib/module/components/PointAnnotation.js.map +1 -1
  56. package/lib/module/components/ShapeSource.js.map +1 -1
  57. package/lib/module/components/Terrain.js.map +1 -1
  58. package/lib/module/components/VectorSource.js +15 -74
  59. package/lib/module/components/VectorSource.js.map +1 -1
  60. package/lib/module/modules/location/locationManager.js +1 -1
  61. package/lib/module/modules/location/locationManager.js.map +1 -1
  62. package/lib/module/types/BaseProps.js +2 -0
  63. package/lib/module/types/BaseProps.js.map +1 -0
  64. package/lib/module/types/OnPressEvent.js +2 -0
  65. package/lib/module/types/OnPressEvent.js.map +1 -0
  66. package/lib/module/utils/Logger.js +7 -7
  67. package/lib/module/utils/Logger.js.map +1 -1
  68. package/lib/module/utils/deprecation.js +2 -2
  69. package/lib/module/utils/nativeRef.js +21 -0
  70. package/lib/module/utils/nativeRef.js.map +1 -0
  71. package/lib/typescript/components/AbstractLayer.d.ts +2 -1
  72. package/lib/typescript/components/AbstractLayer.d.ts.map +1 -1
  73. package/lib/typescript/components/AbstractSource.d.ts +2 -1
  74. package/lib/typescript/components/AbstractSource.d.ts.map +1 -1
  75. package/lib/typescript/components/Atmosphere.d.ts +2 -1
  76. package/lib/typescript/components/Atmosphere.d.ts.map +1 -1
  77. package/lib/typescript/components/Camera.d.ts.map +1 -1
  78. package/lib/typescript/components/Images.d.ts +1 -1
  79. package/lib/typescript/components/Images.d.ts.map +1 -1
  80. package/lib/typescript/components/Light.d.ts +17 -0
  81. package/lib/typescript/components/Light.d.ts.map +1 -0
  82. package/lib/typescript/components/PointAnnotation.d.ts +2 -1
  83. package/lib/typescript/components/PointAnnotation.d.ts.map +1 -1
  84. package/lib/typescript/components/ShapeSource.d.ts +3 -13
  85. package/lib/typescript/components/ShapeSource.d.ts.map +1 -1
  86. package/lib/typescript/components/Terrain.d.ts +2 -1
  87. package/lib/typescript/components/Terrain.d.ts.map +1 -1
  88. package/lib/typescript/components/VectorSource.d.ts +144 -0
  89. package/lib/typescript/components/VectorSource.d.ts.map +1 -0
  90. package/lib/typescript/modules/location/locationManager.d.ts +1 -1
  91. package/lib/typescript/modules/location/locationManager.d.ts.map +1 -1
  92. package/lib/typescript/types/BaseProps.d.ts +4 -0
  93. package/lib/typescript/types/BaseProps.d.ts.map +1 -0
  94. package/lib/typescript/types/OnPressEvent.d.ts +12 -0
  95. package/lib/typescript/types/OnPressEvent.d.ts.map +1 -0
  96. package/lib/typescript/utils/Logger.d.ts +53 -0
  97. package/lib/typescript/utils/Logger.d.ts.map +1 -0
  98. package/lib/typescript/utils/deprecation.d.ts +4 -3
  99. package/lib/typescript/utils/deprecation.d.ts.map +1 -1
  100. package/lib/typescript/utils/nativeRef.d.ts +21 -0
  101. package/lib/typescript/utils/nativeRef.d.ts.map +1 -0
  102. package/package.json +1 -1
  103. package/javascript/components/Light.js +0 -47
  104. package/javascript/components/VectorSource.js +0 -203
@@ -23,7 +23,7 @@ import com.mapbox.rctmgl.location.LocationManager
23
23
  class LocationComponentManager(mapView: RCTMGLMapView, context: Context) {
24
24
  var mMapView = mapView
25
25
  var mContext = context
26
- private var mState = State(showUserLocation=false, followUserLocation=false, hidden=false, tintColor= null, bearingImage = null, puckBearingSource =null)
26
+ private var mState = State(showUserLocation=false, followUserLocation=false, tintColor= null, bearingImage = null, puckBearingSource =null)
27
27
 
28
28
  private var mLocationManager: LocationManager = LocationManager.getInstance(context)
29
29
 
@@ -34,13 +34,15 @@ class LocationComponentManager(mapView: RCTMGLMapView, context: Context) {
34
34
  data class State(
35
35
  val showUserLocation: Boolean,
36
36
  val followUserLocation: Boolean,
37
- val hidden: Boolean, // in case it isn't native
38
37
  val tintColor: Int?, // tint of location puck
39
38
  var bearingImage: Drawable?, // bearing image (background)
40
39
  var puckBearingSource: PuckBearingSource? // bearing source
41
40
  ) {
42
41
  val enabled: Boolean
43
42
  get() = showUserLocation || followUserLocation
43
+
44
+ val hidden: Boolean
45
+ get() = followUserLocation && !showUserLocation
44
46
  }
45
47
 
46
48
  fun update(newStateCallback: (currentState: State) -> State) {
@@ -246,8 +246,13 @@ abstract class RCTLayer<T : Layer?>(protected var mContext: Context) : AbstractS
246
246
  }
247
247
 
248
248
  override fun removeFromMap(mapView: RCTMGLMapView) {
249
- if (style != null) {
250
- style!!.removeStyleLayer(mLayer!!.layerId)
249
+ style?.let {
250
+ val layer = mLayer
251
+ if (layer != null) {
252
+ it.removeStyleLayer(layer.layerId)
253
+ } else {
254
+ Logger.e("RCTLayer","mLayer is null on removal layer from map")
255
+ }
251
256
  }
252
257
  super.removeFromMap(mapView)
253
258
  }
package/index.d.ts CHANGED
@@ -1,13 +1,7 @@
1
1
  declare module 'react-native-mapbox-gl__maps';
2
2
 
3
3
  import { Component, FC, ReactNode } from 'react';
4
- import {
5
- ViewProps,
6
- ViewStyle,
7
- StyleProp,
8
- TextStyle,
9
- ImageSourcePropType,
10
- } from 'react-native';
4
+ import { ViewProps, ViewStyle, StyleProp, TextStyle } from 'react-native';
11
5
  import ReactNative from 'react-native';
12
6
  import {
13
7
  Geometry,
@@ -70,6 +64,8 @@ import {
70
64
  ShapeSource as _ShapeSource,
71
65
  Props as _ShapeSourceProps,
72
66
  } from './javascript/components/ShapeSource';
67
+ import _VectorSource from './javascript/components/VectorSource';
68
+ import _Light from './javascript/components/Light';
73
69
  import type {
74
70
  MapboxGLEvent as _MapboxGLEvent,
75
71
  AnimatedPoint as _AnimatedPoint,
@@ -80,6 +76,13 @@ import type {
80
76
  Location as _Location,
81
77
  LocationManager,
82
78
  } from './javascript/modules/location/locationManager';
79
+ import type { OnPressEvent as _OnPressEvent } from './javascript/types/OnPressEvent';
80
+ import {
81
+ type LogLevel,
82
+ type LogObject,
83
+ type LogCallback,
84
+ Logger as _Logger,
85
+ } from './javascript/utils/Logger';
83
86
 
84
87
  // prettier-ignore
85
88
  type ExpressionName =
@@ -130,17 +133,7 @@ type Visibility = 'visible' | 'none';
130
133
  type Alignment = 'map' | 'viewport';
131
134
  type AutoAlignment = Alignment | 'auto';
132
135
 
133
- export type OnPressEvent = {
134
- features: Array<GeoJSON.Feature>;
135
- coordinates: {
136
- latitude: number;
137
- longitude: number;
138
- };
139
- point: {
140
- x: number;
141
- y: number;
142
- };
143
- };
136
+ export type OnPressEvent = _OnPressEvent;
144
137
 
145
138
  declare namespace MapboxGL {
146
139
  function removeCustomHeader(headerName: string): void;
@@ -156,6 +149,8 @@ declare namespace MapboxGL {
156
149
  const getAnnotationsLayerID = _getAnnotationsLayerID;
157
150
  type getAnnotationsLayerID = _getAnnotationsLayerID;
158
151
 
152
+ const Logger = _Logger;
153
+ type Logger = _Logger;
159
154
  const Camera = _Camera;
160
155
  type Camera = _Camera;
161
156
  type CameraStop = _CameraStop;
@@ -334,7 +329,7 @@ declare namespace MapboxGL {
334
329
 
335
330
  class UserLocation extends Component<UserLocationProps> {}
336
331
 
337
- class Light extends Component<LightProps> {}
332
+ const Light = _Light;
338
333
 
339
334
  class Callout extends Component<CalloutProps> {}
340
335
  type Style = FC<StyleProps>;
@@ -342,7 +337,8 @@ declare namespace MapboxGL {
342
337
  /**
343
338
  * Sources
344
339
  */
345
- class VectorSource extends Component<VectorSourceProps> {}
340
+ type VectorSource = typeof _VectorSource;
341
+ const VectorSource = _VectorSource;
346
342
  class RasterSource extends Component<RasterSourceProps> {}
347
343
  class RasterDemSource extends Component<RasterSourceProps> {}
348
344
 
@@ -643,14 +639,6 @@ export interface TileSourceProps extends ViewProps {
643
639
  maxZoomLevel?: number;
644
640
  }
645
641
 
646
- export interface VectorSourceProps extends TileSourceProps {
647
- onPress?: (event: OnPressEvent) => void;
648
- hitbox?: {
649
- width: number;
650
- height: number;
651
- };
652
- }
653
-
654
642
  export interface RasterSourceProps extends TileSourceProps {
655
643
  tileSize?: number;
656
644
  }
@@ -667,35 +655,6 @@ export interface LayerBaseProps<T = object> extends Omit<ViewProps, 'style'> {
667
655
  maxZoomLevel?: number;
668
656
  }
669
657
 
670
- export interface BackgroundLayerProps extends LayerBaseProps {
671
- style?: StyleProp<BackgroundLayerStyle>;
672
- }
673
-
674
- export interface CircleLayerProps extends LayerBaseProps {
675
- style?: StyleProp<CircleLayerStyle>;
676
- }
677
-
678
- export interface FillExtrusionLayerProps extends Omit<LayerBaseProps, 'id'> {
679
- id: string;
680
- style?: StyleProp<FillExtrusionLayerStyle>;
681
- }
682
-
683
- export interface FillLayerProps extends LayerBaseProps {
684
- style?: StyleProp<FillLayerStyle>;
685
- }
686
-
687
- export interface LineLayerProps extends LayerBaseProps {
688
- style?: StyleProp<LineLayerStyle>;
689
- }
690
-
691
- export interface RasterLayerProps extends LayerBaseProps {
692
- style?: StyleProp<RasterLayerStyle>;
693
- }
694
-
695
- export interface HeatmapLayerProps extends LayerBaseProps {
696
- style?: StyleProp<HeatmapLayerStyle>;
697
- }
698
-
699
658
  export interface ImageSourceProps extends ViewProps {
700
659
  id: string;
701
660
  url?: number | string;
@@ -732,21 +691,7 @@ export interface SkyLayerProps extends LayerBaseProps {
732
691
  style?: StyleProp<SkyLayerStyle>;
733
692
  }
734
693
 
735
- // Logger class
736
- type LogLevel = 'error' | 'warning' | 'info' | 'debug' | 'verbose';
737
-
738
- interface LogObject {
739
- level: LogLevel;
740
- message: string;
741
- tag: string;
742
- }
743
-
744
- type LogCallback = (object: LogObject) => void;
745
-
746
- export class Logger {
747
- public static setLogCallback: (cb: LogCallback) => boolean;
748
- public static setLogLevel: (level: LogLevel) => void;
749
- }
694
+ export import Logger = MapboxGL.Logger;
750
695
 
751
696
  export import MapView = MapboxGL.MapView;
752
697
 
@@ -790,6 +735,8 @@ export import AnimatedMapPoint = MapboxGL.AnimatedPoint;
790
735
  export import AnimatedShape = MapboxGL.AnimatedShape;
791
736
  export import Images = MapboxGL.Images;
792
737
  export import Image = MapboxGL.Image;
738
+ export import Light = MapboxGL.Light;
739
+ export import VectorSource = MapboxGL.VectorSource;
793
740
 
794
741
  export const { offlineManager } = MapboxGL;
795
742
 
@@ -5,8 +5,9 @@ import { NativeMethods, processColor } from 'react-native';
5
5
  import { getFilter } from '../utils/filterUtils';
6
6
  import { AllLayerStyleProps, FilterExpression } from '../utils/MapboxStyles';
7
7
  import { transformStyle } from '../utils/StyleValue';
8
+ import type { BaseProps } from '../types/BaseProps';
8
9
 
9
- type PropsBase = {
10
+ type PropsBase = BaseProps & {
10
11
  id: string;
11
12
  sourceID?: string;
12
13
  minZoomLevel?: number;
@@ -1,10 +1,12 @@
1
1
  import React from 'react';
2
2
  import { NativeMethods } from 'react-native';
3
3
 
4
+ import type { BaseProps } from '../types/BaseProps';
5
+
4
6
  class AbstractSource<
5
7
  PropsType,
6
8
  NativePropsType extends object,
7
- > extends React.PureComponent<PropsType> {
9
+ > extends React.PureComponent<PropsType & BaseProps> {
8
10
  _nativeRef?: React.Component<NativePropsType> & Readonly<NativeMethods>;
9
11
 
10
12
  setNativeProps(props: NativePropsType) {
@@ -3,10 +3,11 @@ import { requireNativeComponent } from 'react-native';
3
3
 
4
4
  import type { AtmosphereLayerStyleProps } from '../utils/MapboxStyles';
5
5
  import { StyleValue, transformStyle } from '../utils/StyleValue';
6
+ import type { BaseProps } from '../types/BaseProps';
6
7
 
7
8
  export const NATIVE_MODULE_NAME = 'RCTMGLAtmosphere';
8
9
 
9
- type Props = {
10
+ type Props = BaseProps & {
10
11
  style: AtmosphereLayerStyleProps;
11
12
  };
12
13
 
@@ -11,6 +11,7 @@ import { NativeModules, requireNativeComponent } from 'react-native';
11
11
 
12
12
  import { MapboxGLEvent } from '../types';
13
13
  import { makeLatLngBounds, makePoint } from '../utils/geoUtils';
14
+ import { type NativeRefType } from '../utils/nativeRef';
14
15
 
15
16
  const NativeModule = NativeModules.MGLModule;
16
17
 
@@ -240,8 +241,9 @@ export const Camera = memo(
240
241
  onUserTrackingModeChange,
241
242
  } = props;
242
243
 
243
- // @ts-expect-error This avoids a type/value mismatch.
244
- const nativeCamera = useRef<RCTMGLCamera>(null);
244
+ const nativeCamera = useRef<typeof RCTMGLCamera>(
245
+ null,
246
+ ) as NativeRefType<NativeCameraProps>;
245
247
 
246
248
  const buildNativeStop = useCallback(
247
249
  (
@@ -352,14 +354,14 @@ export const Camera = memo(
352
354
  if (_nativeStop) {
353
355
  _nativeStops = [..._nativeStops, _nativeStop];
354
356
  }
355
- nativeCamera.current.setNativeProps({
357
+ nativeCamera.current?.setNativeProps({
356
358
  stop: { stops: _nativeStops },
357
359
  });
358
360
  }
359
361
  } else if (config.type === 'CameraStop') {
360
362
  const _nativeStop = buildNativeStop(config);
361
363
  if (_nativeStop) {
362
- nativeCamera.current.setNativeProps({ stop: _nativeStop });
364
+ nativeCamera.current?.setNativeProps({ stop: _nativeStop });
363
365
  }
364
366
  }
365
367
  };
@@ -69,7 +69,7 @@ interface Props {
69
69
  /**
70
70
  * Images defines the images used in Symbol etc. layers.
71
71
  */
72
- class Images extends React.Component<Props> {
72
+ class Images extends React.PureComponent<Props> {
73
73
  static NATIVE_ASSETS_KEY = 'assets';
74
74
 
75
75
  _getImages() {
@@ -0,0 +1,60 @@
1
+ import React, { forwardRef, memo, useImperativeHandle, useRef } from 'react';
2
+ import { requireNativeComponent } from 'react-native';
3
+
4
+ import { LightLayerStyleProps } from '../utils/MapboxStyles';
5
+ import { StyleValue } from '../utils/StyleValue';
6
+ import { type BaseProps } from '../types/BaseProps';
7
+ import { transformStyle } from '../utils/StyleValue';
8
+ import nativeRef from '../utils/nativeRef';
9
+
10
+ export const NATIVE_MODULE_NAME = 'RCTMGLLight';
11
+
12
+ type Props = BaseProps & {
13
+ /**
14
+ * Customizable style attributes
15
+ */
16
+ style: LightLayerStyleProps;
17
+ };
18
+
19
+ type NativeProps = Omit<Props, 'style'> & {
20
+ reactStyle?: { [key: string]: StyleValue };
21
+ };
22
+
23
+ interface LightMethods {
24
+ setNativeProps(props: { [key: string]: unknown }): void;
25
+ }
26
+
27
+ /**
28
+ * Light represents the light source for extruded geometries
29
+ */
30
+ function Light(props: Props, ref: React.ForwardedRef<LightMethods>) {
31
+ const { style, ...propWithoutStyle } = props;
32
+
33
+ const nativeLightRef = nativeRef(useRef<typeof RCTMGLLight>(null));
34
+
35
+ useImperativeHandle(ref, () => ({
36
+ setNativeProps(_props: { [key: string]: unknown }) {
37
+ let propsToPass = _props;
38
+ if (_props.style) {
39
+ propsToPass = {
40
+ ..._props,
41
+ reactStyle: transformStyle(_props.style),
42
+ };
43
+ }
44
+ nativeLightRef.current?.setNativeProps(propsToPass);
45
+ },
46
+ }));
47
+
48
+ return (
49
+ <RCTMGLLight
50
+ ref={nativeLightRef}
51
+ testID="rctmglLight"
52
+ {...propWithoutStyle}
53
+ reactStyle={transformStyle(style)}
54
+ />
55
+ );
56
+ }
57
+
58
+ const RCTMGLLight = requireNativeComponent<NativeProps>(NATIVE_MODULE_NAME);
59
+
60
+ export default memo(forwardRef(Light));
@@ -9,6 +9,7 @@ import { type Feature } from 'geojson';
9
9
 
10
10
  import { toJSONString, isFunction } from '../utils';
11
11
  import { makePoint } from '../utils/geoUtils';
12
+ import { type BaseProps } from '../types/BaseProps';
12
13
 
13
14
  import NativeBridgeComponent, { type RNMBEvent } from './NativeBridgeComponent';
14
15
 
@@ -26,7 +27,7 @@ type FeaturePayload = {
26
27
  feature: Feature;
27
28
  };
28
29
 
29
- type Props = {
30
+ type Props = BaseProps & {
30
31
  /**
31
32
  * A string that uniquely identifies the annotation
32
33
  */
@@ -14,6 +14,7 @@ import {
14
14
  isAndroid,
15
15
  } from '../utils';
16
16
  import { copyPropertiesAsDeprecated } from '../utils/deprecation';
17
+ import { OnPressEvent } from '../types/OnPressEvent';
17
18
 
18
19
  import AbstractSource from './AbstractSource';
19
20
  import NativeBridgeComponent from './NativeBridgeComponent';
@@ -22,17 +23,6 @@ const MapboxGL = NativeModules.MGLModule;
22
23
 
23
24
  export const NATIVE_MODULE_NAME = 'RCTMGLShapeSource';
24
25
 
25
- export type OnPressEvent = {
26
- features: Array<GeoJSON.Feature>;
27
- coordinates: {
28
- latitude: number;
29
- longitude: number;
30
- };
31
- point: {
32
- x: number;
33
- y: number;
34
- };
35
- };
36
26
  type OnPressEventDeprecated = OnPressEvent & {
37
27
  nativeEvent?: OnPressEvent;
38
28
  };
@@ -3,10 +3,11 @@ import { HostComponent, requireNativeComponent } from 'react-native';
3
3
 
4
4
  import type { TerrainLayerStyleProps, Value } from '../utils/MapboxStyles';
5
5
  import { StyleValue, transformStyle } from '../utils/StyleValue';
6
+ import type { BaseProps } from '../types/BaseProps';
6
7
 
7
8
  export const NATIVE_MODULE_NAME = 'RCTMGLTerrain';
8
9
 
9
- type Props = {
10
+ type Props = BaseProps & {
10
11
  /**
11
12
  * Name of a source of raster_dem type to be used for terrain elevation.
12
13
  */
@@ -0,0 +1,209 @@
1
+ import React from 'react';
2
+ import {
3
+ NativeMethods,
4
+ NativeModules,
5
+ NativeSyntheticEvent,
6
+ requireNativeComponent,
7
+ } from 'react-native';
8
+
9
+ import { cloneReactChildrenWithProps, isFunction, isAndroid } from '../utils';
10
+ import { getFilter } from '../utils/filterUtils';
11
+ import { copyPropertiesAsDeprecated } from '../utils/deprecation';
12
+ import { OnPressEvent } from '../types/OnPressEvent';
13
+
14
+ import AbstractSource from './AbstractSource';
15
+ import NativeBridgeComponent from './NativeBridgeComponent';
16
+
17
+ const MapboxGL = NativeModules.MGLModule;
18
+
19
+ export const NATIVE_MODULE_NAME = 'RCTMGLVectorSource';
20
+
21
+ interface Props {
22
+ /**
23
+ * A string that uniquely identifies the source.
24
+ */
25
+ id: string;
26
+
27
+ /**
28
+ * A URL to a TileJSON configuration file describing the source’s contents and other metadata.
29
+ */
30
+ url?: string;
31
+
32
+ /**
33
+ * An array of tile URL templates. If multiple endpoints are specified, clients may use any combination of endpoints.
34
+ * Example: https://example.com/vector-tiles/{z}/{x}/{y}.pbf
35
+ */
36
+ tileUrlTemplates?: string[];
37
+
38
+ /**
39
+ * An unsigned integer that specifies the minimum zoom level at which to display tiles from the source.
40
+ * The value should be between 0 and 22, inclusive, and less than
41
+ * maxZoomLevel, if specified. The default value for this option is 0.
42
+ */
43
+ minZoomLevel?: number;
44
+
45
+ /**
46
+ * An unsigned integer that specifies the maximum zoom level at which to display tiles from the source.
47
+ * The value should be between 0 and 22, inclusive, and less than
48
+ * minZoomLevel, if specified. The default value for this option is 22.
49
+ */
50
+ maxZoomLevel?: number;
51
+
52
+ /**
53
+ * Influences the y direction of the tile coordinates. (tms inverts y axis)
54
+ */
55
+ tms?: boolean;
56
+
57
+ /**
58
+ * An HTML or literal text string defining the buttons to be displayed in an action sheet when the
59
+ * source is part of a map view’s style and the map view’s attribution button is pressed.
60
+ */
61
+ attribution?: string;
62
+
63
+ /**
64
+ * Source press listener, gets called when a user presses one of the children layers only
65
+ * if that layer has a higher z-index than another source layers
66
+ *
67
+ * @param {Object} event
68
+ * @param {Object[]} event.features - the geojson features that have hit by the press (might be multiple)
69
+ * @param {Object} event.coordinates - the coordinates of the click
70
+ * @param {Object} event.point - the point of the click
71
+ */
72
+ onPress?: (event: OnPressEvent) => void;
73
+
74
+ /**
75
+ * Overrides the default touch hitbox(44x44 pixels) for the source layers
76
+ */
77
+ hitbox?: {
78
+ /**
79
+ * `width` of hitbox
80
+ */
81
+ width: number;
82
+ /**
83
+ * `height` of hitbox
84
+ */
85
+ height: number;
86
+ };
87
+
88
+ children: React.ReactElement | React.ReactElement[];
89
+ }
90
+
91
+ //interface NativeProps extends Omit<Props, 'children'> {}
92
+ type NativeProps = Props; // Omit<Props, 'children'>;
93
+ /**
94
+ * VectorSource is a map content source that supplies tiled vector data in Mapbox Vector Tile format to be shown on the map.
95
+ * 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.
96
+ */
97
+ class VectorSource extends NativeBridgeComponent(
98
+ AbstractSource<Props, NativeProps>,
99
+ NATIVE_MODULE_NAME,
100
+ ) {
101
+ static defaultProps = {
102
+ id: MapboxGL.StyleSource.DefaultSourceID,
103
+ };
104
+
105
+ constructor(props: Props) {
106
+ super(props);
107
+ }
108
+
109
+ _setNativeRef(
110
+ nativeRef: (React.Component<NativeProps> & Readonly<NativeMethods>) | null,
111
+ ) {
112
+ if (nativeRef) {
113
+ this.setNativeRef(nativeRef);
114
+ // this._nativeRef = nativeRef;
115
+ super._runPendingNativeCommands(nativeRef);
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Returns all features that match the query parameters regardless of whether or not the feature is
121
+ * currently rendered on the map. The domain of the query includes all currently-loaded vector tiles
122
+ * and GeoJSON source tiles. This function does not check tiles outside of the visible viewport.
123
+ *
124
+ * @example
125
+ * vectorSource.features(['id1', 'id2'])
126
+ *
127
+ * @param {Array=} layerIDs - A set of strings that correspond to the names of layers defined in the current style. Only the features contained in these layers are included in the returned array.
128
+ * @param {Array=} filter - an optional filter statement to filter the returned Features.
129
+ * @return {FeatureCollection}
130
+ */
131
+ async features(layerIDs = [], filter = []) {
132
+ const res: { data: string } = await this._runNativeCommand(
133
+ 'features',
134
+ this._nativeRef,
135
+ [layerIDs, getFilter(filter)],
136
+ );
137
+
138
+ if (isAndroid()) {
139
+ return JSON.parse(res.data);
140
+ }
141
+
142
+ return res.data;
143
+ }
144
+
145
+ onPress(
146
+ event: NativeSyntheticEvent<{
147
+ payload: OnPressEvent;
148
+ }>,
149
+ ) {
150
+ const {
151
+ nativeEvent: {
152
+ payload: { features, coordinates, point },
153
+ },
154
+ } = event;
155
+ let newEvent = {
156
+ features,
157
+ coordinates,
158
+ point,
159
+ };
160
+ newEvent = copyPropertiesAsDeprecated(
161
+ event,
162
+ newEvent,
163
+ (key) => {
164
+ console.warn(
165
+ `event.${key} is deprecated on VectorSource#onPress, please use event.features`,
166
+ );
167
+ },
168
+ {
169
+ nativeEvent: (origNativeEvent: unknown) => ({
170
+ ...(origNativeEvent as OnPressEvent),
171
+ payload: features[0],
172
+ }),
173
+ },
174
+ );
175
+ const { onPress } = this.props;
176
+ if (onPress) {
177
+ onPress(newEvent);
178
+ }
179
+ }
180
+
181
+ render() {
182
+ const props = {
183
+ id: this.props.id,
184
+ url: this.props.url,
185
+ tileUrlTemplates: this.props.tileUrlTemplates,
186
+ minZoomLevel: this.props.minZoomLevel,
187
+ maxZoomLevel: this.props.maxZoomLevel,
188
+ tms: this.props.tms,
189
+ attribution: this.props.attribution,
190
+ hitbox: this.props.hitbox,
191
+ hasPressListener: isFunction(this.props.onPress),
192
+ onMapboxVectorSourcePress: this.onPress.bind(this),
193
+ onPress: undefined,
194
+ onAndroidCallback: isAndroid() ? this._onAndroidCallback : undefined,
195
+ };
196
+ return (
197
+ <RCTMGLVectorSource ref={(r) => this._setNativeRef(r)} {...props}>
198
+ {cloneReactChildrenWithProps(this.props.children, {
199
+ sourceID: this.props.id,
200
+ })}
201
+ </RCTMGLVectorSource>
202
+ );
203
+ }
204
+ }
205
+
206
+ const RCTMGLVectorSource =
207
+ requireNativeComponent<NativeProps>(NATIVE_MODULE_NAME);
208
+
209
+ export default VectorSource;
@@ -69,7 +69,7 @@ interface Coordinates {
69
69
  /**
70
70
  * LocationManager is a singleton, see `locationManager`
71
71
  */
72
- class LocationManager {
72
+ export class LocationManager {
73
73
  _listeners: ((location: Location) => void)[];
74
74
  _lastKnownLocation: Location | null;
75
75
  _isListening: boolean;
@@ -0,0 +1,3 @@
1
+ export type BaseProps = {
2
+ testID?: string | undefined;
3
+ };
@@ -0,0 +1,11 @@
1
+ export type OnPressEvent = {
2
+ features: Array<GeoJSON.Feature>;
3
+ coordinates: {
4
+ latitude: number;
5
+ longitude: number;
6
+ };
7
+ point: {
8
+ x: number;
9
+ y: number;
10
+ };
11
+ };