2021-05-15 18:05:53 +02:00
|
|
|
import { IconKey } from 'skycons-ts';
|
|
|
|
|
|
|
|
export interface WeatherCondition {
|
|
|
|
code: number;
|
|
|
|
icon: {
|
|
|
|
day: IconKey;
|
|
|
|
night: IconKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export enum TimeOfDay {
|
|
|
|
day,
|
|
|
|
night
|
|
|
|
}
|
|
|
|
|
2022-09-02 20:17:34 +02:00
|
|
|
const mapFromJson = require('./WeatherMapping.json')
|
|
|
|
|
2021-05-15 18:05:53 +02:00
|
|
|
export class IconMapping {
|
2022-09-02 20:17:34 +02:00
|
|
|
private conditions: WeatherCondition[] = mapFromJson.mapping
|
2021-05-15 18:05:53 +02:00
|
|
|
|
|
|
|
mapIcon(weatherStatusCode: number, timeOfDay: TimeOfDay): IconKey {
|
|
|
|
const mapping = this.conditions.find((condition: WeatherCondition) => condition.code === weatherStatusCode);
|
|
|
|
|
|
|
|
if (mapping) {
|
|
|
|
if (timeOfDay === TimeOfDay.day) {
|
|
|
|
return mapping.icon.day;
|
|
|
|
} else if (timeOfDay === TimeOfDay.night) {
|
|
|
|
return mapping.icon.night;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'clear-day';
|
|
|
|
}
|
|
|
|
}
|