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

@@@ -14,8 -14,8 +14,10 @@@ export class Map 
  
      map:Object;
      http: Http;
 +    LEVEL: number;
 +    runned: boolean;
+     parent: Object;
+     currentPos = Object;
  
      constructor(http:Http) {
          this.newactive = new EventEmitter();
          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){
+         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);
              }
          );
  
  
              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: