← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2385: (GIS) Improved code: Correct use of scope + map view bug fixed.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 2385 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: trunk
timestamp: Mon 2010-10-18 18:52:20 +0200
message:
  (GIS) Improved code: Correct use of scope + map view bug fixed.
modified:
  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-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-10-14 15:22:45 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js	2010-10-18 16:09:03 +0000
@@ -80,7 +80,12 @@
         success: function(r) {
             var mv = Ext.util.JSON.decode(r.responseText).mapView[0];
             if (PARAMETER) {
-                PARAMETER.mapView = mv;
+                if (!mv.id) {
+                    PARAMETER = false;
+                }
+                else {
+                    PARAMETER.mapView = mv;
+                }
             }
             
             Ext.Ajax.request({
@@ -2262,53 +2267,39 @@
                                                 Ext.getCmp('map_cb2').clearValue();
 												Ext.getCmp('mapview_cb').clearValue();
                                                 
-												if (MAPSOURCE == GLOBALS.config.map_source_type_geojson) {
-													Ext.getCmp('register_chb').enable();
-													
-													if (Ext.getCmp('register_chb').checked) {
-														mapping.show();
-														shapefilePanel.show();
-													}
-                                                    
-                                                    choropleth.prepareMapViewMap();
-                                                    Ext.getCmp('map_cb2').showField();
-                                                    Ext.getCmp('map_tf2').hideField();
-                                                    
-                                                    if (MAPDATETYPE == GLOBALS.config.map_date_type_start_end) {
-                                                        MAPDATETYPE = GLOBALS.config.map_date_type_fixed;
-                                                        Ext.getCmp('mapdatetype_cb').setValue(MAPDATETYPE);
-                                                        choropleth.prepareMapViewDateType();
-                                                    }
-												}
-												else if (MAPSOURCE == GLOBALS.config.map_source_type_shapefile) {
-													Ext.getCmp('register_chb').enable();
-													
-													if (Ext.getCmp('register_chb').checked) {
-														mapping.show();
-														shapefilePanel.show();
-													}
-                                                    
-                                                    choropleth.prepareMapViewMap();
-                                                    Ext.getCmp('map_cb2').showField();
-                                                    Ext.getCmp('map_tf2').hideField();
-                                                    
-                                                    if (MAPDATETYPE == GLOBALS.config.map_date_type_start_end) {
-                                                        MAPDATETYPE = GLOBALS.config.map_date_type_fixed;
-                                                        Ext.getCmp('mapdatetype_cb').setValue(MAPDATETYPE);
-                                                        choropleth.prepareMapViewDateType();
-                                                    }
-												}
-												else if (MAPSOURCE == GLOBALS.config.map_source_type_database) {
-													Ext.getCmp('register_chb').disable();
-													
+                                                if (MAPSOURCE == GLOBALS.config.map_source_type_database) {
+													Ext.getCmp('register_chb').disable();													
 													mapping.hide();
 													shapefilePanel.hide();
+												}
+                                                else {
+                                                    Ext.getCmp('register_chb').enable();
+													
+													if (Ext.getCmp('register_chb').checked) {
+														mapping.show();
+														shapefilePanel.show();
+													}
                                                     
-                                                    choropleth.prepareMapViewMap();
-                                                    Ext.getCmp('map_cb2').hideField();
-                                                    Ext.getCmp('map_tf2').showField();
+                                                    if (MAPDATETYPE == GLOBALS.config.map_date_type_start_end) {
+                                                        MAPDATETYPE = GLOBALS.config.map_date_type_fixed;
+                                                        Ext.getCmp('mapdatetype_cb').setValue(MAPDATETYPE);
+                                                        choropleth.prepareMapViewDateType();
+                                                        proportionalSymbol.prepareMapViewDateType();
+                                                    }
+										
+                                                    if (MAPSOURCE == GLOBALS.config.map_source_type_geojson) {
+                                                        mapLayerMapSourceFileComboBox.show();
+                                                        mapLayerPathWMSOverlayTextField.hide();
+                                                    }
+                                                    else if (MAPSOURCE == GLOBALS.config.map_source_type_shapefile) {
+                                                        mapLayerMapSourceFileComboBox.hide();
+                                                        mapLayerPathWMSOverlayTextField.show();
+                                                    }
 												}
                                                 
+                                                choropleth.prepareMapViewMap();
+                                                proportionalSymbol.prepareMapViewMap();
+                                                
 												if (MAP.layers.length > 2) {
 													for (var i = 0; i < MAP.layers.length; i++) {
                                                         if (MAP.layers[i].isOverlay) {
@@ -2320,15 +2311,6 @@
 												Ext.message.msg(true, '<span class="x-msg-hl">' + cb.getRawValue() + '</span> '+i18n_is_saved_as_map_source);
 											}
 										});
-										
-										if (MAPSOURCE == GLOBALS.config.map_source_type_geojson) {
-											mapLayerMapSourceFileComboBox.show();
-											mapLayerPathWMSOverlayTextField.hide();
-										}
-										else if (MAPSOURCE == GLOBALS.config.map_source_type_shapefile) {
-											mapLayerMapSourceFileComboBox.hide();
-											mapLayerPathWMSOverlayTextField.show();
-										}
 									}
 								}
 							}
@@ -2403,27 +2385,8 @@
                                             params: {mapSourceType: MAPSOURCE, mapDateType: MAPDATETYPE},
                                             success: function() {
                                                 Ext.message.msg(true, '<span class="x-msg-hl">' + cb.getRawValue() + '</span> '+i18n_saved_as_date_type);
-                                                
-                                                if (MAPDATETYPE == GLOBALS.config.map_date_type_fixed) {
-                                                    Ext.getCmp('periodtype_cb').showField();
-                                                    Ext.getCmp('periodtype_cb2').showField();
-                                                    Ext.getCmp('period_cb').showField();
-                                                    Ext.getCmp('period_cb2').showField();
-                                                    Ext.getCmp('startdate_df').hideField();
-                                                    Ext.getCmp('startdate_df2').hideField();
-                                                    Ext.getCmp('enddate_df').hideField();
-                                                    Ext.getCmp('enddate_df2').hideField();
-                                                }
-                                                else if (MAPDATETYPE == GLOBALS.config.map_date_type_start_end) {
-                                                    Ext.getCmp('periodtype_cb').hideField();
-                                                    Ext.getCmp('periodtype_cb2').hideField();
-                                                    Ext.getCmp('period_cb').hideField();
-                                                    Ext.getCmp('period_cb2').hideField();
-                                                    Ext.getCmp('startdate_df').showField();
-                                                    Ext.getCmp('startdate_df2').showField();
-                                                    Ext.getCmp('enddate_df').showField();
-                                                    Ext.getCmp('enddate_df2').showField();
-                                                }
+                                                choropleth.prepareMapViewDateType();
+                                                proportionalSymbol.prepareMapViewDateType();
                                             }
                                         });
                                     }
@@ -3366,17 +3329,17 @@
         separator: '<br/><span style="color:#666;">y: &nbsp;</span>'
     }));
     
-    var vmap0 = new OpenLayers.Layer.WMS(
-        "World",
-        "http://labs.metacarta.com/wms/vmap0";, 
-        {layers: "basic"}
-    );
-    
     MAP.addControl(new OpenLayers.Control.OverviewMap({
         div: $('overviewmap'),
         size: new OpenLayers.Size(188, 97),
         minRectSize: 0,
-        layers: [vmap0]
+        layers: [
+            new OpenLayers.Layer.WMS(
+                "World",
+                "http://labs.metacarta.com/wms/vmap0";, 
+                {layers: "basic"}
+            )
+        ]
     }));
     
     MAP.addControl(new OpenLayers.Control.ZoomBox());
@@ -3410,55 +3373,22 @@
             }
         }
     });
-        
+    
     Ext.getCmp('mapsource_cb').setValue(MAPSOURCE);
     Ext.getCmp('mapdatetype_cb').setValue(MAPDATETYPE);
     
-    Ext.getCmp('maplegendset_cb').hideField();
-    Ext.getCmp('maplegendset_cb2').hideField();
-	Ext.getCmp('bounds_tf').hideField();
-    Ext.getCmp('bounds_tf2').hideField();
-	Ext.getCmp('dataelementgroup_cb').hideField();
-    Ext.getCmp('dataelementgroup_cb2').hideField();
-	Ext.getCmp('dataelement_cb').hideField();
-    Ext.getCmp('dataelement_cb2').hideField();
-    
-    if (MAPSOURCE == GLOBALS.config.map_source_type_database) {
-        Ext.getCmp('map_cb').hideField();
-        Ext.getCmp('map_cb2').hideField();
-        Ext.getCmp('map_tf').showField();
-        Ext.getCmp('map_tf2').showField();
-    }
-    else {
-        Ext.getCmp('map_cb').showField()
-        Ext.getCmp('map_cb2').showField();
-        Ext.getCmp('map_tf').hideField();
-        Ext.getCmp('map_tf2').hideField();
-    }
-    
-    if (MAPDATETYPE == GLOBALS.config.map_date_type_fixed) {
-        Ext.getCmp('periodtype_cb').showField();
-        Ext.getCmp('periodtype_cb2').showField();
-        Ext.getCmp('period_cb').showField();
-        Ext.getCmp('period_cb2').showField();
-        Ext.getCmp('startdate_df').hideField();
-        Ext.getCmp('startdate_df2').hideField();
-        Ext.getCmp('enddate_df').hideField();
-        Ext.getCmp('enddate_df2').hideField();
-    }
-    else {
-        Ext.getCmp('periodtype_cb').hideField();
-        Ext.getCmp('periodtype_cb2').hideField();
-        Ext.getCmp('period_cb').hideField();
-        Ext.getCmp('period_cb2').hideField();
-        Ext.getCmp('startdate_df').showField();
-        Ext.getCmp('startdate_df2').showField();
-        Ext.getCmp('enddate_df').showField();
-        Ext.getCmp('enddate_df2').showField();
-    }
-    
-    Ext.get('loading').fadeOut({remove: true});
-	
+    choropleth.prepareMapViewValueType();
+    proportionalSymbol.prepareMapViewValueType();
+    
+    choropleth.prepareMapViewDateType();
+    proportionalSymbol.prepareMapViewDateType();
+    
+    choropleth.prepareMapViewLegend();
+    proportionalSymbol.prepareMapViewLegend();
+    
+    choropleth.prepareMapViewMap();
+    proportionalSymbol.prepareMapViewMap();
+    
 	}});
 	}});
 	}});

