@maplibre/maplibre-react-native 9.1.0 → 10.0.0-alpha.2

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 (141) hide show
  1. package/.eslintrc.js +10 -2
  2. package/.husky/pre-commit +5 -0
  3. package/.yarn/plugins/@yarnpkg/plugin-typescript.cjs +9 -0
  4. package/.yarn/sdks/eslint/bin/eslint.js +20 -0
  5. package/.yarn/sdks/eslint/lib/api.js +20 -0
  6. package/.yarn/sdks/eslint/package.json +6 -0
  7. package/.yarn/sdks/integrations.yml +5 -0
  8. package/.yarn/sdks/prettier/index.js +20 -0
  9. package/.yarn/sdks/prettier/package.json +6 -0
  10. package/.yarn/sdks/typescript/bin/tsc +20 -0
  11. package/.yarn/sdks/typescript/bin/tsserver +20 -0
  12. package/.yarn/sdks/typescript/lib/tsc.js +20 -0
  13. package/.yarn/sdks/typescript/lib/tsserver.js +225 -0
  14. package/.yarn/sdks/typescript/lib/tsserverlibrary.js +225 -0
  15. package/.yarn/sdks/typescript/lib/typescript.js +20 -0
  16. package/.yarn/sdks/typescript/package.json +6 -0
  17. package/CHANGELOG.md +18 -0
  18. package/android/rctmgl/build.gradle +7 -7
  19. package/android/rctmgl/src/main/java/com/mapbox/rctmgl/location/LocationManager.java +2 -2
  20. package/android/rctmgl/src/main/java/com/mapbox/rctmgl/modules/RCTMGLOfflineModule.java +21 -26
  21. package/docs/Annotation.md +8 -9
  22. package/docs/BackgroundLayer.md +2 -10
  23. package/docs/Callout.md +5 -5
  24. package/docs/Camera.md +18 -47
  25. package/docs/CircleLayer.md +2 -10
  26. package/docs/FillExtrusionLayer.md +2 -10
  27. package/docs/FillLayer.md +2 -10
  28. package/docs/HeatmapLayer.md +2 -10
  29. package/docs/ImageSource.md +3 -2
  30. package/docs/Images.md +5 -3
  31. package/docs/Light.md +1 -1
  32. package/docs/LineLayer.md +2 -10
  33. package/docs/MapView.md +53 -37
  34. package/docs/MarkerView.md +4 -2
  35. package/docs/NativeUserLocation.md +2 -2
  36. package/docs/PointAnnotation.md +5 -8
  37. package/docs/RasterLayer.md +2 -10
  38. package/docs/RasterSource.md +3 -2
  39. package/docs/ShapeSource.md +12 -7
  40. package/docs/Style.md +1 -1
  41. package/docs/SymbolLayer.md +3 -10
  42. package/docs/UserLocation.md +8 -10
  43. package/docs/VectorSource.md +6 -5
  44. package/docs/coordinates.md +6 -0
  45. package/docs/docs.json +518 -1272
  46. package/docs/location.md +6 -0
  47. package/docs/snapshotManager.md +3 -3
  48. package/javascript/@types/assets.d.ts +4 -0
  49. package/javascript/MGLModule.ts +37 -0
  50. package/javascript/Maplibre.ts +65 -0
  51. package/javascript/components/AbstractLayer.tsx +107 -0
  52. package/javascript/components/AbstractSource.tsx +27 -0
  53. package/javascript/components/BackgroundLayer.tsx +43 -0
  54. package/javascript/components/{Callout.js → Callout.tsx} +67 -65
  55. package/javascript/components/{Camera.js → Camera.tsx} +266 -251
  56. package/javascript/components/CircleLayer.tsx +46 -0
  57. package/javascript/components/FillExtrusionLayer.tsx +47 -0
  58. package/javascript/components/FillLayer.tsx +41 -0
  59. package/javascript/components/{HeadingIndicator.js → HeadingIndicator.tsx} +8 -8
  60. package/javascript/components/HeatmapLayer.tsx +44 -0
  61. package/javascript/components/ImageSource.tsx +78 -0
  62. package/javascript/components/Images.tsx +134 -0
  63. package/javascript/components/Light.tsx +67 -0
  64. package/javascript/components/LineLayer.tsx +42 -0
  65. package/javascript/components/{MapView.js → MapView.tsx} +365 -354
  66. package/javascript/components/MarkerView.tsx +104 -0
  67. package/javascript/components/{NativeBridgeComponent.js → NativeBridgeComponent.tsx} +44 -13
  68. package/javascript/components/NativeUserLocation.tsx +33 -0
  69. package/javascript/components/PointAnnotation.tsx +221 -0
  70. package/javascript/components/RasterLayer.tsx +41 -0
  71. package/javascript/components/RasterSource.tsx +117 -0
  72. package/javascript/components/ShapeSource.tsx +383 -0
  73. package/javascript/components/{Style.js → Style.tsx} +129 -38
  74. package/javascript/components/SymbolLayer.tsx +72 -0
  75. package/javascript/components/{UserLocation.js → UserLocation.tsx} +111 -110
  76. package/javascript/components/VectorSource.tsx +207 -0
  77. package/javascript/components/annotations/Annotation.tsx +134 -0
  78. package/javascript/index.ts +4 -0
  79. package/javascript/modules/location/{locationManager.js → locationManager.ts} +71 -10
  80. package/javascript/modules/offline/{OfflineCreatePackOptions.js → OfflineCreatePackOptions.ts} +20 -4
  81. package/javascript/modules/offline/{OfflinePack.js → OfflinePack.ts} +23 -7
  82. package/javascript/modules/offline/{offlineManager.js → offlineManager.ts} +81 -24
  83. package/javascript/modules/snapshot/{SnapshotOptions.js → SnapshotOptions.ts} +43 -6
  84. package/javascript/modules/snapshot/{snapshotManager.js → snapshotManager.ts} +5 -5
  85. package/javascript/requestAndroidLocationPermissions.ts +29 -0
  86. package/javascript/types/BaseProps.ts +5 -0
  87. package/javascript/types/OnPressEvent.ts +13 -0
  88. package/javascript/types/index.ts +7 -0
  89. package/javascript/utils/BridgeValue.ts +90 -0
  90. package/javascript/utils/{Logger.js → Logger.ts} +37 -18
  91. package/javascript/utils/MaplibreStyles.d.ts +1486 -0
  92. package/javascript/utils/StyleValue.ts +49 -0
  93. package/javascript/utils/animated/AbstractAnimatedCoordinates.ts +134 -0
  94. package/javascript/utils/animated/AnimatedCoordinatesArray.ts +112 -0
  95. package/javascript/utils/animated/{AnimatedExtractCoordinateFromArray.js → AnimatedExtractCoordinateFromArray.ts} +5 -5
  96. package/javascript/utils/animated/{AnimatedPoint.js → AnimatedPoint.ts} +20 -12
  97. package/javascript/utils/animated/{AnimatedRouteCoordinatesArray.js → AnimatedRouteCoordinatesArray.ts} +39 -14
  98. package/javascript/utils/animated/{AnimatedShape.js → AnimatedShape.ts} +31 -10
  99. package/javascript/utils/{deprecation.js → deprecation.ts} +9 -6
  100. package/javascript/utils/filterUtils.ts +9 -0
  101. package/javascript/utils/geoUtils.ts +79 -0
  102. package/javascript/utils/{index.js → index.ts} +44 -24
  103. package/javascript/utils/styleMap.ts +264 -0
  104. package/package.json +35 -27
  105. package/plugin/build/withMapLibre.js +18 -3
  106. package/scripts/autogenHelpers/globals.js +1 -1
  107. package/scripts/autogenerate.js +14 -6
  108. package/scripts/download-style-spec.sh +1 -1
  109. package/scripts/templates/MaplibreStyles.ts.ejs +99 -0
  110. package/scripts/templates/index.d.ts.ejs +71 -42
  111. package/scripts/templates/{styleMap.js.ejs → styleMap.ts.ejs} +3 -33
  112. package/setup-jest.js +1 -10
  113. package/tsconfig.json +20 -61
  114. package/index.d.ts +0 -955
  115. package/javascript/components/AbstractLayer.js +0 -75
  116. package/javascript/components/AbstractSource.js +0 -15
  117. package/javascript/components/BackgroundLayer.js +0 -97
  118. package/javascript/components/CircleLayer.js +0 -101
  119. package/javascript/components/FillExtrusionLayer.js +0 -98
  120. package/javascript/components/FillLayer.js +0 -94
  121. package/javascript/components/HeatmapLayer.js +0 -99
  122. package/javascript/components/ImageSource.js +0 -82
  123. package/javascript/components/Images.js +0 -119
  124. package/javascript/components/Light.js +0 -47
  125. package/javascript/components/LineLayer.js +0 -94
  126. package/javascript/components/MarkerView.js +0 -87
  127. package/javascript/components/NativeUserLocation.js +0 -41
  128. package/javascript/components/PointAnnotation.js +0 -216
  129. package/javascript/components/RasterLayer.js +0 -95
  130. package/javascript/components/RasterSource.js +0 -124
  131. package/javascript/components/ShapeSource.js +0 -372
  132. package/javascript/components/SymbolLayer.js +0 -120
  133. package/javascript/components/VectorSource.js +0 -200
  134. package/javascript/components/annotations/Annotation.js +0 -122
  135. package/javascript/index.js +0 -149
  136. package/javascript/utils/BridgeValue.js +0 -81
  137. package/javascript/utils/animated/AnimatedCoordinatesArray.js +0 -191
  138. package/javascript/utils/filterUtils.js +0 -7
  139. package/javascript/utils/geoUtils.js +0 -73
  140. package/javascript/utils/styleMap.js +0 -1932
  141. /package/javascript/utils/animated/{Animated.js → Animated.ts} +0 -0
