2020-02-04 12:54:53 +00:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {HttpClient} from '@angular/common/http';
|
|
|
|
import {AppConfig} from '../shared/app.config';
|
|
|
|
import {Observable} from 'rxjs';
|
|
|
|
import {WeatherCurrentObservation} from '../models/weatherCurrentObservation';
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root',
|
|
|
|
})
|
|
|
|
export class WeatherService {
|
|
|
|
private apiUrl = '/api/v1/weather/currentobservation';
|
|
|
|
|
|
|
|
constructor(public httpClient: HttpClient, public appConfig: AppConfig) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public GetCurrentObservation(centroid: number[]): Observable<WeatherCurrentObservation> {
|
2020-02-04 16:38:04 +00:00
|
|
|
const endpoint = this.appConfig.getConfig('weatherApiEndPoint');
|
|
|
|
const apiKey = this.appConfig.getConfig('weatherApiKey');
|
|
|
|
const observationUrl = `${endpoint}${this.apiUrl}/?c=${centroid[0]},${centroid[1]}&key=${apiKey}`;
|
2020-02-04 12:54:53 +00:00
|
|
|
|
|
|
|
return this.httpClient.get<WeatherCurrentObservation>(observationUrl);
|
|
|
|
}
|
|
|
|
}
|