]> git.uio.no Git - u/erikhf/frm.git/commitdiff
merged AddorgUnit into ExpandLevels
authorJulie Hill Roa <julie.hill.roa@gmail.com>
Thu, 26 Nov 2015 14:07:34 +0000 (15:07 +0100)
committerJulie Hill Roa <julie.hill.roa@gmail.com>
Thu, 26 Nov 2015 14:07:34 +0000 (15:07 +0100)
src/components/map/map.ts

index 5f573564797da92d4b798b6e6c529cf8b2f48d81..f4856177f1063f5885d6883c4790f36d7a367395 100644 (file)
@@ -14,6 +14,8 @@ export class Map {
 
     map:Object;
     http: Http;
+    LEVEL: number;
+    runned: boolean;
     parent: Object;
     currentPos = Object;
 
@@ -23,10 +25,12 @@ export class Map {
         this.map = new google.maps.Map(document.getElementById("map"),{center: {lat:0,lng:0}, zoom:12});
         this.init();
         this.http = http;
+        this.LEVEL = 2;
+        this.runned = false;
+        this.getData('?paging=false&level=2',this);
         this.parent =null ;
         this.currentPos = null;
-       // this.getData('?paging=false&level=2',this);
-        this.getData('?paging=false&level=3',this);
+
     }
 
     setcurrentPos(latlng){
@@ -41,14 +45,23 @@ export class Map {
     }
     getParent(){
         return this.parent;
+
+    }
+
+    setRunned(value){
+        this.runned = value;
     }
 
+    addLevel(){
+        this.LEVEL++;
+    }
 
     init() {
 
         let initMap = this.initMap;
         let instance = this;
         let map = this.map;
+
         let pos = {lat: 9.1, lng: -10.6};
         initMap(pos,map,instance);
 
@@ -59,6 +72,7 @@ export class Map {
 
 
         map.setCenter(location,2);
+
         let infowindow = new google.maps.InfoWindow({
             //TODO: Style this
             content:'<div>Du you want to add a new OrgUnit here ?    <button onclick="instance.myFunction()">Yes</button></div>'
@@ -85,6 +99,7 @@ export class Map {
                      marker.setMap(null);
              });
 
+
             }
         );
 
@@ -100,27 +115,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){
+    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;
@@ -149,26 +167,37 @@ export class Map {
                 },
                 "properties": {
                     "name": item.name,
-                    "id": item.id
-                }
+                    "id": item.id,
+
+                },
+                "style": null
             };
+            if(unit.geometry.type == 'Point'){
+               //ToDO: add en style på markeren ! 
+
+
+            }
             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);
+
 
                 let id = event.feature.O.id;
                 instance.setParent(id);
                 console.log(id);
 
-                instance.map.data.forEach(function(feature) {
-                    instance.map.data.remove(feature);
-                });
-               // instance.getData('/' + id+'/children',instance);
-                instance.getData('/' + id,instance);
 
-            });
+                    instance.map.data.forEach(function(feature) {
+                        instance.map.data.remove(feature);
+                    });
+                    instance.addLevel();
+                    instance.getData('/' + id+'/children',instance);
+                }
 
+            });
 
         }else {
             // ToDO: