[Commits] r369 - sandbox/opengeo/alachua/lib/GeoExt/widgets

commits at geoext.org commits at geoext.org
Wed Apr 8 17:06:52 CEST 2009


Author: tcoulter
Date: 2009-04-08 17:06:52 +0200 (Wed, 08 Apr 2009)
New Revision: 369

Modified:
   sandbox/opengeo/alachua/lib/GeoExt/widgets/MapPanel.js
Log:
Updated map panel, just for posterity.

Modified: sandbox/opengeo/alachua/lib/GeoExt/widgets/MapPanel.js
===================================================================
--- sandbox/opengeo/alachua/lib/GeoExt/widgets/MapPanel.js	2009-04-07 23:57:06 UTC (rev 368)
+++ sandbox/opengeo/alachua/lib/GeoExt/widgets/MapPanel.js	2009-04-08 15:06:52 UTC (rev 369)
@@ -1,25 +1,12 @@
-/*
- * Initial code
- * (C) 2008 Tim Coulter, The Open Planning Project
- *
- * Misc tweaks for inclusion into trunk GeoExt
- * (C) 2009 Eric Lemoine, Camptocamp France SAS
- * (C) 2009 Andreas Hocevar, The Open Planning Project
- *
- * This file is part of GeoExt
- *
- * GeoExt is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * GeoExt is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GeoExt.  If not, see <http://www.gnu.org/licenses/>.
+/* Copyright (C) 2008-2009 The Open Source Geospatial Foundation ¹
+ * Published under the BSD license.
+ * See http://geoext.org/svn/geoext/core/trunk/license.txt for the full text
+ * of the license.
+ * 
+ * ¹ pending approval */
+
+/**
+ * @include GeoExt/data/LayerStore.js
  */
 
 Ext.namespace("GeoExt");
@@ -77,10 +64,11 @@
     
     /**
      * APIProperty: layers
-     * {Ext.data.Store} A store holding records representing a map's layers.
-     *     The data hash of a layer record contains a layer property
-     *     referencing the layer. Read-only.
-     *     {<GeoExt.data.LayerStore>} will be created.
+     * {GeoExt.data.LayerStore|GeoExt.data.GroupingStore|Array(OpenLayers.Layer)}
+     *     A store holding records. If not provided, an empty
+     *     {<GeoExt.data.LayerStore>} will be created. After instantiation
+     *     this property will always be an {Ext.data.Store}, even if an array
+     *     of {OpenLayers.Layer} was provided.
      */
     layers: null,
 
@@ -114,25 +102,53 @@
      */
     initComponent: function(){
         if(!(this.map instanceof OpenLayers.Map)) {
-            this.map = new OpenLayers.Map(this.map);
+            this.map = new OpenLayers.Map(
+                Ext.applyIf(this.map || {}, {allOverlays: true})
+            );
         }
-        this.layers = new GeoExt.data.LayerStore({map: this.map});
+        var layers = this.layers;
+        if(!layers || layers instanceof Array) {
+            this.layers = new GeoExt.data.LayerStore({
+                layers: layers,
+                map: this.map
+            });
+        }
         
-        this.on("render", this.gx_onRender, this);
-        this.on("bodyresize", this.gx_onBodyResize, this);
-
+        if(typeof this.center == "string") {
+            this.center = OpenLayers.LonLat.fromString(this.center);
+        } else if(this.center instanceof Array) {
+            this.center = new OpenLayers.LonLat(this.center[0], this.center[1]);
+        }
+        if(typeof this.extent == "string") {
+            this.extent = OpenLayers.Bounds.fromString(this.extent);
+        } else if(this.extent instanceof Array) {
+            this.extent = OpenLayers.Bounds.fromArray(this.extent);
+        }
+        
         GeoExt.MapPanel.superclass.initComponent.call(this);       
     },
     
     /**
-     * Method: gx_onRender
+     * Method: updateMapSize
+     * Tell the map that it needs to recaculate its size and position.
+     */
+    updateMapSize: function() {
+        if(this.map) {
+            this.map.updateSize();
+        }
+    },
+    
+    /**
+     * Method: onRender
      *     Private method called after the panel has been
      *     rendered.
      */
-    gx_onRender: function() {
+    onRender: function() {
+        GeoExt.MapPanel.superclass.onRender.apply(this, arguments);
         this.map.render(this.body.dom);
         if(this.map.layers.length > 0) {
-            if(this.center && this.zoom) {
+            if(this.center) {
+                // zoom does not have to be defined
                 this.map.setCenter(this.center, this.zoom);
             }  else if(this.extent) {
                 this.map.zoomToExtent(this.extent);
@@ -141,15 +157,42 @@
             }
         }
     },
+    
+    /**
+     * Method: afterRender
+     * Private method called after the panel has been rendered.
+     */
+    afterRender: function() {
+        GeoExt.MapPanel.superclass.afterRender.apply(this, arguments);
+        if(this.ownerCt) {
+            this.ownerCt.on("move", this.updateMapSize, this);
+        }
+    },    
 
     /**
-     * Method: gx_onBodyResize
+     * Method: onResize
      *     Private method called after the panel has been
      *     resized.
      */
-    gx_onBodyResize: function() {
-        this.map.updateSize();
+    onResize: function() {
+        GeoExt.MapPanel.superclass.onResize.apply(this, arguments);
+        this.updateMapSize();
+    },
+    
+    /**
+     * Method: onDestroy
+     * Private method called during the destroy sequence.
+     */
+    onDestroy: function() {
+        if(this.ownerCt) {
+            this.ownerCt.un("move", this.updateMapSize, this);
+        }
+        GeoExt.MapPanel.superclass.onDestroy.apply(this, arguments);
     }
+    
 });
 
+/**
+ * XType: gx_mappanel
+ */
 Ext.reg('gx_mappanel', GeoExt.MapPanel); 



More information about the Commits mailing list