Resolved merge conflixts
authorJulie Hill Roa <julie.hill.roa@gmail.com>
Thu, 3 Dec 2015 17:55:25 +0000 (18:55 +0100)
committerJulie Hill Roa <julie.hill.roa@gmail.com>
Thu, 3 Dec 2015 17:55:25 +0000 (18:55 +0100)
1  2 
src/components/map/map.ts

@@@ -23,8 -26,10 +26,10 @@@ export class Map 
      // COLORS:Object;
  
      constructor(http:Http) {
+         this.activeId = null;
          this.newactive = new EventEmitter();
 -        this.newOrg = 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.parent = null;
          this.currentPos = null;
          this.uprunned = false;
+         this.currentMarker = null;
          // this.COLORS = {'red','brown',',yellow','green',',pink','purple','gray','black'};
+         this.hideModal = document.getElementById("topLevel").style.visibility = "hidden";
+         this.hideModal = document.getElementById("middleLevel").style.visibility = "hidden";
+         this.hideModal = document.getElementById("bottomLevel").style.visibility = "hidden";
          this.hideModal = document.getElementById("divModal").style.visibility = "hidden";
 -
      }
  
      showModal() {
  
  
              this.map.data.addListener('click', function (event) {
+                 instance.setActiveId(event.feature.O.id);
+                 instance.setcurrentPos(event.latLng);
  
-                 //TODO: spør om man vil ned/opp eller se info
                  //TODO: finne liste over alle levels slike at man ikke har hardkodet inn < 4 !!
+                 if (instance.uprunned == false && instance.LEVEL == 2) {
+                     this.hideModal = document.getElementById("topLevel").style.visibility = "visible";
+                     this.hideModal = document.getElementById("middleLevel").style.visibility = "hidden";
+                     this.hideModal = document.getElementById("bottomLevel").style.visibility = "hidden";
+                     instance.showModal();
  
-                 if (instance.runned == false && instance.LEVEL < 4) {
-                     instance.setRunned(true);
+                 }
+                 else if (instance.runned == false && instance.LEVEL < 4) {
+                     this.hideModal = document.getElementById("topLevel").style.visibility = "hidden";
+                     this.hideModal = document.getElementById("middleLevel").style.visibility = "visible";
+                     this.hideModal = document.getElementById("bottomLevel").style.visibility = "hidden";
+                     instance.showModal();
+                 } else if (instance.runned == false && instance.LEVEL <= 4) {
  
-                     let infowindow = new google.maps.InfoWindow({
-                         //TODO: Style this
-                         content: '<div> <button >DrillUP</button>' +
-                         ' <button ">DrillDOWN</button>' +
-                         '<button ">SEEINFO</button></div>'
-                     });
+                     this.hideModal = document.getElementById("topLevel").style.visibility = "hidden";
+                     this.hideModal = document.getElementById("middleLevel").style.visibility = "hidden";
+                     this.hideModal = document.getElementById("bottomLevel").style.visibility = "visible";
  
-                     infowindow.setPosition(event.latlng);
-                     // infowindow.open(instance.map);
+                     instance.setcurrentPos(event.latLng);
+                     instance.showModal();
  
-                     let id = event.feature.O.id;
-                     instance.setParent(id);
+                 }
  
-                     instance.map.data.forEach(function (feature) {
-                         if (!(feature.O.id == id && instance.LEVEL == 3)) {
-                             instance.map.data.remove(feature);
 +
-                         }
-                     });
+             });
+         }
+         else {
+             // ToDO:
+             console.log("fiks meg! gi warning på topp av kart");
+         }
+     }
  
-                     instance.addLevel();
-                     instance.getData('/' + id + '/children', instance);
-                 } else if (instance.runned == false && instance.LEVEL >= 4) {
-                     instance.setRunned(true);
+     drillDown() {
+         this.closeModal();
+         let map = this.getMap();
+         let id = this.activeId;
+         let level = this.LEVEL;
+         console.log(id);
+         this.setRunned(true);
+         this.setParent(id);
  
-                     instance.setcurrentPos(event.latLng);
+         map.data.forEach(function (feature) {
+             if (!(feature.O.id == id && level == 3)) {
+                 map.data.remove(feature);
  
-                     var marker = new google.maps.Marker({
-                         position: event.latLng,
-                         map: instance.map,
-                         title: 'newOrg',
-                         icon: {
-                             path: google.maps.SymbolPath.CIRCLE,
-                             scale: 5
-                         }
+             }
+         });
  
-                     });
+         this.addLevel();
+         this.getData('/' + id + '/children', this);
  
-                     marker.setMap(instance.map);
-                     instance.showModal();
-                 }
-             });
  
+     }
  
-             this.map.data.addListener('rightclick', function (event) {
-                 if (instance.uprunned == false) {
-                     instance.setupRunned(true);
-                     instance.upLevel();
+     drillUp() {
  
-                     if (instance.LEVEL > 1) {
-                         instance.map.data.forEach(function (feature) {
-                             instance.map.data.remove(feature);
-                         });
+         if (this.LEVEL > 2) {
+             this.setupRunned(true);
+             this.upLevel();
+             let instance = this;
+             this.closeModal();
+             this.map.data.forEach(function (feature) {
+                 instance.map.data.remove(feature);
  
-                         let parent = instance.getParent();
-                         instance.getData('/' + parent, instance, true);
-                     }
-                     else {
-                         instance.addLevel();
-                         instance.setupRunned(true);
-                         //TODO skriv en warning om at man ikke kan gå opp
-                     }
-                 }
              });
+             let parent = instance.getParent();
+             instance.getData('/' + parent, instance, true);
          }
-         else {
-             // ToDO:
-             console.log("fiks meg! gi warning på topp av kart");
-         }
+         this.closeModal();
+     }
+     seeDetails() {
+         let map = this.getMap();
+         let id = this.activeId;
+         this.closeModal();
+         map.data.forEach(function (feature) {
+             if (feature.getProperty('id') == id) {
+                 feature.setProperty('color', 'red');
+             }
+         });
+         this.newactive.next(this.activeId);
      }
  
      addUnit() {
-         let parent = this.getParent();
+         this.closeModal();
          let pos = this.getcurrentPos();
          let lat = pos.lat();
-         let lng = pos.lng()
+         let lng = pos.lng();
+         let map = this.map;
+           var
+          marker = new google.maps.Marker({
+          position: pos,
+          map: map,
+          title: 'newOrg',
+          icon: {
+          path: google.maps.SymbolPath.CIRCLE,
+          scale: 3
+          }
+          });
+          this
+          .
+          currentMarker = marker;
+          marker
+          .
+          setMap(map);
+         let parent = this.getParent();
          let location = {lat: lat, lng: lng};
          let event = {location, parent};
 -        this.newOrg.next(event);
 +        this.neworg.next(event);
 +        this.closeModal();
-         this.setRunned(false); 
++        this.setRunned(false);
      }
  
      update(event) {
-         this.newactive.next(event);
-         let test = this.getMap();
 -
++        this.neworg.next(event);
+         let map = this.getMap();
          let http = this.getHttp();
  
-         test.data.forEach(function (feature) {
-             test.data.remove(feature);
+         map.data.forEach(function (feature) {
+             map.data.remove(feature);
          });
          http.get(dhisAPI + '/api/organisationUnits/' + event)
              .map(res => res.json())