Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

share|improve this question
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 Jan 22 '13 at 2:52
    
do you mean searching a feature in a vector layer? –  Aragon Jan 22 '13 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 Jan 22 '13 at 14:29
    
@ Aragon Yes, that's exactly what I mean. –  slevin Jan 22 '13 at 14:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.