|
@@ -1,17 +1,20 @@
|
|
|
import {HttpClient} from '@angular/common/http';
|
|
import {HttpClient} from '@angular/common/http';
|
|
|
import {Injectable} from '@angular/core';
|
|
import {Injectable} from '@angular/core';
|
|
|
|
|
+import {Vector as VectorLayer} from 'ol/layer';
|
|
|
|
|
+import {Vector as VectorSource} from 'ol/source';
|
|
|
|
|
|
|
|
|
|
+import {HsLayerManagerMetadataService} from 'hslayers-ng/components/layermanager/layermanager-metadata.service';
|
|
|
import {HsLayerManagerService} from 'hslayers-ng/components/layermanager';
|
|
import {HsLayerManagerService} from 'hslayers-ng/components/layermanager';
|
|
|
import {HsUtilsService} from 'hslayers-ng/components/utils/utils.service';
|
|
import {HsUtilsService} from 'hslayers-ng/components/utils/utils.service';
|
|
|
|
|
|
|
|
import clusteringMethods from '../data/clustering_methods.json';
|
|
import clusteringMethods from '../data/clustering_methods.json';
|
|
|
-import {obce, osmLayer} from '../app.config';
|
|
|
|
|
|
|
+import {obce, obceLayer, osmLayer} from '../app.config';
|
|
|
|
|
|
|
|
@Injectable({providedIn: 'root'})
|
|
@Injectable({providedIn: 'root'})
|
|
|
export class AdjusterService {
|
|
export class AdjusterService {
|
|
|
serviceBaseUrl: string;
|
|
serviceBaseUrl: string;
|
|
|
factors = [];
|
|
factors = [];
|
|
|
- clusters = [];
|
|
|
|
|
|
|
+ //clusters = [];
|
|
|
numberOfClusters;
|
|
numberOfClusters;
|
|
|
method: string;
|
|
method: string;
|
|
|
methods: Array<{
|
|
methods: Array<{
|
|
@@ -20,9 +23,11 @@ export class AdjusterService {
|
|
|
type: string;
|
|
type: string;
|
|
|
}>;
|
|
}>;
|
|
|
private _clusteringInProcess: boolean;
|
|
private _clusteringInProcess: boolean;
|
|
|
|
|
+ private _loadInProcess: boolean;
|
|
|
private _raiInProcess: boolean;
|
|
private _raiInProcess: boolean;
|
|
|
|
|
|
|
|
constructor(
|
|
constructor(
|
|
|
|
|
+ public hsLayerMetadataService: HsLayerManagerMetadataService,
|
|
|
public hsLayerManagerService: HsLayerManagerService,
|
|
public hsLayerManagerService: HsLayerManagerService,
|
|
|
public hsUtilsService: HsUtilsService,
|
|
public hsUtilsService: HsUtilsService,
|
|
|
public $http: HttpClient
|
|
public $http: HttpClient
|
|
@@ -43,8 +48,8 @@ export class AdjusterService {
|
|
|
* and applies the returned values
|
|
* and applies the returned values
|
|
|
*/
|
|
*/
|
|
|
apply(): void {
|
|
apply(): void {
|
|
|
- //this.calculateIndex();
|
|
|
|
|
- this.calculateClusters();
|
|
|
|
|
|
|
+ this.calculateIndex();
|
|
|
|
|
+ //this.calculateClusters();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
calculateIndex(): void {
|
|
calculateIndex(): void {
|
|
@@ -108,7 +113,7 @@ export class AdjusterService {
|
|
|
}
|
|
}
|
|
|
Object.keys(featureData).forEach((key, index) => {
|
|
Object.keys(featureData).forEach((key, index) => {
|
|
|
if (key !== 'lau2') {
|
|
if (key !== 'lau2') {
|
|
|
- feature.set(key, featureData[key]);
|
|
|
|
|
|
|
+ feature.set(key, featureData[key], true); //true stands for "silent" - important!
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
/*feature.set(
|
|
/*feature.set(
|
|
@@ -134,6 +139,8 @@ export class AdjusterService {
|
|
|
);
|
|
);
|
|
|
});*/
|
|
});*/
|
|
|
});
|
|
});
|
|
|
|
|
+ // Since we are updating the features silently, we now have to refresh manually
|
|
|
|
|
+ obce.getFeatures()[0].dispatchEvent('change');
|
|
|
console.timeEnd('forEachObce');
|
|
console.timeEnd('forEachObce');
|
|
|
this._raiInProcess = false;
|
|
this._raiInProcess = false;
|
|
|
})
|
|
})
|
|
@@ -168,6 +175,29 @@ export class AdjusterService {
|
|
|
let logs = 0;
|
|
let logs = 0;
|
|
|
let errs = 0;
|
|
let errs = 0;
|
|
|
const clusterData = data.response;
|
|
const clusterData = data.response;
|
|
|
|
|
+ console.log(obceLayer);
|
|
|
|
|
+ /*let sublayers = [];
|
|
|
|
|
+ const oldSublayers = obceLayer.get('Layer');
|
|
|
|
|
+ if (oldSublayers !== undefined && Array.isArray(oldSublayers)) {
|
|
|
|
|
+ for (const sublyr of oldSublayers) {
|
|
|
|
|
+ sublyr.getSource().clear();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (oldSublayers.length > this.numberOfClusters) {
|
|
|
|
|
+ sublayers = oldSublayers.slice(0, this.numberOfClusters);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ let i = sublayers.length;
|
|
|
|
|
+ while (sublayers.length < this.numberOfClusters) {
|
|
|
|
|
+ const sublyr = new VectorLayer({
|
|
|
|
|
+ title: `Cluster ${i + 1}`,
|
|
|
|
|
+ name: i + 1 + '',
|
|
|
|
|
+ source: new VectorSource({}),
|
|
|
|
|
+ });
|
|
|
|
|
+ sublayers.push(sublyr);
|
|
|
|
|
+ sublyr.Title = `Cluster ${i + 1}`;
|
|
|
|
|
+ sublyr.Name = `c${i + 1}`;
|
|
|
|
|
+ i++;
|
|
|
|
|
+ }*/
|
|
|
console.time('forEachObceCluster');
|
|
console.time('forEachObceCluster');
|
|
|
obce.forEachFeature((feature) => {
|
|
obce.forEachFeature((feature) => {
|
|
|
// Pair each feature with its clustering data
|
|
// Pair each feature with its clustering data
|
|
@@ -175,10 +205,14 @@ export class AdjusterService {
|
|
|
// NOTE: Do NOT add triple equal sign!
|
|
// NOTE: Do NOT add triple equal sign!
|
|
|
(item) => item['lau2'] == feature.get('nationalCode')
|
|
(item) => item['lau2'] == feature.get('nationalCode')
|
|
|
);
|
|
);
|
|
|
- if (!featureData && errs < 20) {
|
|
|
|
|
- errs++;
|
|
|
|
|
- console.warn(`No data for feature ${feature.get('nationalCode')}`);
|
|
|
|
|
- console.log(feature);
|
|
|
|
|
|
|
+ if (!featureData) {
|
|
|
|
|
+ if (errs < 20) {
|
|
|
|
|
+ errs++;
|
|
|
|
|
+ console.warn(
|
|
|
|
|
+ `No data for feature ${feature.get('nationalCode')}`
|
|
|
|
|
+ );
|
|
|
|
|
+ console.log(feature);
|
|
|
|
|
+ }
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
logs++;
|
|
logs++;
|
|
@@ -187,19 +221,49 @@ export class AdjusterService {
|
|
|
}
|
|
}
|
|
|
Object.keys(featureData).forEach(function (key, index) {
|
|
Object.keys(featureData).forEach(function (key, index) {
|
|
|
if (key !== 'lau2') {
|
|
if (key !== 'lau2') {
|
|
|
- feature.set(key, featureData[key]);
|
|
|
|
|
|
|
+ feature.set(key, featureData[key], true);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
- const clusters = [];
|
|
|
|
|
- for (const region of clusterData) {
|
|
|
|
|
|
|
+ //const clusters = [];
|
|
|
|
|
+ //const obceFeatures: Array<any> = obce.getFeatures();
|
|
|
|
|
+ /*for (const region of clusterData) {
|
|
|
if (!clusters.includes(region[this.method])) {
|
|
if (!clusters.includes(region[this.method])) {
|
|
|
clusters.push(region[this.method]);
|
|
clusters.push(region[this.method]);
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ const feature = obceFeatures.find(
|
|
|
|
|
+ // NOTE: Do NOT add triple equal sign!
|
|
|
|
|
+ (f) => f.get('nationalCode') == region['lau2']
|
|
|
|
|
+ );
|
|
|
|
|
+ if (!feature) {
|
|
|
|
|
+ if (errs < 20) {
|
|
|
|
|
+ errs++;
|
|
|
|
|
+ console.warn(`No feature matches region ${region['lau2']}`);
|
|
|
|
|
+ console.log(region);
|
|
|
|
|
+ }
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ logs++;
|
|
|
|
|
+ if (logs % 100 == 0) {
|
|
|
|
|
+ console.log(`processed ${logs} items`);
|
|
|
|
|
+ }
|
|
|
|
|
+ Object.keys(region).forEach(function (key, index) {
|
|
|
|
|
+ if (key !== 'lau2') {
|
|
|
|
|
+ feature.set(key, region[key], true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ if (logs % 100 == 0) {
|
|
|
|
|
+ //sublayers[0].getSource().addFeature(feature);
|
|
|
|
|
+ }
|
|
|
|
|
+ //sublayers[region[this.method] - 1].getSource().addFeature(feature);
|
|
|
|
|
+ }*/
|
|
|
|
|
+ //obceLayer.set('Layer', sublayers);
|
|
|
|
|
+ //this.hsLayerMetadataService.fillMetadata(obceLayer);
|
|
|
|
|
+ //console.log(sublayers[0].getSource().getFeatures());
|
|
|
|
|
+ console.log(obceLayer);
|
|
|
console.timeEnd('forEachObceCluster');
|
|
console.timeEnd('forEachObceCluster');
|
|
|
console.log('clustering done!');
|
|
console.log('clustering done!');
|
|
|
- this.clusters = clusters;
|
|
|
|
|
|
|
+ //this.clusters = clusters;
|
|
|
this._clusteringInProcess = false;
|
|
this._clusteringInProcess = false;
|
|
|
//this.adjusterEventService.clustersLoaded.next({success: true});
|
|
//this.adjusterEventService.clustersLoaded.next({success: true});
|
|
|
})
|
|
})
|
|
@@ -217,13 +281,17 @@ export class AdjusterService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
init(): void {
|
|
init(): void {
|
|
|
- this._raiInProcess = true;
|
|
|
|
|
|
|
+ this._loadInProcess = true;
|
|
|
this.$http
|
|
this.$http
|
|
|
.get(this.serviceBaseUrl + 'datasets/cz')
|
|
.get(this.serviceBaseUrl + 'datasets/cz')
|
|
|
.toPromise()
|
|
.toPromise()
|
|
|
.then((data: any) => {
|
|
.then((data: any) => {
|
|
|
this.factors = data.map((dataset) => {
|
|
this.factors = data.map((dataset) => {
|
|
|
- return {name: dataset.Factor, weight: 1, datasets: []};
|
|
|
|
|
|
|
+ return {
|
|
|
|
|
+ name: dataset.Factor,
|
|
|
|
|
+ weight: dataset.Factor == 'Udržitelná města a obce' ? 1 : 0,
|
|
|
|
|
+ datasets: [],
|
|
|
|
|
+ };
|
|
|
});
|
|
});
|
|
|
this.factors = this.hsUtilsService.removeDuplicates(
|
|
this.factors = this.hsUtilsService.removeDuplicates(
|
|
|
this.factors,
|
|
this.factors,
|
|
@@ -240,21 +308,35 @@ export class AdjusterService {
|
|
|
};
|
|
};
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
- this._raiInProcess = false;
|
|
|
|
|
|
|
+ this._loadInProcess = false;
|
|
|
this.apply();
|
|
this.apply();
|
|
|
this.hsLayerManagerService.setGreyscale(osmLayer);
|
|
this.hsLayerManagerService.setGreyscale(osmLayer);
|
|
|
})
|
|
})
|
|
|
.catch((error) => {
|
|
.catch((error) => {
|
|
|
console.warn(`Web service at ${this.serviceBaseUrl} unavailable!`);
|
|
console.warn(`Web service at ${this.serviceBaseUrl} unavailable!`);
|
|
|
console.log(error);
|
|
console.log(error);
|
|
|
- this._raiInProcess = false;
|
|
|
|
|
|
|
+ this._loadInProcess = false;
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * @returns {boolean} true if clustering or index processing is in process, false otherwise
|
|
|
|
|
|
|
+ * @returns {boolean} true if clustering or index processing is in process or loading data, false otherwise
|
|
|
*/
|
|
*/
|
|
|
isInProcess(): boolean {
|
|
isInProcess(): boolean {
|
|
|
- return this._clusteringInProcess || this._raiInProcess;
|
|
|
|
|
|
|
+ return (
|
|
|
|
|
+ this._loadInProcess || this._clusteringInProcess || this._raiInProcess
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ isLoading(): boolean {
|
|
|
|
|
+ return this._loadInProcess;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ isClustering(): boolean {
|
|
|
|
|
+ return this._clusteringInProcess;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ isCalculatingRAI(): boolean {
|
|
|
|
|
+ return this._raiInProcess;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|