|
|
@@ -1,11 +1,13 @@
|
|
|
-import {catchError} from 'rxjs/operators';
|
|
|
import {HttpClient} from '@angular/common/http';
|
|
|
import {Injectable} from '@angular/core';
|
|
|
+import {catchError} from 'rxjs/operators';
|
|
|
|
|
|
import {HsConfig} from 'hslayers-ng';
|
|
|
|
|
|
import {ZonesService} from './zones.service';
|
|
|
|
|
|
+export type Index = 'EVI' | 'RVI4S1';
|
|
|
+
|
|
|
@Injectable({providedIn: 'root'})
|
|
|
export class CalculatorService {
|
|
|
availableDates: Array<string>;
|
|
|
@@ -15,18 +17,32 @@ export class CalculatorService {
|
|
|
//TODO: temporary hard-coded hack
|
|
|
centroid = {type: 'Point', coordinates: [16.944, 49.228]};
|
|
|
//TODO: temporarry hard-coded hack
|
|
|
- field = {type: 'Polygon', coordinates: [[[17.008032903697003,49.259378350222214],[17.012346093160815,49.26055145480218],[17.01341275235608,49.25661998865008],[17.01578237120672,49.251834177355896],[17.01243531034079,49.24966645404407],[17.009126895621744,49.24897297823598],[17.003117114964958,49.253454830509305],[17.008032903697003,49.259378350222214]]]};
|
|
|
+ field = {
|
|
|
+ type: 'Polygon',
|
|
|
+ coordinates: [
|
|
|
+ [
|
|
|
+ [17.008032903697003, 49.259378350222214],
|
|
|
+ [17.012346093160815, 49.26055145480218],
|
|
|
+ [17.01341275235608, 49.25661998865008],
|
|
|
+ [17.01578237120672, 49.251834177355896],
|
|
|
+ [17.01243531034079, 49.24966645404407],
|
|
|
+ [17.009126895621744, 49.24897297823598],
|
|
|
+ [17.003117114964958, 49.253454830509305],
|
|
|
+ [17.008032903697003, 49.259378350222214],
|
|
|
+ ],
|
|
|
+ ],
|
|
|
+ };
|
|
|
//[[[17.01403296191603, 49.24858329768389], [17.014029303734432, 49.24849340104692], [17.01389198448605, 49.2484957958039], [17.013754665219444, 49.24849819039773], [17.013751007554088, 49.248408293744056], [17.013613688518262, 49.24841068816722], [17.013476369464207, 49.24841308242727], [17.013469055184203, 49.248233289084894], [17.01333173660994, 49.24823568316671], [17.01319441801745, 49.24823807708539], [17.013183448228144, 49.24796838701452], [17.013320766073623, 49.24796599311847], [17.01331710926463, 49.247876096432506], [17.013729061944726, 49.24786891378824], [17.01373271950072, 49.24795881045155], [17.0138700372733, 49.24795641590298], [17.013873695096525, 49.24804631255717], [17.014285649051903, 49.24803912791008], [17.014281990481678, 49.247949231278554], [17.014419308181342, 49.247946836077475], [17.014422967000566, 49.24803673270145], [17.015246874309636, 49.24802235802403], [17.015384192130647, 49.24801996167353], [17.01540249521542, 49.24846944450495], [17.01526517614939, 49.248471840893245], [17.01526151574496, 49.24838194432262], [17.015124196909692, 49.24838434054022], [17.015127857065117, 49.248474237118394], [17.01457858054565, 49.248483820387705], [17.014582239723282, 49.248573716994485], [17.01403296191603, 49.24858329768389]]]};
|
|
|
|
|
|
constructor(
|
|
|
private hsConfig: HsConfig,
|
|
|
private httpClient: HttpClient,
|
|
|
- private zonesService: ZonesService,
|
|
|
- ) {
|
|
|
+ private zonesService: ZonesService
|
|
|
+ ) {
|
|
|
//TODO: temporary hard-coded hack
|
|
|
this.selectedField = this.centroid;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
noFieldSelected(): boolean {
|
|
|
return this.selectedField === undefined;
|
|
|
}
|
|
|
@@ -40,43 +56,50 @@ export class CalculatorService {
|
|
|
const data = await this.httpClient
|
|
|
.get<{dates: string[]}>(
|
|
|
(this.proxyEnabled() ? this.hsConfig.proxyPrefix : '') +
|
|
|
- this.serviceBaseUrl +
|
|
|
- 'get_dates?' +
|
|
|
- 'product=' +
|
|
|
- product +
|
|
|
- '¢roid=' +
|
|
|
- JSON.stringify(this.centroid)
|
|
|
- ).toPromise();
|
|
|
+ this.serviceBaseUrl +
|
|
|
+ 'get_dates?' +
|
|
|
+ 'product=' +
|
|
|
+ product +
|
|
|
+ '¢roid=' +
|
|
|
+ JSON.stringify(this.centroid)
|
|
|
+ )
|
|
|
+ .toPromise();
|
|
|
console.log('data received!');
|
|
|
console.log(data);
|
|
|
this.availableDates = data.dates;
|
|
|
//TODO: temporary hard-coded hack
|
|
|
this.selectedField = this.field;
|
|
|
- } catch(err) {
|
|
|
+ } catch (err) {
|
|
|
console.error('Somethin fucked up!');
|
|
|
console.log(err);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- async getZones({product, date}: {product: Index, date: string}) {
|
|
|
+
|
|
|
+ async getZones({product, date}: {product: Index; date: string}) {
|
|
|
try {
|
|
|
const data = await this.httpClient
|
|
|
.post(
|
|
|
(this.proxyEnabled() ? this.hsConfig.proxyPrefix : '') +
|
|
|
- this.serviceBaseUrl +
|
|
|
- 'get_zones', {
|
|
|
+ this.serviceBaseUrl +
|
|
|
+ 'get_zones',
|
|
|
+ {
|
|
|
product,
|
|
|
date,
|
|
|
format: 'geojson',
|
|
|
- geometry: this.selectedField
|
|
|
- }, {
|
|
|
- headers: {'Content-Type': 'application/json', 'Accept': 'application/json'}
|
|
|
+ geometry: this.selectedField,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
+ 'Accept': 'application/json',
|
|
|
+ },
|
|
|
}
|
|
|
- ).toPromise();
|
|
|
+ )
|
|
|
+ .toPromise();
|
|
|
console.log('data received!');
|
|
|
console.log(data);
|
|
|
this.zonesService.updateZones(data);
|
|
|
- } catch(err) {
|
|
|
+ } catch (err) {
|
|
|
console.error('Somethin fucked up!');
|
|
|
console.log(err);
|
|
|
}
|
|
|
@@ -86,5 +109,3 @@ export class CalculatorService {
|
|
|
return this.hsConfig.useProxy === undefined || this.hsConfig.useProxy;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-export type Index = 'EVI' | 'RVI4S1';
|