[OpenLayers-Users] Drawing Colored Shapes "The Right Way"

wls wls at wwco.com
Fri May 13 15:37:53 EDT 2011


I'm looking for advice on the "right" way to draw to the map -- I'm new to
OpenLayers and am untangling some inherited code that can't possibly be
right.  Things "work" but for the wrong reason.

I have a layer, it has a custom StyleMap with 
http://docs.openlayers.org/library/feature_styling.html lots of rules , and
when a Feature is drawn to it, the getters in the StyleMap look at the
passed in feature's .attributes property dictionary, and use the values
there to show shapes on the map.  That's good, and the long term goal is to
use this universal StyleMap I'm making.

Some drawing code, which I'm happy with, activates a handler, which draws a
shape, and when done, invokes a callback, which takes that feature and
attaches the user-defined attributes to it, and when rendering happens (see
above), all's good.

However, some other drawing code gets properties from the user, builds a
local StyleMap, and when it's getters are invoked, it actually modifies the
passed in object!  It's like there's intimate implementation knowledge
knowing that if the style map is being used, the object is drawing, and in a
state that can be altered.  This. Just. Doesn't. Feel. Right.

What I'm expecting is that OpenLayers has a way to say "I know you're about
to draw a shape, and that shape doesn't exist yet, but when you're about to
create it, could you make this its .attributes property, because the layer
you're drawing to is going to need it."

All that said, I'm fairly new to the darker corners of OpenLayers, and I've
been searching for examples online -- most are concerned with setting up
handlers or how to use a StyleMap -- but I think I'm looking for something
that demonstrates the order to do things without having to revert to hacking
side-effects into getters (unless I've totally misunderstood that StyleMaps
are not passive-only objects).

Thanks,
-Walt Stoneburner (wls at wwco.com)

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Drawing-Colored-Shapes-The-Right-Way-tp6360813p6360813.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list