@@ -0,0 +1,104 @@
1
+ import {toJSONString} from '../utils';
2
+ import {makePoint} from '../utils/geoUtils';
3
+
4
+ import PointAnnotation from './PointAnnotation';
5
+
6
+ import React, {ReactElement} from 'react';
7
+ import {Platform, requireNativeComponent, ViewProps} from 'react-native';
8
+
9
+ export const NATIVE_MODULE_NAME = 'RCTMGLMarkerView';
10
+
11
+ interface MarkerViewProps extends ViewProps {
12
+ /**
13
+ * The center point (specified as a map coordinate) of the marker.
14
+ * See also #anchor.
15
+ */
16
+ coordinate: number[];
17
+ /**
18
+ * Specifies the anchor being set on a particular point of the annotation.
19
+ * The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0],
20
+ * where (0, 0) is the top-left corner of the image, and (1, 1) is the bottom-right corner.
21
+ * Note this is only for custom annotations not the default pin view.
22
+ * Defaults to the center of the view.
23
+ */
24
+ anchor: {
25
+ /**
26
+ * `x` of anchor
27
+ */
28
+ x: number;
29
+ /**
30
+ * `y` of anchor
31
+ */
32
+ y: number;
33
+ };
34
+ allowOverlap: boolean;
35
+ isSelected: boolean;
36
+ /**
37
+ * Expects one child - can be container with multiple elements
38
+ */
39
+ children: React.ReactElement;
40
+ }
41
+
42
+ interface NativeProps extends ViewProps {
43
+ coordinate: string | undefined;
44
+ anchor: {x: number; y: number};
45
+ allowOverlap: boolean;
46
+ isSelected: boolean;
47
+ }
48
+
49
+ /**
50
+ * MarkerView allows you to place a interactive react native marker to the map.
51
+ *
52
+ * If you have static view consider using PointAnnotation or SymbolLayer they'll offer much better performance
53
+ * .
54
+ * This is based on [MakerView plugin](https://docs.mapbox.com/android/plugins/overview/markerview/) on Android
55
+ * and PointAnnotation on iOS.
56
+ */
57
+ class MarkerView extends React.PureComponent<MarkerViewProps> {
58
+ static defaultProps = {
59
+ anchor: {x: 0.5, y: 0.5},
60
+ allowOverlap: false,
61
+ isSelected: false,
62
+ };
63
+
64
+ static lastId = 0;
65
+ __idForPointAnnotation?: string;
66
+
67
+ _idForPointAnnotation(): string {
68
+ if (this.__idForPointAnnotation === undefined) {
69
+ MarkerView.lastId = MarkerView.lastId + 1;
70
+ this.__idForPointAnnotation = `MV-${MarkerView.lastId}`;
71
+ }
72
+ return this.__idForPointAnnotation;
73
+ }
74
+
75
+ _getCoordinate(): string | undefined {
76
+ if (!this.props.coordinate) {
77
+ return undefined;
78
+ }
79
+ return toJSONString(makePoint(this.props.coordinate));
80
+ }
81
+
82
+ render(): ReactElement {
83
+ if (Platform.OS === 'ios') {
84
+ return (
85
+ <PointAnnotation id={this._idForPointAnnotation()} {...this.props} />
86
+ );
87
+ }
88
+
89
+ const props = {
90
+ ...this.props,
91
+ anchor: this.props.anchor,
92
+ coordinate: this._getCoordinate(),
93
+ };
94
+
95
+ return (
96
+ <RCTMGLMarkerView {...props}>{this.props.children}</RCTMGLMarkerView>
97
+ );
98
+ }
99
+ }
100
+
101
+ const RCTMGLMarkerView =
102
+ requireNativeComponent<NativeProps>(NATIVE_MODULE_NAME);
103
+
104
+ export default MarkerView;
@@ -1,27 +1,50 @@
1
- import {runNativeCommand, isAndroid} from '../utils';
1
+ import {runNativeCommand, isAndroid, NativeArg} from '../utils';
2
+
3
+ import {Component, SyntheticEvent} from 'react';
4
+
5
+ export type RNMLEvent<PayloadType = {[key: string]: string}> = {
6
+ payload: PayloadType;
7
+ type: string;
8
+ };
2
9
 
