[OpenLayers-Commits] r5137 - in sandbox/camptocamp/text: examples examples/xml lib/OpenLayers lib/OpenLayers/Format lib/OpenLayers/Layer lib/OpenLayers/Rule

commits at openlayers.org commits at openlayers.org
Wed Nov 7 03:39:48 EST 2007


Author: pgiraud
Date: 2007-11-07 03:39:47 -0500 (Wed, 07 Nov 2007)
New Revision: 5137

Modified:
   sandbox/camptocamp/text/examples/georss-category.xml
   sandbox/camptocamp/text/examples/georss.html
   sandbox/camptocamp/text/examples/gml-tasmania-sld.html
   sandbox/camptocamp/text/examples/vector-features-with-text.html
   sandbox/camptocamp/text/examples/xml/sld-tasmania.xml
   sandbox/camptocamp/text/lib/OpenLayers/Format/SLD.js
   sandbox/camptocamp/text/lib/OpenLayers/Layer/TileCache.js
   sandbox/camptocamp/text/lib/OpenLayers/Layer/Vector.js
   sandbox/camptocamp/text/lib/OpenLayers/Rule.js
   sandbox/camptocamp/text/lib/OpenLayers/Rule/Comparison.js
   sandbox/camptocamp/text/lib/OpenLayers/Style.js
Log:
applied recent modifications made by Andreas in the sldRenderer
the Style.js file is now the exact copy of the one in sldRenderer
it includes the generic createLiteral method

Modified: sandbox/camptocamp/text/examples/georss-category.xml
===================================================================
--- sandbox/camptocamp/text/examples/georss-category.xml	2007-11-06 23:23:43 UTC (rev 5136)
+++ sandbox/camptocamp/text/examples/georss-category.xml	2007-11-07 08:39:47 UTC (rev 5137)
@@ -22,6 +22,7 @@
 <link>http://platial.com/place/62200</link>
 <title>Allen Hall</title>
 <description><![CDATA[My dorm at UIUC.<br/>Address: 1301 W Gregory Dr, Urbana, IL<br/>Tags: dorm, uiuc, college<br/><a href="http://platial.com/place/62200"><img src="http://platial.comhttp://static.flickr.com/4/8576450_0d59cc2531_s.jpg"/></a><br/><br /><br /><a href="http://platial.com/place/62200">Map this on Platial</a><br /> <a href="http://platial.com/place_grab/62200">Grab this on Platial</a> ]]></description>
+<category>gold</category>
 <georss:point>40.104172 -88.220623</georss:point>
 <dc:creator>crschmidt</dc:creator>
 <dc:date>2006-04-14T08:01:01.872873+00:00</dc:date>

Modified: sandbox/camptocamp/text/examples/georss.html
===================================================================
--- sandbox/camptocamp/text/examples/georss.html	2007-11-06 23:23:43 UTC (rev 5136)
+++ sandbox/camptocamp/text/examples/georss.html	2007-11-07 08:39:47 UTC (rev 5137)
@@ -12,6 +12,12 @@
         var map, layer;
 
         var style = new OpenLayers.Style();
+        
+        // by default, use the category as part of the image name for styling
+        style.defaultStyle.externalGraphic = "../img/marker-${category}.png";
+        
+        // define rules for pre-defined categories to style with specific
+        // markers
         var rule = new OpenLayers.Rule.Comparison({
                 type: OpenLayers.Rule.Comparison.Type.EQUAL_TO,
                 property: 'category'});
@@ -48,7 +54,7 @@
    GeoRSS URL: <input type="text" id="url" size="50" /><input type="submit" onclick="addUrl(); return false;" value="Load Feed" onsubmit="addUrl(); return false;" />
     </form>  
     <p>The above input box allows the input of a URL to a GeoRSS feed. This feed can be local to the HTML page -- for example, entering 'georss.xml' will work by default, because there is a local file in the directory called georss.xml -- or, with a properly set up ProxyHost variable (as is used here), it will be able to load any HTTP URL which contains GeoRSS and display it. Anything else will simply have no effect.</p>    
