I am using Openlayers,Geoserver & Postgis.... My postgis tables are having columns as id, name, POINT/POLYGON/LINE. Each table corresponds to a layer that I am showing in layerswitcher in OL. I am getting these layers via WMS from geoserver.
I want to implement search functionality so that whenever a user gives a string(name value of the table) in search box, he should be zoomed to that particular feature on the map.
Can anyone guide me how to achieve this functionality??? Any help is highly appreciated
The idea I got is:
Step 1: User has to check only one layer(the layer in which he want to search) in layerswitcher before searching . But how to get which layer has been selected??
Step 2: After knowing the selected layer , Using php search that corresponding table for the search string in names column , if it is present get the latitude and longitude values. But how to get these values and what if they are polygons/lines???
Step 3: how to send these latitude longitude values to JS so that I can zoom to that point???
I have completed 2 1/2 steps. I am using st_box2d and getting the bounds of the feature as "BOX(minx miny,maxx maxy)"...... where bounds contain BOX(minx miny,maxx maxy)
the code below is the ajax function for fetching bounds from db. Now how to use bounds variable to zoom to that feature.
<?-- code for displaying map -->
function searchfunction(form)
{
httpObject = getHTTPObject();
var searchvalue=form.searchvalue.value;
if (httpObject != null)
{
httpObject.open("GET","searchfeature.php?selectedlayer="+selLayer+"&searchvalue="+searchvalue,true);
httpObject.send(null);
httpObject.onreadystatechange = function()
{
if(httpObject.readyState == 4)
{
bounds=httpObject.responseText;
}
}
}
}