|
|
@@ -16,11 +16,21 @@ import {FieldService} from './field.service';
|
|
|
import {ZonesService} from './zones.service';
|
|
|
import {imageWmsTLayer, imageWmsTSource} from './image-wms-t-layer';
|
|
|
|
|
|
-export type Index = 'EVI' | 'NDVI' | 'RVI4S1';
|
|
|
+/**
|
|
|
+ * Set of precalculated indices
|
|
|
+ */
|
|
|
+const INDICES_PRE_FLIGHT = ['EVI', 'NDVI', 'RVI4S1'] as const;
|
|
|
+/**
|
|
|
+ * Set of indices which are calculated on the fly
|
|
|
+ */
|
|
|
+const INDICES_ON_THE_FLY = ['NDWI', 'NDTI', 'NDRE'] as const;
|
|
|
+export type IndexPreFlight = typeof INDICES_PRE_FLIGHT[number];
|
|
|
+export type IndexOnTheFly = typeof INDICES_ON_THE_FLY[number];
|
|
|
+export type Index = IndexPreFlight | IndexOnTheFly;
|
|
|
|
|
|
@Injectable({providedIn: 'root'})
|
|
|
export class CalculatorService {
|
|
|
- AVAILABLE_PRODUCTS = ['EVI', 'NDVI', 'RVI4S1'] as const;
|
|
|
+ AVAILABLE_PRODUCTS = [...INDICES_PRE_FLIGHT, ...INDICES_ON_THE_FLY].sort();
|
|
|
BLUR_MIN_VALUE = 0 as const;
|
|
|
BLUR_MAX_VALUE = 5 as const;
|
|
|
MIN_LPIS_VISIBLE_ZOOM = 15 as const;
|
|
|
@@ -126,17 +136,20 @@ export class CalculatorService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Call 'get_zones' API method
|
|
|
+ * Call 'get_zones' or 'get_zones_exp' API method
|
|
|
*/
|
|
|
async getZones({product}: {product: Index}) {
|
|
|
this.lastError = '';
|
|
|
this._zonesLoading = true;
|
|
|
+ const endpoint = INDICES_PRE_FLIGHT.includes(product as IndexPreFlight)
|
|
|
+ ? 'get_zones'
|
|
|
+ : 'get_zones_exp';
|
|
|
try {
|
|
|
const data = await this.httpClient
|
|
|
.post(
|
|
|
(this.proxyEnabled() ? this.hsConfig.apps.default.proxyPrefix : '') +
|
|
|
this.SERVICE_BASE_URL +
|
|
|
- 'get_zones',
|
|
|
+ endpoint,
|
|
|
{
|
|
|
product,
|
|
|
number_of_quantiles: this.quantileCount,
|
|
|
@@ -154,6 +167,11 @@ export class CalculatorService {
|
|
|
)
|
|
|
.toPromise();
|
|
|
console.log('data received!', data);
|
|
|
+ // in case of unreliable data the return value is {"error": "data is not reliable."}
|
|
|
+ // TODO: show this error message to user
|
|
|
+ if (data['error']) {
|
|
|
+ throw new Error(data['error']);
|
|
|
+ }
|
|
|
this._zonesLoading = false;
|
|
|
await this.zonesService.updateZones(data, {
|
|
|
quantileCount: this.quantileCount,
|