[OpenLayers-Users] rules depending on state

Pierre GIRAUD bluecarto at gmail.com
Tue May 13 10:56:42 EDT 2008


Yep,
I already tried that and this works great.
However, what if I want to set fillColor, strokeColor, fillOpacity and
strokeOpacity at the same time ? This is really painful.
And it seems like I need to provide a valid value for each possible
value of state. Default style won't be applied to features that aren't
in the switch cases.

I would prefer something like :
var lookup = {
    'Insert': {
        fillColor: 'green',
        fillOpacity: 0.5
    },
    ...
};

Regards,
Pierre


On Tue, May 13, 2008 at 4:35 PM, Andreas Hocevar
<andreas.hocevar at gmail.com> wrote:
> Hey Pierre,
>
>  without having tried, something like the following should work:
>
>  var context = {
>    getStateColor: function(feature) {
>        switch(feature.state) {
>            case "Insert": return "green";
>            case "Update": return "yellow";
>            case "Delete": retrun "red";
>        }
>    }
>  }
>
>  var styleMap = new OpenLayers.StyleMap(new OpenLayers.Style({
>    strokeColor: "${getStateColor}"
>  }, {context: context}));
>
>  Regards,
>  Andreas.
>
>
>  Pierre GIRAUD wrote:
>
> >
> >
> >
> > Hello OpenLayers styleMap gurus,
> >
> > I would like to have different symbolizers for the features depending
> > on their state property.
> > The addUniqueValueRules would look perfect for that but the context of
> > the generated rules is feature.attributes. The state will not be
> > evaluated because it's not one of those attributes.
> >
> > Has anyone a workaround to advice ?
> >
> > Regards,
> >
> > Pierre
> > _______________________________________________
> > Users mailing list
> > Users at openlayers.org
> > http://openlayers.org/mailman/listinfo/users
> >
> >
>
>



More information about the Users mailing list