|
@@ -175,10 +175,15 @@ export class AdjusterService {
|
|
|
.toPromise()
|
|
.toPromise()
|
|
|
.then((data: any) => {
|
|
.then((data: any) => {
|
|
|
console.log('data received', data);
|
|
console.log('data received', data);
|
|
|
- let logs = 0;
|
|
|
|
|
|
|
+ //let logs = 0;
|
|
|
let errs = 0;
|
|
let errs = 0;
|
|
|
const clusterData = data.response;
|
|
const clusterData = data.response;
|
|
|
- console.log(obceIndexLayer);
|
|
|
|
|
|
|
+ // 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;
|
|
|
|
|
+ });
|
|
|
/*let sublayers = [];
|
|
/*let sublayers = [];
|
|
|
const oldSublayers = obceLayer.get('Layer');
|
|
const oldSublayers = obceLayer.get('Layer');
|
|
|
if (oldSublayers !== undefined && Array.isArray(oldSublayers)) {
|
|
if (oldSublayers !== undefined && Array.isArray(oldSublayers)) {
|
|
@@ -202,39 +207,52 @@ export class AdjusterService {
|
|
|
i++;
|
|
i++;
|
|
|
}*/
|
|
}*/
|
|
|
console.time('forEach-Cluster');
|
|
console.time('forEach-Cluster');
|
|
|
- obce.forEachFeature((feature) => {
|
|
|
|
|
- // Pair each feature with its clustering data
|
|
|
|
|
- const featureData = clusterData.find(
|
|
|
|
|
- // NOTE: Do NOT add triple equal sign!
|
|
|
|
|
- (item) => item['lau2'] == feature.get('nationalCode')
|
|
|
|
|
- );
|
|
|
|
|
- if (!featureData) {
|
|
|
|
|
- if (errs < 20) {
|
|
|
|
|
- errs++;
|
|
|
|
|
- console.warn(
|
|
|
|
|
- `No data for feature ${feature.get('nationalCode')}`
|
|
|
|
|
- );
|
|
|
|
|
- console.log(feature);
|
|
|
|
|
- }
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- logs++;
|
|
|
|
|
- if (logs % 100 == 0) {
|
|
|
|
|
- console.log(`processed ${logs} items`);
|
|
|
|
|
- }
|
|
|
|
|
- Object.keys(featureData).forEach(function (key, index) {
|
|
|
|
|
- if (key !== 'lau2') {
|
|
|
|
|
- feature.set(key, featureData[key], true);
|
|
|
|
|
|
|
+ for (const method of this.methods) {
|
|
|
|
|
+ method.layer.getSource().forEachFeature((feature) => {
|
|
|
|
|
+ // Pair each feature with its clustering data
|
|
|
|
|
+ const featureData =
|
|
|
|
|
+ codeRecordRelations[feature.get('nationalCode')];
|
|
|
|
|
+ /*const featureData = clusterData.find(
|
|
|
|
|
+ // NOTE: Do NOT add triple equal sign!
|
|
|
|
|
+ (item) => item['lau2'] == feature.get('nationalCode')
|
|
|
|
|
+ );*/
|
|
|
|
|
+ if (!featureData) {
|
|
|
|
|
+ if (errs < 20) {
|
|
|
|
|
+ errs++;
|
|
|
|
|
+ console.warn(
|
|
|
|
|
+ `No data for feature ${feature.get('nationalCode')}`
|
|
|
|
|
+ );
|
|
|
|
|
+ console.log(feature);
|
|
|
|
|
+ }
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
+ /*logs++;
|
|
|
|
|
+ if (logs % 100 == 0) {
|
|
|
|
|
+ console.log(`processed ${logs} items`);
|
|
|
|
|
+ }*/
|
|
|
|
|
+ feature.set(method.codename, featureData[method.codename], true);
|
|
|
|
|
+ /*Object.keys(featureData).forEach(function (key, index) {
|
|
|
|
|
+ if (key !== 'lau2') {
|
|
|
|
|
+ feature.set(key, featureData[key], true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });*/
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
+ // Since we are updating the features silently, we now have to refresh manually
|
|
|
|
|
+ method.layer.getSource().getFeatures()[0].dispatchEvent('change');
|
|
|
|
|
+ }
|
|
|
//const clusters = [];
|
|
//const clusters = [];
|
|
|
//const obceFeatures: Array<any> = obce.getFeatures();
|
|
//const obceFeatures: Array<any> = obce.getFeatures();
|
|
|
- /*for (const region of clusterData) {
|
|
|
|
|
- if (!clusters.includes(region[this.method])) {
|
|
|
|
|
- clusters.push(region[this.method]);
|
|
|
|
|
- }
|
|
|
|
|
- const feature = obceFeatures.find(
|
|
|
|
|
|
|
+ // Array of arrays
|
|
|
|
|
+ /*const methodsFeatures = this.methods.map((m) =>
|
|
|
|
|
+ m.layer.getSource().getFeatures()
|
|
|
|
|
+ );
|
|
|
|
|
+ for (const region of clusterData) {
|
|
|
|
|
+ //if (!clusters.includes(region[this.method])) {
|
|
|
|
|
+ // clusters.push(region[this.method]);
|
|
|
|
|
+ //}
|
|
|
|
|
+ for (const features of methodsFeatures) {
|
|
|
|
|
+
|
|
|
|
|
+ const feature = features.find(
|
|
|
// NOTE: Do NOT add triple equal sign!
|
|
// NOTE: Do NOT add triple equal sign!
|
|
|
(f) => f.get('nationalCode') == region['lau2']
|
|
(f) => f.get('nationalCode') == region['lau2']
|
|
|
);
|
|
);
|
|
@@ -246,24 +264,21 @@ export class AdjusterService {
|
|
|
}
|
|
}
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- logs++;
|
|
|
|
|
- if (logs % 100 == 0) {
|
|
|
|
|
- console.log(`processed ${logs} items`);
|
|
|
|
|
- }
|
|
|
|
|
Object.keys(region).forEach(function (key, index) {
|
|
Object.keys(region).forEach(function (key, index) {
|
|
|
if (key !== 'lau2') {
|
|
if (key !== 'lau2') {
|
|
|
feature.set(key, region[key], true);
|
|
feature.set(key, region[key], true);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- if (logs % 100 == 0) {
|
|
|
|
|
- //sublayers[0].getSource().addFeature(feature);
|
|
|
|
|
- }
|
|
|
|
|
- //sublayers[region[this.method] - 1].getSource().addFeature(feature);
|
|
|
|
|
- }*/
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ logs++;
|
|
|
|
|
+ if (logs % 100 == 0) {
|
|
|
|
|
+ console.log(`processed ${logs} items`);
|
|
|
|
|
+ }
|
|
|
|
|
+ //sublayers[region[this.method] - 1].getSource().addFeature(feature);
|
|
|
|
|
+ }*/
|
|
|
//obceLayer.set('Layer', sublayers);
|
|
//obceLayer.set('Layer', sublayers);
|
|
|
//this.hsLayerMetadataService.fillMetadata(obceLayer);
|
|
//this.hsLayerMetadataService.fillMetadata(obceLayer);
|
|
|
//console.log(sublayers[0].getSource().getFeatures());
|
|
//console.log(sublayers[0].getSource().getFeatures());
|
|
|
- obce.getFeatures()[0].dispatchEvent('change');
|
|
|
|
|
console.timeEnd('forEach-Cluster');
|
|
console.timeEnd('forEach-Cluster');
|
|
|
console.log('clustering done!');
|
|
console.log('clustering done!');
|
|
|
//this.clusters = clusters;
|
|
//this.clusters = clusters;
|