Added "this is you" marker
authorJulie Hill Roa <julie.hill.roa@gmail.com>
Thu, 19 Nov 2015 08:56:26 +0000 (09:56 +0100)
committerJulie Hill Roa <julie.hill.roa@gmail.com>
Thu, 19 Nov 2015 08:56:26 +0000 (09:56 +0100)
src/components/map/map.ts

index 97c05e0..8bed45f 100644 (file)
@@ -10,15 +10,18 @@ import {Headers, Http} from 'angular2/http';
 
 
 export class Map {
-    result: Object;
-    map: Object;
-    constructor(http: Http){
+    result:Object;
+    map:Object;
+    pos:Object;
+    marker:Object;
+
+    constructor(http:Http) {
         this.initMap();
 
         var authHeader = new Headers();
         authHeader.append('Authorization', 'Basic YWRtaW46ZGlzdHJpY3Q=');
-        this.result = {organisationUnits:[]};
-       // http.get(dhisAPI+'/api/organisationUnits?paging=false', {headers: authHeader})
+        this.result = {organisationUnits: []};
+        // http.get(dhisAPI+'/api/organisationUnits?paging=false', {headers: authHeader})
         http.get('http://mydhis.com:8082/api/organisationUnits?paging=false', {headers: authHeader})
             .map(res => res.json()).subscribe(
             res => this.result = res,
@@ -28,30 +31,69 @@ export class Map {
 
 
     initMap() {
-        this.map = new google.maps.Map(document.getElementById("map"),
-            {center: {lat: 59, lng: 11}, zoom: 12});
 
-        let marker = new google.maps.Marker({
-            position: {lat: 59, lng: 11},
-            map: this.map,
-            title: 'This is YOU!'
-        });
+        if (navigator.geolocation) {
+            navigator.geolocation.getCurrentPosition(function (position) {
+                    this.pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
+                    this.map = new google.maps.Map(document.getElementById("map"),
+                        {center: this.pos, zoom: 12});
+                    this.marker = new google.maps.Marker({
+                        position: this.pos,
+                        map: this.map,
+                        title: 'Me'
+                    });
 
-        let infowindow = new google.maps.InfoWindow({
-            content: "This is You"
-        });
+                    let infowindow = new google.maps.InfoWindow({
+                        content: "This is You"
+                    });
+                    this.marker.addListener('click', function () {
+                        infowindow.open(this.map, this.marker);
+                    });
+                   // this.map.addListener('click', this.addMarker(position.coords.latitude, position.coords.longitude));
 
-        marker.addListener('click', function () {
-            infowindow.open(this.map, marker);
-        });
+                }, function () {
+                    //handleNoGeolocation(true);
+                }
+            );
+        } else {
+            alert("You do not support geolocation");
+        }
 
-        //Other map functions
 
     }
 
+
+    //Other map functions
+   // addMarker(lat, lng) {
+
+     //   let marker = new google.maps.Marker({
+       //     position: {lat, lng},
+         //   map: this.map,
+        //    title: 'Me'
+        //});
+    //}
+
     logError(error) {
         console.error(error);
 
     }
 
 }
+
+
+/* showOnMap(){
+ var bermudaTriangle = new google.maps.Polygon({
+ paths: triangleCoords,
+ strokeColor: '#FF0000',
+ strokeOpacity: 0.8,
+ strokeWeight: 2,
+ fillColor: '#FF0000',
+ fillOpacity: 0.35
+ });
+ bermudaTriangle.setMap(this.map);
+
+ }*/
+
+
+
+