mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-17 17:19:30 -07:00
current conditions LDL
This commit is contained in:
@@ -1,85 +1,3 @@
|
||||
/* globals luxon, _TravelCities */
|
||||
|
||||
var canvasRegionalObservations;
|
||||
|
||||
var canvasRegionalForecast1;
|
||||
var canvasRegionalForecast2;
|
||||
|
||||
var canvasLocalRadar;
|
||||
|
||||
var canvasCurrentWeather;
|
||||
|
||||
var canvasExtendedForecast1;
|
||||
var canvasExtendedForecast2;
|
||||
|
||||
var canvasLocalForecast;
|
||||
|
||||
var divHazards;
|
||||
var divHazardsScroll;
|
||||
var canvasHazards;
|
||||
|
||||
var canvasAlmanac;
|
||||
var canvasAlmanacTides;
|
||||
var canvasOutlook;
|
||||
var canvasMarineForecast;
|
||||
var canvasAirQuality;
|
||||
|
||||
var canvasTravelForecast;
|
||||
|
||||
var divOutlookTemp;
|
||||
var divOutlookPrcp;
|
||||
|
||||
var canvasLatestObservations;
|
||||
|
||||
var _WeatherParameters = null;
|
||||
|
||||
var _UpdateWeatherUpdateMs = 50;
|
||||
var canvasBackGroundDateTime = null;
|
||||
var canvasBackGroundCurrentConditions = null;
|
||||
|
||||
var _UpdateWeatherCurrentConditionType = CurrentConditionTypes.Title;
|
||||
var _UpdateWeatherCurrentConditionCounterMs = 0;
|
||||
|
||||
var _UpdateCustomScrollTextMs = 0;
|
||||
|
||||
var _UpdateHazardsY = 0;
|
||||
|
||||
const GetMonthPrecipitation = async (WeatherParameters) => {
|
||||
const DateTime = luxon.DateTime;
|
||||
const today = DateTime.local().startOf('day').toISO().replace('.000','');
|
||||
|
||||
try {
|
||||
const cliProducts = await $.ajaxCORS({
|
||||
type: 'GET',
|
||||
url: 'https://api.weather.gov/products',
|
||||
data: {
|
||||
location: WeatherParameters.WeatherOffice,
|
||||
type: 'CLI',
|
||||
start: today,
|
||||
},
|
||||
dataType: 'json',
|
||||
crossDomain: true,
|
||||
});
|
||||
|
||||
// get the first url from the list
|
||||
const cli = await $.ajaxCORS({
|
||||
type: 'GET',
|
||||
url: cliProducts['@graph'][0]['@id'],
|
||||
dataType: 'json',
|
||||
crossDomain: true,
|
||||
});
|
||||
|
||||
WeatherParameters.WeatherMonthlyTotals = WeatherMonthlyTotalsParser(cli.productText);
|
||||
console.log(WeatherParameters.WeatherMonthlyTotals);
|
||||
|
||||
} catch (e) {
|
||||
console.error('GetMonthPrecipitation failed');
|
||||
console.error(e.status, e.responseJSON);
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var GetWeatherHazards3 = function (WeatherParameters) {
|
||||
var ZoneId = WeatherParameters.ZoneId;
|
||||
var HazardUrls = [];
|
||||
@@ -166,87 +84,6 @@ var GetWeatherHazards3 = function (WeatherParameters) {
|
||||
});
|
||||
};
|
||||
|
||||
$(() => {
|
||||
canvasBackGroundDateTime = $('#canvasBackGroundDateTime');
|
||||
canvasBackGroundCurrentConditions = $('#canvasBackGroundCurrentConditions');
|
||||
canvasProgress = $('#canvasProgress');
|
||||
divProgress = $('#divProgress');
|
||||
|
||||
canvasLocalRadar = $('#canvasLocalRadar');
|
||||
|
||||
canvasRegionalForecast1 = $('#canvasRegionalForecast1');
|
||||
canvasRegionalForecast2 = $('#canvasRegionalForecast2');
|
||||
|
||||
canvasRegionalObservations = $('#canvasRegionalObservations');
|
||||
|
||||
canvasCurrentWeather = $('#canvasCurrentWeather');
|
||||
|
||||
canvasExtendedForecast1 = $('#canvasExtendedForecast1');
|
||||
canvasExtendedForecast2 = $('#canvasExtendedForecast2');
|
||||
|
||||
canvasLocalForecast = $('#canvasLocalForecast');
|
||||
|
||||
divHazards = $('#divHazards');
|
||||
divHazardsScroll = $('#divHazardsScroll');
|
||||
canvasHazards = $('#canvasHazards');
|
||||
|
||||
canvasAlmanac = $('#canvasAlmanac');
|
||||
canvasAlmanacTides = $('#canvasAlmanacTides');
|
||||
canvasOutlook = $('#canvasOutlook');
|
||||
canvasMarineForecast = $('#canvasMarineForecast');
|
||||
canvasAirQuality = $('#canvasAirQuality');
|
||||
|
||||
divOutlookTemp = $('#divOutlookTemp');
|
||||
divOutlookPrcp = $('#divOutlookPrcp');
|
||||
|
||||
canvasTravelForecast = $('#canvasTravelForecast');
|
||||
|
||||
canvasLatestObservations = $('#canvasLatestObservations');
|
||||
|
||||
|
||||
canvasProgress.mousemove(canvasProgress_mousemove);
|
||||
canvasProgress.click(canvasProgress_click);
|
||||
|
||||
_WeatherParameters = {};
|
||||
|
||||
_WeatherParameters.WeatherHazardConditions = {};
|
||||
|
||||
const WeatherCanvases = [];
|
||||
WeatherCanvases.push(canvasProgress);
|
||||
WeatherCanvases.push(canvasCurrentWeather);
|
||||
WeatherCanvases.push(canvasLatestObservations);
|
||||
WeatherCanvases.push(canvasTravelForecast);
|
||||
WeatherCanvases.push(canvasRegionalForecast1);
|
||||
WeatherCanvases.push(canvasRegionalForecast2);
|
||||
WeatherCanvases.push(canvasRegionalObservations);
|
||||
WeatherCanvases.push(canvasAlmanac);
|
||||
WeatherCanvases.push(canvasAlmanacTides);
|
||||
WeatherCanvases.push(canvasOutlook);
|
||||
WeatherCanvases.push(canvasMarineForecast);
|
||||
WeatherCanvases.push(canvasAirQuality);
|
||||
WeatherCanvases.push(canvasLocalForecast);
|
||||
WeatherCanvases.push(canvasExtendedForecast1);
|
||||
WeatherCanvases.push(canvasExtendedForecast2);
|
||||
WeatherCanvases.push(canvasHazards);
|
||||
WeatherCanvases.push(canvasLocalRadar);
|
||||
_WeatherParameters.WeatherCanvases = WeatherCanvases;
|
||||
|
||||
$(WeatherCanvases).each(function () {
|
||||
var WeatherCanvas = $(this);
|
||||
WeatherCanvas.css('position', 'absolute');
|
||||
WeatherCanvas.css('top', '0px');
|
||||
WeatherCanvas.css('left', '0px');
|
||||
WeatherCanvas.hide();
|
||||
});
|
||||
canvasProgress.show();
|
||||
|
||||
_WeatherParameters.TravelCities = _TravelCities;
|
||||
|
||||
_WeatherParameters.Progress = new Progress({
|
||||
WeatherParameters: _WeatherParameters,
|
||||
});
|
||||
});
|
||||
|
||||
var canvasProgress_mousemove = function (e) {
|
||||
canvasProgress.css('cursor', '');
|
||||
|
||||
@@ -449,161 +286,3 @@ var UpdateHazards = function (Offset) {
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
const WeatherMonthlyTotalsParser = (text) => {
|
||||
return +text.match(/MONTH TO DATE\s*(\d{1,2}\.\d\d)/)[1];
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
const DrawCustomScrollText = (WeatherParameters, context) => {
|
||||
const font = 'Star4000';
|
||||
const size = '24pt';
|
||||
const color = '#ffffff';
|
||||
const shadow = 2;
|
||||
let x = 640;
|
||||
const y = 430;
|
||||
|
||||
if (WeatherParameters.Progress.GetTotalPercentage() !== 100) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear the date and time area.
|
||||
context.drawImage(canvasBackGroundCurrentConditions[0], 0, 0, 640, 75, 0, 405, 640, 75);
|
||||
|
||||
const text = _ScrollText;
|
||||
|
||||
x = 640 - ((_UpdateCustomScrollTextMs / _UpdateWeatherUpdateMs) * 5);
|
||||
// Wait an extra 5 characters.
|
||||
if (x < ((text.length + 10) * 15 * -1)) {
|
||||
_UpdateCustomScrollTextMs = 0;
|
||||
x = 640;
|
||||
}
|
||||
|
||||
// Draw the current condition.
|
||||
DrawText(context, font, size, color, x, y, text, shadow);
|
||||
|
||||
};
|
||||
|
||||
const AssignScrollText = (e) => {
|
||||
_ScrollText = e.ScrollText;
|
||||
_UpdateCustomScrollTextMs = 0;
|
||||
_UpdateWeatherCurrentConditionType = CurrentConditionTypes.Title;
|
||||
_UpdateWeatherCurrentConditionCounterMs = 0;
|
||||
};
|
||||
|
||||
var DrawCurrentConditions = function (WeatherParameters, context) {
|
||||
var Humidity;
|
||||
var DewPoint;
|
||||
var Temperature;
|
||||
var TemperatureUnit;
|
||||
var HeatIndex;
|
||||
var WindChill;
|
||||
var Pressure;
|
||||
var PressureDirection;
|
||||
var WindSpeed;
|
||||
var WindDirection;
|
||||
var WindGust;
|
||||
var WindUnit;
|
||||
var Visibility;
|
||||
var VisibilityUnit;
|
||||
var Ceiling;
|
||||
var CeilingUnit;
|
||||
var PrecipitationTotal;
|
||||
var PrecipitationTotalUnit;
|
||||
|
||||
var text;
|
||||
|
||||
if (WeatherParameters.Progress.GetTotalPercentage() != 100) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear the date and time area.
|
||||
context.drawImage(canvasBackGroundCurrentConditions[0], 0, 0, 640, 75, 0, 405, 640, 75);
|
||||
|
||||
var WeatherCurrentConditions = WeatherParameters.WeatherCurrentConditions;
|
||||
var WeatherMonthlyTotals = WeatherParameters.WeatherMonthlyTotals;
|
||||
|
||||
|
||||
if (_UpdateWeatherCurrentConditionCounterMs >= 4000) {
|
||||
_UpdateWeatherCurrentConditionCounterMs = 0;
|
||||
_UpdateWeatherCurrentConditionType++;
|
||||
if (_UpdateWeatherCurrentConditionType > CurrentConditionTypes.MonthPrecipitation) {
|
||||
_UpdateWeatherCurrentConditionType = CurrentConditionTypes.Title;
|
||||
}
|
||||
}
|
||||
|
||||
switch(_UpdateWeatherCurrentConditionType) {
|
||||
case CurrentConditionTypes.Title:
|
||||
// mjb 06/01/19 text = "Conditions at " + WeatherCurrentConditions.StationName;
|
||||
text = 'Conditions at ' + WeatherCurrentConditions.StationName.substr(0, 20); // mjb 06/01/19
|
||||
break;
|
||||
case CurrentConditionTypes.Conditions:
|
||||
text = WeatherCurrentConditions.Conditions;
|
||||
break;
|
||||
case CurrentConditionTypes.Temperature:
|
||||
text = 'Temp: ' + Temperature + String.fromCharCode(176) + TemperatureUnit;
|
||||
if (HeatIndex != Temperature) {
|
||||
text += ' ';
|
||||
text += 'Heat Index: ' + HeatIndex + String.fromCharCode(176) + TemperatureUnit;
|
||||
} else if (WindChill != '' && WindChill < Temperature) {
|
||||
text += ' ';
|
||||
text += 'Wind Chill: ' + WindChill + String.fromCharCode(176) + TemperatureUnit;
|
||||
}
|
||||
break;
|
||||
case CurrentConditionTypes.HumidityDewpoint:
|
||||
text = 'Humidity: ' + Humidity + '%';
|
||||
text += ' ';
|
||||
text += 'Dewpoint: ' + DewPoint + String.fromCharCode(176) + TemperatureUnit;
|
||||
break;
|
||||
case CurrentConditionTypes.BarometricPressure:
|
||||
text = 'Barometric Pressure: ' + Pressure + ' ' + PressureDirection;
|
||||
break;
|
||||
case CurrentConditionTypes.Wind:
|
||||
if (WindSpeed > 0) {
|
||||
text = 'Wind: ' + WindDirection + ' ' + WindSpeed + WindUnit;
|
||||
} else if (WindSpeed == 'NA') {
|
||||
text = 'Wind: NA';
|
||||
} else {
|
||||
text = 'Wind: Calm';
|
||||
}
|
||||
if (WindGust != '') {
|
||||
text += ' ';
|
||||
text += 'Gusts to ' + WindGust;
|
||||
}
|
||||
break;
|
||||
case CurrentConditionTypes.VisibilityCeiling:
|
||||
text = 'Visib: ' + parseInt(Visibility).toString() + VisibilityUnit;
|
||||
text += ' ';
|
||||
text += 'Ceiling: ' + (Ceiling == '' ? 'Unlimited' : Ceiling + CeilingUnit);
|
||||
break;
|
||||
case CurrentConditionTypes.MonthPrecipitation:
|
||||
if (PrecipitationTotal.toString() == '') {
|
||||
_UpdateWeatherCurrentConditionCounterMs += 4000;
|
||||
DrawCurrentConditions(WeatherParameters, context);
|
||||
return;
|
||||
}
|
||||
|
||||
// mjb 10/02/19 Begin
|
||||
//text = WeatherMonthlyTotals.MonthName + " Precipitation: " + PrecipitationTotal.toString() + PrecipitationTotalUnit;
|
||||
|
||||
if (PrecipitationTotal.toString() == 'T') {
|
||||
text = WeatherMonthlyTotals.MonthName + ' Precipitation: Trace';
|
||||
} else {
|
||||
text = WeatherMonthlyTotals.MonthName + ' Precipitation: ' + PrecipitationTotal.toString() + PrecipitationTotalUnit;
|
||||
}
|
||||
|
||||
// mjb 10/02/19 End
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
// Draw the current condition.
|
||||
DrawText(context, font, size, color, x, y, text, shadow);
|
||||
|
||||
//_UpdateWeatherCurrentConditionCounterMs += _UpdateWeatherUpdateMs;
|
||||
//console.log(_UpdateWeatherUpdateMs);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user