3
10
  let callbackIncrement = 0;
4
11
 
5
- const NativeBridgeComponent = B =>
6
- class extends B {
7
- constructor(props, nativeModuleName) {
8
- super(props);
12
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/explicit-module-boundary-types
13
+ const NativeBridgeComponent = <
14
+ Props extends object,
15
+ BaseComponent extends new (...args: any[]) => Component<Props>,
16
+ >(
17
+ B: BaseComponent,
18
+ nativeModuleName: string,
19
+ ) => {
20
+ const NativeBridge = class extends B {
21
+ _nativeModuleName: string;
22
+ _onAndroidCallback: (e: any) => void;
23
+ _callbackMap: Map<string, any>;
24
+ _preRefMapMethodQueue: any[];
25
+
26
+ constructor(...args: any[]) {
27
+ super(...args);
9
28
 
10
29
  this._nativeModuleName = nativeModuleName;
11
- this._onAndroidCallback = this._onAndroidCallback.bind(this);
30
+ this._onAndroidCallback = this._onAndroidCallback0.bind(this);
12
31
  this._callbackMap = new Map();
13
32
  this._preRefMapMethodQueue = [];
14
33
  }
15
34
 
16
- _addAddAndroidCallback(id, resolve, reject) {
35
+ _addAddAndroidCallback<ReturnType>(
36
+ id: string,
37
+ resolve: (value: ReturnType) => void,
38
+ reject: (error: Error) => void,
39
+ ): void {
17
40
  this._callbackMap.set(id, {resolve, reject});
18
41
  }
19
42
 
20
- _removeAndroidCallback(id) {
21
- this._callbackMap.remove(id);
43
+ _removeAndroidCallback(id: string): void {
44
+ this._callbackMap.delete(id);
22
45
  }
23
46
 
24
- _onAndroidCallback(e) {
47
+ _onAndroidCallback0(e: SyntheticEvent<Element, RNMLEvent>): void {
25
48
  const callbackID = e.nativeEvent.type;
26
49
  const callback = this._callbackMap.get(callbackID);
27
50
 
@@ -30,7 +53,7 @@ const NativeBridgeComponent = B =>
30
53
  }
31
54
 
32
55
  this._callbackMap.delete(callbackID);
33
- let {payload} = e.nativeEvent;
56
+ const {payload} = e.nativeEvent;
34
57
  if (payload.error) {
35
58
  callback.reject.call(null, new Error(payload.error));
36
59
  } else {
@@ -38,7 +61,9 @@ const NativeBridgeComponent = B =>
38
61
  }
39
62
  }
40
63
 
41
- async _runPendingNativeCommands(nativeRef) {
64
+ async _runPendingNativeCommands<RefType extends Component>(
65
+ nativeRef: RefType | null | undefined,
66
+ ): Promise<void> {
42
67
  if (nativeRef) {
43
68
  while (this._preRefMapMethodQueue.length > 0) {
44
69
  const item = this._preRefMapMethodQueue.pop();
@@ -55,7 +80,11 @@ const NativeBridgeComponent = B =>
55
80
  }
56
81
  }
57
82
 
58
- _runNativeCommand(methodName, nativeRef, args = []) {
83
+ _runNativeCommand<RefType extends Component, ReturnType = NativeArg>(
84
+ methodName: string,
85
+ nativeRef: RefType | undefined | null,
86
+ args: NativeArg[] = [],
87
+ ): Promise<ReturnType> {
59
88
  if (!nativeRef) {
60
89
  return new Promise(resolve => {
61
90
  this._preRefMapMethodQueue.push({
@@ -82,5 +111,7 @@ const NativeBridgeComponent = B =>
82
111
  );
83
112
  }
84
113
  };
114
+ return NativeBridge;
115
+ };
85
116
 
86
117
  export default NativeBridgeComponent;
@@ -0,0 +1,33 @@
1
+ import React, {ReactElement} from 'react';
2
+ import {requireNativeComponent} from 'react-native';
3
+
4
+ const NATIVE_MODULE_NAME = 'RCTMGLNativeUserLocation';
5
+
6
+ interface NativeUserLocationProps {
7
+ /**
8
+ * Android render mode.
9
+ *
10
+ * - normal: just a circle
11
+ * - compass: triangle with heading
12
+ * - gps: large arrow
13
+ *
14
+ * @platform android
15
+ */
16
+ androidRenderMode?: 'normal' | 'compass' | 'gps';
17
+ /**
18
+ * iOS only. A Boolean value indicating whether the user location annotation may display a permanent heading indicator.
19
+ *
20
+ * @platform ios
21
+ */
22
+ iosShowsUserHeadingIndicator?: boolean;
23
+ }
24
+
25
+ class NativeUserLocation extends React.Component<NativeUserLocationProps> {
26
+ render(): ReactElement {
27
+ return <RCTMGLNativeUserLocation {...this.props} />;
28
+ }
29
+ }
30
+
31
+ const RCTMGLNativeUserLocation = requireNativeComponent(NATIVE_MODULE_NAME);
32
+
33
+ export default NativeUserLocation;
@@ -0,0 +1,221 @@
1
+ import {toJSONString, isFunction} from '../utils';
2
+ import {makePoint} from '../utils/geoUtils';
3
+
4
+ import NativeBridgeComponent, {RNMLEvent} from './NativeBridgeComponent';
5
+
6
+ import React, {Component, ReactElement, SyntheticEvent} from 'react';
7
+ import {
8
+ requireNativeComponent,
9
+ StyleSheet,
10
+ Platform,
11
+ ViewProps,
12
+ } from 'react-native';
13
+
14
+ export const NATIVE_MODULE_NAME = 'RCTMGLPointAnnotation';
15
+
16
+ const styles = StyleSheet.create({
17
+ container: {
18
+ alignItems: 'center',
19
+ justifyContent: 'center',
20
+ position: 'absolute',
21
+ },
22
+ });
23
+
24
+ type FeaturePayload = GeoJSON.Feature<
25
+ GeoJSON.Point,
26
+ {
27
+ screenPointX: number;
28
+ screenPointY: number;
29
+ }
30
+ >;
31
+
32
+ interface PointAnnotationProps {
33
+ /**
34
+ * A string that uniquely identifies the annotation
35
+ */
36
+ id: string;
37
+ /**
38
+ * The string containing the annotation’s title. Note this is required to be set if you want to see a callout appear on iOS.
39
+ */
40
+ title?: string;
41
+ /**
42
+ * The string containing the annotation’s snippet(subtitle). Not displayed in the default callout.
43
+ */
44
+ snippet?: string;
45
+ /**
46
+ * Manually selects/deselects annotation
47
+ * @type {[type]}
48
+ */
49
+ selected?: boolean;
50
+ /**
51
+ * Enable or disable dragging. Defaults to false.
52
+ */
53
+ draggable?: boolean;
54
+ /**
55
+ * The center point (specified as a map coordinate) of the annotation.
56
+ */
57
+ coordinate: number[];
58
+ /**
59
+ * Specifies the anchor being set on a particular point of the annotation.
60
+ * The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0],
61
+ * where (0, 0) is the top-left corner of the image, and (1, 1) is the bottom-right corner.
62
+ * Note this is only for custom annotations not the default pin view.
63
+ * Defaults to the center of the view.
64
+ */
65
+ anchor?: {
66
+ /**
67
+ * See anchor
68
+ */
69
+ x: number;
70
+ /**
71
+ * See anchor
72
+ */
73
+ y: number;
74
+ };
75
+ /**
76
+ * This callback is fired once this annotation is selected. Returns a Feature as the first param.
77
+ */
78
+ onSelected?(payload: FeaturePayload): void;
79
+ /**
80
+ * This callback is fired once this annotation is deselected.
81
+ */
82
+ onDeselected?(payload: FeaturePayload): void;
83
+ /**
84
+ * This callback is fired once this annotation has started being dragged.
85
+ */
86
+ onDragStart?(payload: FeaturePayload): void;
87
+ /**
88
+ * This callback is fired once this annotation has stopped being dragged.
89
+ */
90
+ onDragEnd?(payload: FeaturePayload): void;
91
+ /**
92
+ * This callback is fired while this annotation is being dragged.
93
+ */
94
+ onDrag?(payload: FeaturePayload): void;
95
+
96
+ /**
97
+ * Expects one child, and an optional callout can be added as well
98
+ */
99
+ children: React.ReactElement | [React.ReactElement, React.ReactElement];
100
+
101
+ style?: ViewProps['style'];
102
+ }
103
+
104
+ /**
105
+ * PointAnnotation represents a one-dimensional shape located at a single geographical coordinate.
106
+ *
107
+ * Consider using ShapeSource and SymbolLayer instead, if you have many points and you have static images,
108
+ * they'll offer much better performance
109
+ *
110
+ * .
111
+ * If you need interctive views please use MarkerView,
112
+ * as with PointAnnotation on Android child views are rendered onto a bitmap for better performance.
113
+ */
114
+ class PointAnnotation extends NativeBridgeComponent(
115
+ React.PureComponent<PointAnnotationProps>,
116
+ NATIVE_MODULE_NAME,
117
+ ) {
118
+ static defaultProps = {
119
+ anchor: {x: 0.5, y: 0.5},
120
+ draggable: false,
121
+ };
122
+
123
+ _nativeRef: Component<NativeProps> | null = null;
124
+
125
+ constructor(props: PointAnnotationProps) {
126
+ super(props);
127
+ this._onSelected = this._onSelected.bind(this);
128
+ this._onDeselected = this._onDeselected.bind(this);
129
+ this._onDragStart = this._onDragStart.bind(this);
130
+ this._onDrag = this._onDrag.bind(this);
131
+ this._onDragEnd = this._onDragEnd.bind(this);
132
+ }
133
+
134
+ _onSelected(e: SyntheticEvent<Element, RNMLEvent<FeaturePayload>>): void {
135
+ if (isFunction(this.props.onSelected)) {
136
+ this.props.onSelected(e.nativeEvent.payload);
137
+ }
138
+ }
139
+
140
+ _onDeselected(e: SyntheticEvent<Element, RNMLEvent<FeaturePayload>>): void {
141
+ if (isFunction(this.props.onDeselected)) {
142
+ this.props.onDeselected(e.nativeEvent.payload);
143
+ }
144
+ }
145
+
146
+ _onDragStart(e: SyntheticEvent<Element, RNMLEvent<FeaturePayload>>): void {
147
+ if (isFunction(this.props.onDragStart)) {
148
+ this.props.onDragStart(e.nativeEvent.payload);
149
+ }
150
+ }
151
+
152
+ _onDrag(e: SyntheticEvent<Element, RNMLEvent<FeaturePayload>>): void {
153
+ if (isFunction(this.props.onDrag)) {
154
+ this.props.onDrag(e.nativeEvent.payload);
155
+ }
156
+ }
157
+
158
+ _onDragEnd(e: SyntheticEvent<Element, RNMLEvent<FeaturePayload>>): void {
159
+ if (isFunction(this.props.onDragEnd)) {
160
+ this.props.onDragEnd(e.nativeEvent.payload);
161
+ }
162
+ }
163
+
164
+ _getCoordinate(): string | undefined {
165
+ if (!this.props.coordinate) {
166
+ return undefined;
167
+ }
168
+ return toJSONString(makePoint(this.props.coordinate));
169
+ }
170
+
171
+ /**
172
+ * On android point annotation is rendered offscreen with a canvas into an image.
173
+ * To rerender the image from the current state of the view call refresh.
174
+ * Call this for example from Image#onLoad.
175
+ */
176
+ refresh(): void {
177
+ if (Platform.OS === 'android') {
178
+ this._runNativeCommand('refresh', this._nativeRef, []);
179
+ }
180
+ }
181
+
182
+ _setNativeRef(nativeRef: Component<NativeProps> | null): void {
183
+ this._nativeRef = nativeRef;
184
+ super._runPendingNativeCommands(nativeRef);
185
+ }
186
+
187
+ render(): ReactElement {
188
+ const props = {
189
+ ...this.props,
190
+ ref: (nativeRef: Component<NativeProps> | null) =>
191
+ this._setNativeRef(nativeRef),
192
+ id: this.props.id,
193
+ title: this.props.title,
194
+ snippet: this.props.snippet,
195
+ anchor: this.props.anchor,
196
+ selected: this.props.selected,
197
+ draggable: this.props.draggable,
198
+ style: [this.props.style, styles.container],
199
+ onMapboxPointAnnotationSelected: this._onSelected,
200
+ onMapboxPointAnnotationDeselected: this._onDeselected,
201
+ onMapboxPointAnnotationDragStart: this._onDragStart,
202
+ onMapboxPointAnnotationDrag: this._onDrag,
203
+ onMapboxPointAnnotationDragEnd: this._onDragEnd,
204
+ coordinate: this._getCoordinate(),
205
+ };
206
+ return (
207
+ <RCTMGLPointAnnotation {...props}>
208
+ {this.props.children}
209
+ </RCTMGLPointAnnotation>
210
+ );
211
+ }
212
+ }
213
+
214
+ interface NativeProps extends Omit<PointAnnotationProps, 'coordinate'> {
215
+ coordinate?: string;
216
+ }
217
+
218
+ const RCTMGLPointAnnotation =
219
+ requireNativeComponent<NativeProps>(NATIVE_MODULE_NAME);
220
+
221
+ export default PointAnnotation;
@@ -0,0 +1,41 @@
1
+ import {RasterLayerStyleProps} from '../utils/MaplibreStyles';
2
+ import BaseProps from '../types/BaseProps';
3
+
4
+ import AbstractLayer, {BaseLayerProps, NativeBaseProps} from './AbstractLayer';
5
+
6
+ import React, {ReactElement} from 'react';
7
+ import {NativeModules, requireNativeComponent} from 'react-native';
8
+
9
+ const MapLibreGL = NativeModules.MGLModule;
10
+
11
+ export const NATIVE_MODULE_NAME = 'RCTMGLRasterLayer';
12
+
13
+ interface RasterLayerProps extends BaseProps, BaseLayerProps {
14
+ /**
15
+ * Customizable style attributes
16
+ */
17
+ style?: RasterLayerStyleProps;
18
+ }
19
+
20
+ interface NativeProps
21
+ extends Omit<RasterLayerProps, 'style'>,
22
+ NativeBaseProps {}
23
+
24
+ class RasterLayer extends AbstractLayer<RasterLayerProps, NativeProps> {
25
+ static defaultProps = {
26
+ sourceID: MapLibreGL.StyleSource.DefaultSourceID,
27
+ };
28
+
29
+ render(): ReactElement {
30
+ const props = {
31
+ ...this.baseProps,
32
+ sourceLayerID: this.props.sourceLayerID,
33
+ };
34
+ return <RCTMGLRasterLayer ref={this.setNativeLayer} {...props} />;
35
+ }
36
+ }
37
+
38
+ const RCTMGLRasterLayer =
39
+ requireNativeComponent<NativeProps>(NATIVE_MODULE_NAME);
40
+
41
+ export default RasterLayer;
@@ -0,0 +1,117 @@
1
+ import {cloneReactChildrenWithProps} from '../utils';
2
+ import BaseProps from '../types/BaseProps';
3
+
4
+ import AbstractSource from './AbstractSource';
5
+
6
+ import {NativeModules, requireNativeComponent} from 'react-native';
7
+ import React, {ReactElement} from 'react';
8
+
9
+ const MapLibreGL = NativeModules.MGLModule;
10
+
11
+ export const NATIVE_MODULE_NAME = 'RCTMGLRasterSource';
12
+
13
+ const isTileTemplateUrl = (url?: string): url is string =>
14
+ !!url &&
15
+ (url.includes('{z}') || url.includes('{bbox-') || url.includes('{quadkey}'));
16
+
17
+ interface RasterSourceProps extends BaseProps {
18
+ /**
19
+ * A string that uniquely identifies the source.
20
+ */
21
+ id: string;
22
+ /**
23
+ * A URL to a TileJSON configuration file describing the source’s contents and other metadata.
24
+ */
25
+ url?: string;
26
+ /**
27
+ * An array of tile URL templates. If multiple endpoints are specified, clients may use any combination of endpoints.
28
+ * Example: https://example.com/raster-tiles/{z}/{x}/{y}.png
29
+ */
30
+ tileUrlTemplates?: string[];
31
+ /**
32
+ * An unsigned integer that specifies the minimum zoom level at which to display tiles from the source.
33
+ * The value should be between 0 and 22, inclusive, and less than
34
+ * maxZoomLevel, if specified. The default value for this option is 0.
35
+ */
36
+ minZoomLevel?: number;
37
+ /**
38
+ * An unsigned integer that specifies the maximum zoom level at which to display tiles from the source.
39
+ * The value should be between 0 and 22, inclusive, and less than
40
+ * minZoomLevel, if specified. The default value for this option is 22.
41
+ */
42
+ maxZoomLevel?: number;
43
+ /**
44
+ * Size of the map tiles.
45
+ * Mapbox urls default to 256, all others default to 512.
46
+ */
47
+ tileSize?: number;
48
+ /**
49
+ * Influences the y direction of the tile coordinates. (tms inverts y axis)
50
+ */
51
+ tms?: boolean;
52
+ /**
53
+ * An HTML or literal text string defining the buttons to be displayed in an action sheet when the
54
+ * source is part of a map view’s style and the map view’s attribution button is pressed.
55
+ */
56
+ attribution?: string;
57
+
58
+ children?: React.ReactElement | React.ReactElement[];
59
+ }
60
+
61
+ type NativeProps = RasterSourceProps;
62
+
63
+ /**
64
+ * RasterSource is a map content source that supplies raster image tiles to be shown on the map.
65
+ * The location of and metadata about the tiles are defined either by an option dictionary
66
+ * or by an external file that conforms to the TileJSON specification.
67
+ */
68
+ class RasterSource extends AbstractSource<RasterSourceProps, NativeProps> {
69
+ static defaultProps = {
70
+ id: MapLibreGL.StyleSource.DefaultSourceID,
71
+ };
72
+
73
+ constructor(props: RasterSourceProps) {
74
+ super(props);
75
+ if (isTileTemplateUrl(props.url)) {
76
+ console.warn(
77
+ `RasterSource 'url' property contains a Tile URL Template, but is intended for a StyleJSON URL. Please migrate your VectorSource to use: \`tileUrlTemplates=["${props.url}"]\` instead.`,
78
+ );
79
+ }
80
+ }
81
+
82
+ render(): ReactElement {
83
+ let {url} = this.props;
84
+ let {tileUrlTemplates} = this.props;
85
+
86
+ // Swapping url for tileUrlTemplates to provide backward compatiblity
87
+ // when RasterSource supported only tile url as url prop
88
+ if (isTileTemplateUrl(url)) {
89
+ tileUrlTemplates = [url];
90
+ url = undefined;
91
+ }
92
+
93
+ const props = {
94
+ ...this.props,
95
+ id: this.props.id,
96
+ url,
97
+ tileUrlTemplates,
98
+ minZoomLevel: this.props.minZoomLevel,
99
+ maxZoomLevel: this.props.maxZoomLevel,
100
+ tileSize: this.props.tileSize,
101
+ tms: this.props.tms,
102
+ attribution: this.props.attribution,
103
+ };
104
+ return (
105
+ <RCTMGLRasterSource ref={this.setNativeRef} {...props}>
106
+ {cloneReactChildrenWithProps(this.props.children, {
107
+ sourceID: this.props.id,
108
+ })}
109
+ </RCTMGLRasterSource>
110
+ );
111
+ }
112
+ }
113
+
114
+ const RCTMGLRasterSource =
115
+ requireNativeComponent<NativeProps>(NATIVE_MODULE_NAME);
116
+
117
+ export default RasterSource;