0

Can I make a rule in Openlayers2.13 in which I will have multiple properties and values? This is what I have now:

new OpenLayers.Rule({
        name: "NORTH",
        filter: new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.EQUAL_TO,
        property: "owner", // name of column in table
        value: "NORTH" }),
        symbolizer: {
                pointRadius: "4",
                fillColor: "#FF0000",
                strokeOpacity: ".8",
                strokeWidth: "1"    
                }
        })

And I need to have something like this:

new OpenLayers.Rule({
        name: "NORTH",
        filter: new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.EQUAL_TO,
        property: "column_I","column_II" // name of column in table
        values: ["NORTH","something_else"] }),
        symbolizer: {
                pointRadius: "4",
                fillColor: "#FF0000",
                strokeOpacity: ".8",
                strokeWidth: "1"    
                }
        })
1

You can combine multiple filters with OpenLayers.Filter.Logical.OR like this:

var rule_filters = [
    new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.EQUAL_TO,
        property: "NAME",
        value: "Young"
    }),
    new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.EQUAL_TO,
        property: "NAME",
        value: 'Wilcannia'
    })];

    var parent_rule_filter = new OpenLayers.Filter.Logical({
        type: OpenLayers.Filter.Logical.OR,
        filters: rule_filters
    });


var rule=
        new OpenLayers.Rule({
        name: "NORTH",
        filter: parent_rule_filter,
        symbolizer: {
                pointRadius: "6",
                fillColor: "#FFFF00",
                strokeColor:"#0000FF",
                strokeOpacity: ".8",
                strokeWidth: "3"    
                }
        });

var layer = new OpenLayers.Layer.Vector("WFS", {

        strategies: [new OpenLayers.Strategy.BBOX()],
        protocol: new OpenLayers.Protocol.WFS({
            url: "http://demo.opengeo.org/geoserver/wfs",
            featureType: "ne_10m_populated_places",
            featureNS: "http://openstreemap.org"
        }),     
        styleMap: new OpenLayers.StyleMap({
            'default': new OpenLayers.Style(null, {
                rules: [rule]
            })
        })
});

Example: http://jsfiddle.net/expedio/c62LqwcL/

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.