[OpenLayers-Commits] r5149 - in sandbox/ianmayo/branches/rss_via_styles/openlayers: examples lib lib/OpenLayers lib/OpenLayers/Control lib/OpenLayers/Feature lib/OpenLayers/Layer tests

commits at openlayers.org commits at openlayers.org
Thu Nov 8 14:45:01 EST 2007


Author: ianmayo
Date: 2007-11-08 14:44:59 -0500 (Thu, 08 Nov 2007)
New Revision: 5149

Added:
   sandbox/ianmayo/branches/rss_via_styles/openlayers/examples/profilingAttributeName.html
   sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Rule.js
   sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Style.js
   sandbox/ianmayo/branches/rss_via_styles/openlayers/tests/test_Rule.html
   sandbox/ianmayo/branches/rss_via_styles/openlayers/tests/test_Style.html
Modified:
   sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers.js
   sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Control/SelectFeature.js
   sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Feature/Vector.js
   sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Layer/Vector.js
   sandbox/ianmayo/branches/rss_via_styles/openlayers/tests/list-tests.html
Log:
catch Andrea's remaining changes

Added: sandbox/ianmayo/branches/rss_via_styles/openlayers/examples/profilingAttributeName.html
===================================================================
--- sandbox/ianmayo/branches/rss_via_styles/openlayers/examples/profilingAttributeName.html	                        (rev 0)
+++ sandbox/ianmayo/branches/rss_via_styles/openlayers/examples/profilingAttributeName.html	2007-11-08 19:44:59 UTC (rev 5149)
@@ -0,0 +1,164 @@
+<html>
+  <head>
+  	<script src="../lib/Firebug/firebug.js"></script>
+    <script>
+      
+      var feature = {
+          attributes: {
+              name: "foo"
+          }
+      };
+      var feature2 = {
+          attributes: {
+              name: "foo",
+              age: 20,
+              address: "somewhere",
+              status: "single"
+          }
+      };
+      var feature3 = {
+          attributes: {
+              name: "foo",
+              age: 20,
+              address: "somewhere",
+              status: "single",
+              one: "one",
+              two: "two",
+              three: "three",
+              four: "four",
+              five: "five"
+          }
+      };
+
+      function profile(initialValue, feature) {
+          console.time("andreas' method");
+          var j = 0;
+          while (j < 1000) {
+              var value = initialValue;
+              if (typeof value == "string" && value.indexOf("${") != -1) {
+                  var attributes = feature.attributes || feature.data;
+                  for (var i in attributes) {
+                      value = value.replace("${"+i+"}", attributes[i]);
+                  }
+                  value = isNaN(value) ? value : parseFloat(value);
+              }
+              j++;
+          }
+          console.log("returned value : " + value);
+          console.timeEnd("andreas' method");
+    
+    
+          console.time("pierre's method");
+          var j = 0;
+          while (j < 1000) {
+              var value = initialValue;
+    
+              if (typeof value == "string" && value.indexOf("${") != -1) {
+                  var attributes = feature.attributes || feature.data;
+                  var re = /\$\{(\w+)\}/;
+                  var a;
+                  while (a = re.exec(value)) {
+                      value = value.replace(a[0], attributes[a[1]]);
+                  }
+                  value = isNaN(value) ? value : parseFloat(value);
+              }
+              j++;
+          }
+          console.log("returned value : " + value);
+          console.timeEnd("pierre's method");
+
+
+          console.time("andreas' method 2");
+          var j = 0;
+          while (j < 1000) {
+              var value = initialValue;
+    
+              if (typeof value == "string" && value.indexOf("${") != -1) {
+                  var attributes = feature.attributes || feature.data;
+                  var tokens = value.split(/\$\{|\}/);
+                  var newValue = new Array(tokens.length);
+                  for (var i=0; i<tokens.length; i++) {
+                      if (!tokens[i]) {
+                          continue;
+                      }
+                      newValue[i] = attributes[tokens[i]] ? attributes[tokens[i]] : tokens[i];
+                  }
+                  value = newValue.join("");
+                  value = isNaN(value) ? value : parseFloat(value);
+              }
+              j++;
+          }
+          console.log("returned value : " + value);
+          console.timeEnd("andreas' method 2");
+
+
+          console.time("andreas' method 3");
+          var j = 0;
+          while (j < 1000) {
+              var value = initialValue;
+    
+              if (typeof value == "string" && value.indexOf("${") != -1) {
+                  var attributes = feature.attributes || feature.data;
+                  var tokens = value.split("${");
+                  for (var i=0; i<tokens.length; i++) {
+                      var close = tokens[i].indexOf("}");
+                      if (close != -1) {
+                          tokens[i] = attributes[tokens[i].substring(0,
+                                  close)] + tokens[i].substring(++close);
+                      }
+                  }
+                  value = tokens.join(""); 
+                  value = isNaN(value) ? value : parseFloat(value);
+              }
+              j++;
+          }
+          console.log("returned value : " + value);
+          console.timeEnd("andreas' method 3");
+      }
+
+      
+      
+      var value = "${name}";
+      console.group(value);
+      console.log("feature");
+      profile(value, feature);
+      console.log("feature2");
+      profile(value, feature2);
+      console.log("feature3");
+      profile(value, feature3);
+      console.groupEnd();
+
+      var value = "name: ${name}, age: ${age}, address: ${address}, status: ${status}";
+      console.group(value);
+      console.log("feature");
+      profile(value, feature);
+      console.log("feature2");
+      profile(value, feature2);
+      console.log("feature3");
+      profile(value, feature3);
+      console.groupEnd();
+
+      
+    </script>
+  </head>
+  <body>
+    In this example we test the following cases :
+    <ul>
+      <li>Different values to create a literal with :
+        <ul>
+          <li>simple value : "${name}"</li>
+          <li>more complex value : "name: ${name}, age: ${age}, address: ${somewhere}, status: ${status}"</li>  
+        </ul>
+      </li>
+      <li>Different features :
+        <ul>
+          <li>one single attribute</li>
+          <li>4 attributes</li>
+          <li>9 attributes</li>
+        </ul>
+      </li>
+    </ul>
+    
+    Each test is made with a 1000 cycles loop.
+  </body>
+</html> 

Modified: sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Control/SelectFeature.js
===================================================================
--- sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Control/SelectFeature.js	2007-11-08 19:17:29 UTC (rev 5148)
+++ sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Control/SelectFeature.js	2007-11-08 19:44:59 UTC (rev 5149)
@@ -5,6 +5,7 @@
 
 /**
  * @requires OpenLayers/Control.js
+ * @requires OpenLayers/Style.js
  * @requires OpenLayers/Feature/Vector.js
  *
  * Class: OpenLayers.Control.SelectFeature
@@ -63,7 +64,11 @@
     
     /**
      * APIProperty: selectStyle 
-     * {Object} Hash of styles
+     * {Object} or {<OpenLayers.Style>} style for selected features.
+     * Thie is either a hash of style properties, or, if the features
+     * should be styled using sld, an OpenLayers.Style instance. These are
+     * created using the OpenLayers.Format.SLD.read() method, which returns a
+     * hash of SLD Styles, each of which can be used here.
      */
     selectStyle: OpenLayers.Feature.Vector.style['select'],
 
@@ -171,7 +176,14 @@
             feature.originalStyle = feature.style;
         }
         this.layer.selectedFeatures.push(feature);
-        feature.style = this.selectStyle;
+        
+        var selectStyle = feature.selectStyle || this.selectStyle;
+        if (selectStyle instanceof OpenLayers.Style) {
+            feature.style = selectStyle.createStyle(feature,
+                    selectStyle.defaultSelectStyle);
+        } else {
+            feature.style = selectStyle;
+        }
         this.layer.drawFeature(feature);
         this.onSelect(feature);
     },

Modified: sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Feature/Vector.js
===================================================================
--- sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Feature/Vector.js	2007-11-08 19:17:29 UTC (rev 5148)
+++ sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Feature/Vector.js	2007-11-08 19:44:59 UTC (rev 5149)
@@ -262,9 +262,10 @@
  *  - externalGraphic,
  *  - graphicWidth,
  *  - graphicHeight,
