[OpenLayers-Users] rules depending on state

Pierre GIRAUD bluecarto at gmail.com
Wed May 14 03:06:09 EDT 2008


I don't think this is that simple.
To me, we can't define a context in addUniqueValueRules because it has
no knowledge of individual features.
I can't find any example where a context is defined at OpenLayers.Rule
instantiation.

Pierre

On Tue, May 13, 2008 at 8:18 PM, Andreas Hocevar
<andreas.hocevar at gmail.com> wrote:
> Pierre GIRAUD wrote:
>
> > 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
> >    },
> >    ...
> > };
> >
> >
>
>  In that case, we would have to add a context option to
> StyleMap.addUniqueValueRules. Should be no big deal. Can you please create a
> ticket so we don't forget that me might want to do that?
>
>  Regards,
>  Andreas.
>
>
>
>
> > 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
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > _______________________________________________
> > Users mailing list
> > Users at openlayers.org
> > http://openlayers.org/mailman/listinfo/users
> >
> >
>
>



More information about the Users mailing list