[OpenLayers-Commits] r5133 - in sandbox/ahocevar/sldRenderer: examples lib/OpenLayers/Format lib/OpenLayers/Layer lib/OpenLayers/Rule
commits at openlayers.org
commits at openlayers.org
Tue Nov 6 17:41:47 EST 2007
Author: ahocevar
Date: 2007-11-06 17:41:45 -0500 (Tue, 06 Nov 2007)
New Revision: 5133
Modified:
sandbox/ahocevar/sldRenderer/examples/gml-tasmania-sld.html
sandbox/ahocevar/sldRenderer/lib/OpenLayers/Format/SLD.js
sandbox/ahocevar/sldRenderer/lib/OpenLayers/Layer/Vector.js
sandbox/ahocevar/sldRenderer/lib/OpenLayers/Rule/Comparison.js
Log:
modifications proposed by Eric. Thanks!
Modified: sandbox/ahocevar/sldRenderer/examples/gml-tasmania-sld.html
===================================================================
--- sandbox/ahocevar/sldRenderer/examples/gml-tasmania-sld.html 2007-11-06 21:09:22 UTC (rev 5132)
+++ sandbox/ahocevar/sldRenderer/examples/gml-tasmania-sld.html 2007-11-06 22:41:45 UTC (rev 5133)
@@ -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/ahocevar/sldRenderer/lib/OpenLayers/Format/SLD.js
===================================================================
--- sandbox/ahocevar/sldRenderer/lib/OpenLayers/Format/SLD.js 2007-11-06 21:09:22 UTC (rev 5132)
+++ sandbox/ahocevar/sldRenderer/lib/OpenLayers/Format/SLD.js 2007-11-06 22:41:45 UTC (rev 5133)
@@ -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) ?
Modified: sandbox/ahocevar/sldRenderer/lib/OpenLayers/Layer/Vector.js
===================================================================
--- sandbox/ahocevar/sldRenderer/lib/OpenLayers/Layer/Vector.js 2007-11-06 21:09:22 UTC (rev 5132)
+++ sandbox/ahocevar/sldRenderer/lib/OpenLayers/Layer/Vector.js 2007-11-06 22:41:45 UTC (rev 5133)
@@ -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/ahocevar/sldRenderer/lib/OpenLayers/Rule/Comparison.js
===================================================================
--- sandbox/ahocevar/sldRenderer/lib/OpenLayers/Rule/Comparison.js 2007-11-06 21:09:22 UTC (rev 5132)
+++ sandbox/ahocevar/sldRenderer/lib/OpenLayers/Rule/Comparison.js 2007-11-06 22:41:45 UTC (rev 5133)
@@ -19,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,
More information about the Commits
mailing list