← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2323: (GIS) Improved startup performance. Initialization done in one single server request.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 2323 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2010-12-09 16:15:32 +0100
message:
  (GIS) Improved startup performance. Initialization done in one single server request.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/InitializeAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonInitialize.vm
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/globals.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Choropleth.js
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Symbol.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-api/src/main/java/org/hisp/dhis/mapping/MappingService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java	2010-11-30 13:04:58 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java	2010-12-09 15:11:24 +0000
@@ -60,6 +60,10 @@
     final String ORGANISATION_UNIT_SELECTION_TYPE_PARENT = "parent";
 
     final String ORGANISATION_UNIT_SELECTION_TYPE_LEVEL = "level";
+    
+    final String MAP_LAYER_TYPE_BASELAYER = "baselayer";
+    
+    final String MAP_LAYER_TYPE_OVERLAY = "overlay";
 
     // -------------------------------------------------------------------------
     // IndicatorMapValue

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/InitializeAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/InitializeAction.java	2010-11-26 17:56:40 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/InitializeAction.java	2010-12-09 15:11:24 +0000
@@ -30,10 +30,16 @@
 import static org.hisp.dhis.mapping.MappingService.KEY_MAP_DATE_TYPE;
 import static org.hisp.dhis.mapping.MappingService.MAP_DATE_TYPE_FIXED;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.mapping.MapLayer;
 import org.hisp.dhis.mapping.MapView;
 import org.hisp.dhis.mapping.MappingService;
+import org.hisp.dhis.mapping.comparator.MapLayerNameComparator;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -95,6 +101,20 @@
         return mapDateType;
     }
 
+    private List<MapLayer> baseLayers;
+
+    public List<MapLayer> getBaseLayers()
+    {
+        return baseLayers;
+    }
+
+    private List<MapLayer> overlays;
+
+    public List<MapLayer> getOverlays()
+    {
+        return overlays;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -113,6 +133,14 @@
             
             mapDateType = mapView.getMapDateType();
         }
