1 import {Component, EventEmitter,CORE_DIRECTIVES,} from 'angular2/angular2';
2 import {Headers, Http} from 'angular2/http';
7 directives: [CORE_DIRECTIVES],
9 templateUrl: './components/map/map.html'
19 constructor(http:Http) {
20 this.newactive = new EventEmitter();
21 this.map = new google.maps.Map(document.getElementById("map"),{center: {lat:0,lng:0}, zoom:12});
25 this.getData('?paging=false&level=2',this);
31 let initMap = this.initMap;
32 let addMarker = this.addMarker;
34 if (navigator.geolocation) {
35 navigator.geolocation.getCurrentPosition(function (position) {
36 let pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
37 initMap(pos,map,addMarker);
39 //handleNoGeoLocation()
43 alert("You do not support geolocation");
50 initMap(location,map,addMarker){
52 map.setCenter(location,12);
53 addMarker(location,map,'This is YOU');
57 map.addListener('click', function (event) {
58 addMarker(event.latLng,map, 'Want to add a new marker here ? <br> <button onclick=\"createOrgUnit()\">Yes</button> <button onclick=\"deleteMarker()">No</button> ');
64 addMarker(location, map, title) {
66 let marker = new google.maps.Marker({
71 let infowindow = new google.maps.InfoWindow({
75 marker.addListener('click', function () {
77 infowindow.open(map,marker);
87 getData(query,instance){
88 console.log(instance.http);
89 instance.http.get(dhisAPI+'/api/organisationUnits'+query)
90 .map(res => res.json())
92 res => instance.parseResult(res),
93 error => instance.logError(error)
100 if(res.organisationUnits) {
101 for (let item in res.organisationUnits) {
102 this.getData('/' + res.organisationUnits[item].id,this);
105 }//else if(res.name != false){
106 // for (let item in res.children) {
107 // this.getData('/' + res.children[item].id,this);
112 this.drawPolygon(res);};
117 let incoming: string;
118 incoming = item.featureType.toLowerCase();
123 case "multi_polygon":
124 feature = 'MultiPolygon';
127 feature = 'MultiPolygon';
131 // TODO: test på feature og behandle type: NONE
132 if(feature !== undefined) {
137 "coordinates": JSON.parse(item.coordinates)
144 this.map.data.addGeoJson(unit);
146 this.map.data.addListener('click', function(event) {
147 //TODO: spør om man vil ned/opp eller se info
149 let id = event.feature.O.id;
152 instance.map.data.forEach(function(feature) {
153 instance.map.data.remove(feature);
155 // instance.getData('/' + id+'/children',instance);
156 instance.getData('/' + id,instance);
163 console.log("fiks meg! gi warning på topp av kart");
171 console.log('you just added a new organisation unit');
175 console.log('you just deleted the marker');
179 this.newactive.next(event);