[OpenLayers-Dev] Fwd: [OpenLayers-Trac] Is it possible to set rules with value extracted wfs data?

Tim Schaub tschaub at opengeo.org
Thu Sep 25 17:41:40 EDT 2008


Hey-

Erik Uzureau wrote:
> ---------- Forwarded message ----------
> Date: Thu, Sep 25, 2008 at 2:09 PM
> Subject: [OpenLayers-Trac] Is it possible to set rules with value
> extracted wfs data?
> To: trac at openlayers.org
> 
> 
> Hi,
> 
> I am new the list (and to openLayers) and have a question I can't find
> an answer to in the posts.
> 
> I am set up rules to adjust the point Radius based on a value
> extracted, but it would be easier to just use the value directly.  Is
> this possible?
> 
> Current Code:
> var distSize = new Array(); distSize = { 0: {pointRadius: 1}, 1:
> {pointRadius: 1}, 2: {pointRadius: 2}, 3: {pointRadius: 3}, 4:
> {pointRadius: 4}, 5: {pointRadius: 5} }
> 
> var distStyles = new OpenLayers.StyleMap();
> distStyles.addUniqueValueRules("default","size",distSize);
> 
> I would prefer something like
> distStyles.addUniqueValueRules("default",pointRadius = "Size Supplied
> from WFS");

Depends on what your feature attribute values are.

If you have something like this:

 >>> feature.attributes.radius
7

Then you create a style map like this:

var styleMap = new OpenLayers.StyleMap({
     "default": {
             fillColor: "olive",
	    pointRadius: "${radius}"
      }
});

If you have a feature with attribute values that are named colors (CSS 
supported colors) or RGB hex values (prefixed with #), then you use a 
similar template for your fillColor property.

             fillColor: "${attrName}"

If you have an attribute value that is not exactly the value that you 
want for one of the symbolizer's property values - you need to use some 
sort of expression to transform your attribute value into the 
appropriate symbolizer property value.

We don't currently support all of the OGC Expressions that can be used 
in SLD.  Instead, we allow you to create style objects with some context 
object.  Symbolizer property values will be evaluated with that context. 
  So, if one of your context properties is a function, it will receive 
the feature and can return some value based on anything about the feature.

See the styles-context.html [1] example for inspiration.  For an example 
of the type of symbolizer property evaluation shown above, see the 
styles-rotation.html [2] example.

Tim

[1] http://openlayers.org/dev/examples/styles-rotation.html
[2] http://openlayers.org/dev/examples/styles-context.html

> 
> It is somewhat trivial to set up an array for pointRadius, but I would
> like to be able to set the colors the same way.
> 
> Thanks!
> 
> Ben
> 
> _______________________________________________
> Trac mailing list
> Trac at openlayers.org
> http://openlayers.org/mailman/listinfo/trac
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev


-- 
Tim Schaub
OpenGeo - http://opengeo.org
Expert service straight from the developers.



More information about the Dev mailing list