@aguacerowx/react-native 0.0.53 → 0.0.54

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 (261) hide show
  1. package/LICENSE +21 -0
  2. package/android/src/main/java/com/aguacerowx/reactnative/NexradRadarLayerView.java +14 -2
  3. package/android/src/main/java/com/aguacerowx/reactnative/WeatherFrameProcessorModule.java +77 -0
  4. package/index.js +1 -1
  5. package/ios/WeatherFrameProcessorModule.m +19 -15
  6. package/ios/WeatherFrameProcessorModule.swift +65 -0
  7. package/lib/commonjs/AguaceroContext.js +0 -4
  8. package/lib/commonjs/AguaceroContext.js.map +1 -1
  9. package/lib/commonjs/GridRenderLayer.js +62 -76
  10. package/lib/commonjs/GridRenderLayer.js.map +1 -1
  11. package/lib/commonjs/MapManager.js +110 -224
  12. package/lib/commonjs/MapManager.js.map +1 -1
  13. package/lib/commonjs/MapRegistry.js +21 -33
  14. package/lib/commonjs/MapRegistry.js.map +1 -1
  15. package/lib/commonjs/NexradRadarLayer.android.js +28 -100
  16. package/lib/commonjs/NexradRadarLayer.android.js.map +1 -1
  17. package/lib/commonjs/NexradRadarLayer.ios.js +26 -97
  18. package/lib/commonjs/NexradRadarLayer.ios.js.map +1 -1
  19. package/lib/commonjs/NexradSitesMapLayer.js +41 -61
  20. package/lib/commonjs/NexradSitesMapLayer.js.map +1 -1
  21. package/lib/commonjs/SatelliteLayer.android.js +26 -38
  22. package/lib/commonjs/SatelliteLayer.android.js.map +1 -1
  23. package/lib/commonjs/SatelliteLayer.ios.js +30 -42
  24. package/lib/commonjs/SatelliteLayer.ios.js.map +1 -1
  25. package/lib/commonjs/StyleApplicator.js +129 -175
  26. package/lib/commonjs/StyleApplicator.js.map +1 -1
  27. package/lib/commonjs/WeatherLayerManager.js +995 -1646
  28. package/lib/commonjs/WeatherLayerManager.js.map +1 -1
  29. package/lib/commonjs/aguaceroCoreDebugHooks.js +58 -130
  30. package/lib/commonjs/aguaceroCoreDebugHooks.js.map +1 -1
  31. package/lib/commonjs/aguaceroRnDebug.js +147 -288
  32. package/lib/commonjs/aguaceroRnDebug.js.map +1 -1
  33. package/lib/commonjs/cdnAuthenticatedFetch.js +104 -0
  34. package/lib/commonjs/cdnAuthenticatedFetch.js.map +1 -0
  35. package/lib/commonjs/dispatchViewManagerCommandCompat.js +51 -88
  36. package/lib/commonjs/dispatchViewManagerCommandCompat.js.map +1 -1
  37. package/lib/commonjs/gridCdnAuth.js +41 -50
  38. package/lib/commonjs/gridCdnAuth.js.map +1 -1
  39. package/lib/commonjs/index.js +14 -0
  40. package/lib/commonjs/index.js.map +1 -1
  41. package/lib/commonjs/nexrad/nexradAndroidController.js +851 -863
  42. package/lib/commonjs/nexrad/nexradAndroidController.js.map +1 -1
  43. package/lib/commonjs/nexrad/nexradCrossSectionSampleAtLatLon.bundled.js +62 -85
  44. package/lib/commonjs/nexrad/nexradCrossSectionSampleAtLatLon.bundled.js.map +1 -1
  45. package/lib/commonjs/nexrad/nexradDiag.js +32 -148
  46. package/lib/commonjs/nexrad/nexradDiag.js.map +1 -1
  47. package/lib/commonjs/nexrad/nexradLevel2Keys.js +261 -0
  48. package/lib/commonjs/nexrad/nexradLevel2Keys.js.map +1 -0
  49. package/lib/commonjs/nexrad/nexradLutBuild.js +64 -111
  50. package/lib/commonjs/nexrad/nexradLutBuild.js.map +1 -1
  51. package/lib/commonjs/nexrad/nexradMapboxFrameOpts.bundled.js +136 -164
  52. package/lib/commonjs/nexrad/nexradMapboxFrameOpts.bundled.js.map +1 -1
  53. package/lib/commonjs/nexrad/nexradSdkImports.js +51 -0
  54. package/lib/commonjs/nexrad/nexradSdkImports.js.map +1 -0
  55. package/lib/commonjs/nexrad/radarArchiveCore.bundled.js +2848 -4455
  56. package/lib/commonjs/nexrad/radarArchiveCore.bundled.js.map +1 -1
  57. package/lib/commonjs/nexrad/radarDecode.worker.bundled.js +445 -648
  58. package/lib/commonjs/nexrad/radarDecode.worker.bundled.js.map +1 -1
  59. package/lib/commonjs/nexrad/radarFrameGpuMatch.bundled.js +52 -68
  60. package/lib/commonjs/nexrad/radarFrameGpuMatch.bundled.js.map +1 -1
  61. package/lib/commonjs/nexradNativeCommandIds.js +24 -0
  62. package/lib/commonjs/nexradNativeCommandIds.js.map +1 -0
  63. package/lib/commonjs/nws/NwsAlertsOverlay.android.js.map +1 -1
  64. package/lib/commonjs/nws/NwsAlertsOverlay.ios.js.map +1 -1
  65. package/lib/commonjs/nws/NwsAlertsOverlay.js +3 -3
  66. package/lib/commonjs/nws/NwsAlertsOverlay.js.map +1 -1
  67. package/lib/commonjs/nws/NwsAlertsOverlay.native.js +235 -361
  68. package/lib/commonjs/nws/NwsAlertsOverlay.native.js.map +1 -1
  69. package/lib/commonjs/nws/eventSourceRnPolyfill.js +92 -146
  70. package/lib/commonjs/nws/eventSourceRnPolyfill.js.map +1 -1
  71. package/lib/commonjs/nws/nwsAndroidConstants.js +2 -8
  72. package/lib/commonjs/nws/nwsAndroidConstants.js.map +1 -1
  73. package/lib/commonjs/satellite/satelliteAndroidController.js +117 -202
  74. package/lib/commonjs/satellite/satelliteAndroidController.js.map +1 -1
  75. package/lib/commonjs/satelliteBridgeDiag.js +3 -13
  76. package/lib/commonjs/satelliteBridgeDiag.js.map +1 -1
  77. package/lib/commonjs/satelliteRnDebug.js +117 -218
  78. package/lib/commonjs/satelliteRnDebug.js.map +1 -1
  79. package/lib/module/AguaceroContext.js +2 -7
  80. package/lib/module/AguaceroContext.js.map +1 -1
  81. package/lib/module/GridRenderLayer.js +66 -80
  82. package/lib/module/GridRenderLayer.js.map +1 -1
  83. package/lib/module/MapManager.js +125 -239
  84. package/lib/module/MapManager.js.map +1 -1
  85. package/lib/module/MapRegistry.js +21 -33
  86. package/lib/module/MapRegistry.js.map +1 -1
  87. package/lib/module/NexradRadarLayer.android.js +32 -104
  88. package/lib/module/NexradRadarLayer.android.js.map +1 -1
  89. package/lib/module/NexradRadarLayer.ios.js +30 -101
  90. package/lib/module/NexradRadarLayer.ios.js.map +1 -1
  91. package/lib/module/NexradSitesMapLayer.js +44 -63
  92. package/lib/module/NexradSitesMapLayer.js.map +1 -1
  93. package/lib/module/SatelliteLayer.android.js +32 -44
  94. package/lib/module/SatelliteLayer.android.js.map +1 -1
  95. package/lib/module/SatelliteLayer.ios.js +36 -48
  96. package/lib/module/SatelliteLayer.ios.js.map +1 -1
  97. package/lib/module/StyleApplicator.js +144 -191
  98. package/lib/module/StyleApplicator.js.map +1 -1
  99. package/lib/module/WeatherLayerManager.js +1024 -1675
  100. package/lib/module/WeatherLayerManager.js.map +1 -1
  101. package/lib/module/aguaceroCoreDebugHooks.js +59 -130
  102. package/lib/module/aguaceroCoreDebugHooks.js.map +1 -1
  103. package/lib/module/aguaceroRnDebug.js +151 -292
  104. package/lib/module/aguaceroRnDebug.js.map +1 -1
  105. package/lib/module/cdnAuthenticatedFetch.js +97 -0
  106. package/lib/module/cdnAuthenticatedFetch.js.map +1 -0
  107. package/lib/module/dispatchViewManagerCommandCompat.js +52 -90
  108. package/lib/module/dispatchViewManagerCommandCompat.js.map +1 -1
  109. package/lib/module/gridCdnAuth.js +38 -50
  110. package/lib/module/gridCdnAuth.js.map +1 -1
  111. package/lib/module/index.js +9 -7
  112. package/lib/module/index.js.map +1 -1
  113. package/lib/module/nexrad/nexradAndroidController.js +865 -876
  114. package/lib/module/nexrad/nexradAndroidController.js.map +1 -1
  115. package/lib/module/nexrad/nexradCrossSectionSampleAtLatLon.bundled.js +62 -85
  116. package/lib/module/nexrad/nexradCrossSectionSampleAtLatLon.bundled.js.map +1 -1
  117. package/lib/module/nexrad/nexradDiag.js +31 -145
  118. package/lib/module/nexrad/nexradDiag.js.map +1 -1
  119. package/lib/module/nexrad/nexradLevel2Keys.js +245 -0
  120. package/lib/module/nexrad/nexradLevel2Keys.js.map +1 -0
  121. package/lib/module/nexrad/nexradLutBuild.js +64 -110
  122. package/lib/module/nexrad/nexradLutBuild.js.map +1 -1
  123. package/lib/module/nexrad/nexradMapboxFrameOpts.bundled.js +136 -163
  124. package/lib/module/nexrad/nexradMapboxFrameOpts.bundled.js.map +1 -1
  125. package/lib/module/nexrad/nexradSdkImports.js +4 -0
  126. package/lib/module/nexrad/nexradSdkImports.js.map +1 -0
  127. package/lib/module/nexrad/radarArchiveCore.bundled.js +2839 -4448
  128. package/lib/module/nexrad/radarArchiveCore.bundled.js.map +1 -1
  129. package/lib/module/nexrad/radarDecode.worker.bundled.js +445 -648
  130. package/lib/module/nexrad/radarDecode.worker.bundled.js.map +1 -1
  131. package/lib/module/nexrad/radarFrameGpuMatch.bundled.js +50 -66
  132. package/lib/module/nexrad/radarFrameGpuMatch.bundled.js.map +1 -1
  133. package/lib/module/nexradNativeCommandIds.js +18 -0
  134. package/lib/module/nexradNativeCommandIds.js.map +1 -0
  135. package/lib/module/nws/NwsAlertsOverlay.android.js +1 -1
  136. package/lib/module/nws/NwsAlertsOverlay.android.js.map +1 -1
  137. package/lib/module/nws/NwsAlertsOverlay.ios.js +1 -1
  138. package/lib/module/nws/NwsAlertsOverlay.ios.js.map +1 -1
  139. package/lib/module/nws/NwsAlertsOverlay.js +5 -5
  140. package/lib/module/nws/NwsAlertsOverlay.js.map +1 -1
  141. package/lib/module/nws/NwsAlertsOverlay.native.js +248 -373
  142. package/lib/module/nws/NwsAlertsOverlay.native.js.map +1 -1
  143. package/lib/module/nws/eventSourceRnPolyfill.js +92 -146
  144. package/lib/module/nws/eventSourceRnPolyfill.js.map +1 -1
  145. package/lib/module/nws/nwsAndroidConstants.js +2 -8
  146. package/lib/module/nws/nwsAndroidConstants.js.map +1 -1
  147. package/lib/module/satellite/satelliteAndroidController.js +123 -208
  148. package/lib/module/satellite/satelliteAndroidController.js.map +1 -1
  149. package/lib/module/satelliteBridgeDiag.js +3 -13
  150. package/lib/module/satelliteBridgeDiag.js.map +1 -1
  151. package/lib/module/satelliteRnDebug.js +123 -223
  152. package/lib/module/satelliteRnDebug.js.map +1 -1
  153. package/lib/typescript/AguaceroContext.d.ts +0 -4
  154. package/lib/typescript/AguaceroContext.d.ts.map +1 -1
  155. package/lib/typescript/GridRenderLayer.d.ts.map +1 -1
  156. package/lib/typescript/MapManager.d.ts +0 -12
  157. package/lib/typescript/MapManager.d.ts.map +1 -1
  158. package/lib/typescript/MapRegistry.d.ts +10 -12
  159. package/lib/typescript/MapRegistry.d.ts.map +1 -1
  160. package/lib/typescript/NexradRadarLayer.android.d.ts.map +1 -1
  161. package/lib/typescript/NexradRadarLayer.ios.d.ts.map +1 -1
  162. package/lib/typescript/NexradSitesMapLayer.d.ts +4 -10
  163. package/lib/typescript/NexradSitesMapLayer.d.ts.map +1 -1
  164. package/lib/typescript/SatelliteLayer.android.d.ts.map +1 -1
  165. package/lib/typescript/SatelliteLayer.ios.d.ts.map +1 -1
  166. package/lib/typescript/StyleApplicator.d.ts +1 -1
  167. package/lib/typescript/StyleApplicator.d.ts.map +1 -1
  168. package/lib/typescript/WeatherLayerManager.d.ts.map +1 -1
  169. package/lib/typescript/aguaceroCoreDebugHooks.d.ts +2 -9
  170. package/lib/typescript/aguaceroCoreDebugHooks.d.ts.map +1 -1
  171. package/lib/typescript/aguaceroRnDebug.d.ts +47 -66
  172. package/lib/typescript/aguaceroRnDebug.d.ts.map +1 -1
  173. package/lib/typescript/cdnAuthenticatedFetch.d.ts +10 -0
  174. package/lib/typescript/cdnAuthenticatedFetch.d.ts.map +1 -0
  175. package/lib/typescript/dispatchViewManagerCommandCompat.d.ts +1 -17
  176. package/lib/typescript/dispatchViewManagerCommandCompat.d.ts.map +1 -1
  177. package/lib/typescript/gridCdnAuth.d.ts +16 -21
  178. package/lib/typescript/gridCdnAuth.d.ts.map +1 -1
  179. package/lib/typescript/index.d.ts +1 -0
  180. package/lib/typescript/nexrad/nexradAndroidController.d.ts +39 -89
  181. package/lib/typescript/nexrad/nexradAndroidController.d.ts.map +1 -1
  182. package/lib/typescript/nexrad/nexradCrossSectionSampleAtLatLon.bundled.d.ts +2 -1
  183. package/lib/typescript/nexrad/nexradCrossSectionSampleAtLatLon.bundled.d.ts.map +1 -1
  184. package/lib/typescript/nexrad/nexradDiag.d.ts +13 -101
  185. package/lib/typescript/nexrad/nexradDiag.d.ts.map +1 -1
  186. package/lib/typescript/nexrad/nexradLevel2Keys.d.ts +36 -0
  187. package/lib/typescript/nexrad/nexradLevel2Keys.d.ts.map +1 -0
  188. package/lib/typescript/nexrad/nexradLutBuild.d.ts +3 -10
  189. package/lib/typescript/nexrad/nexradLutBuild.d.ts.map +1 -1
  190. package/lib/typescript/nexrad/nexradMapboxFrameOpts.bundled.d.ts +4 -3
  191. package/lib/typescript/nexrad/nexradMapboxFrameOpts.bundled.d.ts.map +1 -1
  192. package/lib/typescript/nexrad/nexradSdkImports.d.ts +2 -0
  193. package/lib/typescript/nexrad/nexradSdkImports.d.ts.map +1 -0
  194. package/lib/typescript/nexrad/radarArchiveCore.bundled.d.ts +12 -7
  195. package/lib/typescript/nexrad/radarArchiveCore.bundled.d.ts.map +1 -1
  196. package/lib/typescript/nexrad/radarDecode.worker.bundled.d.ts +20 -20
  197. package/lib/typescript/nexrad/radarDecode.worker.bundled.d.ts.map +1 -1
  198. package/lib/typescript/nexrad/radarFrameGpuMatch.bundled.d.ts +4 -3
  199. package/lib/typescript/nexrad/radarFrameGpuMatch.bundled.d.ts.map +1 -1
  200. package/lib/typescript/nexradNativeCommandIds.d.ts +2 -0
  201. package/lib/typescript/nexradNativeCommandIds.d.ts.map +1 -0
  202. package/lib/typescript/nws/NwsAlertsOverlay.native.d.ts +6 -17
  203. package/lib/typescript/nws/NwsAlertsOverlay.native.d.ts.map +1 -1
  204. package/lib/typescript/nws/eventSourceRnPolyfill.d.ts +0 -3
  205. package/lib/typescript/nws/eventSourceRnPolyfill.d.ts.map +1 -1
  206. package/lib/typescript/nws/nwsAndroidConstants.d.ts +0 -5
  207. package/lib/typescript/nws/nwsAndroidConstants.d.ts.map +1 -1
  208. package/lib/typescript/satellite/satelliteAndroidController.d.ts +9 -47
  209. package/lib/typescript/satellite/satelliteAndroidController.d.ts.map +1 -1
  210. package/lib/typescript/satelliteBridgeDiag.d.ts +1 -5
  211. package/lib/typescript/satelliteBridgeDiag.d.ts.map +1 -1
  212. package/lib/typescript/satelliteRnDebug.d.ts +24 -30
  213. package/lib/typescript/satelliteRnDebug.d.ts.map +1 -1
  214. package/package.json +75 -74
  215. package/src/AguaceroContext.js +1 -7
  216. package/src/GridRenderLayer.js +1 -128
  217. package/src/MapManager.js +1 -277
  218. package/src/MapRegistry.js +1 -56
  219. package/src/NexradRadarLayer.android.js +1 -121
  220. package/src/NexradRadarLayer.ios.js +1 -115
  221. package/src/NexradSitesMapLayer.js +1 -75
  222. package/src/SatelliteLayer.android.js +1 -63
  223. package/src/SatelliteLayer.ios.js +1 -70
  224. package/src/StyleApplicator.js +1 -241
  225. package/src/WeatherLayerManager.js +1 -2045
  226. package/src/aguaceroCoreDebugHooks.js +1 -142
  227. package/src/aguaceroRnDebug.js +1 -336
  228. package/src/cdnAuthenticatedFetch.js +1 -0
  229. package/src/dispatchViewManagerCommandCompat.js +1 -100
  230. package/src/gridCdnAuth.js +1 -56
  231. package/src/index.js +1 -27
  232. package/src/nexrad/nexradAndroidController.js +1 -1078
  233. package/src/nexrad/nexradCrossSectionSampleAtLatLon.bundled.js +1 -91
  234. package/src/nexrad/nexradDiag.js +1 -150
  235. package/src/nexrad/nexradLevel2Keys.js +1 -0
  236. package/src/nexrad/nexradLutBuild.js +1 -126
  237. package/src/nexrad/nexradMapboxFrameOpts.bundled.js +1 -245
  238. package/src/nexrad/nexradSdkImports.js +1 -0
  239. package/src/nexrad/radarArchiveCore.bundled.js +1 -7085
  240. package/src/nexrad/radarDecode.worker.bundled.js +1 -813
  241. package/src/nexrad/radarFrameGpuMatch.bundled.js +1 -79
  242. package/src/nexradNativeCommandIds.js +1 -0
  243. package/src/nws/NwsAlertsOverlay.android.js +1 -1
  244. package/src/nws/NwsAlertsOverlay.ios.js +1 -1
  245. package/src/nws/NwsAlertsOverlay.js +1 -7
  246. package/src/nws/NwsAlertsOverlay.native.js +1 -463
  247. package/src/nws/eventSourceRnPolyfill.js +7 -193
  248. package/src/nws/nwsAndroidConstants.js +1 -8
  249. package/src/satellite/satelliteAndroidController.js +1 -257
  250. package/src/satelliteBridgeDiag.js +1 -15
  251. package/src/satelliteRnDebug.js +1 -269
  252. package/lib/commonjs/nexrad/nexradNativeCommandIds.js +0 -51
  253. package/lib/commonjs/nexrad/nexradNativeCommandIds.js.map +0 -1
  254. package/lib/module/nexrad/nexradNativeCommandIds.js +0 -44
  255. package/lib/module/nexrad/nexradNativeCommandIds.js.map +0 -1
  256. package/lib/typescript/nexrad/nexradNativeCommandIds.d.ts +0 -9
  257. package/lib/typescript/nexrad/nexradNativeCommandIds.d.ts.map +0 -1
  258. package/src/nexrad/nexradNativeCommandIds.js +0 -44
  259. /package/lib/commonjs/{nexrad/nexradSitesUs.json → nexradSitesUs.json} +0 -0
  260. /package/lib/module/{nexrad/nexradSitesUs.json → nexradSitesUs.json} +0 -0
  261. /package/src/{nexrad/nexradSitesUs.json → nexradSitesUs.json} +0 -0