-    <p>Entering 'georss-category.xml' in the above input box will load a feed with a 'category' property for some items. The example is configured with style objects to render the items with different icons, depending on the category.</p>
+    <p>Entering 'georss-category.xml' in the above input box will load a feed with a 'category' property for some items. The example is configured with style rules to render the items with different icons, depending on the category. The golden marker is directly created by looking at the category of the item, the others are lookup values inside rules.</p>
     <div id="map"></div>
   </body>
 </html>

Modified: sandbox/camptocamp/text/examples/gml-tasmania-sld.html
===================================================================
--- sandbox/camptocamp/text/examples/gml-tasmania-sld.html	2007-11-06 23:23:43 UTC (rev 5136)
+++ sandbox/camptocamp/text/examples/gml-tasmania-sld.html	2007-11-07 08:39:47 UTC (rev 5137)
@@ -33,19 +33,21 @@
                     new OpenLayers.Layer.GML("StateBoundaries",
                             "tasmania/TasmaniaStateBoundaries.xml",
                             {style: sld["Default Styler"]}),
-                    // use the style from the sld NamedLayer "Roads"
-                    // that is marked "IsDefault"
                     new OpenLayers.Layer.GML("Roads",
-                            "tasmania/TasmaniaRoads.xml",
-                            {style: sld}),
+                            "tasmania/TasmaniaRoads.xml"),
 			              new OpenLayers.Layer.GML("WaterBodies",
-                            "tasmania/TasmaniaWaterBodies.xml",
-                            {style: sld}),
+                            "tasmania/TasmaniaWaterBodies.xml"),
                     new OpenLayers.Layer.GML("Cities",
-                            "tasmania/TasmaniaCities.xml",
-                            {style: sld})];
+                            "tasmania/TasmaniaCities.xml")];
  
-            for (var i=0; i<gmlLayers.length; i++) {
+            // add the first layer with the style passed to the constructor
+            map.addLayer(gmlLayers[0]);
+            // add the other layers after setting the style using the
+            // setStyle() method, which will pick the correct default style
+            // from the styles hash we got back from
+            // OpenLayers.Format.SLD.read()
+            for (var i=1; i<gmlLayers.length; i++) {
+                gmlLayers[i].setStyle(sld);
 			          map.addLayer(gmlLayers[i]);
             }
             

Modified: sandbox/camptocamp/text/examples/vector-features-with-text.html
===================================================================
--- sandbox/camptocamp/text/examples/vector-features-with-text.html	2007-11-06 23:23:43 UTC (rev 5136)
+++ sandbox/camptocamp/text/examples/vector-features-with-text.html	2007-11-07 08:39:47 UTC (rev 5137)
@@ -26,7 +26,7 @@
                 fillOpacity: 0.5,
                 pointRadius: 6,
                 pointerEvents: "visiblePainted",
-                label : "name: {name}, age: {age}",
+                label : "name: ${name}, age: ${age}",
                 fontColor: "red",
                 fontWeight: "bold"
             };

Modified: sandbox/camptocamp/text/examples/xml/sld-tasmania.xml
===================================================================
--- sandbox/camptocamp/text/examples/xml/sld-tasmania.xml	2007-11-06 23:23:43 UTC (rev 5136)
+++ sandbox/camptocamp/text/examples/xml/sld-tasmania.xml	2007-11-07 08:39:47 UTC (rev 5137)
@@ -27,16 +27,14 @@
           <sld:MaxScaleDenominator>3000000</sld:MaxScaleDenominator>
           <sld:PolygonSymbolizer>
             <sld:Fill>
