@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
@@ -1,119 +0,0 @@
1
- import {viewPropTypes} from '../utils';
2
-
3
- import ShapeSource from './ShapeSource';
4
-
5
- import PropTypes from 'prop-types';
6
- import React from 'react';
7
- import {requireNativeComponent} from 'react-native';
8
- import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';
9
-
10
- export const NATIVE_MODULE_NAME = 'RCTMGLImages';
11
-
12
- function _isUrlOrPath(value) {
13
- return (
14
- (typeof value === 'string' || value instanceof String) &&
15
- (value.startsWith('file://') ||
16
- value.startsWith('http://') ||
17
- value.startsWith('https://') ||
18
- value.startsWith('data:') ||
19
- value.startsWith('asset://') ||
20
- value.startsWith('/'))
21
- );
22
- }
23
-
24
- /**
25
- * Images defines the images used in Symbol etc layers
26
- */
27
- class Images extends React.Component {
28
- static NATIVE_ASSETS_KEY = 'assets';
29
-
30
- static propTypes = {
31
- ...viewPropTypes,
32
-
33
- /**
34
- * Specifies the external images in key-value pairs required for the shape source.
35
- * Keys are names - see iconImage expressions, values can be either urls-s objects
36
- * with format {uri: 'http://...'}` or `require('image.png')` or `import 'image.png'`
37
- */
38
- images: PropTypes.object,
39
-
40
- /**
41
- * If you have an asset under Image.xcassets on iOS and the drawables directory on android
42
- * you can specify an array of string names with assets as the key `['pin']`.
43
- */
44
- nativeAssetImages: PropTypes.arrayOf(PropTypes.string),
45
-
46
- /**
47
- * Gets called when a Layer is trying to render an image whose key is not present in
48
- * any of the `Images` component of the Map.
49
- */
50
- onImageMissing: PropTypes.func,
51
- };
52
-
53
- _getImages() {
54
- if (!this.props.images && !this.props.nativeAssetImages) {
55
- return {};
56
- }
57
-
58
- const images = {};
59
- let nativeImages = [];
60
-
61
- if (this.props.images) {
62
- const imageNames = Object.keys(this.props.images);
63
- for (const imageName of imageNames) {
64
- const value = this.props.images[imageName];
65
- if (
66
- imageName === ShapeSource.NATIVE_ASSETS_KEY &&
67
- Array.isArray(value)
68
- ) {
69
- console.warn(
70
- `Use of ${ShapeSource.NATIVE_ASSETS_KEY} in Images#images is deprecated please use Images#nativeAssetImages`,
71
- );
72
- nativeImages = value;
73
- } else if (_isUrlOrPath(value)) {
74
- images[imageName] = value;
75
- } else {
76
- const res = resolveAssetSource(value);
77
- if (res && res.uri) {
78
- images[imageName] = res;
79
- }
80
- }
81
- }
82
- }
83
-
84
- if (this.props.nativeAssetImages) {
85
- nativeImages = this.props.nativeAssetImages;
86
- }
87
-
88
- return {
89
- images,
90
- nativeImages,
91
- };
92
- }
93
-
94
- _onImageMissing(event) {
95
- if (this.props.onImageMissing) {
96
- this.props.onImageMissing(event.nativeEvent.payload.imageKey);
97
- }
98
- }
99
-
100
- render() {
101
- const props = {
102
- id: this.props.id,
103
- hasOnImageMissing: !!this.props.onImageMissing,
104
- onImageMissing: this._onImageMissing.bind(this),
105
- ...this._getImages(),
106
- };
107
-
108
- return <RCTMGLImages {...props}>{this.props.children}</RCTMGLImages>;
109
- }
110
- }
111
-
112
- const RCTMGLImages = requireNativeComponent(NATIVE_MODULE_NAME, Images, {
113
- nativeOnly: {
114
- nativeImages: true,
115
- onImageMissing: true,
116
- },
117
- });
118
-
119
- export default Images;
@@ -1,47 +0,0 @@
1
- import {viewPropTypes} from '../utils';
2
- import {LightLayerStyleProp} from '../utils/styleMap';
3
-
4
- import AbstractLayer from './AbstractLayer';
5
-
6
- import React from 'react';
7
- import {requireNativeComponent} from 'react-native';
8
-
9
- export const NATIVE_MODULE_NAME = 'RCTMGLLight';
10
-
11
- /**
12
- * Light represents the light source for extruded geometries
13
- */
14
- class Light extends AbstractLayer {
15
- static propTypes = {
16
- ...viewPropTypes,
17
-
18
- /**
19
- * Customizable style attributes
20
- */
21
- style: LightLayerStyleProp,
22
- };
23
-
24
- setNativeProps(props) {
25
- if (this.refs.nativeLight) {
26
- this.refs.nativeLight.setNativeProps(props);
27
- }
28
- }
29
-
30
- render() {
31
- return (
32
- <RCTMGLLight
33
- ref="nativeLight"
34
- testID="rctmglLight"
35
- {...this.props}
36
- style={undefined}
37
- reactStyle={this.getStyle()}
38
- />
39
- );
40
- }
41
- }
42
-
43
- const RCTMGLLight = requireNativeComponent(NATIVE_MODULE_NAME, Light, {
44
- nativeOnly: {reactStyle: true},
45
- });
46
-
47
- export default Light;
@@ -1,94 +0,0 @@
1
- import {viewPropTypes} from '../utils';
2
- import {LineLayerStyleProp} from '../utils/styleMap';
3
-
4
- import AbstractLayer from './AbstractLayer';
5
-
6
- import PropTypes from 'prop-types';
7
- import React from 'react';
8
- import {NativeModules, requireNativeComponent} from 'react-native';
9
-
10
- const MapLibreGL = NativeModules.MGLModule;
11
-
12
- export const NATIVE_MODULE_NAME = 'RCTMGLLineLayer';
13
-
14
- /**
15
- * LineLayer is a style layer that renders one or more stroked polylines on the map.
16
- */
17
- class LineLayer extends AbstractLayer {
18
- static propTypes = {
19
- ...viewPropTypes,
20
-
21
- /**
22
- * A string that uniquely identifies the source in the style to which it is added.
23
- */
24
- id: PropTypes.string.isRequired,
25
-
26
- /**
27
- * The source from which to obtain the data to style.
28
- * If the source has not yet been added to the current style, the behavior is undefined.
29
- * Inferred from parent source only if the layer is a direct child to it.
30
- */
31
- sourceID: PropTypes.string,
32
-
33
- /**
34
- * Identifier of the layer within the source identified by the sourceID property from which the receiver obtains the data to style.
35
- */
36
- sourceLayerID: PropTypes.string,
37
-
38
- /**
39
- * Inserts a layer above aboveLayerID.
40
- */
41
- aboveLayerID: PropTypes.string,
42
-
43
- /**
44
- * Inserts a layer below belowLayerID
45
- */
46
- belowLayerID: PropTypes.string,
47
-
48
- /**
49
- * Inserts a layer at a specified index
50
- */
51
- layerIndex: PropTypes.number,
52
-
53
- /**
54
- * Filter only the features in the source layer that satisfy a condition that you define
55
- */
56
- filter: PropTypes.array,
57
-
58
- /**
59
- * The minimum zoom level at which the layer gets parsed and appears.
60
- */
61
- minZoomLevel: PropTypes.number,
62
-
63
- /**
64
- * The maximum zoom level at which the layer gets parsed and appears.
65
- */
66
- maxZoomLevel: PropTypes.number,
67
-
68
- /**
69
- * Customizable style attributes
70
- */
71
- style: PropTypes.oneOfType([
72
- LineLayerStyleProp,
73
- PropTypes.arrayOf(LineLayerStyleProp),
74
- ]),
75
- };
76
-
77
- static defaultProps = {
78
- sourceID: MapLibreGL.StyleSource.DefaultSourceID,
79
- };
80
-
81
- render() {
82
- const props = {
83
- ...this.baseProps,
84
- sourceLayerID: this.props.sourceLayerID,
85
- };
86
- return <RCTMGLLineLayer ref="nativeLayer" {...props} />;
87
- }
88
- }
89
-
90
- const RCTMGLLineLayer = requireNativeComponent(NATIVE_MODULE_NAME, LineLayer, {
91
- nativeOnly: {reactStyle: true},
92
- });
93
-
94
- export default LineLayer;
@@ -1,87 +0,0 @@
1
- import {toJSONString, viewPropTypes} from '../utils';
2
- import {makePoint} from '../utils/geoUtils';
3
-
4
- import PointAnnotation from './PointAnnotation';
5
-
6
- import PropTypes from 'prop-types';
7
- import React from 'react';
8
- import {Platform, requireNativeComponent} from 'react-native';
9
-
10
- export const NATIVE_MODULE_NAME = 'RCTMGLMarkerView';
11
-
12
- /**
13
- * MarkerView allows you to place a interactive react native marker to the map.
14
- *
15
- * If you have static view consider using PointAnnotation or SymbolLayer they'll offer much better performance
16
- * .
17
- * This is based on [MakerView plugin](https://docs.mapbox.com/android/plugins/overview/markerview/) on Android
18
- * and PointAnnotation on iOS.
19
- */
20
- class MarkerView extends React.PureComponent {
21
- static propTypes = {
22
- ...viewPropTypes,
23
-
24
- /**
25
- * The center point (specified as a map coordinate) of the marker.
26
- * See also #anchor.
27
- */
28
- coordinate: PropTypes.arrayOf(PropTypes.number).isRequired,
29
-
30
- /**
31
- * Specifies the anchor being set on a particular point of the annotation.
32
- * The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0],
33
- * where (0, 0) is the top-left corner of the image, and (1, 1) is the bottom-right corner.
34
- * Note this is only for custom annotations not the default pin view.
35
- * Defaults to the center of the view.
36
- */
37
- anchor: PropTypes.shape({
38
- /**
39
- * `x` of anchor
40
- */
41
- x: PropTypes.number.isRequired,
42
- /**
43
- * `y` of anchor
44
- */
45
- y: PropTypes.number.isRequired,
46
- }),
47
-
48
- /**
49
- * Expects one child - can be container with multiple elements
50
- */
51
- children: PropTypes.element.isRequired,
52
- };
53
-
54
- static defaultProps = {
55
- anchor: {x: 0.5, y: 0.5},
56
- };
57
-
58
- _getCoordinate() {
59
- if (!this.props.coordinate) {
60
- return undefined;
61
- }
62
- return toJSONString(makePoint(this.props.coordinate));
63
- }
64
-
65
- render() {
66
- if (Platform.OS === 'ios') {
67
- return <PointAnnotation {...this.props} />;
68
- }
69
-
70
- const props = {
71
- ...this.props,
72
- anchor: this.props.anchor,
73
- coordinate: this._getCoordinate(),
74
- };
75
-
76
- return (
77
- <RCTMGLMarkerView {...props}>{this.props.children}</RCTMGLMarkerView>
78
- );
79
- }
80
- }
81
-
82
- const RCTMGLMarkerView =
83
- Platform.OS === 'android'
84
- ? requireNativeComponent(NATIVE_MODULE_NAME, MarkerView, {})
85
- : undefined;
86
-
87
- export default MarkerView;
@@ -1,41 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import React from 'react';
3
- import {requireNativeComponent} from 'react-native';
4
-
5
- const NATIVE_MODULE_NAME = 'RCTMGLNativeUserLocation';
6
-
7
- class NativeUserLocation extends React.Component {
8
- static propTypes = {
9
- /**
10
- * Android render mode.
11
- *
12
- * - normal: just a circle
13
- * - compass: triangle with heading
14
- * - gps: large arrow
15
- *
16
- * @platform android
17
- */
18
- androidRenderMode: PropTypes.oneOf(['normal', 'compass', 'gps']),
19
-
20
- /**
21
- * iOS only. A Boolean value indicating whether the user location annotation may display a permanent heading indicator.
22
- *
23
- * @platform ios
24
- */
25
- iosShowsUserHeadingIndicator: PropTypes.bool,
26
- };
27
-
28
- render() {
29
- return <RCTMGLNativeUserLocation {...this.props} />;
30
- }
31
- }
32
-
33
- const RCTMGLNativeUserLocation = requireNativeComponent(
34
- NATIVE_MODULE_NAME,
35
- NativeUserLocation,
36
- {
37
- nativeOnly: {},
38
- },
39
- );
40
-
41
- export default NativeUserLocation;
@@ -1,216 +0,0 @@
1
- import {toJSONString, isFunction, viewPropTypes} from '../utils';
2
- import {makePoint} from '../utils/geoUtils';
3
-
4
- import NativeBridgeComponent from './NativeBridgeComponent';
5
-
6
- import PropTypes from 'prop-types';
7
- import React from 'react';
8
- import {requireNativeComponent, StyleSheet, Platform} from 'react-native';
9
-
10
- export const NATIVE_MODULE_NAME = 'RCTMGLPointAnnotation';
11
-
12
- const styles = StyleSheet.create({
13
- container: {
14
- alignItems: 'center',
15
- justifyContent: 'center',
16
- position: 'absolute',
17
- },
18
- });
19
-
20
- /**
21
- * PointAnnotation represents a one-dimensional shape located at a single geographical coordinate.
22
- *
23
- * Consider using ShapeSource and SymbolLayer instead, if you have many points and you have static images,
24
- * they'll offer much better performance
25
- *
26
- * .
27
- * If you need interctive views please use MarkerView,
28
- * as with PointAnnotation on Android child views are rendered onto a bitmap for better performance.
29
- */
30
- class PointAnnotation extends NativeBridgeComponent(React.PureComponent) {
31
- static propTypes = {
32
- ...viewPropTypes,
33
-
34
- /**
35
- * A string that uniquely identifies the annotation
36
- */
37
- id: PropTypes.string.isRequired,
38
-
39
- /**
40
- * The string containing the annotation’s title. Note this is required to be set if you want to see a callout appear on iOS.
41
- */
42
- title: PropTypes.string,
43
-
44
- /**
45
- * The string containing the annotation’s snippet(subtitle). Not displayed in the default callout.
46
- */
47
- snippet: PropTypes.string,
48
-
49
- /**
50
- * Manually selects/deselects annotation
51
- * @type {[type]}
52
- */
53
- selected: PropTypes.bool,
54
-
55
- /**
56
- * Enable or disable dragging. Defaults to false.
57
- */
58
- draggable: PropTypes.bool,
59
-
60
- /**
61
- * The center point (specified as a map coordinate) of the annotation.
62
- */
63
- coordinate: PropTypes.arrayOf(PropTypes.number).isRequired,
64
-
65
- /**
66
- * Specifies the anchor being set on a particular point of the annotation.
67
- * The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0],
68
- * where (0, 0) is the top-left corner of the image, and (1, 1) is the bottom-right corner.
69
- * Note this is only for custom annotations not the default pin view.
70
- * Defaults to the center of the view.
71
- */
72
- anchor: PropTypes.shape({
73
- /**
74
- * See anchor
75
- */
76
- x: PropTypes.number.isRequired,
77
- /**
78
- * See anchor
79
- */
80
- y: PropTypes.number.isRequired,
81
- }),
82
-
83
- /**
84
- * This callback is fired once this annotation is selected. Returns a Feature as the first param.
85
- */
86
- onSelected: PropTypes.func,
87
-
88
- /**
89
- * This callback is fired once this annotation is deselected.
90
- */
91
- onDeselected: PropTypes.func,
92
-
93
- /**
94
- * This callback is fired once this annotation has started being dragged.
95
- */
96
- onDragStart: PropTypes.func,
97
-
98
- /**
99
- * This callback is fired once this annotation has stopped being dragged.
100
- */
101
- onDragEnd: PropTypes.func,
102
-
103
- /**
104
- * This callback is fired while this annotation is being dragged.
105
- */
106
- onDrag: PropTypes.func,
107
- };
108
-
109
- static defaultProps = {
110
- anchor: {x: 0.5, y: 0.5},
111
- draggable: false,
112
- };
113
-
114
- constructor(props) {
115
- super(props, NATIVE_MODULE_NAME);
116
- this._onSelected = this._onSelected.bind(this);
117
- this._onDeselected = this._onDeselected.bind(this);
118
- this._onDragStart = this._onDragStart.bind(this);
119
- this._onDrag = this._onDrag.bind(this);
120
- this._onDragEnd = this._onDragEnd.bind(this);
121
- }
122
-
123
- _onSelected(e) {
124
- if (isFunction(this.props.onSelected)) {
125
- this.props.onSelected(e.nativeEvent.payload);
126
- }
127
- }
128
-
129
- _onDeselected(e) {
130
- if (isFunction(this.props.onDeselected)) {
131
- this.props.onDeselected(e.nativeEvent.payload);
132
- }
133
- }
134
-
135
- _onDragStart(e) {
136
- if (isFunction(this.props.onDragStart)) {
137
- this.props.onDragStart(e.nativeEvent.payload);
138
- }
139
- }
140
-
141
- _onDrag(e) {
142
- if (isFunction(this.props.onDrag)) {
143
- this.props.onDrag(e.nativeEvent.payload);
144
- }
145
- }
146
-
147
- _onDragEnd(e) {
148
- if (isFunction(this.props.onDragEnd)) {
149
- this.props.onDragEnd(e.nativeEvent.payload);
150
- }
151
- }
152
-
153
- _getCoordinate() {
154
- if (!this.props.coordinate) {
155
- return undefined;
156
- }
157
- return toJSONString(makePoint(this.props.coordinate));
158
- }
159
-
160
- /**
161
- * On android point annotation is rendered offscreen with a canvas into an image.
162
- * To rerender the image from the current state of the view call refresh.
163
- * Call this for example from Image#onLoad.
164
- */
165
- refresh() {
166
- if (Platform.OS === 'android') {
167
- this._runNativeCommand('refresh', this._nativeRef, []);
168
- }
169
- }
170
-
171
- _setNativeRef(nativeRef) {
172
- this._nativeRef = nativeRef;
173
- super._runPendingNativeCommands(nativeRef);
174
- }
175
-
176
- render() {
177
- const props = {
178
- ...this.props,
179
- ref: nativeRef => this._setNativeRef(nativeRef),
180
- id: this.props.id,
181
- title: this.props.title,
182
- snippet: this.props.snippet,
183
- anchor: this.props.anchor,
184
- selected: this.props.selected,
185
- draggable: this.props.draggable,
186
- style: [this.props.style, styles.container],
187
- onMapboxPointAnnotationSelected: this._onSelected,
188
- onMapboxPointAnnotationDeselected: this._onDeselected,
189
- onMapboxPointAnnotationDragStart: this._onDragStart,
190
- onMapboxPointAnnotationDrag: this._onDrag,
191
- onMapboxPointAnnotationDragEnd: this._onDragEnd,
192
- coordinate: this._getCoordinate(),
193
- };
194
- return (
195
- <RCTMGLPointAnnotation {...props}>
196
- {this.props.children}
197
- </RCTMGLPointAnnotation>
198
- );
199
- }
200
- }
201
-
202
- const RCTMGLPointAnnotation = requireNativeComponent(
203
- NATIVE_MODULE_NAME,
204
- PointAnnotation,
205
- {
206
- nativeOnly: {
207
- onMapboxPointAnnotationSelected: true,
208
- onMapboxPointAnnotationDeselected: true,
209
- onMapboxPointAnnotationDragStart: true,
210
- onMapboxPointAnnotationDrag: true,
211
- onMapboxPointAnnotationDragEnd: true,
212
- },
213
- },
214
- );
215
-
216
- export default PointAnnotation;
@@ -1,95 +0,0 @@
1
- import {viewPropTypes} from '../utils';
2
- import {RasterLayerStyleProp} from '../utils/styleMap';
3
-
4
- import AbstractLayer from './AbstractLayer';
5
-
6
- import PropTypes from 'prop-types';
7
- import React from 'react';
8
- import {NativeModules, requireNativeComponent} from 'react-native';
9
-
10
- const MapLibreGL = NativeModules.MGLModule;
11
-
12
- export const NATIVE_MODULE_NAME = 'RCTMGLRasterLayer';
13
-
14
- class RasterLayer extends AbstractLayer {
15
- static propTypes = {
16
- ...viewPropTypes,
17
-
18
- /**
19
- * A string that uniquely identifies the source in the style to which it is added.
20
- */
21
- id: PropTypes.string.isRequired,
22
-
23
- /**
24
- * The source from which to obtain the data to style.
25
- * If the source has not yet been added to the current style, the behavior is undefined.
26
- * Inferred from parent source only if the layer is a direct child to it.
27
- */
28
- sourceID: PropTypes.string,
29
-
30
- /**
31
- * Identifier of the layer within the source identified by the sourceID property from which the receiver obtains the data to style.
32
- */
33
- sourceLayerID: PropTypes.string,
34
-
35
- /**
36
- * Inserts a layer above aboveLayerID.
37
- */
38
- aboveLayerID: PropTypes.string,
39
-
40
- /**
41
- * Inserts a layer below belowLayerID
42
- */
43
- belowLayerID: PropTypes.string,
44
-
45
- /**
46
- * Inserts a layer at a specified index
47
- */
48
- layerIndex: PropTypes.number,
49
-
50
- /**
51
- * Filter only the features in the source layer that satisfy a condition that you define
52
- */
53
- filter: PropTypes.array,
54
-
55
- /**
56
- * The minimum zoom level at which the layer gets parsed and appears.
57
- */
58
- minZoomLevel: PropTypes.number,
59
-
60
- /**
61
- * The maximum zoom level at which the layer gets parsed and appears.
62
- */
63
- maxZoomLevel: PropTypes.number,
64
-
65
- /**
66
- * Customizable style attributes
67
- */
68
- style: PropTypes.oneOfType([
69
- RasterLayerStyleProp,
70
- PropTypes.arrayOf(RasterLayerStyleProp),
71
- ]),
72
- };
73
-
74
- static defaultProps = {
75
- sourceID: MapLibreGL.StyleSource.DefaultSourceID,
76
- };
77
-
78
- render() {
79
- const props = {
80
- ...this.baseProps,
81
- sourceLayerID: this.props.sourceLayerID,
82
- };
83
- return <RCTMGLRasterLayer ref="nativeLayer" {...props} />;
84
- }
85
- }
86
-
87
- const RCTMGLRasterLayer = requireNativeComponent(
88
- NATIVE_MODULE_NAME,
89
- RasterLayer,
90
- {
91
- nativeOnly: {reactStyle: true},
92
- },
93
- );
94
-
95
- export default RasterLayer;