Hello,<br><br clear="all">I have been trying to create a search tool which the user would select the wfs layer (via a radio button) and then type the name or number or even postcode in the textfield and the results will be presented in a gridpanel. The issue i am having is that i can only search on one of the layers and even if i select any other layer. I am quite new to coding and GeoExt but i am quickly learning (i think...). Any help whatsoever would be greatly appreciated.<br>
<br>Please see an extract from my code below - <br><br><html><br> <head><br> <!-- Search Tools --><br> <script type="text/javascript" src="GeoExt/lib/GeoExt/widgets/form/SearchAction.js"><br>
</script><br> <script type="text/javascript" src="GeoExt/lib/GeoExt/widgets/form/BasicForm.js"><br> </script><br> <script type="text/javascript" src="GeoExt/lib/GeoExt/widgets/form/FormPanel.js"><br>
</script><br> <script type="text/javascript" src="GeoExt.ux/ux/Toolbar/ux/widgets/MousePositionItem.js"><br> </script><br> <script type="text/javascript"><br>
<br> var vectorLayer = new OpenLayers.Layer.Vector("vectorLayer");<br> <br> // THE SELECTIONMODEL IS DECLARED OUTSIDE THE FORMPANEL<br><br> var select = new GeoExt.grid.FeatureSelectionModel();<br>
<br> // DEFINE THE SEARCH (WFS) DATA SOURCE<br>//********************************************<br><br>// Define protocol variables for the four web services<br> var prtclLRM = OpenLayers.Protocol.WFS({<br> url: "<a href="http://localhost/geoserver/wfs">http://localhost/geoserver/wfs</a>?",<br>
featureType: "LRMsheets",<br> featureNS: "<a href="http://www.website.com">http://www.website.com</a>",<br> srsName: "EPSG:27700"<br>
});<br><br> var prtclEXP = OpenLayers.Protocol.WFS({<br> url: "<a href="http://localhost/geoserver/wfs">http://localhost/geoserver/wfs</a>?",<br> featureType: "EXPsheets",<br>
featureNS: "<a href="http://www.website.com">http://www.website.com</a>",<br> srsName: "EPSG:27700"<br> });<br><br> var prtclPostcode = OpenLayers.Protocol.WFS({<br>
url: "<a href="http://localhost/geoserver/wfs">http://localhost/geoserver/wfs</a>?",<br> featureType: "AL2_POSTAL",<br> featureNS: "<a href="http://www.website.com">http://www.website.com</a>",<br>
srsName: "EPSG:27700"<br> });<br> var prtclGrids = OpenLayers.Protocol.WFS({<br> url: "<a href="http://localhost/geoserver/wfs">http://localhost/geoserver/wfs</a>?",<br>
featureType: "Grids",<br> featureNS: "<a href="http://www.website.com">http://www.website.com</a>",<br> srsName: "EPSG:27700"<br> });<br>
//Add default prototcol<br> var prtcl=prtclLRM<br><br>// CREATE A GEOEXT FORM PANEL (CONFIGURED WITH AN OPENLAYERS.PROTOCOL INSTANCE) AND RADIO BUTTONS<br>//*******************************************************************************************************************************************************<br>
<br>// /CREATING A GROUP OF RADIOBUTTONS<br> var radios = new Ext.form.RadioGroup({<br> //fieldLabel: 'Select',<br> columns: 2, //display the radiobuttons in two columns<br>
vertical: true,<br> items: [{<br> boxLabel: 'Landranger',<br> name: 'NUMBER',<br> inputValue: 'Landranger',<br>
checked: true<br> }, {<br> boxLabel: 'Explorer',<br> name: 'NUMBER',<br> //name: 'EXPNUMBER',<br>
inputValue: 'Explorer'<br> }, {<br> boxLabel: 'Grid reference',<br> name: 'NUMBER',<br> inputValue: 'Grid'<br>
}, {<br> boxLabel: 'Postcode',<br> name: 'RM_DP_PC',<br> inputValue: 'Postcode'<br> }],<br>
<br> // ADD A LISTENER FOR THE RADIO GROUP<br> listeners: {<br> change: function(radiogroup, radio){<br> rad=radio.inputValue;<br> if (rad=="Landranger"){<br>
prtcl=prtclLRM;<br> }<br> if (rad=="Explorer"){<br> prtcl=prtclEXP;<br> }<br> if (rad=="Grid"){<br> prtcl=prtclGrids;<br> }<br>
if (rad=="Postcode"){<br> prtcl=prtclPostcode;<br> }<br> }<br> }<br> });<br> formPanel = new GeoExt.form.FormPanel({<br>
<br> border: true,<br> layout: 'anchor',<br> bodyStyle: 'padding: 10px',<br> protocol: prtcl,<br> items: [{<br> xtype: "textfield",<br>
width: 220,<br> name: "NUMBER",<br> value: "",<br> emptyText: 'Type here...',<br> fieldLabel: "Find",<br>
allowblank: false<br><br> }, radios],<br><br> listeners: {<br> actioncomplete: function(form, action){<br><br> // THIS LISTENER TRIGGERS WHEN THE SEARCH REQUEST IS COMPLETE, THE OPENLAYERS.PROTOCOL.RESPONSE<br>
// RESULTING FROM THE REQUEST IS AVAILABLE THROUGH "ACTION.RESPONSE"<br><br> features = action.response.features;<br> store.loadData(features);<br><br>
//form.getForm().getValues();<br><br>//*******************************************************************************************************************************<br>// CHECKS THE MAP TO FIND ANY LAYERS CALLED RESULTS THEN IF IT FINDS NONE IT CREATES AN OPENLAYERS VECTOR LAYER (CALLED RESULTS)<br>
// ADDS IT TO THE MAP AND THEN BINDS THE LAYER TO THE STORE (WHICH HAS THE DATA) AND THE SELECTION MODEL (SELECT).<br>// THIS MEANS THAT AFTER THE NEXT SEARCH THE LAYER WILL AUTOMATICALLY GET NOTIFIED THAT THE DATA CHANGED.<br>
//********************************************************************************************************************************<br> DVsearch = map.getLayersByName("Results");<br> if (DVsearch.length === 0) {<br>
DVLayer = new OpenLayers.Layer.Vector("Results", {<br> displayInLayerSwitcher: false<br> });<br> map.addLayer(DVLayer);<br>
store.bind(DVLayer);<br> select.bind(DVLayer);<br> }<br> }<br> },<br> buttons: [{<br>
text: 'Search',<br> handler: function(){<br> formPanel.search();<br> }<br> }, {<br> text: 'Clear Results',<br>
handler: function(){<br> store.removeAll(), <br> formPanel.getForm().reset(); <br> }<br> }],<br> keys: [{<br>
key: [Ext.EventObject.ENTER],<br> handler: function(){<br> formPanel.search();<br> }<br> }]<br> });<br>
<br> var cols = [{<br> name: 'NUMBER',<br> type: 'integer'<br> }, {<br> name: 'MAP_TITLE',<br> type: 'string'<br>
}, {<br> name: 'INSET_NAME',<br> type: 'string'<br> }, {<br> name: 'LATITUDE',<br> type: 'float'<br>
}, {<br> name: 'LONGITUDE',<br> type: 'float'<br> }];<br> var reader = new GeoExt.data.FeatureReader({}, cols);<br> var store = new GeoExt.data.FeatureStore({<br>
reader: reader,<br> fields: cols,<br> //layer: [protocol1, protocol2, protocol3],<br> autoLoad: false<br> });<br><br> // CREATE GRID PANEL CONFIGURED WITH FEATURE STORE<br>
//**************************************************************<br> Results_gridPanel = new Ext.grid.GridPanel({<br> title: "Results",<br> height: 500,<br> //region:"center",<br>
stripeRows: true,<br> autoExpandColumn: 'NUMBER',<br> store: store,<br> columns: [{<br> id: "NUMBER",<br>
header: "Number",<br> width: 10,<br> sortable: true,<br> dataIndex: "NUMBER"<br> }, {<br>
header: "Map Title",<br> width: 200,<br> dataIndex: "MAP_TITLE"<br> }, {<br> header: "Map Inset",<br>
width: 150,<br> align: 'left',<br> dataIndex: "INSET_NAME"<br> }],<br> sm: select<br> });<br>
Results_gridPanel.on('rowdblclick', function(g, rowIdx, r){<br> rec = store.getAt(rowIdx);<br> map.setCenter(new OpenLayers.LonLat(rec.get('LATITUDE'), rec.get('LONGITUDE')), 0);<br>
});<br><br><br>Many thanks in advance.<br><br>Egbe<br><br>