-              <sld:CssParameter name="fill">
-                <ogc:Literal>blue</ogc:Literal>
-              </sld:CssParameter>
+              <sld:CssParameter name="fill">blue</sld:CssParameter>
               <sld:CssParameter name="fill-opacity">
                 <ogc:Literal>1.0</ogc:Literal>
               </sld:CssParameter>
             </sld:Fill>
             <sld:Stroke>
               <sld:CssParameter name="stroke">
-                <ogc:Literal>#808080</ogc:Literal>
+                <ogc:Literal>#C0C0C0</ogc:Literal>
               </sld:CssParameter>
               <sld:CssParameter name="stroke-linecap">
                 <ogc:Literal>butt</ogc:Literal>

Modified: sandbox/camptocamp/text/lib/OpenLayers/Format/SLD.js
===================================================================
--- sandbox/camptocamp/text/lib/OpenLayers/Format/SLD.js	2007-11-06 23:23:43 UTC (rev 5136)
+++ sandbox/camptocamp/text/lib/OpenLayers/Format/SLD.js	2007-11-07 08:39:47 UTC (rev 5137)
@@ -231,7 +231,7 @@
      * xmlNode - {<DOMElement>}
      * 
      * Returns:
-     * {String} JavaScript eval'able boolean snippet
+     * {<OpenLayers.Rule>} rule representing the filter
      */
     parseFilter: function(xmlNode) {
         var nodeName = (xmlNode.prefix) ?
@@ -385,43 +385,33 @@
             }
             
             // get the property value from the node matching attributeName
-            // and attributeValue
+            // and attributeValue, eg.:
+            // <CssParameter name="stroke">
+            //     <ogc:Literal>red</ogc:Literal>
+            // </CssParameter>
+            // or:
+            // <CssParameter name="stroke">red</CssParameter>
             if (attributeName && attributeValue) {
                 propertyNode = this.getNodeWithAttribute(propertyNodeList,
                         attributeName, attributeValue);
-                result = propertyNode ?
-                        propertyNode.text || propertyNode.textContent : null;
+                result = this.parseParameter(propertyNode);
             }
 
-            // get the attribute value and use it as result
+            // get the attribute value and use it as result, eg.:
+            // <sld:OnlineResource xlink:href="../img/marker.png"/>
             if (attributeName && !attributeValue) {
                 var propertyNode = this.getNodeWithAttribute(propertyNodeList,
                         attributeName);
                 result = propertyNode.getAttribute(attributeName);                
             }
             
+            // get the property value directly or from an ogc:propertyName,
+            // ogc:Literal or any other property at the level of the property
+            // node, eg.:
+            // <sld:Opacity>0.5</sld:Opacity>
             if (!attributeName) {
-
-                // get the property value from the textContent of the first
-                // node
-                propertyNode = propertyNodeList[0];
-                result = propertyNode.text || propertyNode.textContent;
-
-                // get the property value from an ogc:Literal at the level of
-                // the property node.
-                if (!result) {
-                    var result = this.parseProperty(
-                            propertyNode, this.ogcns, "Literal");
-                }
-                
-                // finally, get the property value from an ogc:Literal at the
-                // same level as the xmlNode
-                if (!result) {
-                    var result = this.parseProperty(xmlNode, this.ogcns,
-                            "Literal");
-                }
+                var result = this.parseParameter(propertyNode);
             }
-            
         }
         
         // adjust the result to be a trimmed string or a number
