preload gifs
This commit is contained in:
parent
36673b1f1d
commit
77c0744cb3
2
dist/index.html
vendored
2
dist/index.html
vendored
File diff suppressed because one or more lines are too long
2
dist/resources/ws.min.js
vendored
2
dist/resources/ws.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -766,7 +766,7 @@ const index = (() => {
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Unable to fetch reverse geocode');
|
console.error('Unable to fetch reverse geocode');
|
||||||
console.error(e);
|
console.error(e.status, e.responseJSONe);
|
||||||
}
|
}
|
||||||
const ZipCode = data.address.Postal;
|
const ZipCode = data.address.Postal;
|
||||||
const City = data.address.City;
|
const City = data.address.City;
|
||||||
|
|
|
@ -38,10 +38,13 @@ class CurrentWeather extends WeatherDisplay {
|
||||||
// TODO: add retry for further stations if observations are unavailable
|
// TODO: add retry for further stations if observations are unavailable
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Unable to get current observations');
|
console.error('Unable to get current observations');
|
||||||
console.error(e);
|
console.error(e.status, e.responseJSON);
|
||||||
this.setStatus(STATUS.failed);
|
this.setStatus(STATUS.failed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// preload the icon
|
||||||
|
utils.image.preload(icons.getWeatherIconFromIconLink(observations.iconPath));
|
||||||
|
|
||||||
// we only get here if there was no error above
|
// we only get here if there was no error above
|
||||||
this.data = Object.assign({}, observations, {station: station});
|
this.data = Object.assign({}, observations, {station: station});
|
||||||
this.setStatus(STATUS.loaded);
|
this.setStatus(STATUS.loaded);
|
||||||
|
@ -64,7 +67,7 @@ class CurrentWeather extends WeatherDisplay {
|
||||||
let WindChill = Math.round(observations.windChill.value);
|
let WindChill = Math.round(observations.windChill.value);
|
||||||
let WindGust = Math.round(observations.windGust.value);
|
let WindGust = Math.round(observations.windGust.value);
|
||||||
let Humidity = Math.round(observations.relativeHumidity.value);
|
let Humidity = Math.round(observations.relativeHumidity.value);
|
||||||
const Icon = icons.getWeatherIconFromIconLink(observations.icon);
|
const Icon = icons.getWeatherIconFromIconLink(observations.iconPath);
|
||||||
let PressureDirection = '';
|
let PressureDirection = '';
|
||||||
const TextConditions = observations.textDescription;
|
const TextConditions = observations.textDescription;
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ class ExtendedForecast extends WeatherDisplay {
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Unable to get extended forecast');
|
console.error('Unable to get extended forecast');
|
||||||
console.error(e);
|
console.error(e.status, e.responseJSON);
|
||||||
this.setStatus(STATUS.failed);
|
this.setStatus(STATUS.failed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,9 @@ class ExtendedForecast extends WeatherDisplay {
|
||||||
fDay.text = this.shortenExtendedForecastText(period.shortForecast);
|
fDay.text = this.shortenExtendedForecastText(period.shortForecast);
|
||||||
fDay.dayName = dates[destIndex];
|
fDay.dayName = dates[destIndex];
|
||||||
|
|
||||||
|
// preload the icon
|
||||||
|
utils.image.preload(fDay.icon);
|
||||||
|
|
||||||
if (period.isDaytime) {
|
if (period.isDaytime) {
|
||||||
// day time is the high temperature
|
// day time is the high temperature
|
||||||
fDay.high = period.temperature;
|
fDay.high = period.temperature;
|
||||||
|
|
|
@ -104,7 +104,7 @@ class LocalForecast extends WeatherDisplay {
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`GetWeatherForecast failed: ${weatherParameters.forecast}`);
|
console.error(`GetWeatherForecast failed: ${weatherParameters.forecast}`);
|
||||||
console.error(e);
|
console.error(e.status, e.responseJSON);
|
||||||
this.setStatus(STATUS.failed);
|
this.setStatus(STATUS.failed);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ class Radar extends WeatherDisplay {
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Unable to get list of radars');
|
console.error('Unable to get list of radars');
|
||||||
console.error(e);
|
console.error(e.status, e.responseJSON);
|
||||||
this.setStatus(STATUS.failed);
|
this.setStatus(STATUS.failed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,9 @@ class RegionalForecast extends WeatherDisplay {
|
||||||
y: cityXY.y,
|
y: cityXY.y,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// preload the icon
|
||||||
|
utils.image.preload(icons.getWeatherRegionalIconFromIconLink(regionalObservation.icon, !regionalObservation.daytime))
|
||||||
|
|
||||||
// return a pared-down forecast
|
// return a pared-down forecast
|
||||||
// 0th object is the current conditions
|
// 0th object is the current conditions
|
||||||
// first object is the next period i.e. if it's daytime then it's the "tonight" forecast
|
// 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) {
|
} catch (e) {
|
||||||
console.log(`No regional forecast data for '${city.Name}'`);
|
console.log(`No regional forecast data for '${city.Name}'`);
|
||||||
console.error(e);
|
console.error(e.status, e.responseJSON);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -162,11 +165,13 @@ class RegionalForecast extends WeatherDisplay {
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
crossDomain: true,
|
crossDomain: true,
|
||||||
});
|
});
|
||||||
|
// preload the image
|
||||||
|
utils.image.preload(icons.getWeatherRegionalIconFromIconLink(observation.properties.icon, !observation.properties.daytime));
|
||||||
// return the observation
|
// return the observation
|
||||||
return observation.properties;
|
return observation.properties;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`Unable to get regional observations for ${city.Name}`);
|
console.log(`Unable to get regional observations for ${city.Name}`);
|
||||||
console.error(e);
|
console.error(e.status, e.responseJSON);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ class TravelForecast extends WeatherDisplay {
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`GetTravelWeather for ${city.Name} failed`);
|
console.error(`GetTravelWeather for ${city.Name} failed`);
|
||||||
console.error(e);
|
console.error(e.status, e.responseJSON);
|
||||||
return {name: city.Name};
|
return {name: city.Name};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,7 +16,7 @@ const utils = (() => {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Unable to get point');
|
console.error('Unable to get point');
|
||||||
console.error(lat,lon);
|
console.error(lat,lon);
|
||||||
console.error(e);
|
console.error(e.status, e.responseJSON);
|
||||||
return false;
|
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 ***********************
|
// *********************************** unit conversions ***********************
|
||||||
|
|
||||||
Math.round2 = (value, decimals) => Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
|
Math.round2 = (value, decimals) => Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
|
||||||
|
@ -360,6 +373,7 @@ const utils = (() => {
|
||||||
image: {
|
image: {
|
||||||
load: loadImg,
|
load: loadImg,
|
||||||
superGifAsync,
|
superGifAsync,
|
||||||
|
preload,
|
||||||
},
|
},
|
||||||
weather: {
|
weather: {
|
||||||
getPoint,
|
getPoint,
|
||||||
|
|
|
@ -146,7 +146,7 @@ const GetMonthPrecipitation = async (WeatherParameters) => {
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('GetMonthPrecipitation failed');
|
console.error('GetMonthPrecipitation failed');
|
||||||
console.error(e);
|
console.error(e.status, e.responseJSON);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
module.exports = '3.1.1';
|
module.exports = '3.1.2';
|
Loading…
Reference in a new issue