]> git.uio.no Git - u/erikhf/frm.git/blobdiff - src/components/map/map.ts
commented code i map.ts
[u/erikhf/frm.git] / src / components / map / map.ts
index ddd06541122a93df63a1e4ae6264fc9bc0f46da2..d3f72f8af47aa25ce247fe7b4df8634ecae49263 100644 (file)
@@ -26,9 +26,12 @@ export class Map {
     popupON:boolean;
     popup:Object;
     COLORS:Object;
-    colornum: number;
-
+    colornum:number;
 
+    /**
+     * initializes all the global variabels
+     * @param http - for http requests
+     */
     constructor(http:Http) {
 
         this.activeId = null;
@@ -56,56 +59,102 @@ export class Map {
         this.currentMarker = null;
         this.isSearched = false;
         this.colornum = 0;
-        this.COLORS = ['#ede1bb', '#1d407e', '#ff512e', '#662d47','#3b3a35', '#419175', '#983e41', '#f3002d', '#b0a875', '#00bfb5', '#926851', '#47a0a4','#333f50','#6f007b'];
+        this.COLORS = ['#ede1bb', '#1d407e', '#ff512e', '#662d47', '#3b3a35', '#419175', '#983e41', '#f3002d', '#b0a875', '#00bfb5', '#926851', '#47a0a4', '#333f50', '#6f007b'];
         this.popupON = false;
         this.popup = null;
     }
 
 
+    /**
+     * Sets the global variabel
+     * @param id - id of the active marker 
+     */
     setActiveId(id) {
         this.activeId = id;
     }
 
+    /**
+     * returns the global map
+     * @returns {Object}
+     */
     getMap() {
         return this.map;
     }
 
+    /**
+     * returns global http
+     * @returns {Http}
+     */
     getHttp() {
         return this.http;
     }
 
+    /**
+     * Sets the avctive markers position
+     * @param latlng - position of the active marker
+     */
     setcurrentPos(latlng) {
         this.currentPos = latlng;
     }
 
+    /**
+     * returns the active markers position
+     * @returns {Object}
+     */
     getcurrentPos() {
         return this.currentPos;
     }
 
+    /**
+     * sets the parent of the avtive marker
+     * @param id - of the parent
+     */
     setParent(id) {
         this.parent = id;
     }
 
+    /**
+     * returns the actice markers parent
+     * @returns {Object}
+     */
     getParent() {
         return this.parent;
     }
 
+    /**
+     * sets a bool value for if the addListner for drilling down has runned (little hack)
+     * @param value - for the runned variabel
+     */
     setRunned(value) {
         this.runned = value;
     }
 
+    /**
+     * sets a bool value for if the addListner for drilling up has runned (little hack)
+     * @param value - for the upRunned variabel
+     */
     setupRunned(value) {
         this.uprunned = value;
     }
 
+    /**
+     * sets the current level in the org.unit hierarchy
+     * @param value - for the level variabel
+     */
     setLevel(value) {
         this.LEVEL = value;
     }
 
+    /**
+     * add level when drilling down (little hack for synconisity)
+     */
     addLevel() {
         this.LEVEL++;
     }
 
+    /**
+     * goes up level when drilling up (little hack for synconisity)
+     */
     upLevel() {
         this.LEVEL--;
     }
@@ -124,7 +173,7 @@ export class Map {
 
     /**
      * prints out error messages in the console
-     * @param error
+     * @param error - the error massage
      */
     logError(error) {
         console.error(error);
@@ -135,7 +184,7 @@ export class Map {
      * gets data from DHIS API
      * @param query - for what kind of data to retrieve
      * @param instance - this instance to use
-     * @param isParent - little hack to see if it is a parent you wish the children to
+     * @param isParent - little hack to see if you want to levels up (the parent of a parent)
      */
     getData(query, instance, isParent) {
         instance.http.get(dhisAPI + '/api/organisationUnits' + query)
@@ -147,7 +196,7 @@ export class Map {
     }
 
     /**
-     * Gets the number of levels the haiercy
+     * Gets the number of levels in the org.unit hierarchy from DHIS
      */
     getLevels() {
         this.http.get(dhisAPI + '/api/organisationUnitLevels')
@@ -158,11 +207,22 @@ export class Map {
             );
     }
 
+    /**
+     * Saves the data from getLevels() in a global variabel and gets all the data from the second level.
+     * @param res - result from getLevels()
+     * @param instance - witch scope we are in
+     */
     saveLevelTotalandGetdata(res, instance) {
         instance.allLevels = res.pager.total;
         instance.getData('?paging=false&level=2', instance, false);
     }
 
+    /**
+     * parses all the data from getData() and calles methods based on the incomming data.
+     * @param res - result from getData()
+     * @param instance - witch scope we are in
+     * @param isParent - if it is a parent we have asked for
+     */
     parseResult(res, instance, isParent) {
         if (isParent) {
             instance.setParent(res.parent.id);
@@ -191,6 +251,11 @@ export class Map {
         }
     }
 
+    /**
+     * creates and draws up the geojson polygons and adds listeners to them.
+     * @param item - an org.unit object
+     * @param instance - witch scope we are in
+     */
     drawPolygon(item, instance) {
         let feature;
         let incoming:string;
@@ -219,13 +284,15 @@ export class Map {
                     "title": item.name,
                     "name": item.name,
                     "id": item.id,
-                    "color":instance.COLORS[instance.colornum],
+                    "color": instance.COLORS[instance.colornum],
                     "icon": null
                 }
             };
-            if(instance.COLORS.length == instance.colornum){
+            if (instance.COLORS.length == instance.colornum) {
                 instance.colornum = 0;
-            }else{ instance.colornum++;}
+            } else {
+                instance.colornum++;
+            }
 
             if (unit.geometry.type == 'Point') {
                 unit.properties.icon = {
@@ -233,7 +300,7 @@ export class Map {
                     strokeColor: 'black',
                     scale: 4
                 };
-                instance.map.setCenter({lat:unit.geometry.coordinates[1],lng:unit.geometry.coordinates[0]});
+                instance.map.setCenter({lat: unit.geometry.coordinates[1], lng: unit.geometry.coordinates[0]});
             }
 
             this.map.data.addGeoJson(unit);
@@ -252,7 +319,7 @@ export class Map {
                     icon: icon
                 });
             });
-            if(instance.isSearched){
+            if (instance.isSearched) {
                 instance.seeDetails();
             }
             this.map.data.addListener('click', function (event) {
@@ -279,27 +346,30 @@ export class Map {
             });
 
 //slette ?? §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
-           /* this.map.data.addListener('mouseover', function (e) {


-                if(!instance.popupON) {
-                    instance.popupON = true;
-
-                    instance.popup = new google.maps.InfoWindow({
-                        content: e.feature.getProperty('name'),
-                        position: e.latLng
-                    });
-                    instance.popup.open(instance.map);
-
-                }
-            });

-            this.map.data.addListener('mouseout', function (event) {


-                instance.popupON = false;
-                instance.popup.open(null);

-            });*/
+            /* this.map.data.addListener('mouseover', function (e) {


+             if(!instance.popupON) {
+             instance.popupON = true;
+
+             instance.popup = new google.maps.InfoWindow({
+             content: e.feature.getProperty('name'),
+             position: e.latLng
+             });
+             instance.popup.open(instance.map);
+
+             }
+             });

+             this.map.data.addListener('mouseout', function (event) {


+             instance.popupON = false;
+             instance.popup.open(null);

+             });*/
 
         }
     }
 
-    drillDown(){
+    /**
+     * removes the polygon on current level and calles getData on one level down in the org.unit hierarchy
+     */
+    drillDown() {
         this.closeModal();
         let map = this.getMap();
         let id = this.activeId;
@@ -319,9 +389,10 @@ export class Map {
 
     }
 
-    drillUp(){
-
-
+    /**
+     *removes the plogons on the current level and calles the get data with tha parents id and set parent true. this to say that we want this parent's parent
+     */
+    drillUp() {
         this.setupRunned(true);
         this.upLevel();
         let instance = this;
@@ -339,6 +410,9 @@ export class Map {
         this.closeModal();
     }
 
+    /**
+     * focuses map and colors to the clicked marker/polygon and fires an event to sidebar with the id of the marker
+     */
     seeDetails() {
         let map = this.getMap();
         let id = this.activeId;
@@ -349,7 +423,7 @@ export class Map {
                 if (feature.getProperty('icon') !== null) {
                     feature.O.icon.strokeColor = 'red';
                 }
-                this.isSearched=false;
+                this.isSearched = false;
             }
             else {
                 feature.setProperty('color', 'gray');
@@ -361,6 +435,9 @@ export class Map {
         this.newactive.next(this.activeId);
     }
 
+    /**
+     * gets the position of the clicked position on the map, saves the parent and sends it in an event.
+     */
     addUnit() {
         this.closeModal();
         let pos = this.getcurrentPos();
@@ -375,6 +452,11 @@ export class Map {
         this.setRunned(false);
     }
 
+    /**
+     * triggered from an event in search and gets the search object from the DHIS API
+     * then calles mapupdate()
+     * @param event - event from an emitter
+     */
     update(event) {
         this.newactive.next(event);
         let map = this.getMap();
@@ -391,6 +473,12 @@ export class Map {
 
     }
 
+    /**
+     * updates varabels activeId, level and parent to matche the incomming object and gets all the children on the same level.
+     * Then it calles drawPolygon()
+     * @param res - org.unit object
+     * @param instance
+     */
     mapUpdate(res, instance) {
         this.setLevel(res.level);
         this.setActiveId(res.id);
@@ -408,6 +496,10 @@ export class Map {
 
     }
 
+    /**
+     * adds a temperary marker so the user can see an update of the latitude and longitude of a marker
+     * @param pos - position for the temp marker
+     */
     tempMarker(pos) {
         let map = this.map;
         if (this.currentMarker)
@@ -427,8 +519,9 @@ export class Map {
     }
 
 
-
-
+    /**
+     * closes the modal box over the map.
+     */
     closeModal() {
         $("#myModal").modal("hide");
         this.setRunned(false);