[OpenLayers-Users] Rule Filter and Context

Arnaud Vandecasteele arnaud.sig at gmail.com
Wed Jul 21 10:05:57 EDT 2010


Hi All,

I'm trying to use a Rule with an context object.
The rule without the context object works fine. But each time I try to
define a context the rule is no more applies.
Do you know what I am doing wrong ?

Here is my code. In this one I would like to apply a specific style
when the features are clustered and a normal style when they are not.

var oStyle = new OpenLayers.Style();

var oStyleMap = new OpenLayers.StyleMap({
            "default": oStyle
});

var ctx = {
    'radius' :function(feature){
        console.log(oStyle);
        if (feature.attributes.count>1){
            return Math.min(feature.attributes.count,7) + 4;
        }
    }
};
var noCluster = new OpenLayers.Rule({
    elseFilter: true,
    filter: new OpenLayers.Filter.Comparison({
      type: OpenLayers.Filter.Comparison.EQUAL_TO,
      property: "count",
      value: 1
    }),
    symbolizer: {pointRadius: '3', fillColor: "red",
               fillOpacity: 0.7, strokeColor: "black"}
});

 var cluster = new OpenLayers.Rule({
    context : ctx,
    elseFilter: true,
    filter: new OpenLayers.Filter.Comparison({
      type: OpenLayers.Filter.Comparison.GREATER_THAN,
      property: "count",
      value: 1
    }),
    symbolizer: {pointRadius: '${radius}', fillColor: "green",
               fillOpacity: 0.7, strokeColor: "black"}
});


oStyle.addRules([noCluster, cluster]);


var vessels =   new OpenLayers.Layer.Vector("vessels", {
                        strategies:[
                           new OpenLayers.Strategy.Cluster()
                        ],
                        styleMap: oStyleMap
                });

Thanks your help.

Regards

Arnaud



More information about the Users mailing list