mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-17 09:09:30 -07:00
better stations list
This commit is contained in:
@@ -19,7 +19,7 @@ class LatestObservations extends WeatherDisplay {
|
||||
// calculate distance to each station
|
||||
const stationsByDistance = Object.keys(_StationInfo).map(key => {
|
||||
const station = _StationInfo[key];
|
||||
const distance = utils.calc.distance(station.Latitude, station.Longitude, weatherParameters.latitude, weatherParameters.longitude);
|
||||
const distance = utils.calc.distance(station.lat, station.lon, weatherParameters.latitude, weatherParameters.longitude);
|
||||
return Object.assign({}, station, {distance});
|
||||
});
|
||||
|
||||
@@ -33,17 +33,17 @@ class LatestObservations extends WeatherDisplay {
|
||||
try {
|
||||
const data = await $.ajax({
|
||||
type: 'GET',
|
||||
url: `https://api.weather.gov/stations/${station.StationId}/observations/latest`,
|
||||
url: `https://api.weather.gov/stations/${station.id}/observations/latest`,
|
||||
dataType: 'json',
|
||||
crossDomain: true,
|
||||
});
|
||||
// format the return values
|
||||
return Object.assign({}, data.properties, {
|
||||
StationId: station.StationId,
|
||||
City: station.City,
|
||||
StationId: station.id,
|
||||
city: station.city,
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(`Unable to get latest observations for ${station.StationId}`);
|
||||
console.log(`Unable to get latest observations for ${station.id}`);
|
||||
return;
|
||||
}
|
||||
}));
|
||||
@@ -95,7 +95,7 @@ class LatestObservations extends WeatherDisplay {
|
||||
WindSpeed = utils.units.kphToMph(WindSpeed);
|
||||
}
|
||||
|
||||
draw.text(this.context, 'Star4000', '24pt', '#FFFFFF', 65, y, condition.City.substr(0, 14), 2);
|
||||
draw.text(this.context, 'Star4000', '24pt', '#FFFFFF', 65, y, condition.city.substr(0, 14), 2);
|
||||
draw.text(this.context, 'Star4000', '24pt', '#FFFFFF', 345, y, this.shortenCurrentConditions(condition.textDescription).substr(0, 9), 2);
|
||||
|
||||
if (WindSpeed > 0) {
|
||||
|
||||
@@ -69,7 +69,7 @@ const navigation = (() => {
|
||||
let city = point.properties.relativeLocation.properties.city;
|
||||
|
||||
if (StationId in _StationInfo) {
|
||||
city = _StationInfo[StationId].City;
|
||||
city = _StationInfo[StationId].city;
|
||||
city = city.split('/')[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class RegionalForecast extends WeatherDisplay {
|
||||
if (weatherParameters.State === 'HI') targetDistance = 1;
|
||||
|
||||
// make station info into an array
|
||||
const stationInfoArray = Object.keys(_StationInfo).map(key => Object.assign({}, _StationInfo[key], {Name: _StationInfo[key].City, targetDistance}));
|
||||
const stationInfoArray = Object.keys(_StationInfo).map(key => Object.assign({}, _StationInfo[key], {targetDistance}));
|
||||
// combine regional cities with station info for additional stations
|
||||
// stations are intentionally after cities to allow cities priority when drawing the map
|
||||
const combinedCities = [..._RegionalCities, ...stationInfoArray];
|
||||
@@ -52,13 +52,13 @@ class RegionalForecast extends WeatherDisplay {
|
||||
// Determine which cities are within the max/min latitude/longitude.
|
||||
const regionalCities = [];
|
||||
combinedCities.forEach(city => {
|
||||
if (city.Latitude > minMaxLatLon.minLat && city.Latitude < minMaxLatLon.maxLat &&
|
||||
city.Longitude > minMaxLatLon.minLon && city.Longitude < minMaxLatLon.maxLon - 1) {
|
||||
if (city.lat > minMaxLatLon.minLat && city.lat < minMaxLatLon.maxLat &&
|
||||
city.lon > minMaxLatLon.minLon && city.lon < minMaxLatLon.maxLon - 1) {
|
||||
// default to 1 for cities loaded from _RegionalCities, use value calculate above for remaining stations
|
||||
const targetDistance = city.targetDistance || 1;
|
||||
// Only add the city as long as it isn't within set distance degree of any other city already in the array.
|
||||
const okToAddCity = regionalCities.reduce((acc, testCity) => {
|
||||
const distance = utils.calc.distance(city.Longitude, city.Latitude, testCity.Longitude, testCity.Latitude);
|
||||
const distance = utils.calc.distance(city.lon, city.lat, testCity.lon, testCity.lat);
|
||||
return acc && distance >= targetDistance;
|
||||
}, true);
|
||||
if (okToAddCity) regionalCities.push(city);
|
||||
@@ -69,7 +69,7 @@ class RegionalForecast extends WeatherDisplay {
|
||||
const regionalForecastPromises = regionalCities.map(async city => {
|
||||
try {
|
||||
// get the point first, then break down into forecast and observations
|
||||
const point = await utils.weather.getPoint(city.Latitude, city.Longitude);
|
||||
const point = await utils.weather.getPoint(city.lat, city.lon);
|
||||
|
||||
// start off the observation task
|
||||
const observationPromise = this.getRegionalObservation(point, city);
|
||||
@@ -89,7 +89,7 @@ class RegionalForecast extends WeatherDisplay {
|
||||
const regionalObservation = {
|
||||
daytime: !!observation.icon.match(/\/day\//),
|
||||
temperature: utils.units.celsiusToFahrenheit(observation.temperature.value),
|
||||
name: city.Name,
|
||||
name: this.formatCity(city.city),
|
||||
icon: observation.icon,
|
||||
x: cityXY.x,
|
||||
y: cityXY.y,
|
||||
@@ -140,7 +140,7 @@ class RegionalForecast extends WeatherDisplay {
|
||||
return {
|
||||
daytime: forecast.isDaytime,
|
||||
temperature: forecast.temperature||0,
|
||||
name: city.Name,
|
||||
name: city.city,
|
||||
icon: forecast.icon,
|
||||
x: cityXY.x,
|
||||
y: cityXY.y,
|
||||
@@ -294,8 +294,8 @@ class RegionalForecast extends WeatherDisplay {
|
||||
getXYForCity (City, MaxLatitude, MinLongitude, state) {
|
||||
if (state === 'AK') this.getXYForCityAK(...arguments);
|
||||
if (state === 'HI') this.getXYForCityHI(...arguments);
|
||||
let x = (City.Longitude - MinLongitude) * 57;
|
||||
let y = (MaxLatitude - City.Latitude) * 70;
|
||||
let x = (City.lon - MinLongitude) * 57;
|
||||
let y = (MaxLatitude - City.lat) * 70;
|
||||
|
||||
if (y < 30) y = 30;
|
||||
if (y > 282) y = 282;
|
||||
@@ -307,8 +307,8 @@ class RegionalForecast extends WeatherDisplay {
|
||||
}
|
||||
|
||||
getXYForCityAK (City, MaxLatitude, MinLongitude) {
|
||||
let x = (City.Longitude - MinLongitude) * 37;
|
||||
let y = (MaxLatitude - City.Latitude) * 70;
|
||||
let x = (City.lon - MinLongitude) * 37;
|
||||
let y = (MaxLatitude - City.lat) * 70;
|
||||
|
||||
if (y < 30) y = 30;
|
||||
if (y > 282) y = 282;
|
||||
@@ -319,8 +319,8 @@ class RegionalForecast extends WeatherDisplay {
|
||||
}
|
||||
|
||||
getXYForCityHI (City, MaxLatitude, MinLongitude) {
|
||||
let x = (City.Longitude - MinLongitude) * 57;
|
||||
let y = (MaxLatitude - City.Latitude) * 70;
|
||||
let x = (City.lon - MinLongitude) * 57;
|
||||
let y = (MaxLatitude - City.lat) * 70;
|
||||
|
||||
if (y < 30) y = 30;
|
||||
if (y > 282) y = 282;
|
||||
@@ -331,6 +331,11 @@ class RegionalForecast extends WeatherDisplay {
|
||||
return { x, y };
|
||||
}
|
||||
|
||||
// to fit on the map, remove anything after punctuation and then limit to 15 characters
|
||||
formatCity(city) {
|
||||
return city.match(/[^-;/\\,]*/)[0].substr(0,12)
|
||||
}
|
||||
|
||||
async drawCanvas() {
|
||||
super.drawCanvas();
|
||||
// break up data into useful values
|
||||
|
||||
Reference in New Issue
Block a user