[OpenLayers-Users] Re: Drawing Colored Shapes "The Right Way" (code sample)

wls wls at wwco.com
Mon May 16 10:12:36 EDT 2011


In my prior question, 
http://osgeo-org.1803224.n2.nabble.com/Drawing-Colored-Shapes-quot-The-Right-Way-quot-td6360813.html
Drawing Colored Shapes "The Right Way" , I was curious to know if, as I
think they are, StyleMaps are supposed to be read-only mechanisms with no
side-effects.


Seeing some code may help:

styleMap = new OpenLayers.StyleMap({
  "default": new OpenLayers.Style({
      fillColor: "${getFillColor}", // call the context's method
    }, {
      context: {
        getFillColor: function (feature) {
          if (typeof feature.attributes.fillColor === "undefined" ||
feature.attributes.fillColor === null) {
            feature.attributes.fillColor = desiredColorFromScopeClosure;
            return desiredColorFromScopeClosure;
          } else {
            return feature.attributes.fillColor;
          }
        }
      }
    }
  });


I'm not happy that the code I inherited changes feature in the middle of a
getter.  But this seems to be the only way the author knew how to set
attributes.fillColor prior to drawing.


I'd like to not have to use one StyleMap to draw and another to render.


-Walt Stoneburner, wls at wwco.com


--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Drawing-Colored-Shapes-The-Right-Way-tp6360813p6368817.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110516/8046c050/attachment.html


More information about the Users mailing list