]> 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)
1  2 
src/components/map/map.ts

index 8b6103eeda0750ec4b308ab1f26290f206079491,5f573564797da92d4b798b6e6c529cf8b2f48d81..f4856177f1063f5885d6883c4790f36d7a367395
@@@ -14,56 -14,77 +14,92 @@@ export class Map 
  
      map:Object;
      http: Http;
 +    LEVEL: number;
 +    runned: boolean;
+     parent: Object;
+     currentPos = Object;
  
      constructor(http:Http) {
          this.newactive = new EventEmitter();
+         this.newOrg = new EventEmitter();
          this.map = new google.maps.Map(document.getElementById("map"),{center: {lat:0,lng:0}, zoom:12});
          this.init();
          this.http = http;
 -       // this.getData('?paging=false&level=2',this);
 -        this.getData('?paging=false&level=3',this);
 +        this.LEVEL = 2;
 +        this.runned = false;
 +        this.getData('?paging=false&level=2',this);
+         this.parent =null ;
+         this.currentPos = null;
++
+     }
+     setcurrentPos(latlng){
+         this.currentPos = latlng;
+     }
+      getcurrentPos(){
+          return this.currentPos;
+      }
+     setParent(id){
+         this.parent=id;
+     }
+     getParent(){
+         return this.parent;
++
 +    }
 +
 +    setRunned(value){
 +        this.runned = value;
      }
  
 +    addLevel(){
 +        this.LEVEL++;
 +    }
  
      init() {
  
          let initMap = this.initMap;
+         let instance = this;
          let map = this.map;
-         if (navigator.geolocation) {
-             navigator.geolocation.getCurrentPosition(function (position) {
-                     //let pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
-                 let pos = {lat:10,lng:39}
-                     initMap(pos,map);
-                 }, function () {
-                 //handleNoGeoLocation()
-                 }
-             );
-         } else {
-             alert("You do not support geolocation");
-         }
 +
+         let pos = {lat: 9.1, lng: -10.6};
+         initMap(pos,map,instance);
  
      }
  
  
-     initMap(location,map){
+     initMap(location,map,instance){
  
-         map.setCenter(location,3);
  
+         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>'
+         });
+         map.addListener('click', function (e) {
+             instance.setcurrentPos(e.latLng);
+             instance.myFunction();
+             var marker = new google.maps.Marker({
+                 position: e.latLng,
+                 map: map,
+                 title: 'newOrg',
+                 icon: {
+                     path: google.maps.SymbolPath.CIRCLE,
+                     scale: 5
+                 }
+             });
+             marker.setMap(map);
+             infowindow.open(map, marker);
+                  infowindow.addListener('closeclick', function (e) {
+                      marker.setMap(null);
+              });
  
-         map.addListener('click', function (event) {
-                 console.log(event.latlng);
 +
              }
          );
  
          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;
                  },
                  "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;
-                     console.log(id);
+                 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:
  
      }
  
+     addUnit(){
+         console.log("Inne i Add funksjonen");
+         let parent = this.getParent();
+         let pos = this.getcurrentPos();
+         let event =  {pos,parent};
+         this.newOrg.next(event);
+     }
+     myFunction(){
+         console.log("Inne i myfunksjonen");
+       
  
-     createOrgUnit(){
-         console.log('you just added a new organisation unit');
      }
  
      update(event){