+        
+        baseLayers = new ArrayList<MapLayer>( mappingService.getMapLayersByType( MappingService.MAP_LAYER_TYPE_BASELAYER ) );
+        
+        Collections.sort( baseLayers, new MapLayerNameComparator() );
+        
+        overlays = new ArrayList<MapLayer>( mappingService.getMapLayersByType( MappingService.MAP_LAYER_TYPE_OVERLAY ) );
+        
+        Collections.sort( overlays, new MapLayerNameComparator() );        
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonInitialize.vm'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonInitialize.vm	2010-11-30 13:04:58 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonInitialize.vm	2010-12-09 15:11:24 +0000
@@ -1,3 +1,5 @@
+#set( $baseLaysersSize = $baseLayers.size() )
+#set( $overlaysSize = $overlays.size() )
 {
   "mapView": { 
     "id": "$!{mapView.id}",
@@ -33,5 +35,39 @@
   },
   "userSettings": {
     "mapDateType": "$!encoder.jsonEncode( ${mapDateType} )"
-  }
+  },
+  "baseLayers": [
+#foreach( $baseLayer in $baseLayers )
+    {
+      "data": {
+        "id": "$!{baseLayer.id}",
+        "name": "$!encoder.jsonEncode( ${baseLayer.name} )",
+        "type": "$!encoder.jsonEncode( ${baseLayer.type} )",
+        "mapSource": "$!encoder.jsonEncode( ${baseLayer.mapSource} )",
+        "layer": "$!encoder.jsonEncode( ${baseLayer.layer} )",
+        "fillColor": "$!encoder.jsonEncode( ${baseLayer.fillColor} )",
+        "fillOpacity": "$!{baseLayer.fillOpacity}",
+        "strokeColor": "$!encoder.jsonEncode( ${baseLayer.strokeColor} )",
+        "strokeWidth": "$!{baseLayer.strokeWidth}"
+      }
+    }#if( $velocityCount < $baseLaysersSize ),#end
+#end
+  ],
+  "overlays": [
+#foreach( $overlay in $overlays )
+    {
+      "data": {
+        "id": "$!{overlay.id}",
+        "name": "$!encoder.jsonEncode( ${overlay.name} )",
+        "type": "$!encoder.jsonEncode( ${overlay.type} )",
+        "mapSource": "$!encoder.jsonEncode( ${overlay.mapSource} )",
+        "layer": "$!encoder.jsonEncode( ${overlay.layer} )",
+        "fillColor": "$!encoder.jsonEncode( ${overlay.fillColor} )",
+        "fillOpacity": "$!{overlay.fillOpacity}",
+        "strokeColor": "$!encoder.jsonEncode( ${overlay.strokeColor} )",
+        "strokeWidth": "$!{overlay.strokeWidth}"
+      }
+    }#if( $velocityCount < $overlaysSize ),#end
+#end
+  ]
 }
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/globals.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/globals.js	2010-12-08 21:53:31 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/globals.js	2010-12-09 15:11:24 +0000
@@ -284,6 +284,8 @@
 GLOBAL.vars = {    
     map: null,
     
+    parameter: null,
+    
     mapSourceType: {
         value: null,
         setDatabase: function() {
@@ -322,8 +324,6 @@
         }
     },
     
-    parameter: null,
-    
     activePanel: {
         value: GLOBAL.conf.thematicMap,
         setPolygon: function() {

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js	2010-12-08 21:53:31 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js	2010-12-09 15:11:24 +0000
@@ -6,7 +6,7 @@
 	
 	GLOBAL.vars.map = new OpenLayers.Map({controls:[new OpenLayers.Control.Navigation(),new OpenLayers.Control.ArgParser(),new OpenLayers.Control.Attribution()]});
 	GLOBAL.vars.mask = new Ext.LoadMask(Ext.getBody(),{msg:i18n_loading,msgCls:'x-mask-loading2'});
-    GLOBAL.vars.parameter = GLOBAL.util.getUrlParam('view') ? {id: GLOBAL.util.getUrlParam('view')} : false;
+    GLOBAL.vars.parameter = GLOBAL.util.getUrlParam('view') ? {id: GLOBAL.util.getUrlParam('view')} : {id: null};
 
     Ext.Ajax.request({
         url: GLOBAL.conf.path_mapping + 'initialize' + GLOBAL.conf.type,
@@ -14,10 +14,10 @@
         params: {id: GLOBAL.vars.parameter.id || null},
         success: function(r) {
             var init = Ext.util.JSON.decode(r.responseText);
-            if (GLOBAL.vars.parameter) {
-                GLOBAL.vars.parameter.mapView = init.mapView;
-            }
-            GLOBAL.vars.mapDateType.value = init.userSettings.mapDateType;
+            GLOBAL.vars.parameter.mapView = init.mapView;
+            GLOBAL.vars.parameter.baseLayers = init.baseLayers;
+            GLOBAL.vars.parameter.overlays = init.overlays;
+            GLOBAL.vars.mapDateType.value = init.userSettings.mapDateType;            
                         
     /* Section: stores */
     var mapViewStore = new Ext.data.JsonStore({
@@ -371,24 +371,35 @@
     };
 	
 	/* Add base layers */	
-	function addBaseLayersToMap() {
+	function addBaseLayersToMap(init) {
 		GLOBAL.vars.map.addLayers([new OpenLayers.Layer.WMS('World', 'http://labs.metacarta.com/wms/vmap0', {layers: 'basic'})]);
 		GLOBAL.vars.map.layers[0].setVisibility(false);
-		
-		GLOBAL.stores.baseLayer.load({callback: function(r) {
-			if (r.length) {
-				for (var i = 0; i < r.length; i++) {
-					GLOBAL.vars.map.addLayers([new OpenLayers.Layer.WMS(r[i].data.name, r[i].data.mapSource, {layers: r[i].data.layer})]);
+        
+        if (init) {
+            var layers = GLOBAL.vars.parameter.baseLayers || [];
+			if (layers.length) {
+				for (var i = 0; i < layers.length; i++) {
+					GLOBAL.vars.map.addLayers([new OpenLayers.Layer.WMS(layers[i].data.name, layers[i].data.mapSource, {layers: layers[i].data.layer})]);
 					GLOBAL.vars.map.layers[GLOBAL.vars.map.layers.length-1].setVisibility(false);
 				}
 			}
-		}});
-	}	
-	addBaseLayersToMap();	
+        }
+        else {
+            GLOBAL.stores.baseLayer.load({callback: function(r) {
+                if (r.length) {
+                    for (var i = 0; i < r.length; i++) {
+                        GLOBAL.vars.map.addLayers([new OpenLayers.Layer.WMS(r[i].data.name, r[i].data.mapSource, {layers: r[i].data.layer})]);
+                        GLOBAL.vars.map.layers[GLOBAL.vars.map.layers.length-1].setVisibility(false);
+                    }
+                }
+            }});
+        }
+	}
+	addBaseLayersToMap(true);
     
-	function addOverlaysToMap() {
-		GLOBAL.stores.overlay.load({callback: function(r) {
-			if (r.length) {
+	function addOverlaysToMap(init) {
+        function add(r) {
+            if (r.length) {
                 var loadStart = function() {
                     GLOBAL.vars.mask.msg = i18n_loading;
                     GLOBAL.vars.mask.show();
@@ -397,39 +408,46 @@
                     GLOBAL.vars.mask.hide();
                 };
                 
-				for (var i = 0; i < r.length; i++) {
-					var url = GLOBAL.vars.mapSourceType.isShapefile() ? GLOBAL.conf.path_geoserver + GLOBAL.conf.wfs + r[i].data.mapSource + GLOBAL.conf.output : GLOBAL.conf.path_mapping + 'getGeoJsonFromFile.action?name=' + r[i].data.mapSource;
-					var fillColor = r[i].data.fillColor;
-					var fillOpacity = parseFloat(r[i].data.fillOpacity);
-					var strokeColor = r[i].data.strokeColor;
-					var strokeWidth = parseFloat(r[i].data.strokeWidth);
-					
-					var overlay = new OpenLayers.Layer.Vector(r[i].data.name, {
-						'visibility': false,
-						'styleMap': new OpenLayers.StyleMap({
-							'default': new OpenLayers.Style(
-								OpenLayers.Util.applyDefaults(
-									{'fillColor': fillColor, 'fillOpacity': fillOpacity, 'strokeColor': strokeColor, 'strokeWidth': strokeWidth},
-									OpenLayers.Feature.Vector.style['default']
-								)
-							)
-						}),
-						'strategies': [new OpenLayers.Strategy.Fixed()],
-						'protocol': new OpenLayers.Protocol.HTTP({
-							'url': url,
-							'format': new OpenLayers.Format.GeoJSON()
-						})
-					});
-					
-					overlay.events.register('loadstart', null, loadStart);					
-					overlay.events.register('loadend', null, loadEnd);
+                for (var i = 0; i < r.length; i++) {
+                    var overlay = new OpenLayers.Layer.Vector(r[i].data.name, {
+                        'visibility': false,
+                        'styleMap': new OpenLayers.StyleMap({
+                            'default': new OpenLayers.Style(
+                                OpenLayers.Util.applyDefaults({
+                                        'fillColor': r[i].data.fillColor,
+                                        'fillOpacity': parseFloat(r[i].data.fillOpacity),
+                                        'strokeColor': r[i].data.strokeColor,
+                                        'strokeWidth': parseFloat(r[i].data.strokeWidth)
+                                    },
+                                    OpenLayers.Feature.Vector.style['default']
+                                )
+                            )
+                        }),
+                        'strategies': [new OpenLayers.Strategy.Fixed()],
+                        'protocol': new OpenLayers.Protocol.HTTP({
+                            'url': GLOBAL.conf.path_mapping + 'getGeoJsonFromFile.action?name=' + r[i].data.mapSource,
+                            'format': new OpenLayers.Format.GeoJSON()
+                        })
+                    });
+                    
+                    overlay.events.register('loadstart', null, loadStart);					
+                    overlay.events.register('loadend', null, loadEnd);
                     overlay.isOverlay = true;
-					GLOBAL.vars.map.addLayer(overlay);
-				}
-			}
-		}});
+                    GLOBAL.vars.map.addLayer(overlay);
+                }
+            }
+        }
+        
+        if (init) {
+            add(GLOBAL.vars.parameter.overlays);
+        }
+        else {
+            GLOBAL.stores.overlay.load({callback: function(r) {
+                add(r);
+            }});
+        }
 	}
-	addOverlaysToMap();
+	addOverlaysToMap(true);
 			
 	/* Section: mapview */
 	var viewNameTextField=new Ext.form.TextField({id:'viewname_tf',emptytext:'',width:GLOBAL.conf.combo_width,hideLabel:true,autoCreate:{tag:'input',type:'text',size:'20',autocomplete:'off', maxlength:'35'}});
@@ -887,18 +905,16 @@
                         indicatorOrDataElement = Ext.getCmp('mapvaluetype_cb').getValue() == GLOBAL.conf.map_value_type_indicator ?
                             Ext.getCmp('indicator_cb').getValue() : Ext.getCmp('dataelement_cb').getValue();
                         period = Ext.getCmp('period_cb').getValue();
-                        mapOrOrganisationUnit = GLOBAL.vars.mapSourceType.isDatabase() ?
-                            Ext.getCmp('boundary_tf').getValue() : Ext.getCmp('map_cb').getValue();
+                        organisationUnit = Ext.getCmp('boundary_tf').getValue();
                     }
                     else if (GLOBAL.vars.activePanel.isPoint()) {
                         indicatorOrDataElement = Ext.getCmp('mapvaluetype_cb2').getValue() == GLOBAL.conf.map_value_type_indicator ?
                             Ext.getCmp('indicator_cb2').getValue() : Ext.getCmp('dataelement_cb2').getValue();
                         period = Ext.getCmp('period_cb2').getValue();
-                        mapOrOrganisationUnit = GLOBAL.vars.mapSourceType.isDatabase() ?
-                            Ext.getCmp('map_tf2').getValue() : Ext.getCmp('map_cb2').getValue();
+                        organisationUnit = Ext.getCmp('map_tf2').getValue();
                     }
                     
-                    if (indicatorOrDataElement && period && mapOrOrganisationUnit) {
+                    if (indicatorOrDataElement && period && organisationUnit) {
                         var title = Ext.getCmp('exportexceltitle_ft').getValue();
                         var svg = document.getElementById('OpenLayers.Layer.Vector_17').innerHTML;	
                         var includeLegend = Ext.getCmp('exportexcelincludelegend_chb').getValue();

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Choropleth.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Choropleth.js	2010-12-08 21:53:31 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Choropleth.js	2010-12-09 15:11:24 +0000
@@ -86,7 +86,7 @@
         
         this.createSelectFeatures();
 
-        if (GLOBAL.vars.parameter) {
+        if (GLOBAL.vars.parameter.id) {
 			if (GLOBAL.vars.parameter.mapView.featureType == GLOBAL.conf.map_feature_type_multipolygon) {
 				this.mapView = GLOBAL.vars.parameter.mapView;
 				this.updateValues = true;

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Symbol.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Symbol.js	2010-12-08 21:53:31 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Symbol.js	2010-12-09 15:11:24 +0000
@@ -85,8 +85,8 @@
         this.createItems();
         
         this.createSelectFeatures();
-        
-        if (GLOBAL.vars.parameter) {
+
+        if (GLOBAL.vars.parameter.id) {
 			if (GLOBAL.vars.parameter.mapView.featureType == GLOBAL.conf.map_feature_type_point) {
 				this.mapView = GLOBAL.vars.parameter.mapView;
 				this.updateValues = true;
@@ -998,8 +998,8 @@
         this.selectFeatures = new OpenLayers.Control.newSelectFeature(
             this.layer, {
                 onHoverSelect: onHoverSelect,
-                onHoverUnselect: onHoverUnselect,
-                onClickSelect: onClickSelect
+                onHoverUnselect: onHoverUnselect
+                //onClickSelect: onClickSelect
             }
         );
         
@@ -1513,7 +1513,7 @@
 
         this.coreComp = new mapfish.GeoStat.Symbol(this.map, coreOptions);
         
-        if (GLOBAL.vars.parameter) {
+        if (GLOBAL.vars.parameter.id) {
 			choropleth.collapse();
 			this.expand();
 			GLOBAL.vars.parameter = false;