I created a store and added layers to a grid Panel, when you click add layer to map it works fine, the problem is that when I call the function controle(layer) I can't select polygons in the layer that is active. When I add layers manually using OpenLayers.Layer.WMS.... and I send the variable that has the layer to the function controle it works fine but from a store it doesn't. What am I doing wrong? Can anyone please help? The objective that I am trying to achieve is to add layers from several databases to a grid Panel, add the layers to a tree Panel and a Map Panel and click on the states or countries and with shift key pressed be able to select another layer and select another polygon from that layer and obtain a WKT text from all the polygons selected.

Thanks :)

        // create a vector layer for selection of polygons
        select = new OpenLayers.Layer.Vector("Selection", {
                styleMap: new OpenLayers.Style(OpenLayers.Feature.Vector.style["select"])

        // create a new WMS capabilities store
            store = new GeoExt.data.WMSCapabilitiesStore({
                url: "http://localhost:9090/geoserver/wms?service=wms&version=1.1.1&request=GetCapabilities",
                autoLoad: true

        // create a grid to display records from the store
            var grid = new Ext.grid.GridPanel({
                title: "WMS Capabilities",
                store: store,
                cm: new Ext.grid.ColumnModel([{
                    header: "Name",
                    dataIndex: "name",
                    sortable: true
                }, {
                    id: "title",
                    header: "Title",
                    dataIndex: "title",
                    sortable: true
                sm: new Ext.grid.RowSelectionModel({
                    singleSelect: true
                autoExpandColumn: "title",
                renderTo: "capgrid",
                height: 300,
                width: 350,
                floating: true,
                x: 10,
                y: 0,
                bbar: ["->",
                    text: "Add Layer",
                    handler: function() {
                        var record = grid.getSelectionModel().getSelected();
                        if (record) {
                            var copy = record.copy();
                            // Ext 3.X does not allow circular references in objects passed 
                            // to record.set 
                            copy.data["layer"] = record.getLayer();
                                format: "image/png",
                                transparent: "true"

        // create a map panel
            panel = new GeoExt.MapPanel({
                renderTo: "mappanel",
                width: 350,
                height: 300,
                floating: true,
                map: map,
                x: 570,
                y: 0

        // create a treePanel
            tree = new Ext.tree.TreePanel({
                renderTo: "tree",
                root: new GeoExt.tree.LayerContainer({
                    text: 'Map Layers',
                    layerStore: panel.layers,
                    leaf: false,
                    expanded: true
                enableDD: true, //
                width: 170,
                height: 300,
                floating: true,
                x: 380,
                y: 0

        // function to getFeature 
        function controle(layer) {
            control = new OpenLayers.Control.GetFeature({
                protocol: OpenLayers.Protocol.WFS.fromWMSLayer(layer),
                multipleKey: "shiftKey"
            control.events.register("featureselected", this, function(e) {
            control.events.register("featureunselected", this, function(e) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.