map:Object;
http: Http;
+ LEVEL: number;
+ runned: boolean;
parent: Object;
currentPos = Object;
this.map = new google.maps.Map(document.getElementById("map"),{center: {lat:0,lng:0}, zoom:12});
this.init();
this.http = http;
+ this.LEVEL = 2;
+ this.runned = false;
+ this.getData('?paging=false&level=2',this);
this.parent =null ;
this.currentPos = null;
- // this.getData('?paging=false&level=2',this);
- this.getData('?paging=false&level=3',this);
+
}
setcurrentPos(latlng){
}
getParent(){
return this.parent;
+
+ }
+
+ setRunned(value){
+ this.runned = value;
}
+ addLevel(){
+ this.LEVEL++;
+ }
init() {
let initMap = this.initMap;
let instance = this;
let map = this.map;
+
let pos = {lat: 9.1, lng: -10.6};
initMap(pos,map,instance);
map.setCenter(location,2);
+
let infowindow = new google.maps.InfoWindow({
//TODO: Style this
content:'<div>Du you want to add a new OrgUnit here ? <button onclick="instance.myFunction()">Yes</button></div>'
marker.setMap(null);
});
+
}
);
instance.http.get(dhisAPI+'/api/organisationUnits'+query)
.map(res => res.json())
.subscribe(
- res => instance.parseResult(res),
+ res => instance.parseResult(res,instance),
error => instance.logError(error)
);
}
- parseResult(res){
+ parseResult(res,instance){
if(res.organisationUnits) {
for (let item in res.organisationUnits) {
this.getData('/' + res.organisationUnits[item].id,this);
}
//liten hack
- }//else if(res.name != false){
- // for (let item in res.children) {
- // this.getData('/' + res.children[item].id,this);
- //}
- //}
+ }else if(!res.displayName && res.children){
+ for (let item in res.children) {
+ if(res.children[item].level == instance.LEVEL){
+ this.getData('/' + res.children[item].id,this);
+ }
+ }
+ instance.setRunned(false);
+ }
else {
-
- this.drawPolygon(res);};
+ this.drawPolygon(res);
+ };
}
drawPolygon(item){
let instance = this;
},
"properties": {
"name": item.name,
- "id": item.id
- }
+ "id": item.id,
+
+ },
+ "style": null
};
+ if(unit.geometry.type == 'Point'){
+ //ToDO: add en style på markeren !
+
+
+ }
this.map.data.addGeoJson(unit);
this.map.data.addListener('click', function(event) {
//TODO: spør om man vil ned/opp eller se info
+ if(instance.runned == false){
+ instance.setRunned(true);
+
let id = event.feature.O.id;
instance.setParent(id);
console.log(id);
- instance.map.data.forEach(function(feature) {
- instance.map.data.remove(feature);
- });
- // instance.getData('/' + id+'/children',instance);
- instance.getData('/' + id,instance);
- });
+ instance.map.data.forEach(function(feature) {
+ instance.map.data.remove(feature);
+ });
+ instance.addLevel();
+ instance.getData('/' + id+'/children',instance);
+ }
+ });
}else {
// ToDO: