@aguacerowx/javascript-sdk 0.0.14 → 0.0.16

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/AguaceroCore.js +33 -34
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aguacerowx/javascript-sdk",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -69,11 +69,14 @@ export class AguaceroCore extends EventEmitter {
69
69
  this.customColormaps = options.customColormaps || {};
70
70
 
71
71
  const userLayerOptions = options.layerOptions || {};
72
+ // EDIT: Determine initial mode from options
73
+ const initialMode = userLayerOptions.mode || 'model';
72
74
  const initialVariable = userLayerOptions.variable || null;
73
75
 
74
76
  this.state = {
75
77
  model: userLayerOptions.model || 'gfs',
76
- isMRMS: false,
78
+ // EDIT: Set isMRMS based on the initial mode
79
+ isMRMS: initialMode === 'mrms',
77
80
  mrmsTimestamp: null,
78
81
  variable: initialVariable,
79
82
  date: null,
@@ -135,15 +138,36 @@ export class AguaceroCore extends EventEmitter {
135
138
  await this.fetchModelStatus(true);
136
139
  await this.fetchMRMSStatus(true);
137
140
 
138
- const latestRun = findLatestModelRun(this.modelStatus, this.state.model);
139
- let initialState = this.state;
141
+ let initialState = { ...this.state };
140
142
 
141
- if (latestRun && !this.state.isMRMS) {
142
- initialState = { ...this.state, ...latestRun, forecastHour: 0 };
143
-
144
- const availableVariables = this.getAvailableVariables(initialState.model);
145
- if (availableVariables && availableVariables.length > 0) {
146
- initialState.variable = availableVariables[0];
143
+ // ADD: Logic to handle an initial MRMS state
144
+ if (initialState.isMRMS) {
145
+ const variable = initialState.variable;
146
+ if (variable && this.mrmsStatus && this.mrmsStatus[variable]) {
147
+ const sortedTimestamps = [...(this.mrmsStatus[variable] || [])].sort((a, b) => b - a);
148
+ initialState.mrmsTimestamp = sortedTimestamps.length > 0 ? sortedTimestamps[0] : null;
149
+ } else {
150
+ // Fallback if the provided variable is not valid
151
+ console.warn(`Initial MRMS variable '${variable}' not found. Using default.`);
152
+ const availableMRMSVars = this.getAvailableVariables('mrms');
153
+ if (availableMRMSVars.length > 0) {
154
+ const firstVar = availableMRMSVars[0];
155
+ initialState.variable = firstVar;
156
+ const sortedTimestamps = [...(this.mrmsStatus[firstVar] || [])].sort((a, b) => b - a);
157
+ initialState.mrmsTimestamp = sortedTimestamps.length > 0 ? sortedTimestamps[0] : null;
158
+ }
159
+ }
160
+ } else {
161
+ // EDIT: This is the existing logic, now in an else block
162
+ const latestRun = findLatestModelRun(this.modelStatus, initialState.model);
163
+ if (latestRun) {
164
+ initialState = { ...initialState, ...latestRun, forecastHour: 0 };
165
+ if (!initialState.variable) {
166
+ const availableVariables = this.getAvailableVariables(initialState.model);
167
+ if (availableVariables && availableVariables.length > 0) {
168
+ initialState.variable = availableVariables[0];
169
+ }
170
+ }
147
171
  }
148
172
  }
149
173
 
@@ -570,30 +594,6 @@ export class AguaceroCore extends EventEmitter {
570
594
  const conversionFunc = getUnitConversionFunction(dataNativeUnit, displayUnit);
571
595
  let displayValue = conversionFunc ? conversionFunc(nativeValue) : nativeValue;
572
596
 
573
- // --- START: ADDED CODE ---
574
-
575
- // Create a variable to hold the precipitation type, if any.
576
- let precipType = null;
577
-
578
- // Check if the current variable is one of the special ptype variables.
579
- if (variable === 'ptypeRefl' || variable === 'ptypeRate') {
580
- const value = nativeValue; // Use the raw, unconverted value for ptype logic
581
-
582
- if (value >= 100 && value < 200) {
583
- displayValue -= 100;
584
- precipType = 'Snow';
585
- } else if (value >= 200 && value < 300) {
586
- displayValue -= 200;
587
- precipType = 'Frzg Rain'; // Abbreviated for tooltips
588
- } else if (value >= 300 && value < 400) {
589
- displayValue -= 300;
590
- precipType = 'Ice Pellets';
591
- } else {
592
- precipType = 'Rain';
593
- }
594
- }
595
-
596
- // Return the final payload, now including the precipType.
597
597
  return {
598
598
  lngLat: { lng, lat },
599
599
  variable: {
@@ -602,7 +602,6 @@ export class AguaceroCore extends EventEmitter {
602
602
  },
603
603
  value: displayValue,
604
604
  unit: displayUnit,
605
- precipType: precipType // NEW: Add this to the return object
606
605
  };
607
606
  } catch (error) {
608
607
  return null;