FarmMapsLib/projects/common/src/fm/services/weather.service.ts

24 lines
868 B
TypeScript
Raw Normal View History

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}`;
return this.httpClient.get<WeatherCurrentObservation>(observationUrl);
}
}