@@ -1,79 +1 @@
1
- function angularDistanceDeg(a, b) {
2
- let d = Math.abs(a - b) % 360;
3
- if (d > 180) d = 360 - d;
4
- return d;
5
- }
6
- function canonicalBinsRadarFrame(frame) {
7
- const nRays = frame.nRays;
8
- const nGates = frame.nGates;
9
- if (nRays <= 0 || nGates <= 0) return frame;
10
- if (frame.rayBoundariesDeg.length < nRays + 1) return frame;
11
- const degPerBin = 360 / nRays;
12
- const bytesPerRay = nGates * 2;
13
- const centers = new Float32Array(nRays);
14
- for (let r = 0; r < nRays; r++) {
15
- const lower = frame.rayBoundariesDeg[r];
16
- const upper = frame.rayBoundariesDeg[r + 1];
17
- const center = (lower + upper) * 0.5;
18
- centers[r] = (center % 360 + 360) % 360;
19
- }
20
- const canonicalGateData = new Uint8Array(nRays * bytesPerRay);
21
- for (let i = 0; i < canonicalGateData.length; i += 2) {
22
- canonicalGateData[i] = 128;
23
- }
24
- const used = new Array(nRays).fill(false);
25
- for (let bin = 0; bin < nRays; bin++) {
26
- const targetDeg = ((bin + 0.5) * degPerBin % 360 + 360) % 360;
27
- let bestR = -1;
28
- let bestDist = Infinity;
29
- for (let r = 0; r < nRays; r++) {
30
- if (used[r]) continue;
31
- const dist = angularDistanceDeg(centers[r], targetDeg);
32
- if (dist < bestDist) {
33
- bestDist = dist;
34
- bestR = r;
35
- }
36
- }
37
- if (bestR >= 0) {
38
- used[bestR] = true;
39
- canonicalGateData.set(
40
- frame.gateData.subarray(bestR * bytesPerRay, (bestR + 1) * bytesPerRay),
41
- bin * bytesPerRay
42
- );
43
- }
44
- }
45
- const canonicalBoundaries = new Float32Array(nRays + 1);
46
- for (let i = 0; i <= nRays; i++) {
47
- canonicalBoundaries[i] = i * degPerBin;
48
- }
49
- return { ...frame, gateData: canonicalGateData, rayBoundariesDeg: canonicalBoundaries };
50
- }
51
- function sortRadarFrameByAzimuth(frame) {
52
- const nRays = frame.nRays;
53
- const nGates = frame.nGates;
54
- const bytesPerRay = nGates * 2;
55
- const rayOrder = Array.from({ length: nRays }, (_, i) => i).sort(
56
- (a, b) => frame.rayBoundariesDeg[a] - frame.rayBoundariesDeg[b]
57
- );
58
- const sortedGateData = new Uint8Array(nRays * bytesPerRay);
59
- const sortedBoundaries = new Float32Array(nRays + 1);
60
- for (let newIdx = 0; newIdx < nRays; newIdx++) {
61
- const oldIdx = rayOrder[newIdx];
62
- sortedGateData.set(
63
- frame.gateData.subarray(oldIdx * bytesPerRay, (oldIdx + 1) * bytesPerRay),
64
- newIdx * bytesPerRay
65
- );
66
- sortedBoundaries[newIdx] = frame.rayBoundariesDeg[oldIdx];
67
- }
68
- sortedBoundaries[nRays] = frame.rayBoundariesDeg[rayOrder[nRays - 1]] + (frame.rayBoundariesDeg[rayOrder[1]] - frame.rayBoundariesDeg[rayOrder[0]]);
69
- return { ...frame, gateData: sortedGateData, rayBoundariesDeg: sortedBoundaries };
70
- }
71
- function prepareRadarFrameForGpuReadout(frame, options) {
72
- const hasLayoutKey = options?.geometryLayoutKey != null && options.geometryLayoutKey !== "";
73
- return hasLayoutKey ? canonicalBinsRadarFrame(frame) : sortRadarFrameByAzimuth(frame);
74
- }
75
- export {
76
- canonicalBinsRadarFrame,
77
- prepareRadarFrameForGpuReadout,
78
- sortRadarFrameByAzimuth
79
- };
1
+ function A(a,r){let o=Math.abs(a-r)%360;return o>180&&(o=360-o),o}function f(a){const r=a.nRays,o=a.nGates;if(r<=0||o<=0||a.rayBoundariesDeg.length<r+1)return a;const s=360/r,u=o*2,i=new Float32Array(r);for(let e=0;e<r;e++){const c=a.rayBoundariesDeg[e],y=a.rayBoundariesDeg[e+1],l=(c+y)*.5;i[e]=(l%360+360)%360}const n=new Uint8Array(r*u);for(let e=0;e<n.length;e+=2)n[e]=128;const t=new Array(r).fill(!1);for(let e=0;e<r;e++){const c=((e+.5)*s%360+360)%360;let y=-1,l=1/0;for(let g=0;g<r;g++){if(t[g])continue;const D=A(i[g],c);D<l&&(l=D,y=g)}y>=0&&(t[y]=!0,n.set(a.gateData.subarray(y*u,(y+1)*u),e*u))}const d=new Float32Array(r+1);for(let e=0;e<=r;e++)d[e]=e*s;return{...a,gateData:n,rayBoundariesDeg:d}}function B(a){const r=a.nRays,o=a.nGates*2,s=Array.from({length:r},(n,t)=>t).sort((n,t)=>a.rayBoundariesDeg[n]-a.rayBoundariesDeg[t]),u=new Uint8Array(r*o),i=new Float32Array(r+1);for(let n=0;n<r;n++){const t=s[n];u.set(a.gateData.subarray(t*o,(t+1)*o),n*o),i[n]=a.rayBoundariesDeg[t]}return i[r]=a.rayBoundariesDeg[s[r-1]]+(a.rayBoundariesDeg[s[1]]-a.rayBoundariesDeg[s[0]]),{...a,gateData:u,rayBoundariesDeg:i}}function m(a,r){return r?.geometryLayoutKey!=null&&r.geometryLayoutKey!==""?f(a):B(a)}export{f as canonicalBinsRadarFrame,m as prepareRadarFrameForGpuReadout,B as sortRadarFrameByAzimuth};
@@ -0,0 +1 @@
1
+ import{Platform as o,UIManager as t}from"react-native";const n="NexradRadarLayer",d=Object.freeze({uploadNexradFrame:1,uploadNexradStyleOnly:2,clearNexrad:3,activateNexradCachedFrame:4});export function resolveNexradCommandId(a){if(o.OS==="ios")return a;try{const r=t.getViewManagerConfig(n)?.Commands?.[a];if(r!=null&&r!==void 0)return r}catch{}const e=d[a];return e!==void 0?e:null}
@@ -1 +1 @@
1
- export { default, resolveNwsAndroidLayerAnchors } from './NwsAlertsOverlay.native.js';
1
+ export{default,resolveNwsAndroidLayerAnchors}from"./NwsAlertsOverlay.native.js";
@@ -1 +1 @@
1
- export { default, resolveNwsAndroidLayerAnchors } from './NwsAlertsOverlay.native.js';
1
+ export{default,resolveNwsAndroidLayerAnchors}from"./NwsAlertsOverlay.native.js";
@@ -1,7 +1 @@
1
- import { Platform } from 'react-native';
2
-
3
- export default Platform.select({
4
- android: require('./NwsAlertsOverlay.android.js').default,
5
- ios: require('./NwsAlertsOverlay.ios.js').default,
6
- default: require('./NwsAlertsOverlay.ios.js').default,
7
- });
1
+ import{Platform as e}from"react-native";export default e.select({android:require("./NwsAlertsOverlay.android.js").default,ios:require("./NwsAlertsOverlay.ios.js").default,default:require("./NwsAlertsOverlay.ios.js").default});
@@ -1,463 +1 @@
1
- /**
2
- * NWS watches/warnings for React Native (iOS + Android) — parity with {@link NwsWatchesWarningsOverlay}
3
- * (archived / slider time via {@link NwsWatchesWarningsOverlay#syncWithMode}, same customization options).
4
- *
5
- * Uses the javascript-sdk NWS overlay engine with a stub Mapbox GL object; GeoJSON + layers render via @rnmapbox/maps.
6
- */
7
-
8
- import './eventSourceRnPolyfill.js';
9
-
10
- import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
11
- import Mapbox from '@rnmapbox/maps';
12
- /** Subpath imports avoid Metro/barrel init ordering where the package root can yield undefined named exports during RN startup. */
13
- import { NwsWatchesWarningsOverlay, NWS_DEFAULT_LINE_BEFORE_LAYER_ID } from '@aguacerowx/javascript-sdk/nws/NwsWatchesWarningsOverlay.js';
14
- import { buildNwsLineDasharrayLiteralExpression } from '@aguacerowx/javascript-sdk/nws/nwsSdkConstants.js';
15
- import { buildAlertClickPayload, normalizeFeatureCollectionForMapboxGl } from '@aguacerowx/javascript-sdk/nws/nwsAlertsSupport.js';
16
- import { computeNwsAlertsFetchHoursFromAguaceroState } from '@aguacerowx/javascript-sdk/nws/nwsAlertsFetchSpec.js';
17
- import { mapRegistry } from '../MapRegistry';
18
- import { AGUACERO_NEXRAD_MAP_LAYER_ID, AGUACERO_SATELLITE_MAP_LAYER_ID } from './nwsAndroidConstants.js';
19
-
20
- const SOURCE_ID = 'aguacero-nws-alerts-source';
21
- const FILL_ID = 'aguacero-nws-alerts-fill';
22
- const LINE_CASING_ID = 'aguacero-nws-alerts-line-casing';
23
- const LINE_CORE_ID = 'aguacero-nws-alerts-line-core';
24
-
25
- class AndroidNwsOverlay extends NwsWatchesWarningsOverlay {
26
- /**
27
- * @param {object} map
28
- * @param {object} options
29
- * @param {(paint: object) => void} onPaint
30
- */
31
- constructor(map, options, onPaint) {
32
- super(map, options);
33
- this._onPaint = onPaint;
34
- }
35
-
36
- /**
37
- * @rnmapbox/maps does not support data-driven `line-dasharray` (match on `event_name`).
38
- * Keep web parity for colors; dash style follows {@link NwsWatchesWarningsOverlay} default `lineDash` only on RN.
39
- */
40
- _buildPaint() {
41
- const p = super._buildPaint();
42
- const mode = this._nwsAlertSettings?.lineDash ?? 'solid';
43
- return {
44
- ...p,
45
- lineDashExpr: buildNwsLineDasharrayLiteralExpression(mode),
46
- fillOpacityExpr: Array.isArray(p.fillOpacityExpr) && p.fillOpacityExpr.length > 2 ? p.fillOpacityExpr[2] : p.fillOpacityExpr,
47
- lineOpacityExpr: Array.isArray(p.lineOpacityExpr) && p.lineOpacityExpr.length > 2 ? p.lineOpacityExpr[2] : p.lineOpacityExpr,
48
- };
49
- }
50
-
51
- /**
52
- * RN renders ShapeSource + layers declaratively (same ids). Only sync GeoJSON + paint; skip imperative addLayer.
53
- */
54
- _ensureLayers() {
55
- const m = this.map;
56
- if (!m?.addSource) return;
57
-
58
- const paint = this._buildPaint();
59
- if (this._onPaint) this._onPaint(paint);
60
-
61
- const sourceData = normalizeFeatureCollectionForMapboxGl(this._workingFc);
62
- if (!m.getSource(this._sourceId)) {
63
- m.addSource(this._sourceId, {
64
- type: 'geojson',
65
- data: sourceData,
66
- });
67
- } else {
68
- m.getSource(this._sourceId).setData(sourceData);
69
- }
70
- }
71
-
72
- _refreshPaint() {
73
- if (this._onPaint) this._onPaint(this._buildPaint());
74
- }
75
-
76
- _applyLayerOrder() {}
77
-
78
- _syncClickHandler() {}
79
- }
80
-
81
- /**
82
- * @param {object} handlers
83
- * @param {() => import('@rnmapbox/maps').default | null} handlers.getMapboxMapView
84
- * @param {(shape: object) => void} handlers.onShape
85
- * @param {() => void} [handlers.onLayersCleared]
86
- */
87
- function createFeatureStateBatcher(handlers) {
88
- /** @type {Map<string, object>} */
89
- const pendingStates = new Map();
90
- let rafId = null;
91
-
92
- function flush() {
93
- rafId = null;
94
- if (handlers.onFeatureStates) {
95
- const activeIds = [];
96
- for (const [fid, state] of pendingStates) {
97
- if (state && state.active !== false) {
98
- activeIds.push(fid);
99
- }
100
- }
101
- handlers.onFeatureStates(activeIds);
102
- }
103
- }
104
-
105
- return {
106
- push(fid, state, sid) {
107
- pendingStates.set(fid, state);
108
- if (rafId == null) {
109
- rafId = requestAnimationFrame(flush);
110
- }
111
- },
112
- clear() {
113
- pendingStates.clear();
114
- if (rafId != null) {
115
- cancelAnimationFrame(rafId);
116
- rafId = null;
117
- }
118
- if (handlers.onFeatureStates) {
119
- handlers.onFeatureStates(null);
120
- }
121
- },
122
- };
123
- }
124
-
125
- function createAndroidNwsStubMap(handlers) {
126
- let sourceAdded = false;
127
- /** Declarative RN layers use the same ids — treat as present after first {@link AndroidNwsOverlay#_ensureLayers}. */
128
- let declarativeLayersReady = false;
129
- const featureStateBatcher = createFeatureStateBatcher(handlers);
130
-
131
- return {
132
- isStyleLoaded: () => true,
133
- once(ev, fn) {
134
- if (ev === 'style.load') {
135
- queueMicrotask(() => fn({ target: {} }));
136
- }
137
- },
138
- __markDeclarativeLayersReady() {
139
- declarativeLayersReady = true;
140
- },
141
- addSource(id, spec) {
142
- if (id === SOURCE_ID) {
143
- sourceAdded = true;
144
- if (spec?.data) handlers.onShape(spec.data);
145
- }
146
- },
147
- getSource(id) {
148
- if (!sourceAdded || id !== SOURCE_ID) return null;
149
- return {
150
- setData: (geojson) => handlers.onShape(geojson),
151
- };
152
- },
153
- addLayer() {},
154
- removeLayer(id) {
155
- if ([FILL_ID, LINE_CASING_ID, LINE_CORE_ID].includes(id)) {
156
- declarativeLayersReady = false;
157
- featureStateBatcher.clear();
158
- handlers.onLayersCleared?.();
159
- }
160
- },
161
- removeSource(id) {
162
- if (id === SOURCE_ID) {
163
- sourceAdded = false;
164
- declarativeLayersReady = false;
165
- featureStateBatcher.clear();
166
- handlers.onLayersCleared?.();
167
- }
168
- },
169
- getLayer(id) {
170
- if (!declarativeLayersReady) return null;
171
- return [FILL_ID, LINE_CASING_ID, LINE_CORE_ID].includes(id) ? { id } : null;
172
- },
173
- getStyle() {
174
- return { layers: [] };
175
- },
176
- moveLayer() {},
177
- setPaintProperty() {},
178
- on() {},
179
- off() {},
180
- fire() {},
181
- setFeatureState(target, state) {
182
- const sid = target?.source;
183
- const fid = target?.id;
184
- if (sid !== SOURCE_ID || fid == null) return;
185
- try {
186
- featureStateBatcher.push(fid, state, sid);
187
- } catch {
188
- /* ignore */
189
- }
190
- },
191
- };
192
- }
193
-
194
- /**
195
- * @param {object} state - {@link AguaceroCore} state
196
- * @param {object} wopt - watches/warnings options (same shape as mapsgl {@link WeatherLayerManager#configureWatchesWarnings})
197
- * @returns {{ weatherLayerId: string | null, fillBelowId: string | null, lineBelowId: string }}
198
- */
199
- export function resolveNwsAndroidLayerAnchors(state, wopt) {
200
- const manualFill = Object.prototype.hasOwnProperty.call(wopt, 'fillBeforeLayerId')
201
- ? wopt.fillBeforeLayerId ?? null
202
- : null;
203
-
204
- let weatherLayerId = null;
205
- if (state?.isNexrad) {
206
- weatherLayerId = AGUACERO_NEXRAD_MAP_LAYER_ID;
207
- } else if (state?.isSatellite) {
208
- weatherLayerId = AGUACERO_SATELLITE_MAP_LAYER_ID;
209
- } else if (state?.isMRMS && state?.variable) {
210
- weatherLayerId = 'aguacero-weather-grid-custom';
211
- }
212
-
213
- const fillBelowId =
214
- manualFill != null && String(manualFill) !== ''
215
- ? String(manualFill)
216
- : weatherLayerId || NWS_DEFAULT_LINE_BEFORE_LAYER_ID;
217
-
218
- const lineBelowId = wopt.lineBeforeLayerId || NWS_DEFAULT_LINE_BEFORE_LAYER_ID;
219
-
220
- return { weatherLayerId, fillBelowId, lineBelowId };
221
- }
222
-
223
- /**
224
- * @param {object} props
225
- * @param {import('@aguacerowx/javascript-sdk').AguaceroCore} props.core
226
- * @param {object} props.watchesWarnings - merged options ({ enabled, alertsBaseUrl, nwsAlertSettings, ... })
227
- * @param {(payload: object) => void} [props.onNwsAlertClick]
228
- */
229
- export default function NwsAlertsOverlay({ core, watchesWarnings, onNwsAlertClick }) {
230
- const [aguaceroState, setAguaceroState] = useState(() => core?.state);
231
-
232
- useEffect(() => {
233
- if (!core) return undefined;
234
- const h = (s) => setAguaceroState(s);
235
- core.on('state:change', h);
236
- return () => core.off('state:change', h);
237
- }, [core]);
238
-
239
- const [shape, setShape] = useState({ type: 'FeatureCollection', features: [] });
240
- const [paint, setPaint] = useState(null);
241
- const [activeIds, setActiveIds] = useState(null);
242
-
243
- const overlayRef = useRef(null);
244
- const stubRef = useRef(null);
245
- const watchesRef = useRef(watchesWarnings);
246
- const optsKeyRef = useRef('');
247
-
248
- watchesRef.current = watchesWarnings;
249
-
250
- const getMapboxMapView = useCallback(() => mapRegistry.getMap(), []);
251
-
252
- const anchors = useMemo(
253
- () => resolveNwsAndroidLayerAnchors(aguaceroState, watchesWarnings || {}),
254
- [aguaceroState, watchesWarnings],
255
- );
256
-
257
- useEffect(() => {
258
- const onPaint = (p) => setPaint(p);
259
-
260
- const stub = createAndroidNwsStubMap({
261
- getMapboxMapView,
262
- onShape: (g) => setShape(g),
263
- onFeatureStates: (ids) => setActiveIds(ids),
264
- onLayersCleared: () => {
265
- setPaint(null);
266
- setActiveIds(null);
267
- },
268
- });
269
- stubRef.current = stub;
270
-
271
- const w0 = watchesRef.current || {};
272
- const overlay = new AndroidNwsOverlay(stub, w0, onPaint);
273
- overlayRef.current = overlay;
274
-
275
- return () => {
276
- overlay.destroy();
277
- overlayRef.current = null;
278
- stubRef.current = null;
279
- };
280
- }, [getMapboxMapView]);
281
-
282
- useEffect(() => {
283
- const ov = overlayRef.current;
284
- if (!ov) return;
285
-
286
- const wopt = watchesWarnings || {};
287
- const nwsAlertSettingsForOpts = {
288
- ...(wopt.nwsAlertSettings ?? {}),
289
- ...(wopt.activeOnlyRealtime !== undefined ? { activeOnlyRealtime: wopt.activeOnlyRealtime } : {}),
290
- };
291
-
292
- const weatherLayerId = anchors.weatherLayerId;
293
- const fillBeforeLayerId = Object.prototype.hasOwnProperty.call(wopt, 'fillBeforeLayerId')
294
- ? wopt.fillBeforeLayerId ?? null
295
- : null;
296
-
297
- const nwsOptsKey = JSON.stringify({
298
- weatherLayerId,
299
- fillBeforeLayerId,
300
- lineBeforeLayerId: wopt.lineBeforeLayerId,
301
- alertsBaseUrl: wopt.alertsBaseUrl,
302
- alertInteractionEnabled: wopt.alertInteractionEnabled,
303
- deltaDebounceMs: wopt.deltaDebounceMs,
304
- fillOpacity: wopt.fillOpacity,
305
- lineOpacity: wopt.lineOpacity,
306
- lineWidth: wopt.lineWidth,
307
- nwsAlertSettings: nwsAlertSettingsForOpts,
308
- });
309
-
310
- if (optsKeyRef.current !== nwsOptsKey) {
311
- optsKeyRef.current = nwsOptsKey;
312
- ov.updateOptions({
313
- alertsBaseUrl: wopt.alertsBaseUrl,
314
- alertInteractionEnabled: wopt.alertInteractionEnabled,
315
- deltaDebounceMs: wopt.deltaDebounceMs,
316
- fillOpacity: wopt.fillOpacity,
317
- lineOpacity: wopt.lineOpacity,
318
- lineWidth: wopt.lineWidth,
319
- weatherLayerId,
320
- fillBeforeLayerId,
321
- lineBeforeLayerId: wopt.lineBeforeLayerId,
322
- nwsAlertSettings: nwsAlertSettingsForOpts,
323
- });
324
- }
325
- }, [watchesWarnings, anchors.weatherLayerId]);
326
-
327
- useEffect(() => {
328
- const ov = overlayRef.current;
329
- if (!ov || !aguaceroState) return;
330
-
331
- const wopt = watchesWarnings || {};
332
- const masterEnabled = wopt.enabled === true;
333
- const enabled = masterEnabled;
334
-
335
- let timelineUnix = null;
336
- let timelineTimes = null;
337
- const st = aguaceroState;
338
- if (st.isSatellite) {
339
- timelineUnix = st.satelliteTimestamp == null ? null : Number(st.satelliteTimestamp);
340
- timelineTimes = st.availableSatelliteTimestamps;
341
- } else if (st.isNexrad) {
342
- timelineUnix = st.nexradTimestamp == null ? null : Number(st.nexradTimestamp);
343
- timelineTimes = st.availableNexradTimestamps;
344
- } else if (st.isMRMS) {
345
- timelineUnix = st.mrmsTimestamp == null ? null : Number(st.mrmsTimestamp);
346
- timelineTimes = st.availableTimestamps;
347
- }
348
-
349
- const hasObservationTimeline = !!(st.isSatellite || st.isNexrad || st.isMRMS);
350
- const alertsFetchHours = computeNwsAlertsFetchHoursFromAguaceroState(st);
351
-
352
- ov.syncWithMode({
353
- enabled,
354
- timelineUnix,
355
- timelineTimes,
356
- hasObservationTimeline,
357
- alertsFetchHours,
358
- });
359
- }, [aguaceroState, watchesWarnings]);
360
-
361
- useLayoutEffect(() => {
362
- const stub = stubRef.current;
363
- const ov = overlayRef.current;
364
- if (!stub || !ov || !paint) return;
365
- stub.__markDeclarativeLayersReady();
366
- try {
367
- ov._applyTimeFilters();
368
- } catch {
369
- /* ignore */
370
- }
371
- }, [paint, shape, aguaceroState?.nexradTimestamp, aguaceroState?.mrmsTimestamp, aguaceroState?.satelliteTimestamp]);
372
-
373
- useEffect(() => {
374
- if (!onNwsAlertClick) return undefined;
375
-
376
- const handler = async (payload) => {
377
- const wopt = watchesRef.current || {};
378
- if (!wopt.enabled || wopt.alertInteractionEnabled === false) return;
379
-
380
- const mapView = mapRegistry.getMap();
381
- if (!mapView?.queryRenderedFeaturesAtPoint) return;
382
-
383
- let screenPoint = null;
384
- if (payload?.properties?.screenPointX != null && payload?.properties?.screenPointY != null) {
385
- screenPoint = [payload.properties.screenPointX, payload.properties.screenPointY];
386
- } else if (payload?.point != null && Array.isArray(payload.point)) {
387
- screenPoint = payload.point;
388
- }
389
- if (!screenPoint) return;
390
-
391
- let feats = await mapView.queryRenderedFeaturesAtPoint(screenPoint, undefined, [
392
- FILL_ID,
393
- LINE_CASING_ID,
394
- LINE_CORE_ID,
395
- ]);
396
- if (!feats?.length && payload?.coordinates) {
397
- const coord = payload.coordinates;
398
- const pt = await mapView.getPointInView(coord);
399
- if (pt) feats = await mapView.queryRenderedFeaturesAtPoint(pt, undefined, [FILL_ID, LINE_CASING_ID, LINE_CORE_ID]);
400
- }
401
- const hit = feats?.find((f) =>
402
- [FILL_ID, LINE_CASING_ID, LINE_CORE_ID].includes(f?.layer?.id),
403
- );
404
- if (!hit?.properties) return;
405
- try {
406
- const built = buildAlertClickPayload(hit);
407
- onNwsAlertClick({ ...built, feature: hit });
408
- } catch {
409
- /* ignore */
410
- }
411
- };
412
-
413
- mapRegistry.addPressListener(handler);
414
- return () => mapRegistry.removePressListener(handler);
415
- }, [onNwsAlertClick]);
416
-
417
- if (!paint) {
418
- return null;
419
- }
420
-
421
- const p = paint;
422
- const lineLayout = p.lineLayout ?? {};
423
- const lineCap = lineLayout['line-cap'] ?? 'round';
424
- const lineJoin = lineLayout['line-join'] ?? 'round';
425
- const lineSortKey = lineLayout['line-sort-key'] ?? ['coalesce', ['get', '_nws_render_priority'], 0];
426
- const fillSortKey = ['coalesce', ['get', '_nws_render_priority'], 0];
427
-
428
- const fillStyle = {
429
- fillColor: p.fillColorExpr,
430
- fillOpacity: p.fillOpacityExpr,
431
- fillSortKey,
432
- };
433
- const casingStyle = {
434
- lineColor: p.dualLine.casingColor,
435
- lineWidth: p.dualLine.casingWidth,
436
- lineOpacity: p.lineOpacityExpr,
437
- lineDasharray: p.lineDashExpr,
438
- lineCap,
439
- lineJoin,
440
- lineSortKey,
441
- };
442
- const coreStyle = {
443
- lineColor: p.dualLine.coreColor,
444
- lineWidth: p.dualLine.coreWidth,
445
- lineOpacity: p.lineOpacityExpr,
446
- lineDasharray: p.lineDashExpr,
447
- lineCap,
448
- lineJoin,
449
- lineSortKey,
450
- };
451
-
452
- const activeFilter = activeIds
453
- ? (activeIds.length > 0 ? ['in', ['id'], ['literal', activeIds]] : ['==', ['id'], -1])
454
- : ['==', ['id'], -1];
455
-
456
- return (
457
- <Mapbox.ShapeSource id={SOURCE_ID} shape={shape}>
458
- <Mapbox.FillLayer id={FILL_ID} belowLayerID={anchors.fillBelowId} style={fillStyle} filter={activeFilter} />
459
- <Mapbox.LineLayer id={LINE_CASING_ID} belowLayerID={anchors.lineBelowId} style={casingStyle} filter={activeFilter} />
460
- <Mapbox.LineLayer id={LINE_CORE_ID} belowLayerID={anchors.lineBelowId} style={coreStyle} filter={activeFilter} />
461
- </Mapbox.ShapeSource>
462
- );
463
- }
1
+ import"./eventSourceRnPolyfill.js";import I,{useCallback as K,useEffect as g,useLayoutEffect as X,useMemo as V,useRef as b,useState as A}from"react";import x from"@rnmapbox/maps";import{NwsWatchesWarningsOverlay as z,NWS_DEFAULT_LINE_BEFORE_LAYER_ID as Y}from"@aguacerowx/javascript-sdk/nws/NwsWatchesWarningsOverlay.js";import{buildNwsLineDasharrayLiteralExpression as Q}from"@aguacerowx/javascript-sdk/nws/nwsSdkConstants.js";import{buildAlertClickPayload as Z,normalizeFeatureCollectionForMapboxGl as $}from"@aguacerowx/javascript-sdk/nws/nwsAlertsSupport.js";import{computeNwsAlertsFetchHoursFromAguaceroState as ee}from"@aguacerowx/javascript-sdk/nws/nwsAlertsFetchSpec.js";import{mapRegistry as P}from"../MapRegistry";import{AGUACERO_NEXRAD_MAP_LAYER_ID as te,AGUACERO_SATELLITE_MAP_LAYER_ID as re}from"./nwsAndroidConstants.js";const O="aguacero-nws-alerts-source",m="aguacero-nws-alerts-fill",h="aguacero-nws-alerts-line-casing",L="aguacero-nws-alerts-line-core";class ae extends z{constructor(t,a,n){super(t,a),this._onPaint=n}_buildPaint(){const t=super._buildPaint(),a=this._nwsAlertSettings?.lineDash??"solid";return{...t,lineDashExpr:Q(a),fillOpacityExpr:Array.isArray(t.fillOpacityExpr)&&t.fillOpacityExpr.length>2?t.fillOpacityExpr[2]:t.fillOpacityExpr,lineOpacityExpr:Array.isArray(t.lineOpacityExpr)&&t.lineOpacityExpr.length>2?t.lineOpacityExpr[2]:t.lineOpacityExpr}}_ensureLayers(){const t=this.map;if(!t?.addSource)return;const a=this._buildPaint();this._onPaint&&this._onPaint(a);const n=$(this._workingFc);t.getSource(this._sourceId)?t.getSource(this._sourceId).setData(n):t.addSource(this._sourceId,{type:"geojson",data:n})}_refreshPaint(){this._onPaint&&this._onPaint(this._buildPaint())}_applyLayerOrder(){}_syncClickHandler(){}}function ne(l){const t=new Map;let a=null;function n(){if(a=null,l.onFeatureStates){const i=[];for(const[s,p]of t)p&&p.active!==!1&&i.push(s);l.onFeatureStates(i)}}return{push(i,s,p){t.set(i,s),a==null&&(a=requestAnimationFrame(n))},clear(){t.clear(),a!=null&&(cancelAnimationFrame(a),a=null),l.onFeatureStates&&l.onFeatureStates(null)}}}function ie(l){let t=!1,a=!1;const n=ne(l);return{isStyleLoaded:()=>!0,once(i,s){i==="style.load"&&queueMicrotask(()=>s({target:{}}))},__markDeclarativeLayersReady(){a=!0},addSource(i,s){i===O&&(t=!0,s?.data&&l.onShape(s.data))},getSource(i){return!t||i!==O?null:{setData:s=>l.onShape(s)}},addLayer(){},removeLayer(i){[m,h,L].includes(i)&&(a=!1,n.clear(),l.onLayersCleared?.())},removeSource(i){i===O&&(t=!1,a=!1,n.clear(),l.onLayersCleared?.())},getLayer(i){return a&&[m,h,L].includes(i)?{id:i}:null},getStyle(){return{layers:[]}},moveLayer(){},setPaintProperty(){},on(){},off(){},fire(){},setFeatureState(i,s){const p=i?.source,f=i?.id;if(!(p!==O||f==null))try{n.push(f,s,p)}catch{}}}}export function resolveNwsAndroidLayerAnchors(l,t){const a=Object.prototype.hasOwnProperty.call(t,"fillBeforeLayerId")?t.fillBeforeLayerId??null:null;let n=null;l?.isNexrad?n=te:l?.isSatellite?n=re:l?.isMRMS&&l?.variable&&(n="aguacero-weather-grid-custom");const i=a!=null&&String(a)!==""?String(a):n||Y,s=t.lineBeforeLayerId||Y;return{weatherLayerId:n,fillBelowId:i,lineBelowId:s}}export default function le({core:l,watchesWarnings:t,onNwsAlertClick:a}){const[n,i]=A(()=>l?.state);g(()=>{if(!l)return;const o=e=>i(e);return l.on("state:change",o),()=>l.off("state:change",o)},[l]);const[s,p]=A({type:"FeatureCollection",features:[]}),[f,R]=A(null),[D,C]=A(null),_=b(null),F=b(null),B=b(t),T=b("");B.current=t;const N=K(()=>P.getMap(),[]),w=V(()=>resolveNwsAndroidLayerAnchors(n,t||{}),[n,t]);if(g(()=>{const o=r=>R(r),e=ie({getMapboxMapView:N,onShape:r=>p(r),onFeatureStates:r=>C(r),onLayersCleared:()=>{R(null),C(null)}});F.current=e;const u=B.current||{},c=new ae(e,u,o);return _.current=c,()=>{c.destroy(),_.current=null,F.current=null}},[N]),g(()=>{const o=_.current;if(!o)return;const e=t||{},u={...e.nwsAlertSettings??{},...e.activeOnlyRealtime!==void 0?{activeOnlyRealtime:e.activeOnlyRealtime}:{}},c=w.weatherLayerId,r=Object.prototype.hasOwnProperty.call(e,"fillBeforeLayerId")?e.fillBeforeLayerId??null:null,y=JSON.stringify({weatherLayerId:c,fillBeforeLayerId:r,lineBeforeLayerId:e.lineBeforeLayerId,alertsBaseUrl:e.alertsBaseUrl,alertInteractionEnabled:e.alertInteractionEnabled,deltaDebounceMs:e.deltaDebounceMs,fillOpacity:e.fillOpacity,lineOpacity:e.lineOpacity,lineWidth:e.lineWidth,nwsAlertSettings:u});T.current!==y&&(T.current=y,o.updateOptions({alertsBaseUrl:e.alertsBaseUrl,alertInteractionEnabled:e.alertInteractionEnabled,deltaDebounceMs:e.deltaDebounceMs,fillOpacity:e.fillOpacity,lineOpacity:e.lineOpacity,lineWidth:e.lineWidth,weatherLayerId:c,fillBeforeLayerId:r,lineBeforeLayerId:e.lineBeforeLayerId,nwsAlertSettings:u}))},[t,w.weatherLayerId]),g(()=>{const o=_.current;if(!o||!n)return;const e=(t||{}).enabled===!0;let u=null,c=null;const r=n;r.isSatellite?(u=r.satelliteTimestamp==null?null:Number(r.satelliteTimestamp),c=r.availableSatelliteTimestamps):r.isNexrad?(u=r.nexradTimestamp==null?null:Number(r.nexradTimestamp),c=r.availableNexradTimestamps):r.isMRMS&&(u=r.mrmsTimestamp==null?null:Number(r.mrmsTimestamp),c=r.availableTimestamps);const y=!!(r.isSatellite||r.isNexrad||r.isMRMS),E=ee(r);o.syncWithMode({enabled:e,timelineUnix:u,timelineTimes:c,hasObservationTimeline:y,alertsFetchHours:E})},[n,t]),X(()=>{const o=F.current,e=_.current;if(!(!o||!e||!f)){o.__markDeclarativeLayersReady();try{e._applyTimeFilters()}catch{}}},[f,s,n?.nexradTimestamp,n?.mrmsTimestamp,n?.satelliteTimestamp]),g(()=>{if(!a)return;const o=async e=>{const u=B.current||{};if(!u.enabled||u.alertInteractionEnabled===!1)return;const c=P.getMap();if(!c?.queryRenderedFeaturesAtPoint)return;let r=null;if(e?.properties?.screenPointX!=null&&e?.properties?.screenPointY!=null?r=[e.properties.screenPointX,e.properties.screenPointY]:e?.point!=null&&Array.isArray(e.point)&&(r=e.point),!r)return;let y=await c.queryRenderedFeaturesAtPoint(r,void 0,[m,h,L]);if(!y?.length&&e?.coordinates){const S=e.coordinates,q=await c.getPointInView(S);q&&(y=await c.queryRenderedFeaturesAtPoint(q,void 0,[m,h,L]))}const E=y?.find(S=>[m,h,L].includes(S?.layer?.id));if(E?.properties)try{const S=Z(E);a({...S,feature:E})}catch{}};return P.addPressListener(o),()=>P.removePressListener(o)},[a]),!f)return null;const d=f,M=d.lineLayout??{},W=M["line-cap"]??"round",k=M["line-join"]??"round",U=M["line-sort-key"]??["coalesce",["get","_nws_render_priority"],0],j=["coalesce",["get","_nws_render_priority"],0],G={fillColor:d.fillColorExpr,fillOpacity:d.fillOpacityExpr,fillSortKey:j},H={lineColor:d.dualLine.casingColor,lineWidth:d.dualLine.casingWidth,lineOpacity:d.lineOpacityExpr,lineDasharray:d.lineDashExpr,lineCap:W,lineJoin:k,lineSortKey:U},J={lineColor:d.dualLine.coreColor,lineWidth:d.dualLine.coreWidth,lineOpacity:d.lineOpacityExpr,lineDasharray:d.lineDashExpr,lineCap:W,lineJoin:k,lineSortKey:U},v=D?D.length>0?["in",["id"],["literal",D]]:["==",["id"],-1]:["==",["id"],-1];return I.createElement(x.ShapeSource,{id:O,shape:s},I.createElement(x.FillLayer,{id:m,belowLayerID:w.fillBelowId,style:G,filter:v}),I.createElement(x.LineLayer,{id:h,belowLayerID:w.lineBelowId,style:H,filter:v}),I.createElement(x.LineLayer,{id:L,belowLayerID:w.lineBelowId,style:J,filter:v}))}