]> git.uio.no Git - u/erikhf/frm.git/blob - src/components/map/map.ts
Added "this is you" marker
[u/erikhf/frm.git] / src / components / map / map.ts
1 import {Component, CORE_DIRECTIVES,} from 'angular2/angular2';
2 import {Headers, Http} from 'angular2/http';
3
4
5 @Component({
6     selector: 'mou-map',
7     directives: [CORE_DIRECTIVES],
8     templateUrl: './components/map/map.html'
9 })
10
11
12 export class Map {
13     result:Object;
14     map:Object;
15     pos:Object;
16     marker:Object;
17
18     constructor(http:Http) {
19         this.initMap();
20
21         var authHeader = new Headers();
22         authHeader.append('Authorization', 'Basic YWRtaW46ZGlzdHJpY3Q=');
23         this.result = {organisationUnits: []};
24         // http.get(dhisAPI+'/api/organisationUnits?paging=false', {headers: authHeader})
25         http.get('http://mydhis.com:8082/api/organisationUnits?paging=false', {headers: authHeader})
26             .map(res => res.json()).subscribe(
27             res => this.result = res,
28             error => this.logError(error)
29         );
30     }
31
32
33     initMap() {
34
35         if (navigator.geolocation) {
36             navigator.geolocation.getCurrentPosition(function (position) {
37                     this.pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
38                     this.map = new google.maps.Map(document.getElementById("map"),
39                         {center: this.pos, zoom: 12});
40                     this.marker = new google.maps.Marker({
41                         position: this.pos,
42                         map: this.map,
43                         title: 'Me'
44                     });
45
46                     let infowindow = new google.maps.InfoWindow({
47                         content: "This is You"
48                     });
49                     this.marker.addListener('click', function () {
50                         infowindow.open(this.map, this.marker);
51                     });
52                    // this.map.addListener('click', this.addMarker(position.coords.latitude, position.coords.longitude));
53
54                 }, function () {
55                     //handleNoGeolocation(true);
56                 }
57             );
58         } else {
59             alert("You do not support geolocation");
60         }
61
62
63     }
64
65
66     //Other map functions
67    // addMarker(lat, lng) {
68
69      //   let marker = new google.maps.Marker({
70        //     position: {lat, lng},
71          //   map: this.map,
72         //    title: 'Me'
73         //});
74     //}
75
76     logError(error) {
77         console.error(error);
78
79     }
80
81 }
82
83
84 /* showOnMap(){
85  var bermudaTriangle = new google.maps.Polygon({
86  paths: triangleCoords,
87  strokeColor: '#FF0000',
88  strokeOpacity: 0.8,
89  strokeWeight: 2,
90  fillColor: '#FF0000',
91  fillOpacity: 0.35
92  });
93  bermudaTriangle.setMap(this.map);
94
95  }*/
96
97
98
99