@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,49 @@
1
+ import BridgeValue, {
2
+ type RawValueType,
3
+ type StyleValueJSON,
4
+ } from './BridgeValue';
5
+ import {AllLayerStyleProps} from './MaplibreStyles';
6
+ import {getStyleType} from './styleMap';
7
+
8
+ import {Image, processColor} from 'react-native';
9
+
10
+ export type StyleValue = {
11
+ styletype: string;
12
+ stylevalue: StyleValueJSON;
13
+ };
14
+
15
+ export function transformStyle(
16
+ style: AllLayerStyleProps | undefined,
17
+ ): undefined | {[key: string]: StyleValue} {
18
+ if (!style) {
19
+ return;
20
+ }
21
+
22
+ const nativeStyle: {[key: string]: StyleValue} = {};
23
+ const styleProps = Object.keys(style) as Array<keyof typeof style>;
24
+ for (const styleProp of styleProps) {
25
+ const styleType = getStyleType(styleProp);
26
+ let rawStyle: RawValueType | undefined = style[styleProp];
27
+
28
+ if (styleType === 'color' && typeof rawStyle === 'string') {
29
+ const color = processColor(rawStyle);
30
+ if (color === null || color === undefined || typeof color === 'symbol') {
31
+ console.error(`RNMaplibre: Invalid color value: ${rawStyle} using red`);
32
+ rawStyle = 'ff0000';
33
+ } else {
34
+ rawStyle = color;
35
+ }
36
+ } else if (styleType === 'image' && typeof rawStyle === 'number') {
37
+ rawStyle =
38
+ (Image.resolveAssetSource(rawStyle) as unknown as RawValueType) || {};
39
+ }
40
+
41
+ const bridgeValue = new BridgeValue(rawStyle);
42
+ nativeStyle[styleProp] = {
43
+ styletype: styleType,
44
+ stylevalue: bridgeValue.toJSON(),
45
+ };
46
+ }
47
+
48
+ return nativeStyle;
49
+ }
@@ -0,0 +1,134 @@
1
+ import {Animated} from 'react-native';
2
+
3
+ // see
4
+ // https://github.com/facebook/react-native/blob/master/Libraries/Animated/src/nodes/AnimatedWithChildren.js
5
+ const AnimatedWithChildren = Object.getPrototypeOf(Animated.ValueXY);
6
+ if (__DEV__) {
7
+ if (AnimatedWithChildren.name !== 'AnimatedWithChildren') {
8
+ console.error(
9
+ 'AnimatedCoordinatesArray could not obtain AnimatedWithChildren base class',
10
+ );
11
+ }
12
+ }
13
+
14
+ export type AnimatedCoordinates = [number, number];
15
+
16
+ const defaultConfig = {
17
+ useNativeDriver: false,
18
+ };
19
+
20
+ abstract class AbstractAnimatedCoordinates<State> extends AnimatedWithChildren {
21
+ constructor(coords: AnimatedCoordinates[]) {
22
+ super();
23
+
24
+ this.state = this.onInitialState(coords);
25
+ }
26
+
27
+ /**
28
+ * Subclasses can override to calculate initial state
29
+ *
30
+ * @param {AnimatedCoordinates} coordinatesArray - to value from animate
31
+ * @returns {object} - the state object
32
+ */
33
+ abstract onInitialState(coords: AnimatedCoordinates[]): State;
34
+ /**
35
+ * Calculates state based on startingState and progress, returns a new state
36
+ *
37
+ * @param {object} state - state object from initialState and/or from calculate
38
+ * @param {number} progress - value between 0 and 1
39
+ * @returns {object} next state
40
+ */
41
+ abstract onCalculate(state: State, progress: number): State;
42
+
43
+ animate(
44
+ progressValue: Animated.Value,
45
+ progressAnimation: Animated.CompositeAnimation,
46
+ config: (
47
+ | Animated.TimingAnimationConfig
48
+ | Animated.SpringAnimationConfig
49
+ | Animated.DecayAnimationConfig
50
+ ) & {toValue: AnimatedCoordinates[]},
51
+ ): Animated.CompositeAnimation {
52
+ const onAnimationStart = (animation: Animated.CompositeAnimation): void => {
53
+ if (this.animation) {
54
+ // there was a started but not finsihed animation
55
+ const actProgress = this.progressValue.__getValue();
56
+ this.animation.stop();
57
+ this.state = this.onCalculate(this.state, actProgress);
58
+ this.progressValue.__removeChild(this);
59
+ this.progressValue = null;
60
+ this.animation = null;
61
+ }
62
+
63
+ this.progressValue = progressValue;
64
+ this.progressValue.__addChild(this);
65
+ this.animation = animation;
66
+ this.state = this.onStart(this.state, config.toValue);
67
+ };
68
+
69
+ const origAnimationStart = progressAnimation.start;
70
+ const newAnimation = progressAnimation;
71
+ newAnimation.start = function start(...args): void {
72
+ onAnimationStart(progressAnimation);
73
+ origAnimationStart(...args);
74
+ };
75
+ return newAnimation;
76
+ }
77
+
78
+ timing(
79
+ config: Animated.TimingAnimationConfig & {
80
+ toValue: AnimatedCoordinates[];
81
+ },
82
+ ): Animated.CompositeAnimation {
83
+ const progressValue = new Animated.Value(0.0);
84
+ return this.animate(
85
+ progressValue,
86
+ Animated.timing(progressValue, {
87
+ ...defaultConfig,
88
+ ...config,
89
+ toValue: 1.0,
90
+ }),
91
+ config,
92
+ );
93
+ }
94
+
95
+ spring(
96
+ config: Animated.SpringAnimationConfig & {toValue: AnimatedCoordinates[]},
97
+ ): Animated.CompositeAnimation {
98
+ const progressValue = new Animated.Value(0.0);
99
+ return this.animate(
100
+ progressValue,
101
+ Animated.spring(progressValue, {
102
+ ...defaultConfig,
103
+ ...config,
104
+ toValue: 1.0,
105
+ }),
106
+ config,
107
+ );
108
+ }
109
+
110
+ decay(
111
+ config: Animated.DecayAnimationConfig & {toValue: AnimatedCoordinates[]},
112
+ ): Animated.CompositeAnimation {
113
+ const progressValue = new Animated.Value(0.0);
114
+ return this.animate(
115
+ progressValue,
116
+ Animated.decay(this.progressValue, {
117
+ ...defaultConfig,
118
+ ...config,
119
+ }),
120
+ config,
121
+ );
122
+ }
123
+
124
+ __getValue(): AnimatedCoordinates[] {
125
+ if (!this.progressValue) {
126
+ return this.onGetValue(this.state);
127
+ }
128
+ return this.onGetValue(
129
+ this.onCalculate(this.state, this.progressValue.__getValue()),
130
+ );
131
+ }
132
+ }
133
+
134
+ export default AbstractAnimatedCoordinates;
@@ -0,0 +1,112 @@
1
+ import AbstractAnimatedCoordinates, {
2
+ AnimatedCoordinates,
3
+ } from './AbstractAnimatedCoordinates';
4
+
5
+ interface CoordinatesState {
6
+ coords: AnimatedCoordinates[];
7
+ targetCoords: AnimatedCoordinates[];
8
+ }
9
+
10
+ class AnimatedCoordinatesArray extends AbstractAnimatedCoordinates<CoordinatesState> {
11
+ constructor(coords: AnimatedCoordinates[]) {
12
+ super(coords);
13
+ }
14
+
15
+ /**
16
+ * Subclasses can override to calculate initial state
17
+ *
18
+ * @param {AnimatedCoordinates} coordinatesArray - to value from animate
19
+ * @returns {object} - the state object
20
+ */
21
+ onInitialState(coordinatesArray: AnimatedCoordinates[]): CoordinatesState {
22
+ return {
23
+ coords: coordinatesArray.map(coord => [coord[0], coord[1]]),
24
+ targetCoords: [],
25
+ };
26
+ }
27
+
28
+ /**
29
+ * Subclasses can override getValue to calculate value from state.
30
+ * Value is typically coordinates array, but can be anything
31
+ *
32
+ * @param {object} state - either state from initialState and/or from calculate
33
+ * @returns {object}
34
+ */
35
+ onGetValue(state: CoordinatesState): CoordinatesState['coords'] {
36
+ return state.coords;
37
+ }
38
+
39
+ /**
40
+ * Calculates state based on startingState and progress, returns a new state
41
+ *
42
+ * @param {object} state - state object from initialState and/or from calculate
43
+ * @param {number} progress - value between 0 and 1
44
+ * @returns {object} next state
45
+ */
46
+ onCalculate(state: CoordinatesState, progress: number): CoordinatesState {
47
+ const {coords, targetCoords} = state;
48
+ const newF = progress;
49
+ const origF = 1.0 - newF;
50
+
51
+ // common
52
+ const commonLen = Math.min(coords.length, targetCoords.length);
53
+ const common = coords
54
+ .slice(0, commonLen)
55
+ .map((origCoord, i): [number, number] => [
56
+ origCoord[0] * origF + targetCoords[i][0] * newF,
57
+ origCoord[1] * origF + targetCoords[i][1] * newF,
58
+ ]);
59
+
60
+ if (targetCoords.length > coords.length) {
61
+ // only in new (adding)
62
+ const addingOrig =
63
+ coords.length > 0 ? coords[coords.length - 1] : targetCoords[0];
64
+ const adding = targetCoords
65
+ .slice(commonLen, targetCoords.length)
66
+ .map((newCoord): [number, number] => [
67
+ addingOrig[0] * origF + newCoord[0] * newF,
68
+ addingOrig[1] * origF + newCoord[1] * newF,
69
+ ]);
70
+ return {coords: [...common, ...adding], targetCoords};
71
+ }
72
+
73
+ if (coords.length > targetCoords.length) {
74
+ // only in orig (dissapearing)
75
+ const dissapearingNew =
76
+ targetCoords.length > 0
77
+ ? targetCoords[targetCoords.length - 1]
78
+ : coords[0];
79
+ const dissapearing = coords
80
+ .slice(commonLen, coords.length)
81
+ .map((origCoord): [number, number] => [
82
+ origCoord[0] * origF + dissapearingNew[0] * newF,
83
+ origCoord[1] * origF + dissapearingNew[1] * newF,
84
+ ]);
85
+ return {coords: [...common, ...dissapearing], targetCoords};
86
+ }
87
+
88
+ return {coords: common, targetCoords};
89
+ }
90
+
91
+ /**
92
+ * Subclasses can override to start a new animation
93
+ *
94
+ * @param {*} toValue - to value from animate
95
+ * @param {*} actCoords - the current coordinates array to start from
96
+ * @returns {object} The state
97
+ */
98
+ onStart(
99
+ state: CoordinatesState,
100
+ toValue: AnimatedCoordinates[],
101
+ ): CoordinatesState {
102
+ const targetCoords = toValue.map(
103
+ (coord): AnimatedCoordinates => [coord[0], coord[1]],
104
+ );
105
+ return {
106
+ ...state,
107
+ targetCoords,
108
+ };
109
+ }
110
+ }
111
+
112
+ export default AnimatedCoordinatesArray;
@@ -12,17 +12,17 @@ if (__DEV__) {
12
12
  }
