mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-14 07:39:29 -07:00
preload gifs
This commit is contained in:
@@ -766,7 +766,7 @@ const index = (() => {
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Unable to fetch reverse geocode');
|
||||
console.error(e);
|
||||
console.error(e.status, e.responseJSONe);
|
||||
}
|
||||
const ZipCode = data.address.Postal;
|
||||
const City = data.address.City;
|
||||
|
||||
@@ -38,10 +38,13 @@ class CurrentWeather extends WeatherDisplay {
|
||||
// TODO: add retry for further stations if observations are unavailable
|
||||
} catch (e) {
|
||||
console.error('Unable to get current observations');
|
||||
console.error(e);
|
||||
console.error(e.status, e.responseJSON);
|
||||
this.setStatus(STATUS.failed);
|
||||
return;
|
||||
}
|
||||
// preload the icon
|
||||
utils.image.preload(icons.getWeatherIconFromIconLink(observations.iconPath));
|
||||
|
||||
// we only get here if there was no error above
|
||||
this.data = Object.assign({}, observations, {station: station});
|
||||
this.setStatus(STATUS.loaded);
|
||||
@@ -64,7 +67,7 @@ class CurrentWeather extends WeatherDisplay {
|
||||
let WindChill = Math.round(observations.windChill.value);
|
||||
let WindGust = Math.round(observations.windGust.value);
|
||||
let Humidity = Math.round(observations.relativeHumidity.value);
|
||||
const Icon = icons.getWeatherIconFromIconLink(observations.icon);
|
||||
const Icon = icons.getWeatherIconFromIconLink(observations.iconPath);
|
||||
let PressureDirection = '';
|
||||
const TextConditions = observations.textDescription;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ class ExtendedForecast extends WeatherDisplay {
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Unable to get extended forecast');
|
||||
console.error(e);
|
||||
console.error(e.status, e.responseJSON);
|
||||
this.setStatus(STATUS.failed);
|
||||
return;
|
||||
}
|
||||
@@ -67,6 +67,9 @@ class ExtendedForecast extends WeatherDisplay {
|
||||
fDay.text = this.shortenExtendedForecastText(period.shortForecast);
|
||||
fDay.dayName = dates[destIndex];
|
||||
|
||||
// preload the icon
|
||||
utils.image.preload(fDay.icon);
|
||||
|
||||
if (period.isDaytime) {
|
||||
// day time is the high temperature
|
||||
fDay.high = period.temperature;
|
||||
|
||||
@@ -104,7 +104,7 @@ class LocalForecast extends WeatherDisplay {
|
||||
|
||||
} catch (e) {
|
||||
console.error(`GetWeatherForecast failed: ${weatherParameters.forecast}`);
|
||||
console.error(e);
|
||||
console.error(e.status, e.responseJSON);
|
||||
this.setStatus(STATUS.failed);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class Radar extends WeatherDisplay {
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Unable to get list of radars');
|
||||
console.error(e);
|
||||
console.error(e.status, e.responseJSON);
|
||||
this.setStatus(STATUS.failed);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -93,6 +93,9 @@ class RegionalForecast extends WeatherDisplay {
|
||||
y: cityXY.y,
|
||||
};
|
||||
|
||||
// preload the icon
|
||||
utils.image.preload(icons.getWeatherRegionalIconFromIconLink(regionalObservation.icon, !regionalObservation.daytime))
|
||||
|
||||
// return a pared-down forecast
|
||||
// 0th object is the current conditions
|
||||
// first object is the next period i.e. if it's daytime then it's the "tonight" forecast
|
||||
@@ -105,7 +108,7 @@ class RegionalForecast extends WeatherDisplay {
|
||||
];
|
||||
} catch (e) {
|
||||
console.log(`No regional forecast data for '${city.Name}'`);
|
||||
console.error(e);
|
||||
console.error(e.status, e.responseJSON);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
@@ -162,11 +165,13 @@ class RegionalForecast extends WeatherDisplay {
|
||||
dataType: 'json',
|
||||
crossDomain: true,
|
||||
});
|
||||
// preload the image
|
||||
utils.image.preload(icons.getWeatherRegionalIconFromIconLink(observation.properties.icon, !observation.properties.daytime));
|
||||
// return the observation
|
||||
return observation.properties;
|
||||
} catch (e) {
|
||||
console.log(`Unable to get regional observations for ${city.Name}`);
|
||||
console.error(e);
|
||||
console.error(e.status, e.responseJSON);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class TravelForecast extends WeatherDisplay {
|
||||
};
|
||||
} catch (e) {
|
||||
console.error(`GetTravelWeather for ${city.Name} failed`);
|
||||
console.error(e);
|
||||
console.error(e.status, e.responseJSON);
|
||||
return {name: city.Name};
|
||||
}
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@ const utils = (() => {
|
||||
} catch (e) {
|
||||
console.error('Unable to get point');
|
||||
console.error(lat,lon);
|
||||
console.error(e);
|
||||
console.error(e.status, e.responseJSON);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -45,6 +45,19 @@ const utils = (() => {
|
||||
});
|
||||
};
|
||||
|
||||
// preload an image
|
||||
// the goal is to get it in the browser's cache so it is available more quickly when the browser needs it
|
||||
// a list of cached icons is used to avoid hitting the cache multiple times
|
||||
const cachedImages = [];
|
||||
const preload = (src) => {
|
||||
if (cachedImages.includes(src)) return false;
|
||||
const img = new Image();
|
||||
img.scr = src;
|
||||
cachedImages.push(src);
|
||||
console.log(cachedImages);
|
||||
return true;
|
||||
};
|
||||
|
||||
// *********************************** unit conversions ***********************
|
||||
|
||||
Math.round2 = (value, decimals) => Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
|
||||
@@ -360,6 +373,7 @@ const utils = (() => {
|
||||
image: {
|
||||
load: loadImg,
|
||||
superGifAsync,
|
||||
preload,
|
||||
},
|
||||
weather: {
|
||||
getPoint,
|
||||
|
||||
@@ -146,7 +146,7 @@ const GetMonthPrecipitation = async (WeatherParameters) => {
|
||||
|
||||
} catch (e) {
|
||||
console.error('GetMonthPrecipitation failed');
|
||||
console.error(e);
|
||||
console.error(e.status, e.responseJSON);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user