1 import {Component, CORE_DIRECTIVES,} from 'angular2/angular2';
2 import {Headers, Http} from 'angular2/http';
7 directives: [CORE_DIRECTIVES],
8 templateUrl: './components/map/map.html'
18 constructor(http:Http) {
20 this.map = new google.maps.Map(document.getElementById("map"),{center: {lat:0,lng:0}, zoom:12});
24 this.getData('?paging=false&level=2');
30 let initMap = this.initMap;
31 let addMarker = this.addMarker;
33 if (navigator.geolocation) {
34 navigator.geolocation.getCurrentPosition(function (position) {
35 let pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
36 initMap(pos,map,addMarker);
38 //handleNoGeolocation(true);
42 alert("You do not support geolocation");
49 initMap(location,map,addMarker){
52 map.setCenter(location,12);
54 addMarker(location,map,'This is YOU');
58 map.addListener('click', function (event) {
59 addMarker(event.latLng,map, 'Want to add a new marker here ? <br> <button onclick=\"createOrgUnit()\">Yes</button> <button onclick=\"deleteMarker()">No</button> ');
65 addMarker(location, map, title) {
67 let marker = new google.maps.Marker({
72 let infowindow = new google.maps.InfoWindow({
76 marker.addListener('click', function () {
78 infowindow.open(map,marker);
90 this.http.get(dhisAPI+'/api/organisationUnits'+query)
91 .map(res => res.json())
93 res => this.parseResult(res),
94 error => this.logError(error)
101 if(res.organisationUnits) {
102 for (let item in res.organisationUnits) {
103 this.getData('/' + res.organisationUnits[item].id);
107 this.drawPolygon(res);};
111 let incoming: string;
112 incoming = item.featureType.toLowerCase();
117 case "multi_polygon":
118 feature = 'MultiPolygon';
121 feature = 'MultiPolygon';
125 // TODO: test på feature og behandle type: NONE
126 if(feature !== undefined) {
131 "coordinates": JSON.parse(item.coordinates)
138 this.map.data.addGeoJson(unit);
140 this.map.data.addListener('click', function(event) {
143 map.data.revertStyle();
144 map.data.overrideStyle(event.feature, {strokeWeight: 8});
146 //.addListener('click', function(){
147 // console.log("Nå klikket du på:" + unit.properties.name + unit.properties.id);
149 /* var featureStyle = {
150 strokeColor: '#66ffff',
154 map.data.setStyle(featureStyle);
155 map.data.addListener('click', function(event) {
157 // This is where I want to check if point(s) fall within it.
164 console.log("fiks meg! gi warning på topp av kart");
172 console.log('you just added a new organisation unit');
176 console.log('you just deleted the marker');