react-native-mapsforge-vtm-ext-grib 0.2.0

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 (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +118 -0
  3. package/android/CMakeLists.txt +13 -0
  4. package/android/build.gradle +108 -0
  5. package/android/generated/java/com/jhotadhari/reactnative/mapsforge/vtm/ext/grib/NativeWeatherOverlaySpec.java +95 -0
  6. package/android/generated/jni/CMakeLists.txt +28 -0
  7. package/android/generated/jni/RNMapsforgeVtmExtGribSpec-generated.cpp +62 -0
  8. package/android/generated/jni/RNMapsforgeVtmExtGribSpec.h +31 -0
  9. package/android/generated/jni/react/renderer/components/RNMapsforgeVtmExtGribSpec/RNMapsforgeVtmExtGribSpecJSI.h +521 -0
  10. package/android/gradle.properties +5 -0
  11. package/android/src/main/AndroidManifest.xml +2 -0
  12. package/android/src/main/AndroidManifestNew.xml +2 -0
  13. package/android/src/main/java/com/jhotadhari/reactnative/mapsforge/vtm/ext/grib/ExtGribPackage.java +62 -0
  14. package/android/src/main/java/com/jhotadhari/reactnative/mapsforge/vtm/ext/grib/modules/WeatherOverlay.java +343 -0
  15. package/android/src/main/java/com/jhotadhari/reactnative/mapsforge/vtm/ext/grib/tiles/ColorRamp.java +165 -0
  16. package/android/src/main/java/com/jhotadhari/reactnative/mapsforge/vtm/ext/grib/tiles/WeatherGridData.java +103 -0
  17. package/android/src/main/java/com/jhotadhari/reactnative/mapsforge/vtm/ext/grib/tiles/WeatherTileDataSource.java +147 -0
  18. package/android/src/main/java/com/jhotadhari/reactnative/mapsforge/vtm/ext/grib/tiles/WeatherTileSource.java +80 -0
  19. package/lib/commonjs/NativeModules/NativeWeatherOverlay.js +9 -0
  20. package/lib/commonjs/NativeModules/NativeWeatherOverlay.js.map +1 -0
  21. package/lib/commonjs/components/WeatherOverlay.js +180 -0
  22. package/lib/commonjs/components/WeatherOverlay.js.map +1 -0
  23. package/lib/commonjs/index.js +21 -0
  24. package/lib/commonjs/index.js.map +1 -0
  25. package/lib/commonjs/package.json +1 -0
  26. package/lib/commonjs/reanimated/index.js +13 -0
  27. package/lib/commonjs/reanimated/index.js.map +1 -0
  28. package/lib/commonjs/reanimated/useWeatherAnimation.js +86 -0
  29. package/lib/commonjs/reanimated/useWeatherAnimation.js.map +1 -0
  30. package/lib/commonjs/reportNativeError.js +14 -0
  31. package/lib/commonjs/reportNativeError.js.map +1 -0
  32. package/lib/commonjs/types.js +2 -0
  33. package/lib/commonjs/types.js.map +1 -0
  34. package/lib/module/NativeModules/NativeWeatherOverlay.js +5 -0
  35. package/lib/module/NativeModules/NativeWeatherOverlay.js.map +1 -0
  36. package/lib/module/components/WeatherOverlay.js +174 -0
  37. package/lib/module/components/WeatherOverlay.js.map +1 -0
  38. package/lib/module/index.js +16 -0
  39. package/lib/module/index.js.map +1 -0
  40. package/lib/module/package.json +1 -0
  41. package/lib/module/reanimated/index.js +4 -0
  42. package/lib/module/reanimated/index.js.map +1 -0
  43. package/lib/module/reanimated/useWeatherAnimation.js +81 -0
  44. package/lib/module/reanimated/useWeatherAnimation.js.map +1 -0
  45. package/lib/module/reportNativeError.js +10 -0
  46. package/lib/module/reportNativeError.js.map +1 -0
  47. package/lib/module/types.js +2 -0
  48. package/lib/module/types.js.map +1 -0
  49. package/lib/typescript/commonjs/package.json +1 -0
  50. package/lib/typescript/commonjs/src/NativeModules/NativeWeatherOverlay.d.ts +63 -0
  51. package/lib/typescript/commonjs/src/NativeModules/NativeWeatherOverlay.d.ts.map +1 -0
  52. package/lib/typescript/commonjs/src/components/WeatherOverlay.d.ts +10 -0
  53. package/lib/typescript/commonjs/src/components/WeatherOverlay.d.ts.map +1 -0
  54. package/lib/typescript/commonjs/src/index.d.ts +11 -0
  55. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  56. package/lib/typescript/commonjs/src/reanimated/index.d.ts +3 -0
  57. package/lib/typescript/commonjs/src/reanimated/index.d.ts.map +1 -0
  58. package/lib/typescript/commonjs/src/reanimated/useWeatherAnimation.d.ts +44 -0
  59. package/lib/typescript/commonjs/src/reanimated/useWeatherAnimation.d.ts.map +1 -0
  60. package/lib/typescript/commonjs/src/reportNativeError.d.ts +3 -0
  61. package/lib/typescript/commonjs/src/reportNativeError.d.ts.map +1 -0
  62. package/lib/typescript/commonjs/src/types.d.ts +51 -0
  63. package/lib/typescript/commonjs/src/types.d.ts.map +1 -0
  64. package/lib/typescript/module/package.json +1 -0
  65. package/lib/typescript/module/src/NativeModules/NativeWeatherOverlay.d.ts +63 -0
  66. package/lib/typescript/module/src/NativeModules/NativeWeatherOverlay.d.ts.map +1 -0
  67. package/lib/typescript/module/src/components/WeatherOverlay.d.ts +10 -0
  68. package/lib/typescript/module/src/components/WeatherOverlay.d.ts.map +1 -0
  69. package/lib/typescript/module/src/index.d.ts +11 -0
  70. package/lib/typescript/module/src/index.d.ts.map +1 -0
  71. package/lib/typescript/module/src/reanimated/index.d.ts +3 -0
  72. package/lib/typescript/module/src/reanimated/index.d.ts.map +1 -0
  73. package/lib/typescript/module/src/reanimated/useWeatherAnimation.d.ts +44 -0
  74. package/lib/typescript/module/src/reanimated/useWeatherAnimation.d.ts.map +1 -0
  75. package/lib/typescript/module/src/reportNativeError.d.ts +3 -0
  76. package/lib/typescript/module/src/reportNativeError.d.ts.map +1 -0
  77. package/lib/typescript/module/src/types.d.ts +51 -0
  78. package/lib/typescript/module/src/types.d.ts.map +1 -0
  79. package/package.json +159 -0
  80. package/react-native.config.js +13 -0
  81. package/src/NativeModules/NativeWeatherOverlay.ts +73 -0
  82. package/src/components/WeatherOverlay.tsx +173 -0
  83. package/src/index.ts +22 -0
  84. package/src/reanimated/index.ts +2 -0
  85. package/src/reanimated/useWeatherAnimation.ts +118 -0
  86. package/src/reportNativeError.ts +15 -0
  87. package/src/types.ts +56 -0
@@ -0,0 +1,118 @@
1
+ import { useCallback, useMemo } from 'react';
2
+ import {
3
+ useSharedValue,
4
+ withTiming,
5
+ type SharedValue,
6
+ } from 'react-native-reanimated';
7
+
8
+ export interface WeatherAnimationControls {
9
+ /** The current animation progress (0.0 to timeSteps.length - 1). */
10
+ progressSv: SharedValue<number>;
11
+ /** Start playing the animation. */
12
+ play: () => void;
13
+ /** Pause the animation. */
14
+ pause: () => void;
15
+ /** Reset to the first time step. */
16
+ reset: () => void;
17
+ /** Seek to a specific time step index (fractional for interpolation). */
18
+ seek: (timeIndex: number) => void;
19
+ }
20
+
21
+ /**
22
+ * Creates a reanimated shared value that drives smooth time-step animation
23
+ * for a weather overlay.
24
+ *
25
+ * The progress value ranges from 0.0 to (numTimeSteps - 1), where the
26
+ * fractional part represents the interpolation between adjacent time steps.
27
+ *
28
+ * Usage with WeatherOverlay:
29
+ * - Pass `Math.floor(progress.value)` as `timeIndex` to the "current" layer
30
+ * - Pass `Math.ceil(progress.value)` as `timeIndex` to the "next" layer
31
+ * - Set the "next" layer's opacity to `progress.value - Math.floor(progress.value)`
32
+ *
33
+ * @param numTimeSteps - Total number of forecast time steps available.
34
+ * @param durationMs - Duration of the full animation in milliseconds.
35
+ * @returns Animation controls including the progress shared value.
36
+ *
37
+ * @example
38
+ * ```tsx
39
+ * const { progressSv, play, pause } = useWeatherAnimation(
40
+ * weatherData.timeSteps.length,
41
+ * 10000
42
+ * );
43
+ *
44
+ * // In a worklet or useDerivedValue:
45
+ * const currentIdx = Math.floor(progressSv.value);
46
+ * const nextAlpha = progressSv.value - currentIdx;
47
+ * ```
48
+ */
49
+ export function useWeatherAnimation(
50
+ numTimeSteps: number,
51
+ durationMs: number = 10000
52
+ ): WeatherAnimationControls {
53
+ const progressSv = useSharedValue<number>(0);
54
+ const isPlayingSv = useSharedValue<boolean>(false);
55
+
56
+ const play = useCallback(() => {
57
+ 'worklet';
58
+ if (isPlayingSv.value) return;
59
+ isPlayingSv.value = true;
60
+
61
+ // Calculate remaining duration based on current progress
62
+ const remainingProgress = numTimeSteps - 1 - progressSv.value;
63
+ const remainingDuration = Math.max(
64
+ 100,
65
+ (remainingProgress / (numTimeSteps - 1)) * durationMs
66
+ );
67
+
68
+ progressSv.value = withTiming(
69
+ numTimeSteps - 1,
70
+ { duration: Math.round(remainingDuration) },
71
+ (finished) => {
72
+ if (finished) {
73
+ isPlayingSv.value = false;
74
+ }
75
+ }
76
+ );
77
+ }, [
78
+ numTimeSteps,
79
+ durationMs,
80
+ progressSv,
81
+ isPlayingSv,
82
+ ]);
83
+
84
+ const pause = useCallback(() => {
85
+ 'worklet';
86
+ isPlayingSv.value = false;
87
+ // Cancel the current timing by setting to current value
88
+ progressSv.value = progressSv.value;
89
+ }, [progressSv, isPlayingSv]);
90
+
91
+ const reset = useCallback(() => {
92
+ 'worklet';
93
+ isPlayingSv.value = false;
94
+ progressSv.value = 0;
95
+ }, [progressSv, isPlayingSv]);
96
+
97
+ const seek = useCallback(
98
+ (timeIndex: number) => {
99
+ 'worklet';
100
+ const clamped = Math.max(0, Math.min(numTimeSteps - 1, timeIndex));
101
+ progressSv.value = clamped;
102
+ },
103
+ [numTimeSteps, progressSv]
104
+ );
105
+
106
+ return useMemo(
107
+ () => ({ progressSv, play, pause, reset, seek }),
108
+ [
109
+ progressSv,
110
+ play,
111
+ pause,
112
+ reset,
113
+ seek,
114
+ ]
115
+ );
116
+ }
117
+
118
+ export default useWeatherAnimation;
@@ -0,0 +1,15 @@
1
+ import type { ErrorBase } from './types';
2
+
3
+ export default function reportNativeError(
4
+ err: ErrorBase,
5
+ onError?: null | ((err: ErrorBase) => void)
6
+ ): void {
7
+ if (onError) {
8
+ onError(err);
9
+ } else if (__DEV__) {
10
+ console.warn(
11
+ '[react-native-mapsforge-vtm-ext-grib]',
12
+ err?.userInfo?.errorMsg ?? 'Unknown native error'
13
+ );
14
+ }
15
+ }
package/src/types.ts ADDED
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Base types shared across the ext-grib library.
3
+ *
4
+ * Mirrors the pattern from react-native-mapsforge-vtm's types.ts.
5
+ */
6
+
7
+ export interface ResponseBase {
8
+ uuid: string;
9
+ nativeNodeHandle: number;
10
+ }
11
+
12
+ export interface ErrorBase {
13
+ userInfo?: {
14
+ errorMsg?: string;
15
+ };
16
+ }
17
+
18
+ /**
19
+ * Represents one time step of gridded weather data.
20
+ * This is the format produced by server-side GRIB to JSON conversion
21
+ * (and later by on-device JGribX parsing).
22
+ */
23
+ export interface WeatherGrid {
24
+ /** UTC ISO timestamp e.g. "2026-07-03T00:00:00Z" */
25
+ validTime: string;
26
+ /** Minimum latitude of the grid (southern edge) */
27
+ minLat: number;
28
+ /** Maximum latitude of the grid (northern edge) */
29
+ maxLat: number;
30
+ /** Minimum longitude of the grid (western edge) */
31
+ minLng: number;
32
+ /** Maximum longitude of the grid (eastern edge) */
33
+ maxLng: number;
34
+ /** Number of grid points in the longitude direction */
35
+ ni: number;
36
+ /** Number of grid points in the latitude direction */
37
+ nj: number;
38
+ /** Row-major grid values, length = ni * nj. Missing values are NaN. */
39
+ values: number[];
40
+ }
41
+
42
+ /**
43
+ * Metadata for a weather data source (returned after loading).
44
+ */
45
+ export interface WeatherMetadata {
46
+ parameter: string;
47
+ levelType?: string;
48
+ unit: string;
49
+ timeSteps: WeatherGrid[];
50
+ }
51
+
52
+ /**
53
+ * Built-in color ramp identifiers.
54
+ */
55
+ export type ColorMapName =
56
+ 'temperature' | 'wind' | 'pressure' | 'rainfall' | 'waves' | 'grayscale';