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

commits at geoext.org commits at geoext.org
Wed Apr 15 09:06:43 CEST 2009


Author: tschaub
Date: 2009-04-15 09:06:43 +0200 (Wed, 15 Apr 2009)
New Revision: 393

Modified:
   apps/opengeo/geoexplorer/trunk/debug.html
   apps/opengeo/geoexplorer/trunk/lib/GeoExplorer.js
Log:
Modify load sequence so capabilities are available before application is activated.  Layer url and other properties come from capabilities.  Title and visibility are configurable.

Modified: apps/opengeo/geoexplorer/trunk/debug.html
===================================================================
--- apps/opengeo/geoexplorer/trunk/debug.html	2009-04-15 07:03:04 UTC (rev 392)
+++ apps/opengeo/geoexplorer/trunk/debug.html	2009-04-15 07:06:43 UTC (rev 393)
@@ -32,9 +32,7 @@
                 ows: "/geoserver/ows",
                 map: {
                     layers: [{
-                        name: "topp:states",
-                        title: "States",
-                        queryable: true
+                        name: "topp:states"
                     }],
                     center: [-96.7, 37.6],
                     zoom: 4

Modified: apps/opengeo/geoexplorer/trunk/lib/GeoExplorer.js
===================================================================
--- apps/opengeo/geoexplorer/trunk/lib/GeoExplorer.js	2009-04-15 07:03:04 UTC (rev 392)
+++ apps/opengeo/geoexplorer/trunk/lib/GeoExplorer.js	2009-04-15 07:06:43 UTC (rev 393)
@@ -23,7 +23,6 @@
  * Valid layer config properties:
  * name - {String} Required WMS layer name.
  * title - {String} Optional title to display for layer.
- * queryable - {Boolean} Layer may be queried (with GetFeatureInfo)
  *
  * Extends:
  *  - Viewer
@@ -44,6 +43,13 @@
     layers: null,
 
     /**
+     * Property: capabilities
+     * {GeoExt.data.WMSCapabilitiesStore} A store containing a record for each
+     *     layer on the server.
+     */
+    capabilities: null,
+
+    /**
      * Property: mapPanel
      * {GeoExt.MapPanel} the MapPanel instance for the main viewport
      */
@@ -55,35 +61,94 @@
      */
     capGrid: null,
 
-
     /**
-     * Property: load
+     * Method: load
      * Called at the end of construction.  This initiates the sequence that
      *     prepares the application for use.
      */
     load: function() {
-        Ext.onReady(this.createLayout, this);
+        this.dispatch(
+            [
+                function(done) {
+                    Ext.onReady(
+                        function() {
+                            this.createLayout();
+                            done();
+                        },
+                        this
+                    );
+                },
+                function(done) {
+                    this.initCapabilities(done);
+                },
+            ],
+            this.activate
+        );
     },
     
     /**
+     * Method: initCapabilities
+     *
+     * Parameters:
+     * callback - {Function} Function to be called when capabilties store is loaded.
+     */
+    initCapabilities: function(callback) {
+        
+        var urlObj = OpenLayers.Util.createUrlObject(this.ows);
+        var url = urlObj.protocol + "//" +
+            urlObj.host + urlObj.pathname + "?" +
+            Ext.urlEncode(Ext.apply(urlObj.args, {
+                SERVICE: "WMS",
+                REQUEST: "GetCapabilities"
+            }));
+        
+        this.capabilities = new GeoExt.data.WMSCapabilitiesStore({
+            url: url,
+            listeners: {
+                load: {
+                    fn: callback,
+                    single: true
+                }
+            }
+        });
+        this.capabilities.load();
+    },
+    
+    /**
      * Method: createLayout
      * Create the various parts that compose the layout.
      */
     createLayout: function() {
         
         // create the map
-        this.initMap();
+        // TODO: check this.initialConfig.map for any map options
+        this.map = new OpenLayers.Map({
+            allOverlays: true,
+            controls: []
+        });
+
+        //TODO: make this more configurable
+        this.map.events.on({
+            "preaddlayer" : function(evt){
+                if(evt.layer.mergeNewParams){
+                    evt.layer.mergeNewParams({
+                        transparent: true,
+                        format: "image/png"
+                    });
+                }
+            },
+            scope : this
+        });
         
-        // create the layers store
-        this.initLayers();
+        // create layer store
+        this.layers = new GeoExt.data.LayerStore({
+            map: this.map
+        });
 
-        var toolbarItems = this.initMapControlsAndToolbar();
-
-        var mapOverlayPanel = this.initMapOverlay();
-        
         // place map in panel
         var mapConfig = this.initialConfig.map || {};
         this.mapPanel = new GeoExt.MapPanel({
+            layout: "anchor",
             border: true,
             region: "center",
             map: this.map,
@@ -91,12 +156,11 @@
             center: mapConfig.center && new OpenLayers.LonLat(mapConfig.center[0], mapConfig.center[1]),
             // TODO: update the OpenLayers.Map constructor to accept an initial zoom
             zoom: mapConfig.zoom,
-            layout: 'anchor',
-            items: [mapOverlayPanel]
+            items: [
+                this.createMapOverlay()
+            ]
         });
 
-        this.initCapabilitiesGrid();
-
         var layersContainer = new Ext.Panel({
             autoScroll: true,
             border: false,
@@ -146,21 +210,37 @@
             ]
         });
 
-        var toolbar = new Ext.Toolbar({
-            region: 'north',
-            items: toolbarItems
-        });
-
         var viewport = new Ext.Viewport({
             layout: "fit",
             hideBorders: true,
             items: {
                 layout: "border",
                 deferredRender: false,
-                items: [toolbar, this.mapPanel, westPanel]
+                items: [
+                    {
+                        xtype: "toolbar",
+                        region: "north",
+                        items: this.createTools()
+                    },
+                    this.mapPanel,
+                    westPanel
+                ]
             }
         });
+
+        this.initCapGrid();
         
+    },
+    
+    /**
+     * Method: activate
+     * Activate the application.  Call after application is configured.
+     */
+    activate: function() {
+        
+        // add any layers from config
+        this.addLayers();
+
         // initialize tooltips
         Ext.QuickTips.init();
 
@@ -192,49 +272,64 @@
     },
     
     /**
-     * Method: initLayers
+     * Method: addLayers
      * Construct the layer store to be used with the map (referenced as <layers>).
      */
