[OpenLayers-Dev] Feature.style doesn't support contexts

Cédric Moullet cedric.moullet at camptocamp.com
Sat Jan 16 01:12:35 EST 2010


Hi Eric,
Thanks for your answer.

However, I'm not sure that I have really understand it. The goal is to set a
style to one feature (to assign feature.style).
I assume that the example
http://www.openlayers.org/dev/examples/symbolizers-fill-stroke-graphic.html
corresponds
to the new way of symbolizing feature. Is it correct ?

What is not clear to me is how to assign a style to a specific feature.
There is a function createSymbolizer(feature) in Style.js (
http://trac.openlayers.org/browser/trunk/openlayers/lib/OpenLayers/Style.js#L148)
and a function createSymbolizer(feature, intent) in StyleMap.js
http://trac.openlayers.org/browser/trunk/openlayers/lib/OpenLayers/StyleMap.js#L108


You proposed to use styleMap.createSymbolizer(feature), shouldn't it be
styleMap.createSymbolizer(feature, intent) ?

This implies that in order to manage "free style", it is required to add a
Style in the StyleMap and assign to feature.style this style. Is it correct
?

In the specific label case, the style needs to contain a rule's symbolizer
with a label property:
styleMap: new OpenLayers.StyleMap({
                    'default': new OpenLayers.Style(null, {
                        rules: [
                            new OpenLayers.Rule({
                                symbolizer: {
                                    graphic: false,
                                    *label: "$(labelAttribute)**",*
                                    labelSelect: true
                                }

Is it correct ?

I have probably missunderstood one key styling concept, so sorry for my
dummy questions.

Cédric
On Fri, Jan 15, 2010 at 11:05 PM, Eric Lemoine
<eric.lemoine at camptocamp.com>wrote:

> On Fri, Jan 15, 2010 at 8:10 PM, Alexandre Dube <adube at mapgears.com>
> wrote:
> > Hi,
> >
> >  I want to be able to save a OpenLayers.Style object or hash to a
> > vector feature.  Currently, in code, feature.style exists but you must
> > define a hash or else it doesn't work.
> >
> >  My problem is that I want to be able to draw features to be used as
> > labels (floating text on the map).  To be able to do so, I need to
> > define a StyleMap with a context to display the label (I manually set
> > feature.isLabel on "featureadded") [1]
> >
> >  That works well, but as soon as I want to "bind / save" the style to
> > the feature, I mean set feature.style,
>
> feature.style is for the old way of styling features
>
> > I need to set a hash and the
> > feature will be rendered without the contexts.
>
> if you want to get the symbolizer (style hash) of a feature use
> styleMap.createSymbolizer(feature, intent).
>
>
> >  I don't fully understand how the contexts, symbolizers, etc. work, but
> > my first guess would be to support OpenLayers.Style object directly in
> > the feature object.  Does that make sense ?
> >
> >  Or maybe I'm doing it wrong and their's an other way of "labeling"
> > features.  My goal is to create features on a "cosmetic" layer with a
> > default style, then to be able to change the style of the features and
> > bind it to them (I mean without using rules on the layer level, but by
> > defining directly the feature style)
>
> I guess binding a symbolizer to a feature can only be done with
> feature.style. So feature.style = styleMap.createSymbolizer(feature)
> may be what you're looking for.
>
> Cheers,
> --
> Eric Lemoine
>
> Camptocamp France SAS
> Savoie Technolac, BP 352
> 73377 Le Bourget du Lac, Cedex
>
> Tel : 00 33 4 79 44 44 96
> Mail : eric.lemoine at camptocamp.com
> http://www.camptocamp.com
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
>



-- 
CTO Geospatial Camptocamp SA
Cédric Moullet
PSE A
CH-1015 Lausanne
www.camptocamp.com  / www.mapfish.org / twitter.com/cedricmoullet /
mapfishblog.blogspot.com/

+41 79 759 69 83 (mobile)
+41 21 619 10 21 (direct)
+41 21 619 10 10 (centrale)
+41 21 619 10 00 (fax)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20100116/5532e921/attachment.html


More information about the Dev mailing list