- *  - graphicOpacity
- *  - graphicXOffset
- *  - graphicYOffset
+ *  - graphicOpacity,
+ *  - graphicXOffset,
+ *  - graphicYOffset,
+ *  - hidden
  */ 
 OpenLayers.Feature.Vector.style = {
     'default': {

Modified: sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Layer/Vector.js
===================================================================
--- sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Layer/Vector.js	2007-11-08 19:17:29 UTC (rev 5148)
+++ sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Layer/Vector.js	2007-11-08 19:44:59 UTC (rev 5149)
@@ -4,6 +4,7 @@
 
 /**
  * @requires OpenLayers/Layer.js
+ * @requires OpenLayers/Style.js
  * @requires OpenLayers/Renderer.js
  * @requires OpenLayers/Feature/Vector.js
  * 
@@ -57,11 +58,13 @@
     reportError: true, 
 
     /** 
-     * APIProperty: style
-     * {Object} Default style for the layer
+     * Property: style
+     * {<OpenLayers.Style>} or {Hash of <OpenLayers.Style>}
+     * Default style for the layer.
+     * Thie is either a hash of style properties or a complex style object.
      */
     style: null,
-
+    
     /**
      * Property: renderers
      * Array({String}) List of supported Renderer classes. Add to this list to
@@ -119,8 +122,8 @@
         if (!this.renderer || !this.renderer.supported()) {
             this.renderer = null;
             this.displayError();
-        } 
-
+        }
+        
         this.features = [];
         this.selectedFeatures = [];
     },
@@ -248,6 +251,8 @@
             features = [features];
         }
 
+        var cloneStyle = !(this.style instanceof OpenLayers.Style);
+
         for (var i = 0; i < features.length; i++) {
             var feature = features[i];
             
@@ -264,7 +269,8 @@
             feature.layer = this;
 
             if (!feature.style) {
-                feature.style = OpenLayers.Util.extend({}, this.style);
+                feature.style = cloneStyle ?
+                        OpenLayers.Util.extend({}, this.style) : this.style;
             }
 
             this.preFeatureInsert(feature);
@@ -275,6 +281,7 @@
             
             this.onFeatureInsert(feature);
         }
+
     },
 
 
@@ -329,13 +336,19 @@
      */
     drawFeature: function(feature, style) {
         if(style == null) {
-            if(feature.style) {
-                style = feature.style;
+            // apply sld styles to the feature style
+            if (feature.style &&
+                    (feature.style instanceof OpenLayers.Style)) {
+                style = feature.style.createStyle(feature);
             } else {
-                style = this.style;
+                style = feature.style ? feature.style : this.style;
             }
         }
-        this.renderer.drawFeature(feature, style);
+        if (style.hidden != true) {
+            this.renderer.drawFeature(feature, style);
+        } else {
+            this.renderer.eraseFeatures([feature]);
+        }
     },
     
     /**
@@ -350,6 +363,59 @@
     },
 
     /**
+     * APIMethod: getDefaultStyle
+     * 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(style) {
+        for (var i in style) {
+            if (style[i] instanceof OpenLayers.Style) {
+                if (style[i].layerName == this.name) {
+                    return style[i];
+                }
+            } else {
+                return style;
+            }
+        }
+    },
+    
+    /**
+     * APIMethod: setStyle
+     * Sets the style for the layer and its features. This function can be
+     * 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 = 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({}, this.style) : this.style;
+        }
+               
+        this.redraw();
+    },
+    
+    /**
      * Method: getFeatureFromEvent
      * Given an event, return a feature if the event occurred over one.
      * Otherwise, return null.

Added: sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Rule.js
===================================================================
--- sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Rule.js	                        (rev 0)
+++ sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Rule.js	2007-11-08 19:44:59 UTC (rev 5149)
@@ -0,0 +1,87 @@
+/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
+ * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt 
+ * for the full text of the license. */
+
+
+/**
+ * Class: OpenLayers.Rule
+ * 
+ * This class represents a OGC Rule, as being used for rule-based SLD styling
+ */
+OpenLayers.Rule = OpenLayers.Class({
+    
+    /**
+     * APIProperty: name
+     * {String} name of this rule
+     */
+    name: 'default',
+
+    /**
+     * Property: symbolizer
+     * {Object} Hash of styles for this rule. Contains hashes of feature
+     * styles. Keys are one or more of ["Point", "Line", "Polygon"]
+     */
+    symbolizer: null,
+    
+    /**
+     * APIProperty: minScaleDenominator
+     * {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} 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,
+
+    /** 
+     * Constructor: OpenLayers.Rule
+     * Creates a Rule.
+     *
+     * Parameters:
+     * options - {Object} An optional object with properties to set on the
+     *           rule
+     * 
+     * Returns:
+     * {<OpenLayers.Rule>}
+     */
+    initialize: function(options) {
+        this.symbolizer = {};
+
+        OpenLayers.Util.extend(this, options);
+    },
+
+    /** 
+     * APIMethod: destroy
+     * nullify references to prevent circular references and memory leaks
+     */
+    destroy: function() {
+        for (var i in this.symbolizer) {
+            this.symbolizer[i] = null;
+        }
+        this.symbolizer = null;
+    },
+    
+    /**
+     * APIMethod: evaluate
+     * evaluates this rule for a specific feature
+     * 
+     * Parameters:
+     * feature - {<OpenLayers.Feature.Vector>} feature to apply the rule to.
+     * 
+     * Returns:
+     * {boolean} true if the rule applies, false if it does not.
+     * This rule is the default rule and always returns true.
+     */
+    evaluate: function(feature) {
+        // Default rule always applies. Subclasses will want to override this.
+        return true;
+    },
+    
+    CLASS_NAME: "OpenLayers.Rule"
+});
\ No newline at end of file

Added: sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Style.js
===================================================================
--- sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Style.js	                        (rev 0)
+++ sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers/Style.js	2007-11-08 19:44:59 UTC (rev 5149)
@@ -0,0 +1,248 @@
+/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
+ * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt 
+ * for the full text of the license. */
+
+
+/**
+ * @requires OpenLayers/Feature/Vector.js
+ *
+ * Class: OpenLayers.Style
+ * 
+ * This class represents a UserStyle obtained
+ * from a SLD, containing styling rules.
+ */
+OpenLayers.Style = OpenLayers.Class({
+
+    /**
+     * APIProperty: name
+     * {String}
+     */
+    name: null,
+    
+    /**
+     * APIProperty: layerName
+     * {<String>} name of the layer that this style belongs to, usually
+     * according to the NamedLayer attribute of an SLD document.
+     */
+    layerName: null,
+    
+    /**
+     * APIProperty: isDefault
+     * {Boolean}
+     */
+    isDefault: false,
+     
+    /** 
+     * APIProperty: rules 
+     * Array({<OpenLayers.Rule>}) 
+     */
+    rules: null,
+    
+    /**
+     * APIProperty: defaultStyle
+     * {Object} hash of style properties to use as default
+     * for merging rule-based styles onto.
+     */
+    defaultStyle: null,
+    
+    /**
+     * APIProperty: defaultSelectStyle
+     * {Object} hash of style properties to use as default
+     * for merging rule-based styles onto when feature is selected.
+     */
+    defaultSelectStyle: null,
+    
+    /**
+     * Property: propertyStyles
+     * {Hash of Boolean} cache of style properties that need to be parsed for
+     * propertyNames. Property names are keys, values won't be used.
+     */
+    propertyStyles: null,
+    
+
+    /** 
+     * Constructor: OpenLayers.Style
+     * Creates a UserStyle.
+     *
+     * Parameters:
+     * options - {Object} An optional object with properties to set on the
+     *           userStyle
+     * 
+     * Return:
+     * {<OpenLayers.Style>}
+     */
+    initialize: function(options) {
+        this.rules = [];
+
+        // simple style with defaults from the SLD spec
+        this.defaultStyle = {
+            fillColor: "#808080",
+            fillOpacity: 1,
+            strokeColor: "#000000",
+            strokeOpacity: 1,
+            strokeWidth: 1,
+            pointRadius: 6
+        }
+        
+        this.defaultSelectStyle = OpenLayers.Util.extend({},
+                OpenLayers.Feature.Vector.style["select"]);
+        
+        OpenLayers.Util.extend(this, options);
+    },
+
+    /** 
+     * APIMethod: destroy
+     * nullify references to prevent circular references and memory leaks
+     */
+    destroy: function() {
+        for (var i=0; i<this.rules.length; i++) {
+            this.rules[i].destroy();
+            this.rules[i] = null;
+        }
+        this.rules = null;
+        this.defaultStyle = null;
+        this.defaultSelectStyle = null;
+    },
+    
+    /**
+     * APIMethod: createStyle
+     * creates a style by applying all feature-dependent rules to the base
+     * style.
+     * 
+     * Parameters:
+     * feature - {<OpenLayers.Feature>} feature to evaluate rules for
+     * baseStyle - {Object} hash of styles feature styles to extend
+     * 
+     * Returns:
+     * {<OpenLayers.Feature.Vector.Style>} hash of feature styles
+     */
+    createStyle: function(feature, baseStyle) {
+        if (!baseStyle) {
+            baseStyle = this.defaultStyle;
+        }
+        var style = OpenLayers.Util.extend({}, baseStyle);
+        
+        var draw = true;
+
+        for (var i=0; i<this.rules.length; i++) {
+            // does the rule apply?        
+            var applies = this.rules[i].evaluate(feature);
+            if (applies) {
+                // check if within minScale/maxScale bounds
+                var scale = feature.layer.map.getScale();
+                if (this.rules[i].minScaleDenominator) {
+                    draw = scale > OpenLayers.Style.createLiteral(
+                            this.rules[i].minScaleDenominator, feature);
+                }
+                if (draw && this.rules[i].maxScaleDenominator) {
+                    draw = scale < OpenLayers.Style.createLiteral(
+                            this.rules[i].maxScaleDenominator, feature);
+                }
+                
+                // determine which symbolizer (Point, Line, Polygon) to use
+                var symbolizerPrefix = feature.geometry ?
+                        this.getSymbolizerPrefix(feature.geometry) :
+                        OpenLayers.Style.SYMBOLIZER_PREFIXES[0];
+
+                // now merge the style with the current style
+                var symbolizer = this.rules[i].symbolizer[symbolizerPrefix];
+                OpenLayers.Util.extend(style, symbolizer);
+            }
+        }
+
+        style.hidden = !draw;
+
+        // create cache of style properties that need to be parsed for
+        // propertyNames. Will only be done on the first call of createStyle.
+        if (!this.propertyStyles) {
+            this.propertyStyles = {};
+            // walk through all rules to check for properties in their
+            // symbolizer
+            var r, s;
+            for (var i in (r = style.rules)) {
+               for (var j in (s = r[i].symbolizer[symbolizerPrefix])) {
+                    if (typeof s[j] == "string" && s[j].match(/\$\{\w+\}/)) {
+                        this.propertyStyles[j] = true;
+                    }
+                }
+            }
+            for (var i in baseStyle) {
+                if (typeof baseStyle[i] == "string" &&
+                        baseStyle[i].match(/\$\{\w+\}/)) {
+                    this.propertyStyles[i] = true;
+                }
+            }
+        }
+
+        // calculate literals for all styles in the propertyStyles cache
+        for (var i in this.propertyStyles) {
+            style[i] = OpenLayers.Style.createLiteral(style[i], feature);
+        }
+        
+        return style;
+    },
+        
+    /**
+     * Method: getSymbolizerPrefix
+     * Returns the correct symbolizer prefix according to the
+     * geometry type of the passed geometry
+     * 
+     * Parameters:
+     * geometry {<OpenLayers.Geometry>}
+     * 
+     * Returns:
+     * {String} key of the according symbolizer
+     */
+    getSymbolizerPrefix: function(geometry) {
+        var prefixes = OpenLayers.Style.SYMBOLIZER_PREFIXES;
+        for (var i=0; i<prefixes.length; i++) {
+            if (geometry.CLASS_NAME.indexOf(prefixes[i]) != -1) {
+                return prefixes[i];
+            }
+        }
+    },
+    
+    CLASS_NAME: "OpenLayers.Style"
+});
+
+
+/**
+ * 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;
+        var tokens = value.split("${");
+        for (var i=0; i<tokens.length; i++) {
+            var close = tokens[i].indexOf("}");
+            if (close != -1) {
+                tokens[i] = attributes[tokens[i].substring(0, close)] +
+                        tokens[i].substring(++close);
+            }
+        }
+        value = tokens.join(""); 
+        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
+ */
+OpenLayers.Style.SYMBOLIZER_PREFIXES = ['Point', 'Line', 'Polygon'];
\ No newline at end of file

Modified: sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers.js
===================================================================
--- sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers.js	2007-11-08 19:17:29 UTC (rev 5148)
+++ sandbox/ianmayo/branches/rss_via_styles/openlayers/lib/OpenLayers.js	2007-11-08 19:44:59 UTC (rev 5149)
@@ -85,6 +85,9 @@
             "OpenLayers/Marker/Box.js",
             "OpenLayers/Popup.js",
             "OpenLayers/Tile.js",
+            "OpenLayers/Feature.js",
+            "OpenLayers/Feature/Vector.js",
+            "OpenLayers/Feature/WFS.js",
             "OpenLayers/Tile/Image.js",
             "OpenLayers/Tile/WFS.js",
             "OpenLayers/Layer/Image.js",
@@ -163,6 +166,11 @@
             "OpenLayers/Renderer/VML.js",
             "OpenLayers/Layer/Vector.js",
             "OpenLayers/Layer/GML.js",
+            "OpenLayers/Style.js",
+            "OpenLayers/Rule.js",
+            "OpenLayers/Rule/FeatureId.js",
+            "OpenLayers/Rule/Logical.js",
+            "OpenLayers/Rule/Comparison.js",
             "OpenLayers/Format.js",
             "OpenLayers/Format/XML.js",
             "OpenLayers/Format/GML.js",
@@ -170,6 +178,7 @@
             "OpenLayers/Format/GeoRSS.js",
             "OpenLayers/Format/WFS.js",
             "OpenLayers/Format/WKT.js",
+            "OpenLayers/Format/SLD.js",
             "OpenLayers/Format/JSON.js",
             "OpenLayers/Format/GeoJSON.js",
             "OpenLayers/Layer/WFS.js",

Modified: sandbox/ianmayo/branches/rss_via_styles/openlayers/tests/list-tests.html
===================================================================
--- sandbox/ianmayo/branches/rss_via_styles/openlayers/tests/list-tests.html	2007-11-08 19:17:29 UTC (rev 5148)
+++ sandbox/ianmayo/branches/rss_via_styles/openlayers/tests/list-tests.html	2007-11-08 19:44:59 UTC (rev 5149)
@@ -22,6 +22,7 @@
     <li>test_Format.html</li>
     <li>Format/test_XML.html</li>
     <li>Format/test_KML.html</li>
+    <li>Format/test_SLD.html</li>
     <li>Format/test_GeoRSS.html</li>
     <li>Format/test_JSON.html</li>
     <li>Format/test_GeoJSON.html</li>
@@ -34,6 +35,11 @@
     <li>Popup/test_Anchored.html</li>
     <li>test_Feature.html</li>
     <li>Feature/test_Vector.html</li>
+    <li>test_Style.html</li>
+    <li>test_Rule.html</li>
+    <li>Rule/test_FeatureId.html</li>
+    <li>Rule/test_Logical.html</li>
+    <li>Rule/test_Comparison.html</li>
     <li>test_Events.html</li>
     <li>test_Util.html</li>
     <li>test_Layer.html</li>

Added: sandbox/ianmayo/branches/rss_via_styles/openlayers/tests/test_Rule.html
===================================================================
--- sandbox/ianmayo/branches/rss_via_styles/openlayers/tests/test_Rule.html	                        (rev 0)
+++ sandbox/ianmayo/branches/rss_via_styles/openlayers/tests/test_Rule.html	2007-11-08 19:44:59 UTC (rev 5149)
@@ -0,0 +1,29 @@
+<html> 
+<head> 
+    <script src="../lib/OpenLayers.js"></script> 
+    <script type="text/javascript">
+
+    function test_Rule_constructor(t) { 
+        t.plan(3); 
+         
+        var options = {'foo': 'bar'}; 
+        var rule = new OpenLayers.Rule(options); 
+        t.ok(rule instanceof OpenLayers.Rule, 
+             "new OpenLayers.Rule returns object" ); 
+        t.eq(rule.foo, "bar", "constructor sets options correctly"); 
+        t.eq(typeof rule.evaluate, "function", "rule has an evaluate function"); 
+    }
+
+    function test_Rule_destroy(t) {
+        t.plan(1);
+        
+        var rule = new OpenLayers.Rule();
+        rule.destroy();
+		t.eq(rule.symbolizer, null, "symbolizer hash nulled properly");
+    }
+
+    </script> 
+</head> 
+<body> 
+</body> 
+</html> 

Added: sandbox/ianmayo/branches/rss_via_styles/openlayers/tests/test_Style.html
===================================================================
--- sandbox/ianmayo/branches/rss_via_styles/openlayers/tests/test_Style.html	                        (rev 0)
+++ sandbox/ianmayo/branches/rss_via_styles/openlayers/tests/test_Style.html	2007-11-08 19:44:59 UTC (rev 5149)
@@ -0,0 +1,29 @@
+<html> 
+<head> 
+    <script src="../lib/OpenLayers.js"></script> 
+    <script type="text/javascript">
+
+    function test_Style_constructor(t) { 
+        t.plan(3); 
+         
+        var options = {'foo': 'bar'}; 
+        var style = new OpenLayers.Style(options); 
+        t.ok(style instanceof OpenLayers.Style, 
+             "new OpenLayers.Style returns object" ); 
+        t.eq(style.foo, "bar", "constructor sets options correctly"); 
+        t.eq(typeof style.createStyle, "function", "style has a createStyle function"); 
+    }
+
+    function test_Style_destroy(t) {
+        t.plan(1);
+        
+        var style = new OpenLayers.Style();
+        style.destroy();
+		t.eq(style.rules, null, "rules array nulled properly");
+    }
+
+    </script> 
+</head> 
+<body> 
+</body> 
+</html> 



More information about the Commits mailing list