I'm using Geoserver/PostGIS/openLayers
I've succesfully set a vector layer. And now I'm trying to create a search functionality. But something goes wrong.
First I set up the layer and add some basic style for the features. So far, everything is ok.
Then I create a function, using javascript, which comes after the layer. This function gets triggered after the user completes a HTML form and hits the "Search" button.
Here's what's inside the function:
//check for empty fields in the form-if not pass the value in a var
if (document.getElementById("typeselect").value!=" ") {var filter_a = document.getElementById("typeselect").value;}
if (document.getElementById("eraselect").value!=" ") {var filter_b = document.getElementById("eraselect").value;}
if (document.getElementById("nm").value!="") { var filter_c = document.getElementById("nm").value;}
if (document.getElementById("descr").value!="") { var filter_d = document.getElementById("descr").value;}
if (document.getElementById("chrono").value!="") { var filter_e = document.getElementById("chrono").value;}
//create a style
var vsd = new OpenLayers.Style();
//put together the final filter, using the vars from above
//filter_a and filter_b are numbers
//filter_c to filter_e are texts
var filter_final = new OpenLayers.Filter.Logical({ type: OpenLayers.Filter.Logical.AND,
filters: [ new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO, property: "p_type", value: filter_a }),
new OpenLayers.Filter.Comparison({ type: OpenLayers.Filter.Comparison.EQUAL_TO, property: "p_era", value: filter_b }),
new OpenLayers.Filter.Comparison({ type: OpenLayers.Filter.Comparison.LIKE, property: "p_name", value: filter_c }),
new OpenLayers.Filter.Comparison({ type: OpenLayers.Filter.Comparison.LIKE, property: "p_descr", value: filter_d }),
new OpenLayers.Filter.Comparison({ type: OpenLayers.Filter.Comparison.LIKE, property: "p_chron", value: filter_e }) ] });
//add the filter as rule to the style
vsd.addRules([filter_final]);
//apply the style as default
var vst = new OpenLayers.StyleMap({'default': vsd});
//apply the new style to the layer (named pins)
pins.styleMap = vst;
This is not working at all. I've tried editing my code, I don't know what to do, I've searched for an answer and nothing really helped me. Please advise...
Thanks.
EDIT
I also added this line at the end and still nothing pins.refresh();
Do I need to use the WFS protocol, combined with the read()
?
EDIT #2
I've replaced pins.refresh();
with pins.refresh({force:true});
and all the features dissappear. I also tried something like this and still nothing. This is a torture...