[Commits] r294 - apps/opengeo/geoexplorer/trunk/lib

commits at geoext.org commits at geoext.org
Mon Mar 30 22:44:40 CEST 2009


Author: dwins
Date: 2009-03-30 22:44:40 +0200 (Mon, 30 Mar 2009)
New Revision: 294

Modified:
   apps/opengeo/geoexplorer/trunk/lib/GeoExplorer.js
Log:
Changes to accommodate GetFeatureInfo control


Modified: apps/opengeo/geoexplorer/trunk/lib/GeoExplorer.js
===================================================================
--- apps/opengeo/geoexplorer/trunk/lib/GeoExplorer.js	2009-03-30 19:43:35 UTC (rev 293)
+++ apps/opengeo/geoexplorer/trunk/lib/GeoExplorer.js	2009-03-30 20:44:40 UTC (rev 294)
@@ -37,17 +37,24 @@
     map: null,
     
     /**
+     * Property: layers
+     * {GeoExt.data.LayerStore} A store containing a record for each layer
+     *     on the map.
+     */
+    layers: null,
+
+    /**
      * Property: mapPanel
-     * {GeoExt.MapPanel} The application's map panel.
+     * {GeoExt.MapPanel} the MapPanel instance for the main viewport
      */
     mapPanel: null,
-    
+
     /**
-     * Property: layers
-     * {GeoExt.data.LayerStore} A store containing a record for each layer
-     *     on the map.
+     * Property: toolbarItems
+     * {Array} An array containing toolbar items suitable for passing as a tbar: property 
+     * on an Ext component
      */
-    layers: null,
+    toolbarItems: null,
     
     /**
      * Property: load
@@ -69,6 +76,9 @@
         
         // create the layers store
         this.initLayers();
+
+        this.initMapControls();
+        this.initToolbar();
         
         // place map in panel
         var mapConfig = this.initialConfig.map || {};
@@ -121,13 +131,18 @@
             ]
         });
 
+        var toolbar = new Ext.Toolbar({
+            region: 'north',
+            items: this.toolbarItems
+        });
+
         var viewport = new Ext.Viewport({
             layout: "fit",
             hideBorders: true,
             items: {
                 layout: "border",
                 deferredRender: false,
-                items: [this.mapPanel, westPanel]
+                items: [toolbar, this.mapPanel, westPanel]
             }
         });
 
@@ -170,14 +185,13 @@
                 layer = new OpenLayers.Layer.WMS(
                     conf.title || conf.name,
                     ows,
-                    {layers: conf.name},
+                    {layers: conf.name, transparent: true},
                     {isBaseLayer: false}
                 );
                 conf.layer = layer;
+                layer.events.register("visibilitychanged", this, this.updateGFILayers);
                 // we could extend the record type with conf fields here
-                records.push(new GeoExt.data.LayerRecord(
-                    conf, layer.id
-                ));
+                records.push(new GeoExt.data.LayerRecord(conf, layer.id));
             }
         }
         this.layers.add(records);
@@ -194,6 +208,69 @@
         });
         
         win.show();
+    },
+
+    initMapControls: function() {
+        this.mapControls = { 
+            getFeatureInfo: new OpenLayers.Control.WMSGetFeatureInfo(this.initialConfig.ows, {
+            })
+        };
+
+        this.updateGFILayers();
+
+        this.mapControls.getFeatureInfo.events.register("getfeatureinfo", this, this.displayPopup);
+
+        for (var key in this.mapControls) {
+            this.map.addControl(this.mapControls[key]);
+        }
+    },
+
+    initToolbar: function() { 
+        var toolGroup = "toolGroup";
+        this.toolbarItems = [
+            new Ext.Button({
+                text: "GetFeatureInfo",
+                enableToggle: true,
+                toggleGroup: toolGroup,
+                handler: function(toggled, item) { 
+                    if (toggled){
+                        this.mapControls.getFeatureInfo.activate(); 
+                    } else {
+                        this.mapControls.getFeatureInfo.deactivate();
+                    }
+                },
+                scope: this
+            })
+        ];
+    },
+
+    updateGFILayers: function() {
+        var layernames = [];
+        for (var i = 0, len = this.map.layers.length; i < len; i++) {
+            if (this.map.layers[i].params && this.map.layers[i].getVisibility()) {
+                layernames.push(this.map.layers[i].params.LAYERS);
+            }
+        }
+
+        this.mapControls.getFeatureInfo.layers = layernames.join(",");
+    },
+
+    displayPopup: function(evt){
+        var html;
+        if (evt.features && evt.features.length) {
+            html =  'Found ' + evt.features.length + ' features';
+        } else {
+            html = evt.text;
+        }
+
+        var lonlat = this.map.getLonLatFromPixel(evt.clickPosition);
+        var win = new Ext.Window({
+            html: html,
+            title: "Feature Info",
+            width: 250,
+            lonlat: lonlat
+        });
+        this.mapPanel.add(win);
+        win.show();
     }
-    
-});
\ No newline at end of file
+});



More information about the Commits mailing list