import {Geometry} from 'ol/geom'; import {Injectable} from '@angular/core'; import {Vector as VectorSource} from 'ol/source'; @Injectable({providedIn: 'root'}) export class AttractivenessIndexService { constructor() {} processIndex( indexSource: VectorSource, codeRecordRelations: Record ): void { /*if (obce.getFeatures()?.length < 1) { obce.once('changefeature', () => this.processIndex(codeRecordRelations)); return; }*/ let errs = 0; //let logs = 0; indexSource.forEachFeature((feature) => { // Pair each feature with its attractivity data const featureData = codeRecordRelations[feature.get('NUTS_ID').toUpperCase()]; if (!featureData) { if (errs < 20) { errs++; console.warn( `No data for feature ${feature.get('NUTS_ID').toUpperCase()}` ); console.log(feature); } return; } /*logs++; if (logs % 100 == 0) { console.log(`processed ${logs} items`); }*/ Object.keys(featureData).forEach((key, index) => { if (key !== 'nuts_id') { feature.set(key, featureData[key], true); //true stands for "silent" - important for performance! } }); }); // Since we are updating the features silently, we now have to refresh manually indexSource.getFeatures()[0].dispatchEvent('change'); } }