2

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...

4
  • 3
    What do you mean by "This is not working at all". Do you mean its crashing, or showing no data, or not showing the data you expected, or something else entirely?
    – BradHards
    Commented Jan 22, 2013 at 2:52
  • do you mean searching a feature in a vector layer?
    – urcm
    Commented Jan 22, 2013 at 7:51
  • @Brad There's no change at the layer. It's shows all the features that got laod when I set the WFS, not the ones I expected, after I perform a search
    – slevin
    Commented Jan 22, 2013 at 14:29
  • @ Aragon Yes, that's exactly what I mean.
    – slevin
    Commented Jan 22, 2013 at 14:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.