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'
22 constructor(http:Http) {
23 this.newactive = new EventEmitter();
24 this.newOrg = new EventEmitter();
25 this.map = new google.maps.Map(document.getElementById("map"),{center: {lat:0,lng:0}, zoom:12});
30 this.getData('?paging=false&level=2',this);
32 this.currentPos = null;
33 this.uprunned = false;
37 setcurrentPos(latlng){
38 this.currentPos = latlng;
41 return this.currentPos;
57 this.uprunned = value;
69 let initMap = this.initMap;
73 let pos = {lat: 9.1, lng: -10.6};
74 initMap(pos,map,instance);
79 initMap(location,map,instance){
80 let add = instance.myFunction;
82 map.setCenter(location,12);
84 let infowindow = new google.maps.InfoWindow({
86 content:'<div>Du you want to add a new OrgUnit here ? <button onclick="myFunction()">Yes</button></div>'
88 map.addListener('click', function (e) {
89 instance.setcurrentPos(e.latLng);
92 var marker = new google.maps.Marker({
97 path: google.maps.SymbolPath.CIRCLE,
104 infowindow.open(map, marker);
106 infowindow.addListener('closeclick', function (e) {
118 console.error(error);
122 getData(query,instance, isParent){
123 instance.http.get(dhisAPI+'/api/organisationUnits'+query)
124 .map(res => res.json())
126 res => instance.parseResult(res,instance,isParent),
127 error => instance.logError(error)
133 parseResult(res,instance){
141 if (res.organisationUnits) {
142 for (let item in res.organisationUnits) {
143 this.getData('/' + res.organisationUnits[item].id, this);
146 instance.setupRunned(false);
148 } else if (!res.displayName && res.children) {
149 for (let item in res.children) {
150 if (res.children[item].level == instance.LEVEL) {
151 this.getData('/' + res.children[item].id, this);
154 instance.setRunned(false);
155 instance.setupRunned(false);
158 this.drawPolygon(res, instance);
165 drawPolygon(item, instance){
167 let incoming: string;
168 incoming = item.featureType.toLowerCase();
173 case "multi_polygon":
174 feature = 'MultiPolygon';
177 feature = 'MultiPolygon';
181 // TODO: test på feature og behandle type: NONE
182 if(feature !== undefined) {
187 "coordinates": JSON.parse(item.coordinates)
196 if(unit.geometry.type == 'Point'){
197 //ToDO: add en style på markeren !
200 this.map.data.addGeoJson(unit);
202 this.map.data.addListener('click', function(event) {
203 //TODO: spør om man vil ned/opp eller se info
205 if(instance.runned == false && instance.LEVEL > 1){
206 instance.setRunned(true);
209 let infowindow = new google.maps.InfoWindow({
211 content:'<div> <button >DrillUP</button>' +
212 ' <button ">DrillDOWN</button>' +
213 '<button ">SEEINFO</button></div>'
217 infowindow.setPosition(event.latlng);
218 // infowindow.open(instance.map);
221 let id = event.feature.O.id;
222 instance.setParent(id);
226 instance.map.data.forEach(function(feature) {
227 instance.map.data.remove(feature);
230 instance.getData('/' + id+'/children',instance);
235 this.map.data.addListener('rightclick', function(event) {
236 if(instance.uprunned == false) {
237 instance.setupRunned(true);
241 if (instance.LEVEL >= 2) {
242 instance.map.data.forEach(function (feature) {
243 instance.map.data.remove(feature);
245 let parent = instance.getParent();
246 instance.getData('/'+parent, instance,true);
247 }/*else if(instance.LEVEL > 2){
248 instance.map.data.forEach(function (feature) {
249 instance.map.data.remove(feature);
251 let parent = instance.getParent();
252 console.log('/' + parent + '/children', instance);
253 instance.getData('/' + parent + '/children', instance);
257 //TODO skriv en warning om at man ikke kan gå opp
267 console.log("fiks meg! gi warning på topp av kart");
275 let parent = this.getParent();
276 let pos = this.getcurrentPos();
279 let location= {lat: lat, lng: lng};
280 let event = {location,parent};
281 this.newOrg.next(event);
286 console.log("Inne i myfunksjonen");
290 this.newactive.next(event);