[OpenLayers-Dev] rules and filters. i'm confused [solved]

Dejung Gewissler dejung.gewissler at oit.state.nj.us
Fri May 23 14:17:02 EDT 2008

I am pretty sure that the styling classes and data formats are separate 
because I actually use GML also in a similar fashion. It seems that the 
difference now is in the Rule class. Before the filters were in the Rule 
class, but now they have moved to a Filter class. That was my problem.

The example below uses the new Filter class and since you are using 
OpenLayers.Layer.GML it expects the data to be in GML (unless you 
specify a different format like I did previously).

    var selectStyle = new OpenLayers.Style({"strokeColor": "red", 
"strokeOpacity": 1, "strokeWidth": 3, "strokeLinecap": "round"});
    var c_style = new OpenLayers.Style();
    var c_l = new OpenLayers.Rule({
        filter: new OpenLayers.Filter.Comparison({
            type: OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO,
            property: "pop2000",
            value: 44000
        symbolizer: {
            Polygon: {fillColor: "#FFFF00", strokeColor: "blue"}
    var c_else = new OpenLayers.Rule({
        elseFilter: true,
        symbolizer: {
            Polygon: {fillColor: "#0000FF", strokeColor: "blue"}

    c_style.addRules([c_l, c_else]);
    var cLayer = new OpenLayers.Layer.GML("Counties", "data/counties.txt",
            styleMap: new OpenLayers.StyleMap({
                "default": c_style,
                "select": selectStyle})       

Hope that helps,

Garthanos wrote:
> So basically you solved this issue by switching to GeoJSON Layer Type.. I
> need the GML layer to work or the WFS layer to integrate filters (as well as
> bbox)
> Basically seems like the GML Layer type in 2.6 has no styling capability is
> that correct?

More information about the Dev mailing list