Sfoglia il codice sorgente

refactor: do not hard-code clustering method

jmacura 5 anni fa
parent
commit
b4a3f2d874
2 ha cambiato i file con 9 aggiunte e 7 eliminazioni
  1. 4 4
      src/adjuster/adjuster.service.js
  2. 5 3
      src/app.component.js

+ 4 - 4
src/adjuster/adjuster.service.js

@@ -5,7 +5,7 @@ import {factors} from './factors.js';
 export class AdjusterService {
   constructor(HsCore, HsUtilsService, $rootScope, $http, $location) {
     'ngInject';
-    this.HsCore = HsCore;
+    //this.HsCore = HsCore;
     this.HsUtilsService = HsUtilsService;
     this.$rootScope = $rootScope;
     this.$http = $http;
@@ -15,6 +15,7 @@ export class AdjusterService {
         : 'https://publish.lesprojekt.cz/nodejs/';
     this.factors = factors;
     this.clusters = [];
+    this.method = 'haclust';
     this._clusteringInProcess = true;
     this.init();
   }
@@ -69,8 +70,8 @@ export class AdjusterService {
           });
           const clusters = [];
           for (const region of clusterData) {
-            if (!clusters.includes(region['haclust'])) {
-              clusters.push(region['haclust']);
+            if (!clusters.includes(region[this.method])) {
+              clusters.push(region[this.method]);
             }
           }
           this.clusters = clusters;
@@ -110,7 +111,6 @@ export class AdjusterService {
               };
             });
         });
-        console.log(this.factors);
         this.apply();
       })
       .catch((error) => {

+ 5 - 3
src/app.component.js

@@ -69,8 +69,10 @@ const nuts2style = new Style({
   }),
 });
 
+// TODO: 'method' must be obtained from AdjusterService
+const method = 'haclust';
 const nuts3style = function (feature) {
-  if (isNaN(feature.get('haclust'))) {
+  if (isNaN(feature.get(method))) {
     return [
       new Style({
         fill: new Fill({
@@ -86,7 +88,7 @@ const nuts3style = function (feature) {
     return [
       new Style({
         fill: new Fill({
-          color: randomColorPalette[feature.get('haclust') - 1],
+          color: randomColorPalette[feature.get(method) - 1],
         }),
       }),
     ];
@@ -112,7 +114,7 @@ nuts3Layer.set('popUp', {
   attributes: [
     {attribute: 'CNTR_CODE', label: 'Country'},
     {attribute: 'NUTS_NAME', label: 'Name'},
-    {attribute: 'km25.cluster', label: 'Cluster ID'},
+    {attribute: method, label: 'Cluster ID'},
   ],
 });