@@ -436,6 +426,41 @@
     },
     
     /**
+     * Method: parseParameter
+     * parses a property for propertyNames, Literals and textContent and
+     * creates the according value string.
+     * 
+     * Parameters:
+     * xmlNode - {<DOMElement>}
+     * 
+     * Returns:
+     * {String} a string holding a value suitable for OpenLayers.Style.value
+     */
+    parseParameter: function(xmlNode) {
+        if (!xmlNode) {
+            return null;
+        }
+        var childNodes = xmlNode.childNodes;
+        if (!childNodes) {
+            return null;
+        }
+
+        var value = new Array(childNodes.length);
+        for (var i=0; i<childNodes.length; i++) {
+            if (childNodes[i].nodeName.indexOf("Literal") != -1) {
+                value[i] = this.getChildValue(childNodes[i]);
+            } else
+            if (childNodes[i].nodeName.indexOf("propertyName") != -1) {
+                value[i] = "${" + this.getChildValue(childNodes[i]) + "}";
+            } else
+            if (childNodes[i].nodeType == 3) {
+                value[i] = childNodes[i].text || childNodes[i].textContent;
+            }
+        }
+        return value.join("");
+    },
+        
+    /**
      * Method: getNodeWithAttribute
      * Walks through a list of xml nodes and returns the fist node that has an
      * attribute with the name and optional value specified.

Modified: sandbox/camptocamp/text/lib/OpenLayers/Layer/TileCache.js
===================================================================
--- sandbox/camptocamp/text/lib/OpenLayers/Layer/TileCache.js	2007-11-06 23:23:43 UTC (rev 5136)
+++ sandbox/camptocamp/text/lib/OpenLayers/Layer/TileCache.js	2007-11-07 08:39:47 UTC (rev 5137)
@@ -8,7 +8,10 @@
  *
  * Class: OpenLayers.Layer.TileCache
  * A read only TileCache layer.  Used to requests tiles cached by TileCache in
- *     a web accessible cache.  Create a new instance with the
+ *     a web accessible cache.  This means that you have to pre-populate your
+ *     cache before this layer can be used.  It is meant only to read tiles
+ *     created by TileCache, and not to make calls to TileCache for tile
+ *     creation.  Create a new instance with the
  *     <OpenLayers.Layer.TileCache> constructor.
  *
  * Inherits from:
@@ -41,7 +44,8 @@
      *
      * Parameters:
      * name - {String} Name of the layer displayed in the interface
-     * url - {String} Location of the web accessible cache
+     * url - {String} Location of the web accessible cache (not the location of
+     *     your tilecache script!)
      * layername - {String} Layer name as defined in the TileCache 
      *     configuration
      * options - {Object} Hashtable of extra options to tag onto the layer

Modified: sandbox/camptocamp/text/lib/OpenLayers/Layer/Vector.js
===================================================================
--- sandbox/camptocamp/text/lib/OpenLayers/Layer/Vector.js	2007-11-06 23:23:43 UTC (rev 5136)
+++ sandbox/camptocamp/text/lib/OpenLayers/Layer/Vector.js	2007-11-07 08:39:47 UTC (rev 5137)
@@ -58,15 +58,10 @@
     reportError: true, 
 
     /** 
-     * APIProperty: style
-     * {Object} or {<OpenLayers.Style>} or {Hash of <OpenLayers.Style>}
+     * Property: style
+     * {<OpenLayers.Style>} or {Hash of <OpenLayers.Style>}
      * Default style for the layer.
-     * Thie is either a hash of style properties, or, if the features
-     * should be styled using sld, a complex style object or an array of such.
-     * A hash of OpenLayers.Style is created using the
-     * OpenLayers.Format.SLD.read() method.
-     * If the passed style is a hash of <OpenLayers.Style>, the style matching
-     * the layerName will be applied if the sld:IsDefault property is set to 1.
+     * Thie is either a hash of style properties or a complex style object.
      */
     style: null,
     
@@ -256,8 +251,7 @@
             features = [features];
         }
 
