[Commits] r253 - in apps/opengeo/geoexplorer/trunk: . lib

commits at geoext.org commits at geoext.org
Mon Mar 23 22:35:14 CET 2009


Author: tschaub
Date: 2009-03-23 22:35:14 +0100 (Mon, 23 Mar 2009)
New Revision: 253

Modified:
   apps/opengeo/geoexplorer/trunk/debug.html
   apps/opengeo/geoexplorer/trunk/lib/GeoExplorer.js
Log:
pulling out application configuration

Modified: apps/opengeo/geoexplorer/trunk/debug.html
===================================================================
--- apps/opengeo/geoexplorer/trunk/debug.html	2009-03-23 21:00:05 UTC (rev 252)
+++ apps/opengeo/geoexplorer/trunk/debug.html	2009-03-23 21:35:14 UTC (rev 253)
@@ -19,7 +19,19 @@
         <script type="text/javascript" src="lib/GeoExplorer.js"></script> 
         <script type="text/javascript" src="lib/GeoExplorer/dispatch.js"></script> 
 
-        <script>var app = new GeoExplorer;</script>
+        <script>
+            var app = new GeoExplorer({
+                ows: "http://sigma.openplans.org/geoserver/ows",
+                map: {
+                    layers: [{
+                        name: "bluemarble",
+                        title: "Global Imagery"
+                    }],
+                    center: [0, 0],
+                    zoom: 2
+                }
+            });
+        </script>
 
     </head>
     <body></body>

Modified: apps/opengeo/geoexplorer/trunk/lib/GeoExplorer.js
===================================================================
--- apps/opengeo/geoexplorer/trunk/lib/GeoExplorer.js	2009-03-23 21:00:05 UTC (rev 252)
+++ apps/opengeo/geoexplorer/trunk/lib/GeoExplorer.js	2009-03-23 21:35:14 UTC (rev 253)
@@ -6,11 +6,29 @@
  * Constructor: GeoExplorer
  * Create a new GeoExplorer application.
  *
+ * Parameters:
+ * config - {Object} Optional application configuration properties.
+ *
+ * Valid config properties:
+ * map - {Object} Map configuration object.
+ * ows - {String} OWS URL
+ *
+ * Valid map config properties:
+ * layers - {Array} A list of layer configuration objects.
+ * center - {Array} A two item array with center coordinates.
+ * zoom - {Number} An initial zoom level.
+ *
+ * Valid layer config properties:
+ * name - {String} Required WMS layer name.
+ * title - {String} Optional title to display for layer.
+ *
  * Extends:
  *  - Ext.util.Observable
  */
-var GeoExplorer = function() {
+var GeoExplorer = function(config) {
     
+    this.initialConfig = Ext.apply({}, config);
+    
     // add any custom application events
     this.addEvents(
         /**
@@ -20,49 +38,61 @@
         "ready"
     );
     
-    // load the app
-    GeoExplorer.dispatch(
-        [
-            function(done) {
-                Ext.onReady(function() {
-                    this.initLayout();
-                    done();
-                }, this);
-            }
-            // other functions to be executed in parallel can go here
-        ], function() {
-            // executed when all of the above are done
-            this.fireEvent("ready");
-        },
-        this // scope for all above functions
-    );
+    this.load();
     
 };
 
 Ext.extend(GeoExplorer, Ext.util.Observable, {
     
     /**
-     * Method: initLayout
+     * Property: map
+     * {OpenLayers.Map} The application's map.
      */
-    initLayout: function() {
+    map: null,
+    
+    /**
+     * Property: load
+     * Called at the end of construction.  This initiates the sequence that
+     *     prepares the application for use.
+     */
+    load: function() {
+        GeoExplorer.dispatch(
+            [
+                function(done) {
+                    Ext.onReady(function() {
+                        this.createLayout();
+                        done();
+                    }, this);
+                }
+                // other functions to be executed in parallel can go here
+            ], function() {
+                // executed when all of the above are done
+                this.fireEvent("ready");
+            },
+            this // scope for all above functions
+        );
+    },
+    
+    /**
+     * Method: createLayout
+     * Create the various parts that compose the layout.
+     */
+    createLayout: function() {
         
-        // keep reference to map handy
-        this.map = new OpenLayers.Map();
+        // create the map
+        this.initMap();
         
+        // place map in panel
+        var mapConfig = this.initialConfig.map || {};
         var mapPanel = new GeoExt.MapPanel({
             border: true,
             region: "center",
             map: this.map,
-            layers: [new OpenLayers.Layer.WMS(
-                "bluemarble",
-                "http://sigma.openplans.org/geoserver/wms?",
-                {layers: 'bluemarble'}
-            )],
-            center: new OpenLayers.LonLat(0, 0),
-            zoom: 2
+            center: mapConfig.center && new OpenLayers.LonLat(mapConfig.center[0], mapConfig.center[1]),
+            zoom: mapConfig.zoom
         });
 
-        this.layersContainer = new Ext.Panel({
+        var layersContainer = new Ext.Panel({
             autoScroll: true,
             title: "Layers",
             anchor: "100%, -200",
@@ -77,7 +107,7 @@
             }]
         });
 
-        this.legendContainer = new Ext.Panel({
+        var legendContainer = new Ext.Panel({
             title: "Legend",
             height: 200,
             items: [{html: ""}]
@@ -92,7 +122,7 @@
             collapsible: true,
             collapseMode: "mini",
             items: [
-                this.layersContainer, this.legendContainer
+                layersContainer, legendContainer
             ]
         });
 
@@ -106,6 +136,44 @@
             }
         });
 
+    },
+    
+    /**
+     * Method: initMap
+     * Construct the map and reference it on the applicaiton as <map>.
+     */
+    initMap: function() {
+        var mapConfig = this.initialConfig.map;
+        var ows = this.initialConfig.ows;
+
+        var map = new OpenLayers.Map();
+        // create a dummy layer that acts as the single "base" layer
+        map.addLayer(
+            new OpenLayers.Layer(null, {
+                isBaseLayer: true,
+                displayInLayerSwitcher: false
+            })
+        );
+
+        if(mapConfig) {
+            if(mapConfig.layers) {
+                var layer, layers = [];
+                for(var i=0, len=mapConfig.layers.length; i<len; ++i) {
+                    layer = mapConfig.layers[i];
+                    layers.push(
+                        new OpenLayers.Layer.WMS(
+                            layer.title || layer.name,
+                            ows,
+                            {layers: layer.name},
+                            {isBaseLayer: false}
+                        )
+                    );
+                }
+            }
+            map.addLayers(layers);
+        }
+        
+        this.map = map;
     }
     
 });
\ No newline at end of file



More information about the Commits mailing list