← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13503: GIS, event coordinate validation

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 13503 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-12-30 23:40:50 +0100
message:
  GIS, event coordinate validation
modified:
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js	2013-12-30 21:38:10 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js	2013-12-30 22:40:03 +0000
@@ -998,10 +998,40 @@
 				success: function(r) {
                     var events = [],
                         features = [],
+                        rows = [],
+                        lonIndex,
+                        latIndex,
                         map;
 
-                    if (!r.rows) {
+                    // name-column map, lonIndex, latIndex
+                    map = Ext.clone(r.metaData.names);
+
+                    for (var i = 0; i < r.headers.length; i++) {
+                        map[r.headers[i].name] = r.headers[i].column;
+
+                        if (r.headers[i].name === 'longitude') {
+							lonIndex = i;
+						}
+
+						if (r.headers[i].name === 'latitude') {
+							latIndex = i;
+						}
+                    }
+
+					// get events with coordinates
+                    if (Ext.isArray(r.rows) && r.rows.length) {
+						for (var i = 0, row; i < r.rows.length; i++) {
+							row = r.rows[i];
+
+							if (row[lonIndex] && row[latIndex]) {
+								rows.push(row);
+							}
+						}
+					}
+
+                    if (!rows.length) {
                         alert('No coordinates found');
+                        olmap.mask.hide();
                         return;
                     }
 
@@ -1013,8 +1043,8 @@
                     }
 
                     // events
-                    for (var i = 0, row, obj; i < r.rows.length; i++) {
-                        row = r.rows[i];
+                    for (var i = 0, row, obj; i < rows.length; i++) {
+                        row = rows[i];						
                         obj = {};
 
                         for (var j = 0; j < row.length; j++) {