=== 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-10-14 16:30:09 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Choropleth.js	2010-10-18 16:47:59 +0000
@@ -106,21 +106,20 @@
             Ext.getCmp('mapsource_cb').setValue(MAPSOURCE);
             Ext.getCmp('mapdatetype_cb').setValue(MAPDATETYPE);
             
-            function mapViewStoreCallback(scope) {
-                Ext.getCmp('mapview_cb').setValue(scope.mapView.id);
+            function mapViewStoreCallback() {
+                Ext.getCmp('mapview_cb').setValue(this.mapView.id);
+                this.valueType = this.mapView.mapValueType;
+                Ext.getCmp('mapvaluetype_cb').setValue(this.valueType);
 
-                scope.valueType = scope.mapView.mapValueType;
-                Ext.getCmp('mapvaluetype_cb').setValue(scope.valueType);
-                
-                scope.setMapView();
+                this.setMapView();
             }
             
             if (this.stores.mapView.isLoaded) {
-                mapViewStoreCallback(this);
+                mapViewStoreCallback.call(this);
             }                    
             else {
                 this.stores.mapView.load({scope: this, callback: function() {
-                    mapViewStoreCallback(this);
+                    mapViewStoreCallback.call(this);
                 }});
             }
         }
@@ -451,18 +450,18 @@
                                     this.legend.type = GLOBALS.config.map_legend_type_predefined;
                                     this.prepareMapViewLegend();
                                     
