]> git.uio.no Git - u/erikhf/frm.git/blobdiff - src/components/map/map.ts
expaned to alle levels downwords
[u/erikhf/frm.git] / src / components / map / map.ts
index 56828c0cb78699fc32201ac85c43499e58674cad..ab9f39c5d54fa7379454aa9eee5ead18e25d2cb2 100644 (file)
@@ -31,6 +31,10 @@ export class Map {
         this.runned = value;
     }
 
+    addLevel(){
+        this.LEVEL++;
+    }
+
     init() {
 
         let initMap = this.initMap;
@@ -54,7 +58,7 @@ export class Map {
 
     initMap(location,map){
 
-        map.setCenter(location,8);
+        map.setCenter(location,3);
 
 
 
@@ -75,27 +79,30 @@ export class Map {
         instance.http.get(dhisAPI+'/api/organisationUnits'+query)
             .map(res => res.json())
             .subscribe(
-                res => instance.parseResult(res),
+                res => instance.parseResult(res,instance),
                 error => instance.logError(error)
             );
 
     }
 
-    parseResult(res){
-        console.log(res);
+    parseResult(res,instance){
+
         if(res.organisationUnits) {
             for (let item in res.organisationUnits) {
                 this.getData('/' + res.organisationUnits[item].id,this);
             }
             //liten hack
-        }//else if(res.name != false){
-           // for (let item in res.children) {
-             //   this.getData('/' + res.children[item].id,this);
-            //}
-        //}
+        }else if(!res.displayName && res.children){
+            for (let item in res.children) {
+                if(res.children[item].level == instance.LEVEL){
+                    this.getData('/' + res.children[item].id,this);
+                }
+            }
+            instance.setRunned(false);
+        }
         else {
-
-            this.drawPolygon(res);};
+            this.drawPolygon(res);
+        };
     }
     drawPolygon(item){
         let instance = this;
@@ -127,10 +134,12 @@ export class Map {
                     "id": item.id
                 }
             };
+            if(unit.geometry.type == 'Point'){
+                unit.geometry.type.);
+            }
             this.map.data.addGeoJson(unit);
 
             this.map.data.addListener('click', function(event) {
-
                //TODO: spør om man vil ned/opp eller se info
                 if(instance.runned == false){
                     instance.setRunned(true);
@@ -142,9 +151,8 @@ export class Map {
                     instance.map.data.forEach(function(feature) {
                         instance.map.data.remove(feature);
                     });
+                    instance.addLevel();
                     instance.getData('/' + id+'/children',instance);
-                   // instance.getData('/' + id,instance);
-
                 }
 
             });