|
|
@@ -1,6 +1,7 @@
|
|
|
import {HttpClient} from '@angular/common/http';
|
|
|
import {Injectable} from '@angular/core';
|
|
|
import {Vector as VectorLayer} from 'ol/layer';
|
|
|
+import {forkJoin} from 'rxjs';
|
|
|
|
|
|
import {HsConfig} from 'hslayers-ng/config.service';
|
|
|
import {HsEventBusService} from 'hslayers-ng/components/core/event-bus.service';
|
|
|
@@ -27,12 +28,14 @@ export class AdjusterService {
|
|
|
/** Used in the UI as a selector */
|
|
|
allowIndex = true;
|
|
|
factors = [];
|
|
|
- numberOfClusters: number;
|
|
|
+ layersReady = new Set();
|
|
|
//method: string;
|
|
|
methods: Array<MethodDescription>;
|
|
|
+ numberOfClusters: number;
|
|
|
private _clusteringInProcess: boolean;
|
|
|
private _clustersLoaded: boolean;
|
|
|
- private _loadInProcess: boolean;
|
|
|
+ /** Once instantiated, the load is definitely in process */
|
|
|
+ private _loadInProcess = true;
|
|
|
private _raiInProcess: boolean;
|
|
|
|
|
|
constructor(
|
|
|
@@ -45,7 +48,7 @@ export class AdjusterService {
|
|
|
public hsUtilsService: HsUtilsService,
|
|
|
public $http: HttpClient
|
|
|
) {
|
|
|
- // First safely set configurable properties
|
|
|
+ /* First safely set configurable properties */
|
|
|
this.allowedClusteringMethods =
|
|
|
attractivenessConfig?.allowedClusteringMethods ?? [];
|
|
|
this.initialWeights = attractivenessConfig?.initialWeights ?? {};
|
|
|
@@ -58,6 +61,25 @@ export class AdjusterService {
|
|
|
this.allowedClusteringMethods.includes(m.codename)
|
|
|
);
|
|
|
this.numberOfClusters = 9;
|
|
|
+
|
|
|
+ /* Wait for all layers to be ready */
|
|
|
+ this.adjusterEventService.layerReady.subscribe(({name}) => {
|
|
|
+ console.log(name + ' ready!');
|
|
|
+ this.layersReady.add(name);
|
|
|
+ /* Layers for each method + layer for index are ready */
|
|
|
+ if (this.layersReady.size == this.methods.length + 1) {
|
|
|
+ this.adjusterEventService.layerReady.complete();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ /* Ensure that all layers and also the loader component are ready */
|
|
|
+ forkJoin({
|
|
|
+ lyr: this.adjusterEventService.layerReady,
|
|
|
+ load: this.adjusterEventService.loaderReady,
|
|
|
+ }).subscribe(() => {
|
|
|
+ console.log('Oll layers Korekt! Initializing adjuster...');
|
|
|
+ this.init();
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -89,7 +111,7 @@ export class AdjusterService {
|
|
|
})
|
|
|
.toPromise()
|
|
|
.then((attractivenessData: any[]) => {
|
|
|
- // Spread the 'aggregate' value between 0 and 1
|
|
|
+ /* Spread the 'aggregate' value between 0 and 1 */
|
|
|
const min = attractivenessData.reduce((a, b) =>
|
|
|
a.aggregate < b.aggregate ? a : b
|
|
|
).aggregate;
|
|
|
@@ -102,8 +124,8 @@ export class AdjusterService {
|
|
|
a.aggregate *= coefficient;
|
|
|
a.aggregate += constant;
|
|
|
});
|
|
|
- // Store relation between region and its data in a hash-table-like structure
|
|
|
- // more memory consuming, but faster then find()
|
|
|
+ /* Store relation between region and its data in a hash-table-like structure
|
|
|
+ * More memory consuming, but faster then find() */
|
|
|
const codeRecordRelations = {};
|
|
|
attractivenessData.forEach((a) => {
|
|
|
codeRecordRelations[a.code] = a;
|
|
|
@@ -147,8 +169,8 @@ export class AdjusterService {
|
|
|
.toPromise()
|
|
|
.then((data: any) => {
|
|
|
const clusterData = data.response;
|
|
|
- // Store relation between region and its data in a hash-table-like structure
|
|
|
- // more memory consuming, but much faster then find()
|
|
|
+ /* Store relation between region and its data in a hash-table-like structure
|
|
|
+ * more memory consuming, but much faster then find() */
|
|
|
const codeRecordRelations = {};
|
|
|
clusterData.forEach((c) => {
|
|
|
codeRecordRelations[c.lau2] = c;
|