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'
20 constructor(http:Http) {
21 this.newactive = new EventEmitter();
22 this.map = new google.maps.Map(document.getElementById("map"),{center: {lat:0,lng:0}, zoom:12});
27 this.getData('?paging=false&level=2',this);
40 let initMap = this.initMap;
42 if (navigator.geolocation) {
43 navigator.geolocation.getCurrentPosition(function (position) {
44 //let pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
45 let pos = {lat:10,lng:39}
48 //handleNoGeoLocation()
52 alert("You do not support geolocation");
59 initMap(location,map){
61 map.setCenter(location,3);
65 map.addListener('click', function (event) {
66 console.log(event.latlng);
77 getData(query,instance){
78 console.log(instance.http);
79 instance.http.get(dhisAPI+'/api/organisationUnits'+query)
80 .map(res => res.json())
82 res => instance.parseResult(res,instance),
83 error => instance.logError(error)
88 parseResult(res,instance){
90 if(res.organisationUnits) {
91 for (let item in res.organisationUnits) {
92 this.getData('/' + res.organisationUnits[item].id,this);
95 }else if(!res.displayName && res.children){
96 for (let item in res.children) {
97 if(res.children[item].level == instance.LEVEL){
98 this.getData('/' + res.children[item].id,this);
101 instance.setRunned(false);
104 this.drawPolygon(res);
110 let incoming: string;
111 incoming = item.featureType.toLowerCase();
116 case "multi_polygon":
117 feature = 'MultiPolygon';
120 feature = 'MultiPolygon';
124 // TODO: test på feature og behandle type: NONE
125 if(feature !== undefined) {
130 "coordinates": JSON.parse(item.coordinates)
137 if(unit.geometry.type == 'Point'){
138 unit.geometry.type.);
140 this.map.data.addGeoJson(unit);
142 this.map.data.addListener('click', function(event) {
143 //TODO: spør om man vil ned/opp eller se info
144 if(instance.runned == false){
145 instance.setRunned(true);
148 let id = event.feature.O.id;
151 instance.map.data.forEach(function(feature) {
152 instance.map.data.remove(feature);
155 instance.getData('/' + id+'/children',instance);
162 console.log("fiks meg! gi warning på topp av kart");
170 console.log('you just added a new organisation unit');
174 this.newactive.next(event);