← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17993: GIS/dashboard, loading Google Maps dynamically.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 17993 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-01-14 17:58:01 +0100
message:
  GIS/dashboard, loading Google Maps dynamically.
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/app.js
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/dashboard.vm
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/eventchart.js
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/eventreport.js
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/map.js
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/table.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-apps/src/main/webapp/dhis-web-mapping/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/app.js	2015-01-14 13:49:18 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-mapping/scripts/app.js	2015-01-14 14:56:08 +0000
@@ -9031,6 +9031,19 @@
 				}()
 			},
             listeners: {
+                render: function() {
+                    var me = this;
+
+                    me.getEl().on('mouseleave', function() {
+                        for (var i = 0, cmp; i < me.trash.length; i++) {
+                            cmp = me.trash[i];
+
+                            if (cmp && cmp.destroy) {
+                                cmp.destroy();
+                            }
+                        }
+                    });
+                },
                 resize: function() {
                     var width = this.getWidth();
 

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/dashboard.vm'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/dashboard.vm	2015-01-14 10:27:59 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/dashboard.vm	2015-01-14 16:50:54 +0000
@@ -1,7 +1,7 @@
 
 #sharingDialog()
 
-<script type="text/javascript" src="//maps.google.com/maps/api/js"></script>
+
 <script type="text/javascript" src="../dhis-web-commons/javascripts/openlayers/OpenLayers.js"></script>
 <script type="text/javascript" src="plugin/table.js"></script>
 <script type="text/javascript" src="plugin/chart.js"></script>

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/eventchart.js'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/eventchart.js	2015-01-14 12:56:58 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/eventchart.js	2015-01-14 14:56:08 +0000
@@ -3244,10 +3244,9 @@
                     }
 
                     ids = Ext.Array.clean(ids.concat(filterIds || []));
-console.log("ids", ids, "xResponse.metaData.names", xResponse.metaData.names);
+
                     if (Ext.isArray(ids) && ids.length) {
                         for (var i = 0; i < ids.length; i++) {
-console.log(ids[i]);
                             text += xResponse.metaData.names[ids[i]];
                             text += i < ids.length - 1 ? ', ' : '';
                         }

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/eventreport.js'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/eventreport.js	2015-01-14 12:56:58 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/eventreport.js	2015-01-14 16:57:19 +0000
@@ -3316,9 +3316,9 @@
 		}
 	};
 