-                                    function load(scope) {
+                                    function load() {
                                         Ext.getCmp('maplegendset_cb').setValue(mapLegendSet.id);
-                                        scope.applyPredefinedLegend();
+                                        this.applyPredefinedLegend();
                                     }
                                     
                                     if (!this.stores.predefinedMapLegendSet.isLoaded) {
                                         this.stores.predefinedMapLegendSet.load({scope: this, callback: function() {
-                                            load(this);
+                                            load.call(this);
                                         }});
                                     }
                                     else {
-                                        load(this);
+                                        load.call(this);
                                     }
                                 }
                                 else {
@@ -539,18 +538,18 @@
                                     this.legend.type = GLOBALS.config.map_legend_type_predefined;
                                     this.prepareMapViewLegend();
                                     
-                                    function load(scope) {
+                                    function load() {
                                         Ext.getCmp('maplegendset_cb').setValue(mapLegendSet.id);
-                                        scope.applyPredefinedLegend();
+                                        this.applyPredefinedLegend();
                                     }
                                     
                                     if (!this.stores.predefinedMapLegendSet.isLoaded) {
                                         this.stores.predefinedMapLegendSet.load({scope: this, callback: function() {
-                                            load(this);
+                                            load.call(this);
                                         }});
                                     }
                                     else {
-                                        load(this);
+                                        load.call(this);
                                     }
                                 }
                                 else {
@@ -712,7 +711,7 @@
                 'focus': {
                     scope: this,
                     fn: function(tf) {
-                        function showTree(scope) {
+                        function showTree() {
                             var value, rawvalue;
                             var w = new Ext.Window({
                                 id: 'orgunit_w',
@@ -771,7 +770,7 @@
                                                 xtype: 'button',
                                                 text: 'Select',
                                                 width: 133,
-                                                scope: scope,
+                                                scope: this,
                                                 handler: function() {
                                                     if (tf.getValue() && tf.getValue() != this.parentId) {
                                                         this.loadFromDatabase(tf.value);
@@ -799,7 +798,7 @@
                         }
 
                         if (TOPLEVELUNIT) {
-                            showTree(this);
+                            showTree.call(this);
                         }
                         else {
                             Ext.Ajax.request({
@@ -814,7 +813,7 @@
                                         name: rootNode.name,
                                         hasChildrenWithCoordinates: rootNode.hasChildrenWithCoordinates
                                     };
-                                    showTree(this);
+                                    showTree.call(this);
                                 }
                             });
                         }
@@ -1095,6 +1094,7 @@
     
     prepareMapViewValueType: function() {
         var obj = {};
+
         if (this.valueType == GLOBALS.config.map_value_type_indicator) {
             Ext.getCmp('indicatorgroup_cb').showField();
             Ext.getCmp('indicator_cb').showField();
@@ -1211,52 +1211,52 @@
     },
     
     setMapView: function() {
-        obj = this.prepareMapViewValueType();
+        var obj = this.prepareMapViewValueType();
         
-        function valueTypeGroupStoreCallback(scope) {
-            obj.components.valueTypeGroup.setValue(scope.mapView[obj.mapView.valueTypeGroup]);
+        function valueTypeGroupStoreCallback() {
+            obj.components.valueTypeGroup.setValue(this.mapView[obj.mapView.valueTypeGroup]);
             
             obj.stores.valueType.setBaseParam(obj.mapView.valueTypeGroup, obj.components.valueTypeGroup.getValue());
-            obj.stores.valueType.load({scope: scope, callback: function() {
-                obj.components.valueType.setValue(scope.mapView[obj.mapView.valueType]);
+            obj.stores.valueType.load({scope: this, callback: function() {
+                obj.components.valueType.setValue(this.mapView[obj.mapView.valueType]);
                 
-                obj = scope.prepareMapViewDateType();
+                obj = this.prepareMapViewDateType();
                 if (MAPDATETYPE == GLOBALS.config.map_date_type_fixed) {
                     if (obj.stores.c1.isLoaded) {
-                        dateTypeGroupStoreCallback(scope);
+                        dateTypeGroupStoreCallback.call(this);
                     }
                     else {
-                        obj.stores.c1.load({scope: scope, callback: function() {
-                            dateTypeGroupStoreCallback(scope);
+                        obj.stores.c1.load({scope: this, callback: function() {
+                            dateTypeGroupStoreCallback.call(this);
                         }});
                     }
                 }
                 else if (MAPDATETYPE == GLOBALS.config.map_date_type_start_end) {
-                    obj.components.c1.setValue(new Date(scope.mapView[obj.mapView.c1]));
-                    obj.components.c2.setValue(new Date(scope.mapView[obj.mapView.c2]));
+                    obj.components.c1.setValue(new Date(this.mapView[obj.mapView.c1]));
+                    obj.components.c2.setValue(new Date(this.mapView[obj.mapView.c2]));
                     
-                    scope.setMapViewLegend();
+                    this.setMapViewLegend();
                 }                
             }});
         }
         
-        function dateTypeGroupStoreCallback(scope) {
-            obj.components.c1.setValue(scope.mapView[obj.mapView.c1]);
+        function dateTypeGroupStoreCallback() {
+            obj.components.c1.setValue(this.mapView[obj.mapView.c1]);
             
-            obj.stores.c2.setBaseParam('name', scope.mapView[obj.mapView.c1]);
-            obj.stores.c2.load({scope: scope, callback: function() {
-                obj.components.c2.setValue(scope.mapView[obj.mapView.c2]);
+            obj.stores.c2.setBaseParam('name', this.mapView[obj.mapView.c1]);
+            obj.stores.c2.load({scope: this, callback: function() {
+                obj.components.c2.setValue(this.mapView[obj.mapView.c2]);
                 
-                scope.setMapViewLegend();
+                this.setMapViewLegend();
             }});
         }
-        
+
         if (obj.stores.valueTypeGroup.isLoaded) {
-            valueTypeGroupStoreCallback(this);
+            valueTypeGroupStoreCallback.call(this);
         }
         else {
             obj.stores.valueTypeGroup.load({scope: this, callback: function() {
-                valueTypeGroupStoreCallback(this);
+                valueTypeGroupStoreCallback.call(this);
             }});
         }
     },
@@ -1264,9 +1264,9 @@
     setMapViewLegend: function() {
         this.prepareMapViewLegend();
         
-        function predefinedMapLegendSetStoreCallback(scope) {
-            Ext.getCmp('maplegendset_cb').setValue(scope.mapView.mapLegendSetId);
-            scope.applyPredefinedLegend(true);
+        function predefinedMapLegendSetStoreCallback() {
+            Ext.getCmp('maplegendset_cb').setValue(this  .mapView.mapLegendSetId);
+            this.applyPredefinedLegend(true);
         }
         
         if (this.legend.type == GLOBALS.config.map_legend_type_automatic) {
@@ -1285,11 +1285,11 @@
         }
         else if (this.legend.type == GLOBALS.config.map_legend_type_predefined) {
             if (this.stores.isLoaded) {
-                predefinedMapLegendSetStoreCallback(this);
+                predefinedMapLegendSetStoreCallback.call(this);
             }
             else {
                 this.stores.predefinedMapLegendSet.load({scope: this, callback: function() {
-                    predefinedMapLegendSetStoreCallback(this);
+                    predefinedMapLegendSetStoreCallback.call(this);
                 }});
             }
         }            
@@ -1348,8 +1348,16 @@
 	},
     
     loadFromDatabase: function(id, isDrillDown) {
+        function load() {
+            MASK.msg = i18n_loading_geojson;
+            MASK.show();
+            
+            this.parentId = id;
+            this.setUrl(GLOBALS.config.path_mapping + 'getGeoJson.action?parentId=' + this.parentId);
+        }
+        
         if (isDrillDown) {
-            load(this);
+            load.call(this);
         }
         else if (id != this.parentId || this.mapView) {
             if (!this.mapView) {
@@ -1361,15 +1369,7 @@
                     return;
                 }
             }
-            load(this);
-        }
-            
-        function load(scope) {
-            MASK.msg = i18n_loading_geojson;
-            MASK.show();
-            
-            scope.parentId = id;
-            scope.setUrl(GLOBALS.config.path_mapping + 'getGeoJson.action?parentId=' + scope.parentId);
+            load.call(this);
         }
     },
     
@@ -1475,7 +1475,7 @@
             colorHigh: this.legend.type == GLOBALS.config.map_legend_type_automatic ? Ext.getCmp('colorB_cf').getValue() : '',
             mapLegendSetId: Ext.getCmp('maplegendset_cb').getValue() || '',
             longitude: MAP.getCenter().lon,
-            latitude: MAP.getCenter().lon,
+            latitude: MAP.getCenter().lat,
             zoom: parseInt(MAP.getZoom())
         };
     },

=== 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-10-14 16:30:09 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/resources/mapfish/widgets/geostat/Symbol.js	2010-10-18 16:47:59 +0000
@@ -418,18 +418,18 @@
                                     this.legend.type = GLOBALS.config.map_legend_type_predefined;
                                     this.prepareMapViewLegend();
                                     
-                                    function load(scope) {
+                                    function load() {
                                         Ext.getCmp('maplegendset_cb2').setValue(mapLegendSet.id);
-                                        scope.applyPredefinedLegend();
+                                        this.applyPredefinedLegend();
                                     }
                                     
                                     if (!this.stores.predefinedMapLegendSet.isLoaded) {
                                         this.stores.predefinedMapLegendSet.load({scope: this, callback: function() {
-                                            load(this);
+                                            load.call(this);
                                         }});
                                     }
                                     else {
-                                        load(this);
+                                        load.call(this);
                                     }
                                 }
                                 else {
@@ -506,18 +506,18 @@
                                     this.legend.type = GLOBALS.config.map_legend_type_predefined;
                                     this.prepareMapViewLegend();
                                     
-                                    function load(scope) {
+                                    function load() {
                                         Ext.getCmp('maplegendset_cb2').setValue(mapLegendSet.id);
-                                        scope.applyPredefinedLegend();
+                                        this.applyPredefinedLegend();
                                     }
                                     
                                     if (!this.stores.predefinedMapLegendSet.isLoaded) {
                                         this.stores.predefinedMapLegendSet.load({scope: this, callback: function() {
-                                            load(this);
+                                            load.call(this);
                                         }});
                                     }
                                     else {
-                                        load(this);
+                                        load.call(this);
                                     }
                                 }
                                 else {
@@ -679,7 +679,7 @@
                 'focus': {
                     scope: this,
                     fn: function(tf) {
-                        function showTree(scope) {
+                        function showTree() {
                             var value, rawvalue;
                             var w = new Ext.Window({
                                 id: 'orgunit_w2',
@@ -738,7 +738,7 @@
                                                 xtype: 'button',
                                                 text: 'Select',
                                                 width: 133,
-                                                scope: scope,
+                                                scope: this,
                                                 handler: function() {
                                                     if (tf.getValue() && tf.getValue() != this.parentId) {
                                                         this.loadFromDatabase(tf.value);
@@ -766,7 +766,7 @@
                         }
 
                         if (TOPLEVELUNIT) {
-                            showTree(this);
+                            showTree.call(this);
                         }
                         else {
                             Ext.Ajax.request({
@@ -781,7 +781,7 @@
                                         name: rootNode.name,
                                         hasChildrenWithCoordinates: rootNode.hasChildrenWithCoordinates
                                     };
-                                    showTree(this);
+                                    showTree.call(this);
                                 }
                             });
                         }
@@ -1147,50 +1147,50 @@
     setMapView: function() {
         obj = this.prepareMapViewValueType();
         
-        function valueTypeGroupStoreCallback(scope) {
-            obj.components.valueTypeGroup.setValue(scope.mapView[obj.mapView.valueTypeGroup]);
+        function valueTypeGroupStoreCallback() {
+            obj.components.valueTypeGroup.setValue(this.mapView[obj.mapView.valueTypeGroup]);
             
             obj.stores.valueType.setBaseParam(obj.mapView.valueTypeGroup, obj.components.valueTypeGroup.getValue());
-            obj.stores.valueType.load({scope: scope, callback: function() {
-                obj.components.valueType.setValue(scope.mapView[obj.mapView.valueType]);
+            obj.stores.valueType.load({scope: this, callback: function() {
+                obj.components.valueType.setValue(this.mapView[obj.mapView.valueType]);
                 
-                obj = scope.prepareMapViewDateType();
+                obj = this.prepareMapViewDateType();
                 if (MAPDATETYPE == GLOBALS.config.map_date_type_fixed) {
                     if (obj.stores.c1.isLoaded) {
-                        dateTypeGroupStoreCallback(scope);
+                        dateTypeGroupStoreCallback.call(this);
                     }
                     else {
-                        obj.stores.c1.load({scope: scope, callback: function() {
-                            dateTypeGroupStoreCallback(scope);
+                        obj.stores.c1.load({scope: this, callback: function() {
+                            dateTypeGroupStoreCallback.call(this);
                         }});
                     }
                 }
                 else if (MAPDATETYPE == GLOBALS.config.map_date_type_start_end) {
-                    obj.components.c1.setValue(new Date(scope.mapView[obj.mapView.c1]));
-                    obj.components.c2.setValue(new Date(scope.mapView[obj.mapView.c2]));
+                    obj.components.c1.setValue(new Date(this.mapView[obj.mapView.c1]));
+                    obj.components.c2.setValue(new Date(this.mapView[obj.mapView.c2]));
                     
-                    scope.setMapViewLegend();
+                    this.setMapViewLegend();
                 }                
             }});
         }
         
-        function dateTypeGroupStoreCallback(scope) {
-            obj.components.c1.setValue(scope.mapView[obj.mapView.c1]);
+        function dateTypeGroupStoreCallback() {
+            obj.components.c1.setValue(this.mapView[obj.mapView.c1]);
             
-            obj.stores.c2.setBaseParam('name', scope.mapView[obj.mapView.c1]);
-            obj.stores.c2.load({scope: scope, callback: function() {
-                obj.components.c2.setValue(scope.mapView[obj.mapView.c2]);
+            obj.stores.c2.setBaseParam('name', this.mapView[obj.mapView.c1]);
+            obj.stores.c2.load({scope: this, callback: function() {
+                obj.components.c2.setValue(this.mapView[obj.mapView.c2]);
                 
-                scope.setMapViewLegend();
+                this.setMapViewLegend();
             }});
         }
         
         if (obj.stores.valueTypeGroup.isLoaded) {
-            valueTypeGroupStoreCallback(this);
+            valueTypeGroupStoreCallback.call(this);
         }
         else {
             obj.stores.valueTypeGroup.load({scope: this, callback: function() {
-                valueTypeGroupStoreCallback(this);
+                valueTypeGroupStoreCallback.call(this);
             }});
         }
     },
@@ -1198,9 +1198,9 @@
     setMapViewLegend: function() {
         this.prepareMapViewLegend();
         
-        function predefinedMapLegendSetStoreCallback(scope) {
-            Ext.getCmp('maplegendset_cb2').setValue(scope.mapView.mapLegendSetId);
-            scope.applyPredefinedLegend(true);
+        function predefinedMapLegendSetStoreCallback() {
+            Ext.getCmp('maplegendset_cb2').setValue(this.mapView.mapLegendSetId);
+            this.applyPredefinedLegend(true);
         }
         
         if (this.legend.type == GLOBALS.config.map_legend_type_automatic) {
@@ -1219,11 +1219,11 @@
         }
         else if (this.legend.type == GLOBALS.config.map_legend_type_predefined) {
             if (this.stores.isLoaded) {
-                predefinedMapLegendSetStoreCallback(this);
+                predefinedMapLegendSetStoreCallback.call(this);
             }
             else {
                 this.stores.predefinedMapLegendSet.load({scope: this, callback: function() {
-                    predefinedMapLegendSetStoreCallback(this);
+                    predefinedMapLegendSetStoreCallback.call(this);
                 }});
             }
         }            
@@ -1280,10 +1280,18 @@
 			}
 		});
 	},
-    
+
     loadFromDatabase: function(id, isDrillDown) {
+        function load() {
+            MASK.msg = i18n_loading_geojson;
+            MASK.show();
+            
+            this.parentId = id;
+            this.setUrl(GLOBALS.config.path_mapping + 'getGeoJson.action?parentId=' + this.parentId);
+        }
+        
         if (isDrillDown) {
-            load(this);
+            load.call(this);
         }
         else if (id != this.parentId || this.mapView) {
             if (!this.mapView) {
@@ -1295,15 +1303,7 @@
                     return;
                 }
             }
-            load(this);
-        }
-            
-        function load(scope) {
-            MASK.msg = i18n_loading_geojson;
-            MASK.show();
-            
-            scope.parentId = id;
-            scope.setUrl(GLOBALS.config.path_mapping + 'getGeoJson.action?parentId=' + scope.parentId);
+            load.call(this);
         }
     },
     
@@ -1409,7 +1409,7 @@
             colorHigh: this.legend.type == GLOBALS.config.map_legend_type_automatic ? Ext.getCmp('colorB_cf2').getValue() : '',
             mapLegendSetId: Ext.getCmp('maplegendset_cb2').getValue() || '',
             longitude: MAP.getCenter().lon,
-            latitude: MAP.getCenter().lon,
+            latitude: MAP.getCenter().lat,
             zoom: parseInt(MAP.getZoom())
         };
     },