13
13
 
14
14
  export default class AnimatedExtractCoordinateFromArray extends AnimatedWithChildren {
15
- _array = null;
15
+ _array: AnimatedExtractCoordinateFromArray;
16
16
 
17
17
  _index = 0;
18
18
 
19
- constructor(array, index) {
19
+ constructor(array: AnimatedExtractCoordinateFromArray, index: number) {
20
20
  super();
21
21
  this._array = array;
22
22
  this._index = index;
23
23
  }
24
24
 
25
- __getValue() {
25
+ __getValue(): AnimatedExtractCoordinateFromArray {
26
26
  const actArray = this._array.__getValue();
27
27
  let index = this._index;
28
28
 
@@ -32,11 +32,11 @@ export default class AnimatedExtractCoordinateFromArray extends AnimatedWithChil
32
32
  return actArray[index];
33
33
  }
34
34
 
35
- __attach() {
35
+ __attach(): void {
36
36
  this._array.__addChild(this);
37
37
  }
38
38
 
39
- __detach() {
39
+ __detach(): void {
40
40
  this._array.__removeChild(this);
41
41
  super.__detach();
42
42
  }
@@ -27,22 +27,22 @@ export class AnimatedPoint extends AnimatedWithChildren {
27
27
  this._listeners = {};
28
28
  }
29
29
 
30
- setValue(point = DEFAULT_POINT) {
30
+ setValue(point = DEFAULT_POINT): void {
31
31
  this.longitude.setValue(point.coordinates[0]);
32
32
  this.latitude.setValue(point.coordinates[1]);
33
33
  }
34
34
 
35
- setOffset(point = DEFAULT_POINT) {
35
+ setOffset(point = DEFAULT_POINT): void {
36
36
  this.longitude.setOffset(point.coordinates[0]);
37
37
  this.latitude.setOffset(point.coordinates[1]);
38
38
  }
39
39
 
40
- flattenOffset() {
40
+ flattenOffset(): void {
41
41
  this.longitude.flattenOffset();
42
42
  this.latitude.flattenOffset();
43
43
  }
44
44
 
45
- stopAnimation(cb) {
45
+ stopAnimation(cb?: (value: GeoJSON.Point) => void): void {
46
46
  this.longitude.stopAnimation();
47
47
  this.latitude.stopAnimation();
48
48
 
@@ -51,11 +51,11 @@ export class AnimatedPoint extends AnimatedWithChildren {
51
51
  }
52
52
  }
53
53
 
54
- addListener(cb) {
54
+ addListener(cb?: (value: GeoJSON.Point) => void): string {
55
55
  uniqueID += 1;
56
56
  const id = `${String(uniqueID)}-${String(Date.now())}`;
57
57
 
58
- const completeCB = () => {
58
+ const completeCB = (): void => {
59
59
  if (typeof cb === 'function') {
60
60
  cb(this.__getValue());
61
61
  }
@@ -69,13 +69,17 @@ export class AnimatedPoint extends AnimatedWithChildren {
69
69
  return id;
70
70
  }
71
71
 
72
- removeListener(id) {
72
+ removeListener(id: string): void {
73
73
  this.longitude.removeListener(this._listeners[id].longitude);
74
74
  this.latitude.removeListener(this._listeners[id].latitude);
75
75
  delete this._listeners[id];
76
76
  }
77
77
 
78
- spring(config = {coordinates: DEFAULT_COORD}) {
78
+ spring(
79
+ config: Partial<Animated.TimingAnimationConfig> & {
80
+ coordinates: GeoJSON.Position;
81
+ } = {coordinates: DEFAULT_COORD},
82
+ ): Animated.CompositeAnimation {
79
83
  return Animated.parallel([
80
84
  Animated.spring(this.longitude, {
81
85
  ...config,
@@ -90,7 +94,11 @@ export class AnimatedPoint extends AnimatedWithChildren {
90
94
  ]);
91
95
  }
92
96
 
93
- timing(config = {coordinates: DEFAULT_COORD}) {
97
+ timing(
98
+ config: Partial<Animated.TimingAnimationConfig> & {
99
+ coordinates: GeoJSON.Position;
100
+ } = {coordinates: DEFAULT_COORD},
101
+ ): Animated.CompositeAnimation {
94
102
  return Animated.parallel([
95
103
  Animated.timing(this.longitude, {
96
104
  ...config,
@@ -105,19 +113,19 @@ export class AnimatedPoint extends AnimatedWithChildren {
105
113
  ]);
106
114
  }
107
115
 
108
- __getValue() {
116
+ __getValue(): GeoJSON.Point {
109
117
  return {
110
118
  type: 'Point',
111
119
  coordinates: [this.longitude.__getValue(), this.latitude.__getValue()],
112
120
  };
113
121
  }
114
122
 
115
- __attach() {
123
+ __attach(): void {
116
124
  this.longitude.__addChild(this);
117
125
  this.latitude.__addChild(this);
118
126
  }
119
127
 
120
- __detach() {
128
+ __detach(): void {
121
129
  this.longitude.__removeChild(this);
122
130
  this.latitude.__removeChild(this);
123
131
  }
@@ -1,21 +1,41 @@
1
- import AnimatedCoordinatesArray from './AnimatedCoordinatesArray';
1
+ import AbstractAnimatedCoordinates, {
2
+ AnimatedCoordinates,
3
+ } from './AbstractAnimatedCoordinates';
2
4
 
3
- import {lineString, point, convertLength} from '@turf/helpers';
5
+ import {lineString, point, convertLength, Coord, Units} from '@turf/helpers';
4
6
  import distance from '@turf/distance';
5
7
  import nearestPointOnLine from '@turf/nearest-point-on-line';
6
8
  import length from '@turf/length';
7
9
 
8
- export default class AnimatedRouteCoordinatesArray extends AnimatedCoordinatesArray {
10
+ interface AnimatedRouteState {
11
+ actRoute?: AnimatedCoordinates[];
12
+ fullRoute: AnimatedCoordinates[];
13
+ end: {
14
+ from: number;
15
+ current?: number;
16
+ to: number;
17
+ point?: Coord;
18
+ along?: Coord;
19
+ };
20
+ }
21
+
22
+ export default class AnimatedRouteCoordinatesArray extends AbstractAnimatedCoordinates<AnimatedRouteState> {
23
+ constructor(coords: AnimatedCoordinates[]) {
24
+ super(coords);
25
+ }
26
+
9
27
  /**
10
28
  * Calculate initial state
11
29
  *
12
30
  * @param {*} args - to value from animate
13
31
  * @returns {object} - the state object
14
32
  */
15
- onInitialState(coordinatesArray) {
33
+ onInitialState(coordinatesArray: AnimatedCoordinates[]): AnimatedRouteState {
16
34
  return {
17
- fullRoute: coordinatesArray.map(coord => [coord[0], coord[1]]),
18
- end: {from: 0},
35
+ fullRoute: coordinatesArray.map(
36
+ (coord): AnimatedCoordinates => [coord[0], coord[1]],
37
+ ),
38
+ end: {from: 0, to: 0},
19
39
  };
20
40
  }
21
41
 
@@ -25,7 +45,9 @@ export default class AnimatedRouteCoordinatesArray extends AnimatedCoordinatesAr
25
45
  * @param {object} state - either state from initialState and/or from calculate
26
46
  * @returns {object}
27
47
  */
28
- onGetValue(state) {
48
+ onGetValue(
49
+ state: AnimatedRouteState,
50
+ ): AnimatedRouteState | AnimatedCoordinates[] {
29
51
  return state.actRoute || state.fullRoute;
30
52
  }
31
53
 
@@ -36,7 +58,7 @@ export default class AnimatedRouteCoordinatesArray extends AnimatedCoordinatesAr
36
58
  * @param {number} progress - value between 0 and 1
37
59
  * @returns {object} next state
38
60
  */
39
- onCalculate(state, progress) {
61
+ onCalculate(state: AnimatedRouteState, progress: number): AnimatedRouteState {
40
62
  const {fullRoute, end} = state;
41
63
  const currentEnd = end.from * (1.0 - progress) + progress * end.to;
42
64
 
@@ -64,7 +86,7 @@ export default class AnimatedRouteCoordinatesArray extends AnimatedCoordinatesAr
64
86
  [
65
87
  fullRoute[i][0] * r + fullRoute[i + 1][0] * or,
66
88
  fullRoute[i][1] * r + fullRoute[i + 1][1] * or,
67
- ],
89
+ ] as AnimatedCoordinates,
68
90
  ];
69
91
  return {fullRoute, end: {...end, current: currentEnd}, actRoute};
70
92
  }
@@ -76,15 +98,18 @@ export default class AnimatedRouteCoordinatesArray extends AnimatedCoordinatesAr
76
98
  * @param {*} actCoords - the current coordinates array to start from
77
99
  * @returns {object} The state
78
100
  */
79
- onStart(state, toValue) {
101
+ onStart(
102
+ state: AnimatedRouteState,
103
+ toValue: {end: {point?: Coord; along?: number}; units?: Units},
104
+ ): AnimatedRouteState {
80
105
  const {fullRoute, end} = state;
81
- let toDist;
106
+ let toDist = 0;
82
107
  if (!toValue.end) {
83
108
  console.error(
84
109
  'RouteCoordinatesArray: toValue should have end with either along or point',
85
110
  );
86
111
  }
87
- if (toValue.end.along != null) {
112
+ if (toValue.end.along) {
88
113
  const {units} = toValue;
89
114
  const ls = lineString(fullRoute);
90
115
  toDist = convertLength(toValue.end.along, units);
@@ -100,7 +125,7 @@ export default class AnimatedRouteCoordinatesArray extends AnimatedCoordinatesAr
100
125
  const ls = lineString(fullRoute);
101
126
 
102
127
  const nearest = nearestPointOnLine(ls, toValue.end.point);
103
- toDist = length(ls) - nearest.properties.location;
128
+ toDist = length(ls) - nearest.properties.location!;
104
129
  } else {
105
130
  console.warn(
106
131
  'RouteCoordinatesArray: toValue.end: should have either along or point',
@@ -118,7 +143,7 @@ export default class AnimatedRouteCoordinatesArray extends AnimatedCoordinatesAr
118
143
  return result;
119
144
  }
120
145
 
121
- get originalRoute() {
146
+ get originalRoute(): AnimatedCoordinates[] {
122
147
  return this.state.fullRoute;
123
148
  }
124
149
  }
@@ -1,3 +1,9 @@
1
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ import AnimatedCoordinatesArray from './AnimatedCoordinatesArray';
4
+ import AnimatedExtractCoordinateFromArray from './AnimatedExtractCoordinateFromArray';
5
+ import AnimatedRouteCoordinatesArray from './AnimatedRouteCoordinatesArray';
6
+
1
7
  import {Animated} from 'react-native';
2
8
 
3
9
  // see
@@ -11,6 +17,18 @@ if (__DEV__) {
11
17
  }
12
18
  }
13
19
 
20
+ type Shape =
21
+ | {
22
+ type: 'Point';
23
+ coordinates:
24
+ | AnimatedExtractCoordinateFromArray
25
+ | AnimatedRouteCoordinatesArray;
26
+ }
27
+ | {
28
+ type: 'LineString';
29
+ coordinates: AnimatedCoordinatesArray;
30
+ };
31
+
14
32
  /**
15
33
  * AnimatedShape can be used to have animated properties inside the shape property
16
34
  * @example
@@ -20,20 +38,21 @@ class AnimatedShape extends AnimatedWithChildren {
20
38
  // equivalent of AnimatedStyle for shapes
21
39
  // https://github.com/facebook/react-native/blob/master/Libraries/Animated/src/nodes/AnimatedStyle.js
22
40
 
23
- constructor(shape) {
41
+ constructor(shape: Shape) {
24
42
  super();
25
43
  this.shape = shape;
26
44
  }
27
45
 
28
- _walkShapeAndGetValues(value) {
46
+ _walkShapeAndGetValues(value: any): any {
29
47
  if (Array.isArray(value)) {
30
48
  return value.map(i => this._walkShapeAndGetValues(i));
31
49
  }
50
+ // @ts-expect-error Animated.Node is not exported
32
51
  if (value instanceof Animated.Node) {
33
- return value.__getValue();
52
+ return (value as any).__getValue();
34
53
  }
35
54
  if (typeof value === 'object') {
36
- const result = {};
55
+ const result: {[key: string]: any} = {};
37
56
  for (const key in value) {
38
57
  result[key] = this._walkShapeAndGetValues(value[key]);
39
58
  }
@@ -42,14 +61,16 @@ class AnimatedShape extends AnimatedWithChildren {
42
61
  return value;
43
62
  }
44
63
 
45
- __getValue() {
64
+ __getValue(): any {
46
65
  const result = this._walkShapeAndGetValues(this.shape);
47
66
  return result;
48
67
  }
49
68
 
50
- _walkAndProcess(value, cb) {
69
+ // @ts-expect-error Animated.Node is not exported
70
+ _walkAndProcess(value: any, cb: (value: Animated.Node) => void): void {
51
71
  if (Array.isArray(value)) {
52
72
  value.forEach(i => this._walkAndProcess(i, cb));
73
+ // @ts-expect-error Animated.Node is not exported
53
74
  } else if (value instanceof Animated.Node) {
54
75
  cb(value);
55
76
  } else if (typeof value === 'object') {
@@ -59,12 +80,12 @@ class AnimatedShape extends AnimatedWithChildren {
59
80
  }
60
81
  }
61
82
 
62
- __attach() {
63
- this._walkAndProcess(this.shape, v => v.__addChild(this));
83
+ __attach(): void {
84
+ this._walkAndProcess(this.shape, v => (v as any).__addChild(this));
64
85
  }
65
86
 
66
- __detach() {
67
- this._walkAndProcess(this.shape, v => v.__removeChild(this));
87
+ __detach(): void {
88
+ this._walkAndProcess(this.shape, v => (v as any).__removeChild(this));
68
89
  super.__detach();
69
90
  }
70
91
  }
@@ -3,12 +3,15 @@
3
3
  * calls onDeprecatedCalled callback in case a copied property is invoked.
4
4
  */
5
5
 
6
- export function copyPropertiesAsDeprecated(
7
- origObject,
8
- newObject,
9
- onDeprecatedCalled,
10
- accessors = {},
11
- ) {
6
+ export function copyPropertiesAsDeprecated<
7
+ DeprecatedType extends object,
8
+ WithDeprecatedType extends Record<string, unknown>,
9
+ >(
10
+ origObject: DeprecatedType,
11
+ newObject: WithDeprecatedType,
12
+ onDeprecatedCalled: (key: string) => void,
13
+ accessors: Record<string, (value: any) => unknown> = {},
14
+ ): WithDeprecatedType {
12
15
  const result = newObject;
13
16
  for (const [key, value] of Object.entries(origObject)) {
14
17
  if (!newObject[key]) {
@@ -0,0 +1,9 @@
1
+ import {FilterExpression} from './MaplibreStyles';
2
+
3
+ export function getFilter(filter: FilterExpression | undefined): string[] {
4
+ if (!Array.isArray(filter) || filter.length === 0) {
5
+ return [];
6
+ }
7
+
8
+ return filter;
9
+ }