@aguacerowx/react-native 0.0.20 → 0.0.22
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.
- package/android/src/main/java/com/aguacerowx/reactnative/GridRenderLayer.java +42 -5
- package/android/src/main/res/raw/fragment_shader.glsl +18 -8
- package/ios/FragmentUniforms.swift +2 -0
- package/ios/GridRenderLayer.swift +24 -4
- package/ios/GridRenderLayerManager.mm +12 -0
- package/ios/GridRenderLayerView.h +1 -7
- package/ios/GridRenderLayerView.m +7 -1
- package/ios/Shaders.metal +131 -71
- package/ios/compiled-shaders/Shaders-device.metallib +0 -0
- package/ios/compiled-shaders/Shaders-simulator.metallib +0 -0
- package/lib/commonjs/android/src/main/java/com/aguacerowx/reactnative/GridRenderLayer.java +42 -5
- package/lib/commonjs/android/src/main/res/raw/fragment_shader.glsl +18 -8
- package/lib/commonjs/ios/FragmentUniforms.swift +2 -0
- package/lib/commonjs/ios/GridRenderLayer.swift +24 -4
- package/lib/commonjs/ios/GridRenderLayerManager.mm +12 -0
- package/lib/commonjs/ios/GridRenderLayerView.h +1 -7
- package/lib/commonjs/ios/GridRenderLayerView.m +7 -1
- package/lib/commonjs/ios/Shaders.metal +131 -71
- package/lib/commonjs/ios/compiled-shaders/Shaders-device.metallib +0 -0
- package/lib/commonjs/ios/compiled-shaders/Shaders-simulator.metallib +0 -0
- package/lib/commonjs/package.json +3 -3
- package/lib/commonjs/scripts/compile-shaders.js +62 -0
- package/lib/commonjs/scripts/compile-shaders.js.map +1 -0
- package/lib/commonjs/scripts/compile-shaders.sh +12 -0
- package/lib/commonjs/src/WeatherLayerManager.js +51 -17
- package/lib/commonjs/src/WeatherLayerManager.js.map +1 -1
- package/lib/module/android/src/main/java/com/aguacerowx/reactnative/GridRenderLayer.java +42 -5
- package/lib/module/android/src/main/res/raw/fragment_shader.glsl +18 -8
- package/lib/module/ios/FragmentUniforms.swift +2 -0
- package/lib/module/ios/GridRenderLayer.swift +24 -4
- package/lib/module/ios/GridRenderLayerManager.mm +12 -0
- package/lib/module/ios/GridRenderLayerView.h +1 -7
- package/lib/module/ios/GridRenderLayerView.m +7 -1
- package/lib/module/ios/Shaders.metal +131 -71
- package/lib/module/ios/compiled-shaders/Shaders-device.metallib +0 -0
- package/lib/module/ios/compiled-shaders/Shaders-simulator.metallib +0 -0
- package/lib/module/lib/commonjs/package.json +3 -3
- package/lib/module/lib/commonjs/scripts/compile-shaders.js +62 -0
- package/lib/module/lib/commonjs/scripts/compile-shaders.js.map +1 -0
- package/lib/module/lib/commonjs/src/WeatherLayerManager.js +51 -17
- package/lib/module/lib/commonjs/src/WeatherLayerManager.js.map +1 -1
- package/lib/module/package.json +3 -3
- package/lib/module/scripts/compile-shaders.js +60 -0
- package/lib/module/scripts/compile-shaders.js.map +1 -0
- package/lib/module/scripts/compile-shaders.sh +12 -0
- package/lib/module/src/WeatherLayerManager.js +51 -17
- package/lib/module/src/WeatherLayerManager.js.map +1 -1
- package/lib/typescript/scripts/compile-shaders.d.ts +3 -0
- package/lib/typescript/scripts/compile-shaders.d.ts.map +1 -0
- package/lib/typescript/src/WeatherLayerManager.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/WeatherLayerManager.js +192 -151
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/AguaceroCore.js +0 -1063
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/AguaceroCore.js.map +0 -1
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/coordinate_configs.js +0 -381
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/coordinate_configs.js.map +0 -1
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/default-colormaps.js +0 -1256
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/default-colormaps.js.map +0 -1
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/dictionaries.js +0 -4041
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/dictionaries.js.map +0 -1
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/events.js +0 -38
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/events.js.map +0 -1
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/fill-layer-worker.js +0 -30
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/fill-layer-worker.js.map +0 -1
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/getBundleId.js +0 -27
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/getBundleId.js.map +0 -1
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/index.js +0 -41
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/index.js.map +0 -1
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/map-styles.js +0 -301
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/map-styles.js.map +0 -1
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/unitConversions.js +0 -126
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/unitConversions.js.map +0 -1
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/package.json +0 -48
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/AguaceroCore.js +0 -1055
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/AguaceroCore.js.map +0 -1
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/coordinate_configs.js +0 -381
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/coordinate_configs.js.map +0 -1
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/default-colormaps.js +0 -1256
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/default-colormaps.js.map +0 -1
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/dictionaries.js +0 -4041
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/dictionaries.js.map +0 -1
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/events.js +0 -38
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/events.js.map +0 -1
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/fill-layer-worker.js +0 -30
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/fill-layer-worker.js.map +0 -1
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/getBundleId.js +0 -27
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/getBundleId.js.map +0 -1
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/index.js +0 -41
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/index.js.map +0 -1
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/map-styles.js +0 -301
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/map-styles.js.map +0 -1
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/unitConversions.js +0 -126
- package/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/unitConversions.js.map +0 -1
- package/lib/module/lib/commonjs/android/build.gradle +0 -108
- package/lib/module/lib/commonjs/android/src/main/AndroidManifest.xml +0 -7
- package/lib/module/lib/commonjs/ios/FragmentUniforms.swift +0 -14
- package/lib/module/lib/commonjs/ios/GridRenderLayer.swift +0 -983
- package/lib/module/lib/commonjs/ios/GridRenderLayerBridge.swift +0 -30
- package/lib/module/lib/commonjs/ios/GridRenderLayerManager.mm +0 -146
- package/lib/module/lib/commonjs/ios/GridRenderLayerView.h +0 -23
- package/lib/module/lib/commonjs/ios/GridRenderLayerView.m +0 -199
- package/lib/module/lib/commonjs/ios/InspectorDataCache.swift +0 -66
- package/lib/module/lib/commonjs/ios/InspectorModule.m +0 -10
- package/lib/module/lib/commonjs/ios/InspectorModule.swift +0 -64
- package/lib/module/lib/commonjs/ios/Shaders.metal +0 -131
- package/lib/module/lib/commonjs/ios/WeatherFrameProcessorModule.m +0 -16
- package/lib/module/lib/commonjs/ios/WeatherFrameProcessorModule.swift +0 -104
- package/lib/module/lib/commonjs/ios/compiled-shaders/Shaders-device.metallib +0 -0
- package/lib/module/lib/commonjs/ios/compiled-shaders/Shaders-simulator.metallib +0 -0
- package/lib/module/lib/commonjs/ios/compiled-shaders/Shaders.metallib +0 -0
- package/lib/module/lib/commonjs/ios/generated/AguaceroWxReactNativeSpec-generated.mm +0 -0
- package/lib/module/lib/commonjs/ios/generated/AguaceroWxReactNativeSpec.h +0 -0
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/AguaceroCore.js +0 -1063
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/AguaceroCore.js.map +0 -1
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/coordinate_configs.js +0 -381
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/coordinate_configs.js.map +0 -1
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/default-colormaps.js +0 -1256
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/default-colormaps.js.map +0 -1
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/dictionaries.js +0 -4041
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/dictionaries.js.map +0 -1
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/events.js +0 -38
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/events.js.map +0 -1
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/fill-layer-worker.js +0 -30
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/fill-layer-worker.js.map +0 -1
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/getBundleId.js +0 -27
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/getBundleId.js.map +0 -1
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/index.js +0 -41
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/index.js.map +0 -1
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/map-styles.js +0 -301
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/map-styles.js.map +0 -1
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/unitConversions.js +0 -126
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/dist/unitConversions.js.map +0 -1
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/package.json +0 -48
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/AguaceroCore.js +0 -1059
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/AguaceroCore.js.map +0 -1
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/coordinate_configs.js +0 -381
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/coordinate_configs.js.map +0 -1
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/default-colormaps.js +0 -1256
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/default-colormaps.js.map +0 -1
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/dictionaries.js +0 -4041
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/dictionaries.js.map +0 -1
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/events.js +0 -38
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/events.js.map +0 -1
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/fill-layer-worker.js +0 -30
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/fill-layer-worker.js.map +0 -1
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/getBundleId.js +0 -27
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/getBundleId.js.map +0 -1
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/index.js +0 -41
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/index.js.map +0 -1
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/map-styles.js +0 -301
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/map-styles.js.map +0 -1
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/unitConversions.js +0 -126
- package/lib/module/lib/commonjs/node_modules/@aguacerowx/javascript-sdk/src/unitConversions.js.map +0 -1
- package/lib/module/lib/commonjs/scripts/compile-shaders.sh +0 -27
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/AguaceroCore.js +0 -1063
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/AguaceroCore.js.map +0 -1
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/coordinate_configs.js +0 -381
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/coordinate_configs.js.map +0 -1
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/default-colormaps.js +0 -1256
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/default-colormaps.js.map +0 -1
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/dictionaries.js +0 -4041
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/dictionaries.js.map +0 -1
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/events.js +0 -38
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/events.js.map +0 -1
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/fill-layer-worker.js +0 -30
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/fill-layer-worker.js.map +0 -1
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/getBundleId.js +0 -27
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/getBundleId.js.map +0 -1
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/index.js +0 -41
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/index.js.map +0 -1
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/map-styles.js +0 -301
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/map-styles.js.map +0 -1
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/unitConversions.js +0 -126
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/dist/unitConversions.js.map +0 -1
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/package.json +0 -48
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/AguaceroCore.js +0 -1047
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/AguaceroCore.js.map +0 -1
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/coordinate_configs.js +0 -375
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/coordinate_configs.js.map +0 -1
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/default-colormaps.js +0 -1250
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/default-colormaps.js.map +0 -1
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/dictionaries.js +0 -4035
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/dictionaries.js.map +0 -1
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/events.js +0 -31
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/events.js.map +0 -1
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/fill-layer-worker.js +0 -29
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/fill-layer-worker.js.map +0 -1
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/getBundleId.js +0 -21
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/getBundleId.js.map +0 -1
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/index.js +0 -12
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/index.js.map +0 -1
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/map-styles.js +0 -295
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/map-styles.js.map +0 -1
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/unitConversions.js +0 -119
- package/lib/module/node_modules/@aguacerowx/javascript-sdk/src/unitConversions.js.map +0 -1
|
@@ -1,1055 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.AguaceroCore = void 0;
|
|
7
|
-
var _events = require("./events.js");
|
|
8
|
-
var _coordinate_configs = require("./coordinate_configs.js");
|
|
9
|
-
var _unitConversions = require("./unitConversions.js");
|
|
10
|
-
var _dictionaries = require("./dictionaries.js");
|
|
11
|
-
var _defaultColormaps = require("./default-colormaps.js");
|
|
12
|
-
var _proj = _interopRequireDefault(require("proj4"));
|
|
13
|
-
var _getBundleId = require("./getBundleId");
|
|
14
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
// AguaceroCore.js - The Headless "Engine"
|
|
16
|
-
|
|
17
|
-
// --- Non-UI Imports ---
|
|
18
|
-
|
|
19
|
-
// --- Non-UI Helper Functions ---
|
|
20
|
-
function hrdpsObliqueTransform(rotated_lon, rotated_lat) {
|
|
21
|
-
const o_lat_p = 53.91148;
|
|
22
|
-
const o_lon_p = 245.305142;
|
|
23
|
-
const DEG_TO_RAD = Math.PI / 180.0;
|
|
24
|
-
const RAD_TO_DEG = 180.0 / Math.PI;
|
|
25
|
-
const o_lat_p_rad = o_lat_p * DEG_TO_RAD;
|
|
26
|
-
const rot_lon_rad = rotated_lon * DEG_TO_RAD;
|
|
27
|
-
const rot_lat_rad = rotated_lat * DEG_TO_RAD;
|
|
28
|
-
const sin_rot_lat = Math.sin(rot_lat_rad);
|
|
29
|
-
const cos_rot_lat = Math.cos(rot_lat_rad);
|
|
30
|
-
const sin_rot_lon = Math.sin(rot_lon_rad);
|
|
31
|
-
const cos_rot_lon = Math.cos(rot_lon_rad);
|
|
32
|
-
const sin_o_lat_p = Math.sin(o_lat_p_rad);
|
|
33
|
-
const cos_o_lat_p = Math.cos(o_lat_p_rad);
|
|
34
|
-
const sin_lat = cos_o_lat_p * sin_rot_lat + sin_o_lat_p * cos_rot_lat * cos_rot_lon;
|
|
35
|
-
let lat = Math.asin(sin_lat) * RAD_TO_DEG;
|
|
36
|
-
const sin_lon_num = cos_rot_lat * sin_rot_lon;
|
|
37
|
-
const sin_lon_den = -sin_o_lat_p * sin_rot_lat + cos_o_lat_p * cos_rot_lat * cos_rot_lon;
|
|
38
|
-
let lon = Math.atan2(sin_lon_num, sin_lon_den) * RAD_TO_DEG + o_lon_p;
|
|
39
|
-
if (lon > 180) lon -= 360;else if (lon < -180) lon += 360;
|
|
40
|
-
return [lon, lat];
|
|
41
|
-
}
|
|
42
|
-
function findLatestModelRun(modelsData, modelName) {
|
|
43
|
-
const model = modelsData?.[modelName];
|
|
44
|
-
if (!model) return null;
|
|
45
|
-
const availableDates = Object.keys(model).sort((a, b) => b.localeCompare(a));
|
|
46
|
-
for (const date of availableDates) {
|
|
47
|
-
const runs = model[date];
|
|
48
|
-
if (!runs) continue;
|
|
49
|
-
const availableRuns = Object.keys(runs).sort((a, b) => b.localeCompare(a));
|
|
50
|
-
if (availableRuns.length > 0) return {
|
|
51
|
-
date: date,
|
|
52
|
-
run: availableRuns[0]
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
class AguaceroCore extends _events.EventEmitter {
|
|
58
|
-
constructor(options = {}) {
|
|
59
|
-
super();
|
|
60
|
-
this.isReactNative = typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
|
|
61
|
-
this.apiKey = options.apiKey;
|
|
62
|
-
this.bundleId = (0, _getBundleId.getBundleId)();
|
|
63
|
-
this.baseGridUrl = 'https://d3dc62msmxkrd7.cloudfront.net';
|
|
64
|
-
if (!this.isReactNative) {
|
|
65
|
-
this.worker = this.createWorker();
|
|
66
|
-
this.workerRequestId = 0;
|
|
67
|
-
this.workerResolvers = new Map();
|
|
68
|
-
this.worker.addEventListener('message', this._handleWorkerMessage.bind(this));
|
|
69
|
-
this.resultQueue = [];
|
|
70
|
-
this.isProcessingQueue = false;
|
|
71
|
-
} else {
|
|
72
|
-
this.worker = null;
|
|
73
|
-
}
|
|
74
|
-
this.statusUrl = 'https://d3dc62msmxkrd7.cloudfront.net/model-status';
|
|
75
|
-
this.modelStatus = null;
|
|
76
|
-
this.mrmsStatus = null;
|
|
77
|
-
this.dataCache = new Map();
|
|
78
|
-
this.abortControllers = new Map();
|
|
79
|
-
this.isPlaying = false;
|
|
80
|
-
this.playIntervalId = null;
|
|
81
|
-
this.playbackSpeed = options.playbackSpeed || 500;
|
|
82
|
-
this.customColormaps = options.customColormaps || {};
|
|
83
|
-
const userLayerOptions = options.layerOptions || {};
|
|
84
|
-
const initialVariable = userLayerOptions.variable || null;
|
|
85
|
-
this.state = {
|
|
86
|
-
model: userLayerOptions.model || 'gfs',
|
|
87
|
-
isMRMS: false,
|
|
88
|
-
mrmsTimestamp: null,
|
|
89
|
-
variable: initialVariable,
|
|
90
|
-
date: null,
|
|
91
|
-
run: null,
|
|
92
|
-
forecastHour: 0,
|
|
93
|
-
visible: true,
|
|
94
|
-
opacity: userLayerOptions.opacity ?? 1,
|
|
95
|
-
units: options.initialUnit || 'imperial',
|
|
96
|
-
shaderSmoothingEnabled: options.shaderSmoothingEnabled ?? true
|
|
97
|
-
};
|
|
98
|
-
this.autoRefreshEnabled = options.autoRefresh ?? false;
|
|
99
|
-
this.autoRefreshIntervalSeconds = options.autoRefreshInterval ?? 60;
|
|
100
|
-
this.autoRefreshIntervalId = null;
|
|
101
|
-
}
|
|
102
|
-
async setState(newState) {
|
|
103
|
-
Object.assign(this.state, newState);
|
|
104
|
-
this._emitStateChange();
|
|
105
|
-
}
|
|
106
|
-
_emitStateChange() {
|
|
107
|
-
const {
|
|
108
|
-
colormap,
|
|
109
|
-
baseUnit
|
|
110
|
-
} = this._getColormapForVariable(this.state.variable);
|
|
111
|
-
const toUnit = this._getTargetUnit(baseUnit, this.state.units);
|
|
112
|
-
const displayColormap = this._convertColormapUnits(colormap, baseUnit, toUnit);
|
|
113
|
-
let availableTimestamps = [];
|
|
114
|
-
if (this.state.isMRMS && this.state.variable && this.mrmsStatus) {
|
|
115
|
-
const timestamps = this.mrmsStatus[this.state.variable] || [];
|
|
116
|
-
availableTimestamps = [...timestamps].reverse();
|
|
117
|
-
}
|
|
118
|
-
const eventPayload = {
|
|
119
|
-
...this.state,
|
|
120
|
-
availableModels: this.modelStatus ? Object.keys(this.modelStatus).sort() : [],
|
|
121
|
-
availableRuns: this.modelStatus?.[this.state.model] || {},
|
|
122
|
-
availableHours: this.state.isMRMS ? [] : this.modelStatus?.[this.state.model]?.[this.state.date]?.[this.state.run] || [],
|
|
123
|
-
availableVariables: this.getAvailableVariables(this.state.isMRMS ? 'mrms' : this.state.model),
|
|
124
|
-
// We need to confirm this line is working as expected.
|
|
125
|
-
availableMRMSVariables: this.getAvailableVariables('mrms'),
|
|
126
|
-
availableTimestamps: availableTimestamps,
|
|
127
|
-
isPlaying: this.isPlaying,
|
|
128
|
-
colormap: displayColormap,
|
|
129
|
-
colormapBaseUnit: toUnit
|
|
130
|
-
};
|
|
131
|
-
this.emit('state:change', eventPayload);
|
|
132
|
-
}
|
|
133
|
-
async initialize(options = {}) {
|
|
134
|
-
await this.fetchModelStatus(true);
|
|
135
|
-
await this.fetchMRMSStatus(true);
|
|
136
|
-
const latestRun = findLatestModelRun(this.modelStatus, this.state.model);
|
|
137
|
-
let initialState = this.state;
|
|
138
|
-
if (latestRun && !this.state.isMRMS) {
|
|
139
|
-
initialState = {
|
|
140
|
-
...this.state,
|
|
141
|
-
...latestRun,
|
|
142
|
-
forecastHour: 0
|
|
143
|
-
};
|
|
144
|
-
const availableVariables = this.getAvailableVariables(initialState.model);
|
|
145
|
-
if (availableVariables && availableVariables.length > 0) {
|
|
146
|
-
initialState.variable = availableVariables[0];
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
await this.setState(initialState);
|
|
150
|
-
if (options.autoRefresh ?? this.autoRefreshEnabled) {
|
|
151
|
-
this.startAutoRefresh(options.refreshInterval ?? this.autoRefreshIntervalSeconds);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
destroy() {
|
|
155
|
-
this.pause();
|
|
156
|
-
this.stopAutoRefresh();
|
|
157
|
-
this.dataCache.clear();
|
|
158
|
-
if (this.worker) {
|
|
159
|
-
this.worker.terminate();
|
|
160
|
-
}
|
|
161
|
-
this.callbacks = {};
|
|
162
|
-
console.log(`AguaceroCore has been destroyed.`);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// --- Public API Methods ---
|
|
166
|
-
|
|
167
|
-
play() {
|
|
168
|
-
if (this.isPlaying) return;
|
|
169
|
-
this.isPlaying = true;
|
|
170
|
-
clearInterval(this.playIntervalId);
|
|
171
|
-
this.playIntervalId = setInterval(() => {
|
|
172
|
-
this.step(1);
|
|
173
|
-
}, this.playbackSpeed);
|
|
174
|
-
this.emit('playback:start', {
|
|
175
|
-
speed: this.playbackSpeed
|
|
176
|
-
});
|
|
177
|
-
this._emitStateChange(); // Notify UI that isPlaying is now true
|
|
178
|
-
}
|
|
179
|
-
pause() {
|
|
180
|
-
if (!this.isPlaying) return;
|
|
181
|
-
this.isPlaying = false;
|
|
182
|
-
clearInterval(this.playIntervalId);
|
|
183
|
-
this.playIntervalId = null;
|
|
184
|
-
this.emit('playback:stop');
|
|
185
|
-
this._emitStateChange(); // Notify UI that isPlaying is now false
|
|
186
|
-
}
|
|
187
|
-
togglePlay() {
|
|
188
|
-
this.isPlaying ? this.pause() : this.play();
|
|
189
|
-
}
|
|
190
|
-
step(direction = 1) {
|
|
191
|
-
// --- THIS IS THE CORRECTED MRMS LOGIC ---
|
|
192
|
-
if (this.state.isMRMS) {
|
|
193
|
-
const {
|
|
194
|
-
variable,
|
|
195
|
-
mrmsTimestamp
|
|
196
|
-
} = this.state;
|
|
197
|
-
if (!this.mrmsStatus || !this.mrmsStatus[variable]) {
|
|
198
|
-
console.warn('[Core.step] MRMS status or variable not available.');
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// CRITICAL FIX: The UI and state emissions use a REVERSED array (newest first).
|
|
203
|
-
// The step logic MUST use the same reversed array for indexes to match.
|
|
204
|
-
const availableTimestamps = [...(this.mrmsStatus[variable] || [])].reverse();
|
|
205
|
-
if (availableTimestamps.length === 0) return;
|
|
206
|
-
const currentIndex = availableTimestamps.indexOf(mrmsTimestamp);
|
|
207
|
-
if (currentIndex === -1) {
|
|
208
|
-
// If not found, reset to the first (newest) frame
|
|
209
|
-
this.setState({
|
|
210
|
-
mrmsTimestamp: availableTimestamps[0]
|
|
211
|
-
});
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
const maxIndex = availableTimestamps.length - 1;
|
|
215
|
-
let nextIndex = currentIndex + direction;
|
|
216
|
-
|
|
217
|
-
// Loop animation
|
|
218
|
-
if (nextIndex > maxIndex) nextIndex = 0;
|
|
219
|
-
if (nextIndex < 0) nextIndex = maxIndex;
|
|
220
|
-
const newTimestamp = availableTimestamps[nextIndex];
|
|
221
|
-
this.setState({
|
|
222
|
-
mrmsTimestamp: newTimestamp
|
|
223
|
-
});
|
|
224
|
-
} else {
|
|
225
|
-
const {
|
|
226
|
-
model,
|
|
227
|
-
date,
|
|
228
|
-
run,
|
|
229
|
-
forecastHour
|
|
230
|
-
} = this.state;
|
|
231
|
-
const forecastHours = this.modelStatus?.[model]?.[date]?.[run];
|
|
232
|
-
if (!forecastHours || forecastHours.length === 0) return;
|
|
233
|
-
const currentIndex = forecastHours.indexOf(forecastHour);
|
|
234
|
-
if (currentIndex === -1) return;
|
|
235
|
-
const maxIndex = forecastHours.length - 1;
|
|
236
|
-
let nextIndex = currentIndex + direction;
|
|
237
|
-
if (nextIndex > maxIndex) nextIndex = 0;
|
|
238
|
-
if (nextIndex < 0) nextIndex = maxIndex;
|
|
239
|
-
const newHour = forecastHours[nextIndex];
|
|
240
|
-
this.setState({
|
|
241
|
-
forecastHour: newHour
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
setPlaybackSpeed(speed) {
|
|
246
|
-
if (speed > 0) {
|
|
247
|
-
this.playbackSpeed = speed;
|
|
248
|
-
if (this.isPlaying) this.play();
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
async setShaderSmoothing(enabled) {
|
|
252
|
-
if (typeof enabled !== 'boolean' || enabled === this.state.shaderSmoothingEnabled) return;
|
|
253
|
-
await this.setState({
|
|
254
|
-
shaderSmoothingEnabled: enabled
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
async setOpacity(newOpacity) {
|
|
258
|
-
const clampedOpacity = Math.max(0, Math.min(1, newOpacity));
|
|
259
|
-
if (clampedOpacity === this.state.opacity) return;
|
|
260
|
-
await this.setState({
|
|
261
|
-
opacity: clampedOpacity
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
async setVariable(variable) {
|
|
265
|
-
await this.setState({
|
|
266
|
-
variable
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
async setModel(modelName) {
|
|
270
|
-
if (modelName === this.state.model || !this.modelStatus?.[modelName]) return;
|
|
271
|
-
const latestRun = findLatestModelRun(this.modelStatus, modelName);
|
|
272
|
-
if (latestRun) {
|
|
273
|
-
await this.setState({
|
|
274
|
-
model: modelName,
|
|
275
|
-
date: latestRun.date,
|
|
276
|
-
run: latestRun.run,
|
|
277
|
-
forecastHour: 0
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
async setRun(runString) {
|
|
282
|
-
const [date, run] = runString.split(':');
|
|
283
|
-
if (date !== this.state.date || run !== this.state.run) {
|
|
284
|
-
await this.setState({
|
|
285
|
-
date,
|
|
286
|
-
run,
|
|
287
|
-
forecastHour: 0
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
async setUnits(newUnits) {
|
|
292
|
-
if (newUnits === this.state.units || !['metric', 'imperial'].includes(newUnits)) return;
|
|
293
|
-
await this.setState({
|
|
294
|
-
units: newUnits
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
async setMRMSVariable(variable) {
|
|
298
|
-
const sortedTimestamps = [...(this.mrmsStatus[variable] || [])].sort((a, b) => b - a);
|
|
299
|
-
const initialTimestamp = sortedTimestamps.length > 0 ? sortedTimestamps[0] : null;
|
|
300
|
-
await this.setState({
|
|
301
|
-
variable,
|
|
302
|
-
isMRMS: true,
|
|
303
|
-
mrmsTimestamp: initialTimestamp
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
async setMRMSTimestamp(timestamp) {
|
|
307
|
-
if (!this.state.isMRMS) return;
|
|
308
|
-
await this.setState({
|
|
309
|
-
mrmsTimestamp: timestamp
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
async switchMode(options) {
|
|
313
|
-
const {
|
|
314
|
-
mode,
|
|
315
|
-
variable,
|
|
316
|
-
model,
|
|
317
|
-
forecastHour,
|
|
318
|
-
mrmsTimestamp
|
|
319
|
-
} = options;
|
|
320
|
-
if (!mode || !variable) {
|
|
321
|
-
console.error("switchMode requires 'mode' ('mrms' | 'model') and 'variable' properties.");
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
if (mode === 'model' && !model) {
|
|
325
|
-
console.error("switchMode with mode 'model' requires a 'model' property.");
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
let targetState = {};
|
|
329
|
-
if (mode === 'mrms') {
|
|
330
|
-
let finalTimestamp = mrmsTimestamp;
|
|
331
|
-
if (finalTimestamp === undefined) {
|
|
332
|
-
const sortedTimestamps = [...(this.mrmsStatus[variable] || [])].sort((a, b) => b - a);
|
|
333
|
-
finalTimestamp = sortedTimestamps.length > 0 ? sortedTimestamps[0] : null;
|
|
334
|
-
}
|
|
335
|
-
targetState = {
|
|
336
|
-
isMRMS: true,
|
|
337
|
-
variable: variable,
|
|
338
|
-
mrmsTimestamp: finalTimestamp,
|
|
339
|
-
model: this.state.model,
|
|
340
|
-
date: null,
|
|
341
|
-
run: null,
|
|
342
|
-
forecastHour: 0
|
|
343
|
-
};
|
|
344
|
-
} else if (mode === 'model') {
|
|
345
|
-
const latestRun = findLatestModelRun(this.modelStatus, model);
|
|
346
|
-
if (!latestRun) {
|
|
347
|
-
console.error(`Could not find a valid run for model: ${model}`);
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
targetState = {
|
|
351
|
-
isMRMS: false,
|
|
352
|
-
model: model,
|
|
353
|
-
variable: variable,
|
|
354
|
-
date: latestRun.date,
|
|
355
|
-
run: latestRun.run,
|
|
356
|
-
forecastHour: forecastHour !== undefined ? forecastHour : 0,
|
|
357
|
-
mrmsTimestamp: null
|
|
358
|
-
};
|
|
359
|
-
} else {
|
|
360
|
-
console.error(`Invalid mode specified in switchMode: '${mode}'`);
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
await this.setState(targetState);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
// --- Data and Calculation Methods ---
|
|
367
|
-
|
|
368
|
-
_reconstructData(decompressedDeltas, encoding) {
|
|
369
|
-
const expectedLength = encoding.length;
|
|
370
|
-
const reconstructedData = new Int8Array(expectedLength);
|
|
371
|
-
if (decompressedDeltas.length > 0 && expectedLength > 0) {
|
|
372
|
-
// First value is absolute
|
|
373
|
-
reconstructedData[0] = decompressedDeltas[0] > 127 ? decompressedDeltas[0] - 256 : decompressedDeltas[0];
|
|
374
|
-
|
|
375
|
-
// Subsequent values are deltas from the previous one
|
|
376
|
-
for (let i = 1; i < expectedLength; i++) {
|
|
377
|
-
const delta = decompressedDeltas[i] > 127 ? decompressedDeltas[i] - 256 : decompressedDeltas[i];
|
|
378
|
-
reconstructedData[i] = reconstructedData[i - 1] + delta;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
// Return as a Uint8Array, which is what the rest of the code expects
|
|
382
|
-
return new Uint8Array(reconstructedData.buffer);
|
|
383
|
-
}
|
|
384
|
-
async _loadGridData(state) {
|
|
385
|
-
if (this.isReactNative) {
|
|
386
|
-
console.warn(`[AguaceroCore] _loadGridData was called in React Native. This is a bypass. Data loading is handled natively.`);
|
|
387
|
-
return null;
|
|
388
|
-
}
|
|
389
|
-
const {
|
|
390
|
-
model,
|
|
391
|
-
date,
|
|
392
|
-
run,
|
|
393
|
-
forecastHour,
|
|
394
|
-
variable,
|
|
395
|
-
isMRMS,
|
|
396
|
-
mrmsTimestamp
|
|
397
|
-
} = state;
|
|
398
|
-
let effectiveSmoothing = 0;
|
|
399
|
-
const customVariableSettings = this.customColormaps[variable];
|
|
400
|
-
if (customVariableSettings && typeof customVariableSettings.smoothing === 'number') {
|
|
401
|
-
effectiveSmoothing = customVariableSettings.smoothing;
|
|
402
|
-
}
|
|
403
|
-
let resourcePath;
|
|
404
|
-
let dataUrlIdentifier;
|
|
405
|
-
if (isMRMS) {
|
|
406
|
-
if (!mrmsTimestamp) return null;
|
|
407
|
-
const mrmsDate = new Date(mrmsTimestamp * 1000);
|
|
408
|
-
const y = mrmsDate.getUTCFullYear(),
|
|
409
|
-
m = (mrmsDate.getUTCMonth() + 1).toString().padStart(2, '0'),
|
|
410
|
-
d = mrmsDate.getUTCDate().toString().padStart(2, '0');
|
|
411
|
-
dataUrlIdentifier = `mrms-${mrmsTimestamp}-${variable}-${effectiveSmoothing}`;
|
|
412
|
-
resourcePath = `/grids/mrms/${y}${m}${d}/${mrmsTimestamp}/0/${variable}/${effectiveSmoothing}`;
|
|
413
|
-
} else {
|
|
414
|
-
dataUrlIdentifier = `${model}-${date}-${run}-${forecastHour}-${variable}-${effectiveSmoothing}`;
|
|
415
|
-
resourcePath = `/grids/${model}/${date}/${run}/${forecastHour}/${variable}/${effectiveSmoothing}`;
|
|
416
|
-
}
|
|
417
|
-
if (this.dataCache.has(dataUrlIdentifier)) {
|
|
418
|
-
return this.dataCache.get(dataUrlIdentifier);
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
// --- EDITED ---
|
|
422
|
-
// If we are in React Native, this function should NOT do any work.
|
|
423
|
-
// The native WeatherFrameProcessorModule is now responsible for all data loading.
|
|
424
|
-
// This function might still be called by a "cache miss" fallback, but it
|
|
425
|
-
// should not fetch data from JS anymore. We return null so the fallback knows
|
|
426
|
-
// that the native module is the only source of truth for new data.
|
|
427
|
-
if (this.isReactNative) {
|
|
428
|
-
console.warn(`_loadGridData was called in React Native for ${dataUrlIdentifier}. This should be handled by the native module. Returning null.`);
|
|
429
|
-
return null;
|
|
430
|
-
}
|
|
431
|
-
const abortController = new AbortController();
|
|
432
|
-
this.abortControllers.set(dataUrlIdentifier, abortController);
|
|
433
|
-
const loadPromise = (async () => {
|
|
434
|
-
if (!this.apiKey) {
|
|
435
|
-
throw new Error('API key is not configured.');
|
|
436
|
-
}
|
|
437
|
-
try {
|
|
438
|
-
const baseUrl = `${this.baseGridUrl}${resourcePath}`;
|
|
439
|
-
const urlWithApiKeyParam = `${baseUrl}?apiKey=${this.apiKey}`;
|
|
440
|
-
const headers = {
|
|
441
|
-
'x-api-key': this.apiKey
|
|
442
|
-
};
|
|
443
|
-
if (this.bundleId && this.isReactNative) {
|
|
444
|
-
headers['x-app-identifier'] = this.bundleId;
|
|
445
|
-
}
|
|
446
|
-
const response = await fetch(urlWithApiKeyParam, {
|
|
447
|
-
headers: headers,
|
|
448
|
-
signal: abortController.signal
|
|
449
|
-
});
|
|
450
|
-
if (!response.ok) {
|
|
451
|
-
throw new Error(`Failed to fetch grid data: ${response.status} ${response.statusText}`);
|
|
452
|
-
}
|
|
453
|
-
const {
|
|
454
|
-
data: b64Data,
|
|
455
|
-
encoding
|
|
456
|
-
} = await response.json();
|
|
457
|
-
const compressedData = Uint8Array.from(atob(b64Data), c => c.charCodeAt(0));
|
|
458
|
-
|
|
459
|
-
// This path is now ONLY for the web worker
|
|
460
|
-
const requestId = this.workerRequestId++;
|
|
461
|
-
const workerPromise = new Promise((resolve, reject) => {
|
|
462
|
-
this.workerResolvers.set(requestId, {
|
|
463
|
-
resolve,
|
|
464
|
-
reject
|
|
465
|
-
});
|
|
466
|
-
});
|
|
467
|
-
this.worker.postMessage({
|
|
468
|
-
requestId,
|
|
469
|
-
compressedData,
|
|
470
|
-
encoding
|
|
471
|
-
}, [compressedData.buffer]);
|
|
472
|
-
const result = await workerPromise;
|
|
473
|
-
const finalData = result.data;
|
|
474
|
-
const transformedData = new Uint8Array(finalData.length);
|
|
475
|
-
for (let i = 0; i < finalData.length; i++) {
|
|
476
|
-
const signedValue = finalData[i] > 127 ? finalData[i] - 256 : finalData[i];
|
|
477
|
-
transformedData[i] = signedValue + 128;
|
|
478
|
-
}
|
|
479
|
-
this.abortControllers.delete(dataUrlIdentifier);
|
|
480
|
-
return {
|
|
481
|
-
data: transformedData,
|
|
482
|
-
encoding
|
|
483
|
-
};
|
|
484
|
-
} catch (error) {
|
|
485
|
-
if (error.name === 'AbortError') {
|
|
486
|
-
console.log(`Request cancelled for ${resourcePath}`);
|
|
487
|
-
} else {
|
|
488
|
-
console.error(`Failed to load data for path ${resourcePath}:`, error);
|
|
489
|
-
}
|
|
490
|
-
this.dataCache.delete(dataUrlIdentifier);
|
|
491
|
-
this.abortControllers.delete(dataUrlIdentifier);
|
|
492
|
-
return null;
|
|
493
|
-
}
|
|
494
|
-
})();
|
|
495
|
-
this.dataCache.set(dataUrlIdentifier, loadPromise);
|
|
496
|
-
return loadPromise;
|
|
497
|
-
}
|
|
498
|
-
cancelAllRequests() {
|
|
499
|
-
// Abort all in-flight requests
|
|
500
|
-
this.abortControllers.forEach((controller, key) => {
|
|
501
|
-
controller.abort();
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
// Clear both maps
|
|
505
|
-
this.abortControllers.clear();
|
|
506
|
-
this.dataCache.clear();
|
|
507
|
-
console.log('All pending requests cancelled');
|
|
508
|
-
}
|
|
509
|
-
async getValueAtLngLat(lng, lat) {
|
|
510
|
-
const {
|
|
511
|
-
variable,
|
|
512
|
-
isMRMS,
|
|
513
|
-
mrmsTimestamp,
|
|
514
|
-
model,
|
|
515
|
-
date,
|
|
516
|
-
run,
|
|
517
|
-
forecastHour,
|
|
518
|
-
units
|
|
519
|
-
} = this.state;
|
|
520
|
-
if (!variable) return null;
|
|
521
|
-
const gridIndices = this._getGridIndexFromLngLat(lng, lat);
|
|
522
|
-
if (!gridIndices) return null;
|
|
523
|
-
const {
|
|
524
|
-
i,
|
|
525
|
-
j
|
|
526
|
-
} = gridIndices;
|
|
527
|
-
const gridModel = isMRMS ? 'mrms' : model;
|
|
528
|
-
const normalizedGridModel = this._normalizeModelName(gridModel);
|
|
529
|
-
const {
|
|
530
|
-
nx
|
|
531
|
-
} = _coordinate_configs.COORDINATE_CONFIGS[normalizedGridModel].grid_params;
|
|
532
|
-
const customSettings = this.customColormaps[variable];
|
|
533
|
-
const effectiveSmoothing = customSettings && typeof customSettings.smoothing === 'number' ? customSettings.smoothing : 0;
|
|
534
|
-
const dataUrlIdentifier = isMRMS ? `mrms-${mrmsTimestamp}-${variable}-${effectiveSmoothing}` : `${model}-${date}-${run}-${forecastHour}-${variable}-${effectiveSmoothing}`;
|
|
535
|
-
const gridDataPromise = this.dataCache.get(dataUrlIdentifier);
|
|
536
|
-
if (!gridDataPromise) return null;
|
|
537
|
-
try {
|
|
538
|
-
const gridData = await gridDataPromise;
|
|
539
|
-
if (!gridData || !gridData.data) return null;
|
|
540
|
-
const index1D = j * nx + i;
|
|
541
|
-
const byteValue = gridData.data[index1D];
|
|
542
|
-
const signedQuantizedValue = byteValue - 128;
|
|
543
|
-
|
|
544
|
-
// --- START OF FIX ---
|
|
545
|
-
// You were missing 'scale_type' in this destructuring assignment.
|
|
546
|
-
const {
|
|
547
|
-
scale,
|
|
548
|
-
offset,
|
|
549
|
-
missing_quantized,
|
|
550
|
-
scale_type
|
|
551
|
-
} = gridData.encoding;
|
|
552
|
-
// --- END OF FIX ---
|
|
553
|
-
|
|
554
|
-
if (signedQuantizedValue === missing_quantized) return null;
|
|
555
|
-
const intermediateValue = signedQuantizedValue * scale + offset;
|
|
556
|
-
|
|
557
|
-
// Step 2: Apply non-linear scaling if specified
|
|
558
|
-
let nativeValue = intermediateValue;
|
|
559
|
-
if (scale_type === 'sqrt') {
|
|
560
|
-
// Square the value while preserving its sign
|
|
561
|
-
nativeValue = intermediateValue < 0 ? -(intermediateValue * intermediateValue) : intermediateValue * intermediateValue;
|
|
562
|
-
}
|
|
563
|
-
const {
|
|
564
|
-
colormap,
|
|
565
|
-
baseUnit
|
|
566
|
-
} = this._getColormapForVariable(variable);
|
|
567
|
-
|
|
568
|
-
// If the value is outside the colormap's bounds, return null.
|
|
569
|
-
if (colormap && colormap.length >= 2) {
|
|
570
|
-
const minBound = colormap[0];
|
|
571
|
-
const maxBound = colormap[colormap.length - 2];
|
|
572
|
-
if (nativeValue < minBound || nativeValue > maxBound) {
|
|
573
|
-
return null;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
let dataNativeUnit = baseUnit || (_dictionaries.DICTIONARIES.fld[variable] || {}).defaultUnit || 'none';
|
|
577
|
-
const displayUnit = this._getTargetUnit(dataNativeUnit, units);
|
|
578
|
-
const conversionFunc = (0, _unitConversions.getUnitConversionFunction)(dataNativeUnit, displayUnit);
|
|
579
|
-
let displayValue = conversionFunc ? conversionFunc(nativeValue) : nativeValue;
|
|
580
|
-
|
|
581
|
-
// --- START: ADDED CODE ---
|
|
582
|
-
|
|
583
|
-
// Create a variable to hold the precipitation type, if any.
|
|
584
|
-
let precipType = null;
|
|
585
|
-
|
|
586
|
-
// Check if the current variable is one of the special ptype variables.
|
|
587
|
-
if (variable === 'ptypeRefl' || variable === 'ptypeRate') {
|
|
588
|
-
const value = nativeValue; // Use the raw, unconverted value for ptype logic
|
|
589
|
-
|
|
590
|
-
if (value >= 100 && value < 200) {
|
|
591
|
-
displayValue -= 100;
|
|
592
|
-
precipType = 'Snow';
|
|
593
|
-
} else if (value >= 200 && value < 300) {
|
|
594
|
-
displayValue -= 200;
|
|
595
|
-
precipType = 'Frzg Rain'; // Abbreviated for tooltips
|
|
596
|
-
} else if (value >= 300 && value < 400) {
|
|
597
|
-
displayValue -= 300;
|
|
598
|
-
precipType = 'Ice Pellets';
|
|
599
|
-
} else {
|
|
600
|
-
precipType = 'Rain';
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
// Return the final payload, now including the precipType.
|
|
605
|
-
return {
|
|
606
|
-
lngLat: {
|
|
607
|
-
lng,
|
|
608
|
-
lat
|
|
609
|
-
},
|
|
610
|
-
variable: {
|
|
611
|
-
code: variable,
|
|
612
|
-
name: this.getVariableDisplayName(variable)
|
|
613
|
-
},
|
|
614
|
-
value: displayValue,
|
|
615
|
-
unit: displayUnit,
|
|
616
|
-
precipType: precipType // NEW: Add this to the return object
|
|
617
|
-
};
|
|
618
|
-
} catch (error) {
|
|
619
|
-
return null;
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
getAvailableVariables(modelName = null) {
|
|
623
|
-
const model = modelName || this.state.model;
|
|
624
|
-
return _dictionaries.MODEL_CONFIGS[model]?.vars || [];
|
|
625
|
-
}
|
|
626
|
-
getVariableDisplayName(variableCode) {
|
|
627
|
-
const varInfo = _dictionaries.DICTIONARIES.fld[variableCode];
|
|
628
|
-
return varInfo?.displayName || varInfo?.name || variableCode;
|
|
629
|
-
}
|
|
630
|
-
_getColormapForVariable(variable) {
|
|
631
|
-
if (!variable) return {
|
|
632
|
-
colormap: [],
|
|
633
|
-
baseUnit: ''
|
|
634
|
-
};
|
|
635
|
-
if (this.customColormaps[variable] && this.customColormaps[variable].colormap) {
|
|
636
|
-
return {
|
|
637
|
-
colormap: this.customColormaps[variable].colormap,
|
|
638
|
-
baseUnit: this.customColormaps[variable].baseUnit || ''
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
const colormapKey = _dictionaries.DICTIONARIES.variable_cmap[variable] || variable;
|
|
642
|
-
const customColormap = this.customColormaps[colormapKey];
|
|
643
|
-
if (customColormap && customColormap.colormap) {
|
|
644
|
-
return {
|
|
645
|
-
colormap: customColormap.colormap,
|
|
646
|
-
baseUnit: customColormap.baseUnit || ''
|
|
647
|
-
};
|
|
648
|
-
}
|
|
649
|
-
const defaultColormapData = _defaultColormaps.DEFAULT_COLORMAPS[colormapKey];
|
|
650
|
-
if (defaultColormapData && defaultColormapData.units) {
|
|
651
|
-
// ✅ Get defaultUnit from the field dictionary
|
|
652
|
-
const fieldInfo = _dictionaries.DICTIONARIES.fld[variable] || {};
|
|
653
|
-
const baseUnit = fieldInfo.defaultUnit || Object.keys(defaultColormapData.units)[0];
|
|
654
|
-
const unitData = defaultColormapData.units[baseUnit];
|
|
655
|
-
if (unitData && unitData.colormap) {
|
|
656
|
-
return {
|
|
657
|
-
colormap: unitData.colormap,
|
|
658
|
-
baseUnit: baseUnit
|
|
659
|
-
};
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
return {
|
|
663
|
-
colormap: [],
|
|
664
|
-
baseUnit: ''
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
_convertColormapUnits(colormap, fromUnits, toUnits) {
|
|
668
|
-
if (fromUnits === toUnits) return colormap;
|
|
669
|
-
const conversionFunc = (0, _unitConversions.getUnitConversionFunction)(fromUnits, toUnits);
|
|
670
|
-
if (!conversionFunc) return colormap;
|
|
671
|
-
const newColormap = [];
|
|
672
|
-
for (let i = 0; i < colormap.length; i += 2) {
|
|
673
|
-
newColormap.push(conversionFunc(colormap[i]), colormap[i + 1]);
|
|
674
|
-
}
|
|
675
|
-
return newColormap;
|
|
676
|
-
}
|
|
677
|
-
_normalizeModelName(modelName) {
|
|
678
|
-
const mapping = {
|
|
679
|
-
'hrrr': ['mpashn', 'mpasrt', 'mpasht', 'hrrrsub', 'rrfs', 'namnest', 'mpasrn', 'mpasrn3', 'mpasht2'],
|
|
680
|
-
'arw': ['arw2', 'fv3', 'href'],
|
|
681
|
-
'rtma': ['nbm'],
|
|
682
|
-
'ecmwf': ['ecmwfaifs'],
|
|
683
|
-
'gfs': ['arpege', 'graphcastgfs']
|
|
684
|
-
};
|
|
685
|
-
for (const [normalized, aliases] of Object.entries(mapping)) {
|
|
686
|
-
if (aliases.includes(modelName)) return normalized;
|
|
687
|
-
}
|
|
688
|
-
return modelName;
|
|
689
|
-
}
|
|
690
|
-
_getGridCornersAndDef(model) {
|
|
691
|
-
const normalizedModel = this._normalizeModelName(model);
|
|
692
|
-
const gridDef = {
|
|
693
|
-
..._coordinate_configs.COORDINATE_CONFIGS[normalizedModel],
|
|
694
|
-
modelName: model
|
|
695
|
-
};
|
|
696
|
-
if (!gridDef) return null;
|
|
697
|
-
const {
|
|
698
|
-
nx,
|
|
699
|
-
ny
|
|
700
|
-
} = gridDef.grid_params;
|
|
701
|
-
const gridType = gridDef.type;
|
|
702
|
-
let corners;
|
|
703
|
-
if (gridType === 'latlon') {
|
|
704
|
-
let {
|
|
705
|
-
lon_first,
|
|
706
|
-
lat_first,
|
|
707
|
-
lat_last,
|
|
708
|
-
lon_last,
|
|
709
|
-
dx_degrees,
|
|
710
|
-
dy_degrees
|
|
711
|
-
} = gridDef.grid_params;
|
|
712
|
-
corners = {
|
|
713
|
-
lon_tl: lon_first,
|
|
714
|
-
lat_tl: lat_first,
|
|
715
|
-
lon_tr: lon_last !== undefined ? lon_last : lon_first + (nx - 1) * dx_degrees,
|
|
716
|
-
lat_tr: lat_first,
|
|
717
|
-
lon_bl: lon_first,
|
|
718
|
-
lat_bl: lat_last !== undefined ? lat_last : lat_first + (ny - 1) * dy_degrees,
|
|
719
|
-
lon_br: lon_last !== undefined ? lon_last : lon_first + (nx - 1) * dx_degrees,
|
|
720
|
-
lat_br: lat_last !== undefined ? lat_last : lat_first + (ny - 1) * dy_degrees
|
|
721
|
-
};
|
|
722
|
-
} else if (gridType === 'rotated_latlon') {
|
|
723
|
-
const [lon_tl, lat_tl] = hrdpsObliqueTransform(gridDef.grid_params.lon_first, gridDef.grid_params.lat_first);
|
|
724
|
-
const [lon_tr, lat_tr] = hrdpsObliqueTransform(gridDef.grid_params.lon_first + (nx - 1) * gridDef.grid_params.dx_degrees, gridDef.grid_params.lat_first);
|
|
725
|
-
const [lon_bl, lat_bl] = hrdpsObliqueTransform(gridDef.grid_params.lon_first, gridDef.grid_params.lat_first + (ny - 1) * gridDef.grid_params.dy_degrees);
|
|
726
|
-
const [lon_br, lat_br] = hrdpsObliqueTransform(gridDef.grid_params.lon_first + (nx - 1) * gridDef.grid_params.dx_degrees, gridDef.grid_params.lat_first + (ny - 1) * gridDef.grid_params.dy_degrees);
|
|
727
|
-
corners = {
|
|
728
|
-
lon_tl,
|
|
729
|
-
lat_tl,
|
|
730
|
-
lon_tr,
|
|
731
|
-
lat_tr,
|
|
732
|
-
lon_bl,
|
|
733
|
-
lat_bl,
|
|
734
|
-
lon_br,
|
|
735
|
-
lat_br
|
|
736
|
-
};
|
|
737
|
-
} else if (gridType === 'lambert_conformal_conic' || gridType === 'polar_ stereographic') {
|
|
738
|
-
let projString = Object.entries(gridDef.proj_params).map(([k, v]) => `+${k}=${v}`).join(' ');
|
|
739
|
-
if (gridType === 'polar_stereographic') projString += ' +lat_0=90';
|
|
740
|
-
const {
|
|
741
|
-
x_origin,
|
|
742
|
-
y_origin,
|
|
743
|
-
dx,
|
|
744
|
-
dy
|
|
745
|
-
} = gridDef.grid_params;
|
|
746
|
-
const [lon_tl, lat_tl] = (0, _proj.default)(projString, 'EPSG:4326', [x_origin, y_origin]);
|
|
747
|
-
const [lon_tr, lat_tr] = (0, _proj.default)(projString, 'EPSG:4326', [x_origin + (nx - 1) * dx, y_origin]);
|
|
748
|
-
const [lon_bl, lat_bl] = (0, _proj.default)(projString, 'EPSG:4326', [x_origin, y_origin + (ny - 1) * dy]);
|
|
749
|
-
const [lon_br, lat_br] = (0, _proj.default)(projString, 'EPSG:4326', [x_origin + (nx - 1) * dx, y_origin + (ny - 1) * dy]);
|
|
750
|
-
corners = {
|
|
751
|
-
lon_tl,
|
|
752
|
-
lat_tl,
|
|
753
|
-
lon_tr,
|
|
754
|
-
lat_tr,
|
|
755
|
-
lon_bl,
|
|
756
|
-
lat_bl,
|
|
757
|
-
lon_br,
|
|
758
|
-
lat_br
|
|
759
|
-
};
|
|
760
|
-
} else {
|
|
761
|
-
return null;
|
|
762
|
-
}
|
|
763
|
-
return {
|
|
764
|
-
corners,
|
|
765
|
-
gridDef
|
|
766
|
-
};
|
|
767
|
-
}
|
|
768
|
-
_getTargetUnit(defaultUnit, system) {
|
|
769
|
-
if (system === 'metric') {
|
|
770
|
-
if (['°F', '°C', 'fahrenheit', 'celsius'].includes(defaultUnit)) return '°C';
|
|
771
|
-
if (['kts', 'mph', 'm/s'].includes(defaultUnit)) return 'km/h';
|
|
772
|
-
if (['in', 'mm', 'cm'].includes(defaultUnit)) return 'mm';
|
|
773
|
-
}
|
|
774
|
-
if (system === 'imperial') {
|
|
775
|
-
if (['°F', '°C', 'fahrenheit', 'celsius'].includes(defaultUnit)) return '°F';
|
|
776
|
-
if (['kts', 'mph', 'm/s'].includes(defaultUnit)) return 'mph';
|
|
777
|
-
if (['in', 'mm', 'cm'].includes(defaultUnit)) return 'in';
|
|
778
|
-
}
|
|
779
|
-
return defaultUnit;
|
|
780
|
-
}
|
|
781
|
-
_getGridIndexFromLngLat(lng, lat) {
|
|
782
|
-
const gridModel = this.state.isMRMS ? 'mrms' : this.state.model;
|
|
783
|
-
const normalizedGridModel = this._normalizeModelName(gridModel);
|
|
784
|
-
const gridDef = _coordinate_configs.COORDINATE_CONFIGS[normalizedGridModel];
|
|
785
|
-
if (!gridDef) return null;
|
|
786
|
-
const {
|
|
787
|
-
nx,
|
|
788
|
-
ny
|
|
789
|
-
} = gridDef.grid_params;
|
|
790
|
-
const pixelCoords = this.latLonToGridPixel(lat, lng, gridDef, gridModel);
|
|
791
|
-
if (!pixelCoords || !isFinite(pixelCoords.x) || !isFinite(pixelCoords.y) || pixelCoords.x < 0 || pixelCoords.y < 0) return null;
|
|
792
|
-
const i = Math.round(pixelCoords.x);
|
|
793
|
-
const j = Math.round(pixelCoords.y);
|
|
794
|
-
if (i >= 0 && i < nx && j >= 0 && j < ny) return {
|
|
795
|
-
i,
|
|
796
|
-
j
|
|
797
|
-
};
|
|
798
|
-
return null;
|
|
799
|
-
}
|
|
800
|
-
latLonToProjected(lat, lon, gridDef) {
|
|
801
|
-
if (!isFinite(lat) || !isFinite(lon)) throw new Error(`Invalid coordinates: lat=${lat}, lon=${lon}`);
|
|
802
|
-
const gridType = gridDef.type;
|
|
803
|
-
if (gridType === 'latlon') return {
|
|
804
|
-
x: lon,
|
|
805
|
-
y: lat
|
|
806
|
-
};
|
|
807
|
-
let projString = Object.entries(gridDef.proj_params).map(([k, v]) => `+${k}=${v}`).join(' ');
|
|
808
|
-
if (gridType === 'polar_stereographic') projString += ' +lat_0=90';
|
|
809
|
-
const projected = (0, _proj.default)('EPSG:4326', projString, [lon, lat]);
|
|
810
|
-
return {
|
|
811
|
-
x: projected[0],
|
|
812
|
-
y: projected[1]
|
|
813
|
-
};
|
|
814
|
-
}
|
|
815
|
-
latLonToGridPixel(lat, lon, gridDef, modelName) {
|
|
816
|
-
if (!gridDef) return null;
|
|
817
|
-
if (modelName === 'rgem' && gridDef.type === 'polar_stereographic') return this.latLonToGridPixelPolarStereographic(lat, lon, gridDef);
|
|
818
|
-
const projected = this.latLonToProjected(lat, lon, gridDef);
|
|
819
|
-
let x, y;
|
|
820
|
-
const gridOrigin = {
|
|
821
|
-
x: gridDef.grid_params.lon_first,
|
|
822
|
-
y: gridDef.grid_params.lat_first
|
|
823
|
-
};
|
|
824
|
-
const gridPixelSize = {
|
|
825
|
-
x: gridDef.grid_params.dx_degrees,
|
|
826
|
-
y: gridDef.grid_params.dy_degrees
|
|
827
|
-
};
|
|
828
|
-
if (gridDef.type === 'latlon' || gridDef.type === 'rotated_latlon') {
|
|
829
|
-
let adjustedLon = projected.x;
|
|
830
|
-
if (modelName === 'mrms') {
|
|
831
|
-
if (adjustedLon < 0) adjustedLon += 360;
|
|
832
|
-
x = (adjustedLon - gridOrigin.x) / gridPixelSize.x;
|
|
833
|
-
y = (gridOrigin.y - projected.y) / gridPixelSize.y;
|
|
834
|
-
} else {
|
|
835
|
-
const isGFSType = gridDef.grid_params && gridDef.grid_params.lon_first === 0.0 && Math.abs(gridDef.grid_params.lat_first) === 90.0;
|
|
836
|
-
const isECMWFType = gridDef.grid_params && gridDef.grid_params.lon_first === 180.0 && gridDef.grid_params.lat_first === 90.0;
|
|
837
|
-
const isGEMType = modelName === 'gem' || gridDef.grid_params.lon_first === 180.0 && gridDef.grid_params.lat_first === -90.0 && gridDef.grid_params.lon_last === 179.85;
|
|
838
|
-
if (isGEMType) {
|
|
839
|
-
while (adjustedLon < gridOrigin.x) adjustedLon += 360;
|
|
840
|
-
x = (adjustedLon - gridOrigin.x) / gridPixelSize.x;
|
|
841
|
-
y = (projected.y - gridOrigin.y) / gridPixelSize.y;
|
|
842
|
-
return {
|
|
843
|
-
x,
|
|
844
|
-
y
|
|
845
|
-
};
|
|
846
|
-
}
|
|
847
|
-
let isFlippedGrid = isECMWFType ? true : gridDef.grid_params.lat_first < (gridDef.grid_params.lat_last || (gridDef.grid_params.ny - 1) * gridDef.grid_params.dy_degrees);
|
|
848
|
-
if (isGFSType) adjustedLon = projected.x + 180;else if (isECMWFType) {
|
|
849
|
-
if (adjustedLon < gridOrigin.x) adjustedLon += 360;
|
|
850
|
-
} else if (['arome1', 'arome25', 'arpegeeu', 'iconeu', 'icond2'].includes(modelName)) {
|
|
851
|
-
while (adjustedLon < 0) adjustedLon += 360;
|
|
852
|
-
while (adjustedLon >= 360) adjustedLon -= 360;
|
|
853
|
-
x = adjustedLon >= gridOrigin.x ? (adjustedLon - gridOrigin.x) / gridPixelSize.x : (adjustedLon + 360 - gridOrigin.x) / gridPixelSize.x;
|
|
854
|
-
if (['arome1', 'arome25', 'arpegeeu'].includes(modelName)) y = (gridOrigin.y - projected.y) / Math.abs(gridPixelSize.y);else if (['iconeu', 'icond2'].includes(modelName)) y = (projected.y - gridOrigin.y) / gridPixelSize.y;
|
|
855
|
-
return {
|
|
856
|
-
x,
|
|
857
|
-
y
|
|
858
|
-
};
|
|
859
|
-
} else {
|
|
860
|
-
const lonFirst = gridOrigin.x;
|
|
861
|
-
if (lonFirst > 180 && adjustedLon < 0) adjustedLon += 360;else if (lonFirst < 0 && adjustedLon > 180) adjustedLon -= 360;
|
|
862
|
-
}
|
|
863
|
-
x = (adjustedLon - gridOrigin.x) / gridPixelSize.x;
|
|
864
|
-
if (isFlippedGrid) {
|
|
865
|
-
if (isECMWFType) y = (gridOrigin.y - projected.y) / Math.abs(gridPixelSize.y);else {
|
|
866
|
-
const maxLat = gridDef.grid_params.lat_last || (gridDef.grid_params.ny - 1) * gridDef.grid_params.dy_degrees;
|
|
867
|
-
y = (maxLat - projected.y) / Math.abs(gridPixelSize.y);
|
|
868
|
-
}
|
|
869
|
-
} else y = (projected.y - gridOrigin.y) / gridPixelSize.y;
|
|
870
|
-
}
|
|
871
|
-
} else {
|
|
872
|
-
const projOrigin = {
|
|
873
|
-
x: gridDef.grid_params.x_origin,
|
|
874
|
-
y: gridDef.grid_params.y_origin
|
|
875
|
-
};
|
|
876
|
-
const projPixelSize = {
|
|
877
|
-
x: gridDef.grid_params.dx,
|
|
878
|
-
y: gridDef.grid_params.dy
|
|
879
|
-
};
|
|
880
|
-
x = (projected.x - projOrigin.x) / projPixelSize.x;
|
|
881
|
-
y = (projOrigin.y - projected.y) / Math.abs(projPixelSize.y);
|
|
882
|
-
}
|
|
883
|
-
return {
|
|
884
|
-
x,
|
|
885
|
-
y
|
|
886
|
-
};
|
|
887
|
-
}
|
|
888
|
-
latLonToGridPixelPolarStereographic(lat, lon, gridDef) {
|
|
889
|
-
try {
|
|
890
|
-
const projParams = gridDef.proj_params;
|
|
891
|
-
let projectionString = `+proj=${projParams.proj}`;
|
|
892
|
-
Object.keys(projParams).forEach(key => {
|
|
893
|
-
if (key !== 'proj') projectionString += ` +${key}=${projParams[key]}`;
|
|
894
|
-
});
|
|
895
|
-
projectionString += ' +lat_0=90 +no_defs';
|
|
896
|
-
const {
|
|
897
|
-
nx,
|
|
898
|
-
ny,
|
|
899
|
-
dx,
|
|
900
|
-
dy,
|
|
901
|
-
x_origin,
|
|
902
|
-
y_origin
|
|
903
|
-
} = gridDef.grid_params;
|
|
904
|
-
const x_min = x_origin;
|
|
905
|
-
const x_max = x_origin + (nx - 1) * dx;
|
|
906
|
-
const y_max = y_origin;
|
|
907
|
-
const y_min = y_origin + (ny - 1) * dy;
|
|
908
|
-
const [proj_x, proj_y] = (0, _proj.default)('EPSG:4326', projectionString, [lon, lat]);
|
|
909
|
-
if (!isFinite(proj_x) || !isFinite(proj_y)) return {
|
|
910
|
-
x: -1,
|
|
911
|
-
y: -1
|
|
912
|
-
};
|
|
913
|
-
const t_x = (proj_x - x_min) / (x_max - x_min);
|
|
914
|
-
const t_y = (proj_y - y_max) / (y_min - y_max);
|
|
915
|
-
const x = t_x * (nx - 1);
|
|
916
|
-
const y = t_y * (ny - 1);
|
|
917
|
-
return {
|
|
918
|
-
x,
|
|
919
|
-
y
|
|
920
|
-
};
|
|
921
|
-
} catch (error) {
|
|
922
|
-
console.warn(`[GridAccessor] RGEM polar stereographic conversion failed for ${lat}, ${lon}:`, error);
|
|
923
|
-
return {
|
|
924
|
-
x: -1,
|
|
925
|
-
y: -1
|
|
926
|
-
};
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
// --- Worker and Status Methods ---
|
|
931
|
-
|
|
932
|
-
createWorker() {
|
|
933
|
-
if (this.isReactNative) return null;
|
|
934
|
-
const workerCode = `
|
|
935
|
-
import { decompress } from 'https://cdn.skypack.dev/fzstd@0.1.1';
|
|
936
|
-
|
|
937
|
-
function _reconstructData(decompressedDeltas, encoding) {
|
|
938
|
-
const expectedLength = encoding.length;
|
|
939
|
-
const reconstructedData = new Int8Array(expectedLength);
|
|
940
|
-
if (decompressedDeltas.length > 0 && expectedLength > 0) {
|
|
941
|
-
reconstructedData[0] = decompressedDeltas[0] > 127 ? decompressedDeltas[0] - 256 : decompressedDeltas[0];
|
|
942
|
-
for (let i = 1; i < expectedLength; i++) {
|
|
943
|
-
const delta = decompressedDeltas[i] > 127 ? decompressedDeltas[i] - 256 : decompressedDeltas[i];
|
|
944
|
-
reconstructedData[i] = reconstructedData[i - 1] + delta;
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
return new Uint8Array(reconstructedData.buffer);
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
self.onmessage = async (e) => {
|
|
951
|
-
const { requestId, compressedData, encoding } = e.data;
|
|
952
|
-
try {
|
|
953
|
-
const decompressedDeltas = await decompress(compressedData);
|
|
954
|
-
const finalData = _reconstructData(decompressedDeltas, encoding);
|
|
955
|
-
self.postMessage({ success: true, requestId: requestId, decompressedData: finalData, encoding: encoding }, [finalData.buffer]);
|
|
956
|
-
} catch (error) {
|
|
957
|
-
self.postMessage({ success: false, requestId: requestId, error: error.message });
|
|
958
|
-
}
|
|
959
|
-
};
|
|
960
|
-
`;
|
|
961
|
-
const blob = new Blob([workerCode], {
|
|
962
|
-
type: 'application/javascript'
|
|
963
|
-
});
|
|
964
|
-
return new Worker(URL.createObjectURL(blob), {
|
|
965
|
-
type: 'module'
|
|
966
|
-
});
|
|
967
|
-
}
|
|
968
|
-
_processResultQueue() {
|
|
969
|
-
while (this.resultQueue.length > 0) {
|
|
970
|
-
const {
|
|
971
|
-
success,
|
|
972
|
-
requestId,
|
|
973
|
-
decompressedData,
|
|
974
|
-
encoding,
|
|
975
|
-
error
|
|
976
|
-
} = this.resultQueue.shift();
|
|
977
|
-
if (this.workerResolvers.has(requestId)) {
|
|
978
|
-
const {
|
|
979
|
-
resolve,
|
|
980
|
-
reject
|
|
981
|
-
} = this.workerResolvers.get(requestId);
|
|
982
|
-
if (success) {
|
|
983
|
-
resolve({
|
|
984
|
-
data: decompressedData
|
|
985
|
-
}); // Return as { data: ... }
|
|
986
|
-
} else {
|
|
987
|
-
reject(new Error(error));
|
|
988
|
-
}
|
|
989
|
-
this.workerResolvers.delete(requestId);
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
this.isProcessingQueue = false;
|
|
993
|
-
}
|
|
994
|
-
_handleWorkerMessage(e) {
|
|
995
|
-
if (this.isReactNative) return;
|
|
996
|
-
const {
|
|
997
|
-
success,
|
|
998
|
-
requestId,
|
|
999
|
-
decompressedData,
|
|
1000
|
-
encoding,
|
|
1001
|
-
error
|
|
1002
|
-
} = e.data;
|
|
1003
|
-
this.resultQueue.push({
|
|
1004
|
-
success,
|
|
1005
|
-
requestId,
|
|
1006
|
-
decompressedData,
|
|
1007
|
-
encoding,
|
|
1008
|
-
error
|
|
1009
|
-
});
|
|
1010
|
-
if (!this.isProcessingQueue) {
|
|
1011
|
-
this.isProcessingQueue = true;
|
|
1012
|
-
requestAnimationFrame(() => this._processResultQueue());
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
async fetchModelStatus(force = false) {
|
|
1016
|
-
if (!this.modelStatus || force) {
|
|
1017
|
-
try {
|
|
1018
|
-
const response = await fetch(this.statusUrl);
|
|
1019
|
-
if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`);
|
|
1020
|
-
this.modelStatus = (await response.json()).models;
|
|
1021
|
-
} catch (error) {
|
|
1022
|
-
this.modelStatus = null;
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
return this.modelStatus;
|
|
1026
|
-
}
|
|
1027
|
-
async fetchMRMSStatus(force = false) {
|
|
1028
|
-
const mrmsStatusUrl = 'https://h3dfvh5pq6euq36ymlpz4zqiha0obqju.lambda-url.us-east-2.on.aws';
|
|
1029
|
-
if (!this.mrmsStatus || force) {
|
|
1030
|
-
try {
|
|
1031
|
-
const response = await fetch(mrmsStatusUrl);
|
|
1032
|
-
if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`);
|
|
1033
|
-
this.mrmsStatus = await response.json();
|
|
1034
|
-
} catch (error) {
|
|
1035
|
-
this.mrmsStatus = null;
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
return this.mrmsStatus;
|
|
1039
|
-
}
|
|
1040
|
-
startAutoRefresh(intervalSeconds) {
|
|
1041
|
-
this.stopAutoRefresh();
|
|
1042
|
-
this.autoRefreshIntervalId = setInterval(async () => {
|
|
1043
|
-
await this.fetchModelStatus(true);
|
|
1044
|
-
this._emitStateChange();
|
|
1045
|
-
}, (intervalSeconds || 60) * 1000);
|
|
1046
|
-
}
|
|
1047
|
-
stopAutoRefresh() {
|
|
1048
|
-
if (this.autoRefreshIntervalId) {
|
|
1049
|
-
clearInterval(this.autoRefreshIntervalId);
|
|
1050
|
-
this.autoRefreshIntervalId = null;
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
|
-
}
|
|
1054
|
-
exports.AguaceroCore = AguaceroCore;
|
|
1055
|
-
//# sourceMappingURL=AguaceroCore.js.map
|