-        var style = this.getDefaultStyle();
-        var cloneStyle = !(style instanceof OpenLayers.Style);
+        var cloneStyle = !(this.style instanceof OpenLayers.Style);
 
         for (var i = 0; i < features.length; i++) {
             var feature = features[i];
@@ -276,7 +270,7 @@
 
             if (!feature.style) {
                 feature.style = cloneStyle ?
-                        OpenLayers.Util.extend({}, style) : style;
+                        OpenLayers.Util.extend({}, this.style) : this.style;
             }
 
             this.preFeatureInsert(feature);
@@ -370,24 +364,27 @@
 
     /**
      * APIMethod: getDefaultStyle
-     * If this layer's style property is a hash of OpenLayers.Style, this
+     * If the passed style is a hash of {<OpenLayers.Style>}, this
      * method will return the style that matches the LayerName and has an
      * IsDefault property. Otherwise, this layer's style will be returned
      * as-is. This method mimics the behavior of a WMS that chooses the style
      * by sld:NamedLayer and sld:IsDefault, according to the SLD specification.
      * 
+     * Parameters:
+     * style - {<OpenLayers.Style>} or {Array(<OpenLayers.Style>)} or hash of
+     *         style properties. 
+     * 
      * Returns:
      * {<OpenLayers.Style>} or hash of style properties
-     * 
      */
-    getDefaultStyle: function() {
-        for (var i in this.style) {
-            if (this.style[i] instanceof OpenLayers.Style) {
-                if (this.style[i].layerName == this.name) {
-                    return this.style[i];
+    getDefaultStyle: function(style) {
+        for (var i in style) {
+            if (style[i] instanceof OpenLayers.Style) {
+                if (style[i].layerName == this.name) {
+                    return style[i];
                 }
             } else {
-                return this.style;
+                return style;
             }
         }
     },
@@ -395,22 +392,24 @@
     /**
      * APIMethod: setStyle
      * Sets the style for the layer and its features. This function can be
-     * used to change the style after the layer has been created. It will
-     * apply the new style to this layer and its features and redraw the layer.
+     * used to set the style, even after the layer has been created or drawn.
+     * It will apply the new style to this layer and its features and redraw
+     * the layer if necessary. If a hash of {<OpenLayers.Style>} is passed,
+     * this method will also determine the correct style that matches the
+     * layer name and has an isDefault property, according to the sld
+     * specification.
      * 
      * Parameters:
      * style - {<OpenLayers.Style>}, {Hash of <OpenLayers.Style>} or hash of
      *         style properties.
      */
     setStyle: function(style) {
-        this.style = style;
-        
-        var styleToApply = this.getDefaultStyle();
-        var cloneStyle = !(styleToApply instanceof OpenLayers.Style);
+        this.style = this.getDefaultStyle(style);
+        var cloneStyle = !(this.style instanceof OpenLayers.Style);
 
         for (var i=0; i<this.features.length; i++) {
             this.features[i].style = cloneStyle ?
-                    OpenLayers.Util.extend({}, styleToApply) : styleToApply;
+                    OpenLayers.Util.extend({}, this.style) : this.style;
         }
                
         this.redraw();

Modified: sandbox/camptocamp/text/lib/OpenLayers/Rule/Comparison.js
===================================================================
--- sandbox/camptocamp/text/lib/OpenLayers/Rule/Comparison.js	2007-11-06 23:23:43 UTC (rev 5136)
+++ sandbox/camptocamp/text/lib/OpenLayers/Rule/Comparison.js	2007-11-07 08:39:47 UTC (rev 5137)
@@ -5,6 +5,7 @@
 
 /**
  * @requires: OpenLayers/Rule.js
+ * @requires: OpenLayers/Style.js
  *
  * Class: OpenLayers.Rule.Comparison
  * 
@@ -18,7 +19,7 @@
 
     /**
      * APIProperty: type
-     * {<OpenLayers.Rule.Logical.Type>} type: type of the comparison.
+     * {<OpenLayers.Rule.Comparison.Type>} type: type of the comparison.
      */
     type: null,
     
@@ -32,21 +33,27 @@
     /**
      * APIProperty: value
      * {Number} or {String}
-     * comparison value for binary comparisons
+     * comparison value for binary comparisons. In the case of a String, this
+     * can be a combination of text and propertyNames in the form
+     * "literal ${propertyName}"
      */
     value: null,
     
     /**
      * APIProperty: lowerBoundary
      * {Number} or {String}
-     * lower boundary for between comparisons
+     * lower boundary for between comparisons. In the case of a String, this
+     * can be a combination of text and propertyNames in the form
+     * "literal ${propertyName}"
      */
     lowerBoundary: null,
     
     /**
      * APIProperty: upperBoundary
      * {Number} or {String}
-     * upper boundary for between comparisons
+     * upper boundary for between comparisons. In the case of a String, this
+     * can be a combination of text and propertyNames in the form
+     * "literal ${propertyName}"
      */
     upperBoundary: null,
 
@@ -87,16 +94,23 @@
             case OpenLayers.Rule.Comparison.Type.GREATER_THAN:
             case OpenLayers.Rule.Comparison.Type.LESS_THAN_OR_EQUAL_TO:
             case OpenLayers.Rule.Comparison.Type.GREATER_THAN_OR_EQUAL_TO:
-                return this.binaryCompare(feature, this.property, this.value);
+                return this.binaryCompare(feature, this.property,
+                        OpenLayers.Style.createLiteral(this.value, feature));
             
             case OpenLayers.Rule.Comparison.Type.BETWEEN:
                 var result =
-                        attributes[this.property] > this.lowerBoundary;
+                        attributes[this.property] >
+                                OpenLayers.Style.createLiteral(
+                                        this.lowerBoundary, feature);
                 result = result &&
-                        attributes[this.property] < this.upperBoundary;
+                        attributes[this.property] <
+                                OpenLayers.Style.createLiteral(
+                                        this.upperBoundary, feature);
                 return result;
             case OpenLayers.Rule.Comparison.Type.LIKE:
-                var regexp = new RegExp(this.value, "gi");
+                var regexp = new RegExp(
+                        OpenLayers.Style.createLiteral(this.value, feature),
+                                "gi");
                 return regexp.test(attributes[this.property]); 
         }
     },

Modified: sandbox/camptocamp/text/lib/OpenLayers/Rule.js
===================================================================
--- sandbox/camptocamp/text/lib/OpenLayers/Rule.js	2007-11-06 23:23:43 UTC (rev 5136)
+++ sandbox/camptocamp/text/lib/OpenLayers/Rule.js	2007-11-07 08:39:47 UTC (rev 5137)
@@ -25,13 +25,17 @@
     
     /**
      * APIProperty: minScaleDenominator
-     * {Number} minimum scale at which to draw the feature.
+     * {Number} or {String} minimum scale at which to draw the feature.
+     * In the case of a String, this can be a combination of text and
+     * propertyNames in the form "literal ${propertyName}"
      */
     minScaleDenominator: null,
 
     /**
      * APIProperty: maxScaleDenominator
-     * {Number} maximum scale at which to draw the feature.
+     * {Number} or {String} maximum scale at which to draw the feature.
+     * In the case of a String, this can be a combination of text and
+     * propertyNames in the form "literal ${propertyName}"
      */
     maxScaleDenominator: null,
 

Modified: sandbox/camptocamp/text/lib/OpenLayers/Style.js
===================================================================
--- sandbox/camptocamp/text/lib/OpenLayers/Style.js	2007-11-06 23:23:43 UTC (rev 5136)
+++ sandbox/camptocamp/text/lib/OpenLayers/Style.js	2007-11-07 08:39:47 UTC (rev 5137)
@@ -77,8 +77,7 @@
             pointRadius: 6
         }
         
-        this.defaultSelectStyle = {};
-        OpenLayers.Util.extend(this.defaultSelectStyle,
+        this.defaultSelectStyle = OpenLayers.Util.extend({},
                 OpenLayers.Feature.Vector.style["select"]);
         
         OpenLayers.Util.extend(this, options);
@@ -104,7 +103,7 @@
      * style.
      * 
      * Parameters:
-     * feature - {<OpenLayers.Feature.Vector>} feature to evaluate rules for
+     * feature - {<OpenLayers.Feature>} feature to evaluate rules for
      * baseStyle - {Object} hash of styles feature styles to extend
      * 
      * Returns:
@@ -114,8 +113,7 @@
         if (!baseStyle) {
             baseStyle = this.defaultStyle;
         }
-        var style = {}
-        OpenLayers.Util.extend(style, baseStyle);
+        var style = OpenLayers.Util.extend({}, baseStyle);
         
         var draw = true;
 
@@ -126,10 +124,12 @@
                 // check if within minScale/maxScale bounds
                 var scale = feature.layer.map.getScale();
                 if (this.rules[i].minScaleDenominator) {
-                    draw = draw && scale > this.rules[i].minScaleDenominator;
+                    draw = scale > OpenLayers.Style.createLiteral(
+                            this.rules[i].minScaleDenominator, feature);
                 }
-                if (this.rules[i].maxScaleDenominator) {
-                    draw = draw && (scale < this.rules[i].maxScaleDenominator);
+                if (draw && this.rules[i].maxScaleDenominator) {
+                    draw = scale < OpenLayers.Style.createLiteral(
+                            this.rules[i].maxScaleDenominator, feature);
                 }
                 
                 // determine which symbolizer (Point, Line, Polygon) to use
@@ -142,17 +142,13 @@
                 OpenLayers.Util.extend(style, symbolizer);
             }
         }
-        
-        if (style.label) {
-            var re = /\{(\w+)\}/g;
-        
-            while (a = re.exec(style.label)) {
-                style.label = style.label.replace(a[0], feature.attributes[a[1]]);
-            }
-        }
 
         style.hidden = !draw;
 
+        for (var i in style) {
+            style[i] = OpenLayers.Style.createLiteral(style[i], feature);
+        }
+        
         return style;
     },
         
@@ -162,7 +158,7 @@
      * geometry type of the passed geometry
      * 
      * Parameters:
-     * geometry {<OpenLayers.Geometry>)
+     * geometry {<OpenLayers.Geometry>}
      * 
      * Returns:
      * {String} key of the according symbolizer
@@ -181,6 +177,40 @@
 
 
 /**
+ * APIMethod: createLiteral
+ * converts a style value holding a combination of PropertyName and Literal
+ * into a Literal, taking the property values from the passed features.
+ * 
+ * Parameters:
+ * value   {String} value to parse. If this string contains a construct like
+ *         "foo ${bar}", then "foo " will be taken as literal, and "${bar}"
+ *         will be replaced by the value of the "bar" attribute of the passed
+ *         feature.
+ * feature {<OpenLayers.Feature>} feature to take attribute values from
+ * 
+ * Returns:
+ * {String} the parsed value. In the example of the value parameter above, the
+ * result would be "foo valueOfBar", assuming that the passed feature has an
+ * attribute named "bar" with the value "valueOfBar".
+ */
+OpenLayers.Style.createLiteral = function(value, feature) {
+    if (typeof value == "string" && value.indexOf("${") != -1) {
+        var attributes = feature.attributes || feature.data;
+        //TBD: try which one is faster
+        //for (var i in attributes) {
+        //    value = value.replace("${"+i+"}", attributes[i]);
+        //}
+        var re = /\$\{(\w+)\}/g;
+        var a;
+        while (a = re.exec(value)) {
+            value = value.replace(a[0], attributes[a[1]]);
+        }
+        value = isNaN(value) ? value : parseFloat(value);
+    }
+    return value;
+}
+    
+/**
  * Constant: OpenLayers.Style.SYMBOLIZER_PREFIXES
  * {Array} prefixes of the sld symbolizers. These are the
  * same as the main geometry types



More information about the Commits mailing list