]> git.uio.no Git - u/erikhf/frm.git/commitdiff
fix in adding and editing markers
authorJulie Hill Roa <julie.hill.roa@gmail.com>
Fri, 11 Dec 2015 13:00:54 +0000 (14:00 +0100)
committerJulie Hill Roa <julie.hill.roa@gmail.com>
Fri, 11 Dec 2015 13:00:54 +0000 (14:00 +0100)
src/components/map/map.ts
src/components/sidebar/sidebar.ts

index 82ed0e736a7231d18f2f2f5c999077e0c910a802..78b0437c0bd0a543ebe307f49470ad4b8bba3663 100644 (file)
@@ -414,8 +414,11 @@ export class Map {
      * focuses map and colors to the clicked marker/polygon and fires an event to sidebar with the id of the marker
      */
     seeDetails() {
+
+        console.log("inne i seeDetails");
         let map = this.getMap();
         let id = this.activeId;
+        let instance = this;
         this.closeModal();
         map.data.forEach(function (feature) {
             if (feature.getProperty('id') == id) {
@@ -424,6 +427,7 @@ export class Map {
                     feature.O.icon.strokeColor = 'red';
                 }
                 this.isSearched = false;
+                console.log(this.isSearched);
             }
             else {
                 feature.setProperty('color', 'gray');
@@ -458,19 +462,24 @@ export class Map {
      * @param event - event from an emitter
      */
     update(event) {
-        this.newactive.next(event);
-        let map = this.getMap();
-        let http = this.getHttp();
+        if(event !== null) {
+            if (this.currentMarker) {
+                this.currentMarker.setMap(null);
+            }
 
-        map.data.forEach(function (feature) {
-            map.data.remove(feature);
-        });
-        http.get(dhisAPI + '/api/organisationUnits/' + event)
-            .map(res => res.json())
-            .subscribe(
-                res => this.mapUpdate(res, this)
-            );
+            this.newactive.next(event);
+            let map = this.getMap();
+            let http = this.getHttp();
 
+            map.data.forEach(function (feature) {
+                map.data.remove(feature);
+            });
+            http.get(dhisAPI + '/api/organisationUnits/' + event)
+                .map(res => res.json())
+                .subscribe(
+                    res => this.mapUpdate(res, this)
+                );
+        }
     }
 
     /**
@@ -484,6 +493,7 @@ export class Map {
         this.setActiveId(res.id);
         this.isSearched = true;
         this.setParent(res.parent.id);
+       // this.setcurrentPos({lat: JSON.parse(res.coordinates)[1],lng: JSON.parse(res.coordinates)[0]});
 
         instance.getData('/' + res.parent.id + '/children', instance);
         if (res.coordinates == null || instance.LEVEL == instance.allLevels) {
@@ -501,33 +511,35 @@ export class Map {
      * @param pos - position for the temp marker
      */
     tempMarker(pos) {
+        if (this.currentMarker)
+            this.currentMarker.setMap(null);
+        if(pos != null) {
+            let current = {};
+            current.lat = Math.round(this.getcurrentPos().lat() * 10000) / 10000;
+            current.lng = Math.round(this.getcurrentPos().lng() * 10000) / 10000;
 
-        let current = {};
-        current.lat = Math.round(this.getcurrentPos().lat() * 10000)/10000;
-        current.lng = Math.round(this.getcurrentPos().lng() * 10000)/10000;
+            let position = {};
+            position.lat = Math.round(pos.lat * 10000) / 10000;
+            position.lng = Math.round(pos.lng * 10000) / 10000;
 
-        let position = {};
-        position.lat= Math.round(pos.lat * 10000) / 10000;
-        position.lng= Math.round(pos.lng * 10000)/10000;
+            if ((current.lat != position.lat) || (current.lng != position.lng)) {
 
-        if((current.lat != position.lat) || (current.lng != position.lng)){
+                let map = this.map;
 
-            let map = this.map;
-            if (this.currentMarker)
-                this.currentMarker.setMap(null);
 
-            this.currentMarker = new google.maps.Marker({
-                position: pos,
-                map: map,
-                title: 'neworg',
-                icon: {
-                    path: google.maps.SymbolPath.CIRCLE,
-                    strokeColor: "#871F78",
-                    scale: 4
-                }
-            });
-            this.currentMarker.setMap(map);
-            map.panTo(this.currentMarker.getPosition());
+                this.currentMarker = new google.maps.Marker({
+                    position: pos,
+                    map: map,
+                    title: 'neworg',
+                    icon: {
+                        path: google.maps.SymbolPath.CIRCLE,
+                        strokeColor: "#871F78",
+                        scale: 4
+                    }
+                });
+                this.currentMarker.setMap(map);
+                map.panTo(this.currentMarker.getPosition());
+            }
         }
 
     }
index c9329f4bcb0eb60b43a4dae400ef79b991701346..497329e941b46c248bccfbe5b3abca178f8287f3 100644 (file)
@@ -209,7 +209,7 @@ export class Sidebar {
                     headers: headers
                 })
                 .map(res => res.json())
-                .subscribe(res => console.log(res));
+                .subscribe(res => this.emitNewUpdatedObject(res));
         }
     }
 
@@ -238,6 +238,7 @@ export class Sidebar {
 
         this.form.controls.lat.updateValue(data.location.lat);
         this.form.controls.lng.updateValue(data.location.lng);
+        this.form.controls.featureType.updateValue("POINT");
         this.form.controls.parent.updateValue(data.parent);
 
     }