mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-22 03:29:31 -07:00
fix metric conversion on regional forecast map
This commit is contained in:
@@ -1,16 +1,21 @@
|
|||||||
import { getWeatherRegionalIconFromIconLink } from './icons.mjs';
|
import { getWeatherRegionalIconFromIconLink } from './icons.mjs';
|
||||||
import { preloadImg } from './utils/image.mjs';
|
import { preloadImg } from './utils/image.mjs';
|
||||||
import { json } from './utils/fetch.mjs';
|
import { json } from './utils/fetch.mjs';
|
||||||
|
import { temperature as temperatureUnit } from './utils/units.mjs';
|
||||||
|
|
||||||
const buildForecast = (forecast, city, cityXY) => ({
|
const buildForecast = (forecast, city, cityXY) => {
|
||||||
daytime: forecast.isDaytime,
|
// get a unit converter
|
||||||
temperature: forecast.temperature || 0,
|
const temperatureConverter = temperatureUnit('us');
|
||||||
name: formatCity(city.city),
|
return {
|
||||||
icon: forecast.icon,
|
daytime: forecast.isDaytime,
|
||||||
x: cityXY.x,
|
temperature: temperatureConverter(forecast.temperature || 0),
|
||||||
y: cityXY.y,
|
name: formatCity(city.city),
|
||||||
time: forecast.startTime,
|
icon: forecast.icon,
|
||||||
});
|
x: cityXY.x,
|
||||||
|
y: cityXY.y,
|
||||||
|
time: forecast.startTime,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const getRegionalObservation = async (point, city) => {
|
const getRegionalObservation = async (point, city) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const round2 = (value, decimals) => Math.trunc(value * 10 ** decimals) / 10 ** d
|
|||||||
|
|
||||||
const kphToMph = (Kph) => Math.round(Kph / 1.609_34);
|
const kphToMph = (Kph) => Math.round(Kph / 1.609_34);
|
||||||
const celsiusToFahrenheit = (Celsius) => Math.round((Celsius * 9) / 5 + 32);
|
const celsiusToFahrenheit = (Celsius) => Math.round((Celsius * 9) / 5 + 32);
|
||||||
|
const fahrenheitToCelsius = (Fahrenheit) => Math.round((Fahrenheit - 32) * 5 / 9);
|
||||||
const kilometersToMiles = (Kilometers) => Math.round(Kilometers / 1.609_34);
|
const kilometersToMiles = (Kilometers) => Math.round(Kilometers / 1.609_34);
|
||||||
const metersToFeet = (Meters) => Math.round(Meters / 0.3048);
|
const metersToFeet = (Meters) => Math.round(Meters / 0.3048);
|
||||||
const pascalToInHg = (Pascal) => round2(Pascal * 0.000_295_3, 2);
|
const pascalToInHg = (Pascal) => round2(Pascal * 0.000_295_3, 2);
|
||||||
@@ -35,7 +36,11 @@ const temperature = (defaultUnit = 'si') => {
|
|||||||
let converter = (passthru) => Math.round(passthru);
|
let converter = (passthru) => Math.round(passthru);
|
||||||
// change the converter if there is a mismatch
|
// change the converter if there is a mismatch
|
||||||
if (defaultUnit !== settings.units.value) {
|
if (defaultUnit !== settings.units.value) {
|
||||||
converter = celsiusToFahrenheit;
|
if (defaultUnit === 'us') {
|
||||||
|
converter = fahrenheitToCelsius;
|
||||||
|
} else {
|
||||||
|
converter = celsiusToFahrenheit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// append units
|
// append units
|
||||||
if (settings.units.value === 'si') {
|
if (settings.units.value === 'si') {
|
||||||
|
|||||||
Reference in New Issue
Block a user