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.newOrg = new EventEmitter();
23 this.map = new google.maps.Map(document.getElementById("map"),{center: {lat:0,lng:0}, zoom:12});
27 this.currentPos = null;
28 // this.getData('?paging=false&level=2',this);
29 this.getData('?paging=false&level=3',this);
38 setcurrentPos(latlng){
39 this.currentPos = latlng;
42 return this.currentPos;
48 let initMap = this.initMap;
50 if (navigator.geolocation) {
51 navigator.geolocation.getCurrentPosition(function (position) {
52 // let pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
53 let pos = {lat: 9.1, lng: -10.6};
56 //handleNoGeoLocation()
60 alert("You do not support geolocation");
67 initMap(location,map){
69 map.setCenter(location,3);
72 let infowindow = new google.maps.InfoWindow({
73 content: '<div>Add an OrganisationUnit here ? <button (click)="addUnit(location)">Yes</button> <button (click)="clear()">NO</button>'
75 map.addListener('click', function (e) {
76 this.setcurrentPos(e.latLng);
77 var marker = new google.maps.Marker({
82 path: google.maps.SymbolPath.CIRCLE,
89 infowindow.open(map, marker);
92 console.log("jule husker");
93 console.log("Nå er parent og location sånn:" + this.getParent()+ " og "+ this.getcurrentPos());
104 console.error(error);
108 getData(query,instance){
109 console.log(instance.http);
110 instance.http.get(dhisAPI+'/api/organisationUnits'+query)
111 .map(res => res.json())
113 res => instance.parseResult(res),
114 error => instance.logError(error)
121 if(res.organisationUnits) {
122 for (let item in res.organisationUnits) {
123 this.getData('/' + res.organisationUnits[item].id,this);
126 }//else if(res.name != false){
127 // for (let item in res.children) {
128 // this.getData('/' + res.children[item].id,this);
133 this.drawPolygon(res);};
138 let incoming: string;
139 incoming = item.featureType.toLowerCase();
144 case "multi_polygon":
145 feature = 'MultiPolygon';
148 feature = 'MultiPolygon';
152 // TODO: test på feature og behandle type: NONE
153 if(feature !== undefined) {
158 "coordinates": JSON.parse(item.coordinates)
165 this.map.data.addGeoJson(unit);
167 this.map.data.addListener('click', function(event) {
168 //TODO: spør om man vil ned/opp eller se info
170 let id = event.feature.O.id;
171 instance.setParent(id);
174 instance.map.data.forEach(function(feature) {
175 instance.map.data.remove(feature);
177 // instance.getData('/' + id+'/children',instance);
178 instance.getData('/' + id,instance);
185 console.log("fiks meg! gi warning på topp av kart");
192 console.log("Inne i Add funksjonen");
193 let parent = this.getParent();
194 let pos = this.getcurrentPos;
195 let event = {pos,parent};
196 this.newOrg.next(event);
201 return new ol.style.Circle({
204 stroke: new ol.style.Stroke({color: 'red', width: 1})
209 this.newactive.next(event);