-    initLayers: function() {
+    addLayers: function() {
         var mapConfig = this.initialConfig.map;
-        
-        this.layers = new GeoExt.data.LayerStore({
-            map: this.map
-        });
 
         if(mapConfig && mapConfig.layers) {
-            var conf, layer, len = mapConfig.layers.length;
-            var records = new Array(len);
-            for(var i=0; i<len; ++i) {
-                conf = Ext.apply({}, mapConfig.layers[i]);
-                layer = new OpenLayers.Layer.WMS(
-                    conf.title || conf.name,
-                    this.ows,
-                    {
-                        layers: conf.name, 
-                        transparent: true
-                    },
-                    {
-                        visibility: ("visibility" in conf? conf.visibility : true)
+            var conf, id, record, layer, records = [];
+            for(var i=0; i<mapConfig.layers.length; ++i) {
+                conf = mapConfig.layers[i];
+                id = this.capabilities.find("name", conf.name);
+                if(id >= 0) {
+                    record = this.capabilities.getAt(id).copy();
+                    layer = record.get("layer");
+
+                    // set layer max extent from capabilities
+                    // TODO: make this SRS independent
+                    layer.maxExtent = OpenLayers.Bounds.fromArray(
+                        record.get("llbbox")
+                    );
+
+                    // set layer visibility from config
+                    layer.visibility = ("visibility" in conf) ?
+                        conf.visibility : true;
+                    
+                    // set layer title from config
+                    if(conf.title) {
+                        layer.name = conf.title;
                     }
-                );
-                conf.layer = layer;
-                layer.events.register("visibilitychanged", this, this.updateGFILayers);
-                // we could extend the record type with conf fields here
-                records[i] = new GeoExt.data.LayerRecord(conf, layer.id);
+
+                    // set any other layer configuration
+
+                    records.push(record);
+                }
             }
             this.layers.add(records);
+            
+            // set map center
+            if(this.mapPanel.center) {
+                // zoom does not have to be defined
+                this.map.setCenter(this.mapPanel.center, this.mapPanel.zoom);
+            } else if (this.mapPanel.extent) {
+                this.map.zoomToExtent(this.mapPanel.extent);
+            } else {
+                this.map.zoomToMaxExtent();
+            }
+            
         }
     },
 
     /**
-     * Method: initCapabilitiesGrid
+     * Method: initCapGrid
      * Constructs a window with a capabilities grid.
      */
-    initCapabilitiesGrid: function(){
+    initCapGrid: function(){
 
         var capGridPanel = new CapabilitiesGrid({
-            url : this.ows,
+            store: this.capabilities,
             mapPanel : this.mapPanel,
             height: 300,
             width: 650
@@ -246,15 +341,16 @@
             items: [
                 capGridPanel
             ],
-            bbar: ["->",
-                   new Ext.Button({
-                       text: "Done",
-                       handler: function() {
-                           this.capGrid.hide();
-                       },
-                       scope: this
-                   })
-                  ]
+            bbar: [
+                "->",
+                new Ext.Button({
+                    text: "Done",
+                    handler: function() {
+                        this.capGrid.hide();
+                    },
+                    scope: this
+                })
+            ]
         });
     },
 
@@ -266,7 +362,7 @@
         this.capGrid.show();
     },
 
-    initMapOverlay: function() {
+    createMapOverlay: function() {
         var scaleLinePanel = new Ext.Panel({
             cls: 'olControlScaleLine',
             border: false,
@@ -326,7 +422,6 @@
                 bottom: 10
             },
             items: [
-                {border: false, html: "hi there"},
                 scaleLinePanel,
                 zoomSelector
             ]
@@ -340,7 +435,7 @@
         return mapOverlay;
     },
 
-    initMapControlsAndToolbar: function() {
+    createTools: function() {
 
         // create a navigation control
         var navControl = new OpenLayers.Control.Navigation();
@@ -408,7 +503,7 @@
         this.map.addControl(measureArea);
 
         var toolGroup = "toolGroup";
-        var toolbarItems = [
+        var tools = [
             new Ext.Button({
                 tooltip: "Bookmark",
                 iconCls: "icon-save",
@@ -501,7 +596,7 @@
             })
         ];
 
-        return toolbarItems;
+        return tools;
     },
 
     createMeasureTool: function(handlerType, title) {
@@ -642,8 +737,6 @@
     extractConfiguration: function(){
         var config = {};
 
-        config.ows = this.ows;
-
         // Map configuration
 
         var center = this.map.getCenter();
@@ -663,7 +756,6 @@
                 name: (layerRecord.get("layer").params 
                        && layerRecord.get("layer").params.LAYERS)
                     || layerRecord.get("name"),
-                queryable: layerRecord.get("queryable"),
                 visibility: layerRecord.get("layer").getVisibility()
             };
 



More information about the Commits mailing list