Added "this is you" marker
[u/erikhf/frm.git] / src / components / map / map.ts
CommitLineData
a2d7d6b4
JHR
1import {Component, CORE_DIRECTIVES,} from 'angular2/angular2';
2import {Headers, Http} from 'angular2/http';
cb2c4ba8 3
1e6ce2f5 4
cb2c4ba8 5@Component({
28765058 6 selector: 'mou-map',
cb2c4ba8 7 directives: [CORE_DIRECTIVES],
28765058 8 templateUrl: './components/map/map.html'
cb2c4ba8
JHR
9})
10
11
28765058 12export class Map {
dd095993
JHR
13 result:Object;
14 map:Object;
15 pos:Object;
16 marker:Object;
17
18 constructor(http:Http) {
1e6ce2f5 19 this.initMap();
a2d7d6b4
JHR
20
21 var authHeader = new Headers();
22 authHeader.append('Authorization', 'Basic YWRtaW46ZGlzdHJpY3Q=');
dd095993
JHR
23 this.result = {organisationUnits: []};
24 // http.get(dhisAPI+'/api/organisationUnits?paging=false', {headers: authHeader})
a2d7d6b4
JHR
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 );
1e6ce2f5
EHF
30 }
31
a2d7d6b4
JHR
32
33 initMap() {
a2d7d6b4 34
dd095993
JHR
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 });
a2d7d6b4 45
dd095993
JHR
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));
a2d7d6b4 53
dd095993
JHR
54 }, function () {
55 //handleNoGeolocation(true);
56 }
57 );
58 } else {
59 alert("You do not support geolocation");
60 }
a2d7d6b4 61
cdcaf46c 62
a2d7d6b4
JHR
63 }
64
dd095993
JHR
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
a2d7d6b4
JHR
76 logError(error) {
77 console.error(error);
78
cb2c4ba8 79 }
28765058 80
cb2c4ba8 81}
dd095993
JHR
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