0

I want to change filter and style like this

-user enter search condition ==> filter condition change

-user enter color of feature ==> style color of feature change

i know how to add filter and style for vector layers when initialization this vector, but i dont know how to change style after that.

1 Answer 1

1

One method to change color dynamically would be

YOUR_VECTOR_FEATURE.style = OpenLayers.Util.applyDefaults({fillColor: YOUR_FILL_COLOR}, 
OpenLayers.Feature.Vector.style["default"]);

I believe this overrides all other styling with defaults (you can just reassign it in the constructor though).

I'm not sure what kind of layer you are trying to filter but you can usually just do it with

YOUR_LAYER.filter = // filter goes here
YOUR_LAYER.refresh();
1
  • function changeFilter() { var queryFilter = new OpenLayers.Filter.Comparison({ type: OpenLayers.Filter.Comparison.GREATER_THAN, property: "code_2004", value: "100" // something that does not exist in your dataset }); wfs.style = OpenLayers.Util.applyDefaults({ fillColor: "#009900" }, OpenLayers.Feature.Vector.style["default"]); wfs.filter = queryFilter; wfs.redraw(); } filter not work but browser have not error
    – Ihenry
    Oct 9, 2015 at 3:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.