-    applyCss = function() {
+    applyCss = function(config) {
         var css = '',
-            arrowUrl = init.dashboard ? '../dhis-web-commons/javascripts/plugin/images/arrowupdown.png' : '//dhis2-cdn.org/v217/plugin/images/arrowupdown.png';
+            arrowUrl = config.dashboard ? '../dhis-web-commons/javascripts/plugin/images/arrowupdown.png' : '//dhis2-cdn.org/v217/plugin/images/arrowupdown.png';
 
         css += 'table.pivot { font-family: arial,sans-serif,ubuntu,consolas; } \n';
         css += '.td-nobreak { white-space: nowrap; } \n';
@@ -3807,7 +3807,7 @@
 				return;
 			}
 
-            applyCss();
+            applyCss(config);
 
 			ns.core = ER.getCore(Ext.clone(init));
             ns.core.init.el = config.el;

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/map.js'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/map.js	2015-01-14 13:49:18 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/map.js	2015-01-14 16:55:31 +0000
@@ -1632,36 +1632,36 @@
             createSelectionHandlers,
             layerNumbers = ['1', '2', '3', '4'];
 
-        if (window.google) {
-            layers.googleStreets = new OpenLayers.Layer.Google('Google Streets', {
-                numZoomLevels: 20,
-                animationEnabled: true,
-                layerType: gis.conf.finals.layer.type_base,
-                layerOpacity: 1,
-                setLayerOpacity: function (number) {
-                    if (number) {
-                        this.layerOpacity = parseFloat(number);
-                    }
-                    this.setOpacity(this.layerOpacity);
-                }
-            });
-            layers.googleStreets.id = 'googleStreets';
+        //if (window.google) {
+            //layers.googleStreets = new OpenLayers.Layer.Google('Google Streets', {
+                //numZoomLevels: 20,
+                //animationEnabled: true,
+                //layerType: gis.conf.finals.layer.type_base,
+                //layerOpacity: 1,
+                //setLayerOpacity: function (number) {
+                    //if (number) {
+                        //this.layerOpacity = parseFloat(number);
+                    //}
+                    //this.setOpacity(this.layerOpacity);
+                //}
+            //});
+            //layers.googleStreets.id = 'googleStreets';
 
-            layers.googleHybrid = new OpenLayers.Layer.Google('Google Hybrid', {
-                type: google.maps.MapTypeId.HYBRID,
-                numZoomLevels: 20,
-                animationEnabled: true,
-                layerType: gis.conf.finals.layer.type_base,
-                layerOpacity: 1,
-                setLayerOpacity: function (number) {
-                    if (number) {
-                        this.layerOpacity = parseFloat(number);
-                    }
-                    this.setOpacity(this.layerOpacity);
-                }
-            });
-            layers.googleHybrid.id = 'googleHybrid';
-        }
+            //layers.googleHybrid = new OpenLayers.Layer.Google('Google Hybrid', {
+                //type: google.maps.MapTypeId.HYBRID,
+                //numZoomLevels: 20,
+                //animationEnabled: true,
+                //layerType: gis.conf.finals.layer.type_base,
+                //layerOpacity: 1,
+                //setLayerOpacity: function (number) {
+                    //if (number) {
+                        //this.layerOpacity = parseFloat(number);
+                    //}
+                    //this.setOpacity(this.layerOpacity);
+                //}
+            //});
+            //layers.googleHybrid.id = 'googleHybrid';
+        //}
 
         layers.openStreetMap = new OpenLayers.Layer.OSM.Mapnik('OpenStreetMap', {
             layerType: gis.conf.finals.layer.type_base,
@@ -4953,9 +4953,9 @@
         gis.layer = GIS.core.getLayers(gis);
         gis.thematicLayers = [gis.layer.thematic1, gis.layer.thematic2, gis.layer.thematic3, gis.layer.thematic4];
 
-        if (window.google) {
-            layers.push(gis.layer.googleStreets, gis.layer.googleHybrid);
-        }
+        //if (window.google) {
+            //layers.push(gis.layer.googleStreets, gis.layer.googleHybrid);
+        //}
 
         layers.push(
             gis.layer.openStreetMap,
@@ -7111,6 +7111,59 @@
 
             gis = GIS.core.getInstance(init);
 
+            // google maps
+            var gm_fn = function() {
+                var googleStreets = new OpenLayers.Layer.Google('Google Streets', {
+                    numZoomLevels: 20,
+                    animationEnabled: true,
+                    layerType: gis.conf.finals.layer.type_base,
+                    layerOpacity: 1,
+                    setLayerOpacity: function (number) {
+                        if (number) {
+                            this.layerOpacity = parseFloat(number);
+                        }
+                        this.setOpacity(this.layerOpacity);
+                    }
+                });
+                googleStreets.id = 'googleStreets';
+
+                var googleHybrid = new OpenLayers.Layer.Google('Google Hybrid', {
+                    type: google.maps.MapTypeId.HYBRID,
+                    numZoomLevels: 20,
+                    animationEnabled: true,
+                    layerType: gis.conf.finals.layer.type_base,
+                    layerOpacity: 1,
+                    setLayerOpacity: function (number) {
+                        if (number) {
+                            this.layerOpacity = parseFloat(number);
+                        }
+                        this.setOpacity(this.layerOpacity);
+                    }
+                });
+                googleHybrid.id = 'googleHybrid';
+
+                gis.olmap.addLayers([googleStreets, googleHybrid]);
+                gis.olmap.setBaseLayer(googleStreets);
+            };
+
+            if (GIS_GM.ready) {
+                console.log("(Item " + config.el + ") GM is ready -> skip queue, add layers, set as baselayer");
+                gm_fn();
+            }
+            else {
+                if (GIS_GM.offline) {
+                    console.log("Deactivate base layer");
+                    gis.olmap.baseLayer.setVisibility(false);
+                }
+                else {
+                    console.log("GM is not ready -> add to queue");
+                    GIS_GM.array.push({
+                        scope: this,
+                        fn: gm_fn
+                    });
+                }
+            }
+
             gis.el = config.el;
             gis.plugin = init.plugin;
             gis.dashboard = init.dashboard;
@@ -7142,18 +7195,52 @@
         }();
     };
 
-    GIS.plugin.getMap = function (config) {
+    GIS.plugin.getMap = function(config) {
         if (Ext.isString(config.url) && config.url.split('').pop() === '/') {
             config.url = config.url.substr(0, config.url.length - 1);
         }
 
         if (isInitComplete) {
             execute(config);
-        } else {
+        }
+        else {
             configs.push(config);
 
             if (!isInitStarted) {
                 isInitStarted = true;
+
+                // google maps
+                GIS_GM = {
+                    ready: false,
+                    array: [],
+                    offline: false
+                };
+
+                GIS_GM_fn = function() {
+                    console.log("GM called back, queue length: " + GIS_GM.array.length);
+                    GIS_GM.ready = true;
+
+                    for (var i = 0, obj; i < GIS_GM.array.length; i++) {
+                        obj = GIS_GM.array[i];
+
+                        if (obj) {
+                            console.log("Running queue obj " + (i + 1));
+                            obj.fn.call(obj.scope);
+                        }
+                    }
+                };
+
+                Ext.Loader.injectScriptElement('//maps.googleapis.com/maps/api/js?callback=GIS_GM_fn',
+                    function() {
+                        console.log("GM available (online)");
+                    },
+                    function() {
+                        console.log("GM not available (offline)");
+                        GIS_GM.offline = true;
+                    }
+                );
+
+                // plugin
                 getInit(config);
             }
         }

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/table.js'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/table.js	2015-01-14 12:56:58 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/table.js	2015-01-14 16:50:54 +0000
@@ -3022,9 +3022,9 @@
 		}
 	};
 
-    applyCss = function() {
+    applyCss = function(config) {
         var css = '',
-            arrowUrl = init.dashboard ? '../dhis-web-commons/javascripts/plugin/images/arrowupdown.png' : '//dhis2-cdn.org/v217/plugin/images/arrowupdown.png';
+            arrowUrl = config.dashboard ? '../dhis-web-commons/javascripts/plugin/images/arrowupdown.png' : '//dhis2-cdn.org/v217/plugin/images/arrowupdown.png';
 
         css += 'table.pivot { font-family: arial,sans-serif,ubuntu,consolas; } \n';
         css += '.td-nobreak { white-space: nowrap; } \n';
@@ -3394,7 +3394,7 @@
 				return;
 			}
 
-            applyCss();
+            applyCss(config);
 
             init.plugin = true;
             init.dashboard = Ext.isBoolean(config.dashboard) ? config.dashboard : false;