| | 1 | /* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license. |
|---|
| | 2 | * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt |
|---|
| | 3 | * for the full text of the license. */ |
|---|
| | 4 | |
|---|
| | 5 | /** |
|---|
| | 6 | * @requires OpenLayers/Format/XML.js |
|---|
| | 7 | * @requires OpenLayers/Style.js |
|---|
| | 8 | * @requires OpenLayers/Rule.js |
|---|
| | 9 | * @requires OpenLayers/Rule/FeatureId.js |
|---|
| | 10 | * @requires OpenLayers/Rule/Logical.js |
|---|
| | 11 | * @requires OpenLayers/Rule/Comparison.js |
|---|
| | 12 | * |
|---|
| | 13 | * Class: OpenLayers.Format.SLD |
|---|
| | 14 | * Read/Wite SLD. Create a new instance with the <OpenLayers.Format.SLD> |
|---|
| | 15 | * constructor. |
|---|
| | 16 | * |
|---|
| | 17 | * Inherits from: |
|---|
| | 18 | * - <OpenLayers.Format.XML> |
|---|
| | 19 | */ |
|---|
| | 20 | OpenLayers.Format.SLD = OpenLayers.Class(OpenLayers.Format.XML, { |
|---|
| | 21 | |
|---|
| | 22 | /** |
|---|
| | 23 | * APIProperty: sldns |
|---|
| | 24 | * Namespace used for sld. |
|---|
| | 25 | */ |
|---|
| | 26 | sldns: "http://www.opengis.net/sld", |
|---|
| | 27 | |
|---|
| | 28 | /** |
|---|
| | 29 | * APIProperty: ogcns |
|---|
| | 30 | * Namespace used for ogc. |
|---|
| | 31 | */ |
|---|
| | 32 | ogcns: "http://www.opengis.net/ogc", |
|---|
| | 33 | |
|---|
| | 34 | /** |
|---|
| | 35 | * APIProperty: gmlns |
|---|
| | 36 | * Namespace used for gml. |
|---|
| | 37 | */ |
|---|
| | 38 | gmlns: "http://www.opengis.net/gml", |
|---|
| | 39 | |
|---|
| | 40 | /** |
|---|
| | 41 | * Constructor: OpenLayers.Format.SLD |
|---|
| | 42 | * Create a new parser for SLD |
|---|
| | 43 | * |
|---|
| | 44 | * Parameters: |
|---|
| | 45 | * options - {Object} An optional object whose properties will be set on |
|---|
| | 46 | * this instance. |
|---|
| | 47 | */ |
|---|
| | 48 | initialize: function(options) { |
|---|
| | 49 | OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); |
|---|
| | 50 | }, |
|---|
| | 51 | |
|---|
| | 52 | /** |
|---|
| | 53 | * APIMethod: read |
|---|
| | 54 | * Read data from a string, and return a list of features. |
|---|
| | 55 | * |
|---|
| | 56 | * Parameters: |
|---|
| | 57 | * data - {String} or {XMLNode} data to read/parse. |
|---|
| | 58 | * |
|---|
| | 59 | * Returns: |
|---|
| | 60 | * {Object} Hash of SLD UserStyles, containing |
|---|
| | 61 | * SLD rules. |
|---|
| | 62 | */ |
|---|
| | 63 | read: function(data) { |
|---|
| | 64 | if (typeof data == "string") { |
|---|
| | 65 | data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); |
|---|
| | 66 | } |
|---|
| | 67 | |
|---|
| | 68 | var userStyles = this.getElementsByTagNameNS(data, this.sldns, |
|---|
| | 69 | "UserStyle"); |
|---|
| | 70 | if (userStyles.length == 0) { |
|---|
| | 71 | return {}; |
|---|
| | 72 | } |
|---|
| | 73 | var styles = {}; |
|---|
| | 74 | for (var i=0; i<userStyles.length; i++) { |
|---|
| | 75 | var name = this.parseProperty(userStyles[i], this.sldns, "Name"); |
|---|
| | 76 | styles[name] = this.parseUserStyle(userStyles[i], name); |
|---|
| | 77 | } |
|---|
| | 78 | |
|---|
| | 79 | return styles; |
|---|
| | 80 | }, |
|---|
| | 81 | |
|---|
| | 82 | /** |
|---|
| | 83 | * Method: parseUserStyle |
|---|
| | 84 | * parses a sld userStyle for rules |
|---|
| | 85 | * |
|---|
| | 86 | * Parameters: |
|---|
| | 87 | * xmlNode - {<DOMElement>} xml node to read the style from |
|---|
| | 88 | * name - {<String>} name of the style |
|---|
| | 89 | * |
|---|
| | 90 | * Returns: |
|---|
| | 91 | * {<OpenLayers.Style>} |
|---|
| | 92 | */ |
|---|
| | 93 | parseUserStyle: function(xmlNode, name) { |
|---|
| | 94 | var userStyle = new OpenLayers.Style({name: name}); |
|---|
| | 95 | |
|---|
| | 96 | userStyle.isDefault = this.parseProperty(xmlNode, this.sldns, |
|---|
| | 97 | "IsDefault") == 1 ? true : false; |
|---|
| | 98 | |
|---|
| | 99 | // get the name of the layer if we have a NamedLayer |
|---|
| | 100 | var namedLayerNode = xmlNode.parentNode; |
|---|
| | 101 | var nameNodes = this.getElementsByTagNameNS(namedLayerNode, this.sldns, "Name"); |
|---|
| | 102 | if (namedLayerNode.nodeName.indexOf("NamedLayer") != -1 && |
|---|
| | 103 | nameNodes && |
|---|
| | 104 | nameNodes.length > 0 && |
|---|
| | 105 | nameNodes[0].parentNode == namedLayerNode) { |
|---|
| | 106 | userStyle.layerName = this.getChildValue(nameNodes[0]); |
|---|
| | 107 | } |
|---|
| | 108 | |
|---|
| | 109 | var ruleNodes = this.getElementsByTagNameNS(xmlNode, this.sldns, |
|---|
| | 110 | "Rule"); |
|---|
| | 111 | if (ruleNodes.length == 0) { return []; } |
|---|
| | 112 | |
|---|
| | 113 | var rules = userStyle.rules; |
|---|
| | 114 | for (var i=0; i<ruleNodes.length; i++) { |
|---|
| | 115 | var name = this.parseProperty(ruleNodes[i], this.sldns, "Name"); |
|---|
| | 116 | rules.push(this.parseRule(ruleNodes[i], name)); |
|---|
| | 117 | } |
|---|
| | 118 | |
|---|
| | 119 | return userStyle; |
|---|
| | 120 | }, |
|---|
| | 121 | |
|---|
| | 122 | /** |
|---|
| | 123 | * Method: parseRule |
|---|
| | 124 | * This function is the core of the SLD parsing code in OpenLayers. |
|---|
| | 125 | * It creates the rule with its constraints and symbolizers. |
|---|
| | 126 | * |
|---|
| | 127 | * Parameters: |
|---|
| | 128 | * xmlNode - {<DOMElement>} |
|---|
| | 129 | * |
|---|
| | 130 | * Returns: |
|---|
| | 131 | * {Object} Hash of rule properties |
|---|
| | 132 | */ |
|---|
| | 133 | parseRule: function(xmlNode, name) { |
|---|
| | 134 | |
|---|
| | 135 | // FILTERS |
|---|
| | 136 | |
|---|
| | 137 | var filter = this.getElementsByTagNameNS(xmlNode, this.ogcns, "Filter"); |
|---|
| | 138 | if (filter && filter.length > 0) { |
|---|
| | 139 | var rule = this.parseFilter(filter[0]); |
|---|
| | 140 | } else { |
|---|
| | 141 | // rule applies to all features |
|---|
| | 142 | var rule = new OpenLayers.Rule(); |
|---|
| | 143 | } |
|---|
| | 144 | rule.name = name; |
|---|
| | 145 | |
|---|
| | 146 | // SCALE DENOMINATORS |
|---|
| | 147 | |
|---|
| | 148 | // MinScaleDenominator |
|---|
| | 149 | var minScale = this.getElementsByTagNameNS(xmlNode, |
|---|
| | 150 | this.sldns, "MinScaleDenominator"); |
|---|
| | 151 | if (minScale && minScale.length > 0) { |
|---|
| | 152 | rule.minScaleDenominator = parseFloat( |
|---|
| | 153 | this.getChildValue(minScale[0])); |
|---|
| | 154 | } |
|---|
| | 155 | |
|---|
| | 156 | // MaxScaleDenominator |
|---|
| | 157 | var maxScale = this.getElementsByTagNameNS(xmlNode, |
|---|
| | 158 | this.sldns, "MaxScaleDenominator"); |
|---|
| | 159 | if (maxScale && maxScale.length > 0) { |
|---|
| | 160 | rule.maxScaleDenominator = parseFloat( |
|---|
| | 161 | this.getChildValue(maxScale[0])); |
|---|
| | 162 | } |
|---|
| | 163 | |
|---|
| | 164 | // STYLES |
|---|
| | 165 | |
|---|
| | 166 | // walk through all symbolizers |
|---|
| | 167 | var prefixes = OpenLayers.Style.SYMBOLIZER_PREFIXES; |
|---|
| | 168 | for (var s=0; s<prefixes.length; s++) { |
|---|
| | 169 | |
|---|
| | 170 | // symbolizer type |
|---|
| | 171 | var symbolizer = this.getElementsByTagNameNS(xmlNode, this.sldns, |
|---|
| | 172 | prefixes[s]+"Symbolizer"); |
|---|
| | 173 | |
|---|
| | 174 | if (symbolizer && symbolizer.length > 0) { |
|---|
| | 175 | |
|---|
| | 176 | var style = {}; |
|---|
| | 177 | |
|---|
| | 178 | // externalGraphic |
|---|
| | 179 | var graphic = this.getElementsByTagNameNS(symbolizer[0], |
|---|
| | 180 | this.sldns, "Graphic"); |
|---|
| | 181 | if (graphic && graphic.length > 0) { |
|---|
| | 182 | style.externalGraphic = this.parseProperty(graphic[0], |
|---|
| | 183 | this.sldns, "OnlineResource", "xlink:href"); |
|---|
| | 184 | style.pointRadius = this.parseProperty(graphic[0], |
|---|
| | 185 | this.sldns, "Size"); |
|---|
| | 186 | style.graphicOpacity = this.parseProperty(graphic[0], |
|---|
| | 187 | this.sldns, "Opacity"); |
|---|
| | 188 | } |
|---|
| | 189 | |
|---|
| | 190 | // fill |
|---|
| | 191 | var fill = this.getElementsByTagNameNS(symbolizer[0], |
|---|
| | 192 | this.sldns, "Fill"); |
|---|
| | 193 | if (fill && fill.length > 0) { |
|---|
| | 194 | style.fillColor = this.parseProperty(fill[0], this.sldns, |
|---|
| | 195 | "CssParameter", "name", "fill"); |
|---|
| | 196 | style.fillOpacity = this.parseProperty(fill[0], |
|---|
| | 197 | this.sldns, "CssParameter", "name", |
|---|
| | 198 | "fill-opacity") || 1; |
|---|
| | 199 | } |
|---|
| | 200 | |
|---|
| | 201 | // stroke |
|---|
| | 202 | var stroke = this.getElementsByTagNameNS(symbolizer[0], |
|---|
| | 203 | this.sldns, "Stroke"); |
|---|
| | 204 | if (stroke && stroke.length > 0) { |
|---|
| | 205 | style.strokeColor = this.parseProperty(stroke[0], |
|---|
| | 206 | this.sldns, "CssParameter", "name", "stroke"); |
|---|
| | 207 | style.strokeOpacity = this.parseProperty(stroke[0], |
|---|
| | 208 | this.sldns, "CssParameter", "name", |
|---|
| | 209 | "stroke-opacity") || 1; |
|---|
| | 210 | style.strokeWidth = this.parseProperty(stroke[0], |
|---|
| | 211 | this.sldns, "CssParameter", "name", |
|---|
| | 212 | "stroke-width"); |
|---|
| | 213 | style.strokeLinecap = this.parseProperty(stroke[0], |
|---|
| | 214 | this.sldns, "CssParameter", "name", |
|---|
| | 215 | "stroke-linecap"); |
|---|
| | 216 | } |
|---|
| | 217 | |
|---|
| | 218 | // set the [point|line|polygon]Symbolizer property of the rule |
|---|
| | 219 | rule.symbolizer[prefixes[s]] = style; |
|---|
| | 220 | } |
|---|
| | 221 | } |
|---|
| | 222 | |
|---|
| | 223 | return rule; |
|---|
| | 224 | }, |
|---|
| | 225 | |
|---|
| | 226 | /** |
|---|
| | 227 | * Method: parseFilter |
|---|
| | 228 | * Parses ogc fiters. |
|---|
| | 229 | * |
|---|
| | 230 | * Parameters: |
|---|
| | 231 | * xmlNode - {<DOMElement>} |
|---|
| | 232 | * |
|---|
| | 233 | * Returns: |
|---|
| | 234 | * {<OpenLayers.Rule>} rule representing the filter |
|---|
| | 235 | */ |
|---|
| | 236 | parseFilter: function(xmlNode) { |
|---|
| | 237 | var nodeName = (xmlNode.prefix) ? |
|---|
| | 238 | xmlNode.nodeName.split(":")[1] : |
|---|
| | 239 | xmlNode.nodeName; |
|---|
| | 240 | |
|---|
| | 241 | // ogc:FeatureId filter |
|---|
| | 242 | var fidFilter = (nodeName == "FeatureId") ? |
|---|
| | 243 | xmlNode : |
|---|
| | 244 | this.getElementsByTagNameNS(xmlNode, this.ogcns, "FeatureId"); |
|---|
| | 245 | if (fidFilter && fidFilter.length > 0) { |
|---|
| | 246 | var rule = new OpenLayers.Rule.FeatureId(); |
|---|
| | 247 | for (var i=0; i<fidFilter.length; i++) { |
|---|
| | 248 | rule.fids.push(fidFilter[i].getAttribute("fid")); |
|---|
| | 249 | } |
|---|
| | 250 | return rule; |
|---|
| | 251 | } |
|---|
| | 252 | |
|---|
| | 253 | // ogc:And filter |
|---|
| | 254 | var andFilter = (nodeName == "And") ? |
|---|
| | 255 | xmlNode : |
|---|
| | 256 | this.getElementsByTagNameNS(xmlNode, this.ogcns, "And"); |
|---|
| | 257 | if (andFilter.length > 0) { |
|---|
| | 258 | andFilter = andFilter[0]; |
|---|
| | 259 | } |
|---|
| | 260 | if (andFilter.childNodes && andFilter.parentNode == xmlNode) { |
|---|
| | 261 | var rule = new OpenLayers.Rule.Logical( |
|---|
| | 262 | {type: OpenLayers.Rule.Logical.Type.AND}); |
|---|
| | 263 | var filters = andFilter.childNodes; |
|---|
| | 264 | for (var i=0; i<filters.length; i++) { |
|---|
| | 265 | if (filters[i].nodeType == 1) { |
|---|
| | 266 | rule.children.push(this.parseFilter(filters[i])); |
|---|
| | 267 | } |
|---|
| | 268 | } |
|---|
| | 269 | return rule; |
|---|
| | 270 | } |
|---|
| | 271 | |
|---|
| | 272 | // ogc:Or filter |
|---|
| | 273 | var orFilter = (nodeName == "Or") ? |
|---|
| | 274 | xmlNode : |
|---|
| | 275 | this.getElementsByTagNameNS(xmlNode, this.ogcns, "Or"); |
|---|
| | 276 | if (orFilter.length > 0) { |
|---|
| | 277 | orFilter = orFilter[0]; |
|---|
| | 278 | } |
|---|
| | 279 | if (orFilter.childNodes && orFilter.parentNode == xmlNode) { |
|---|
| | 280 | var rule = new OpenLayers.Rule.Logical( |
|---|
| | 281 | {type: OpenLayers.Rule.Logical.Type.OR}) |
|---|
| | 282 | var filters = orFilter.childNodes; |
|---|
| | 283 | for (var i=0; i<filters.length; i++) { |
|---|
| | 284 | if (filters[i].nodeType == 1) { |
|---|
| | 285 | rule.children.push(this.parseFilter(filters[i])); |
|---|
| | 286 | } |
|---|
| | 287 | } |
|---|
| | 288 | return rule; |
|---|
| | 289 | } |
|---|
| | 290 | |
|---|
| | 291 | // ogc:Not filter |
|---|
| | 292 | var notFilter = (nodeName == "Not") ? |
|---|
| | 293 | xmlNode : |
|---|
| | 294 | this.getElementsByTagNameNS(xmlNode, this.ogcns, "Not"); |
|---|
| | 295 | if (notFilter.length > 0) { |
|---|
| | 296 | notFilter = notFilter[0]; |
|---|
| | 297 | } |
|---|
| | 298 | if (notFilter.childNodes && notFilter.parentNode == xmlNode) { |
|---|
| | 299 | var rule = new OpenLayers.Rule.Logical( |
|---|
| | 300 | {type: OpenLayers.Rule.Logical.Type.NOT}); |
|---|
| | 301 | rule.children.push(this.parseFilter(notFilter)); |
|---|
| | 302 | return rule; |
|---|
| | 303 | } |
|---|
| | 304 | |
|---|
| | 305 | // Comparison filters |
|---|
| | 306 | for (var i in OpenLayers.Rule.Comparison.Type) { |
|---|
| | 307 | // calculate the rule node name |
|---|
| | 308 | var type = OpenLayers.String.camelize("-property-is-"+ |
|---|
| | 309 | i.replace( |
|---|
| | 310 | /_/g, "-").toLowerCase()); |
|---|
| | 311 | var comparisonFilter = (nodeName == type) ? |
|---|
| | 312 | xmlNode : |
|---|
| | 313 | this.getElementsByTagNameNS(xmlNode, this.ogcns, type); |
|---|
| | 314 | if (comparisonFilter.length > 0) { |
|---|
| | 315 | comparisonFilter = comparisonFilter[0]; |
|---|
| | 316 | } |
|---|
| | 317 | if (comparisonFilter.childNodes) { |
|---|
| | 318 | var rule = new OpenLayers.Rule.Comparison({ |
|---|
| | 319 | type: OpenLayers.Rule.Comparison.Type[i], |
|---|
| | 320 | property: this.parseProperty( |
|---|
| | 321 | comparisonFilter, this.ogcns, "PropertyName")}); |
|---|
| | 322 | // ogc:PropertyIsBetween |
|---|
| | 323 | if (OpenLayers.Rule.Comparison.Type[i] == |
|---|
| | 324 | OpenLayers.Rule.Comparison.Type.BETWEEN) { |
|---|
| | 325 | rule.lowerBoundary = this.parseProperty( |
|---|
| | 326 | comparisonFilter, this.ogcns, "LowerBoundary"); |
|---|
| | 327 | rule.upperBoudary = this.parseProperty( |
|---|
| | 328 | comparisonFilter, this.ogcns, "UpperBoundary"); |
|---|
| | 329 | } else { |
|---|
| | 330 | rule.value = this.parseProperty( |
|---|
| | 331 | comparisonFilter, this.ogcns, "Literal"); |
|---|
| | 332 | // ogc:PropertyIsLike |
|---|
| | 333 | if (OpenLayers.Rule.Comparison.Type[i] == |
|---|
| | 334 | OpenLayers.Rule.Comparison.Type.LIKE) { |
|---|
| | 335 | var wildCard = comparisonFilter.getAttribute("wildCard"); |
|---|
| | 336 | var singleChar = comparisonFilter.getAttribute("singleChar"); |
|---|
| | 337 | var escape = comparisonFilter.getAttribute("escape"); |
|---|
| | 338 | rule.value2regex(wildCard, singleChar, escape); |
|---|
| | 339 | } |
|---|
| | 340 | } |
|---|
| | 341 | return rule; |
|---|
| | 342 | } |
|---|
| | 343 | } |
|---|
| | 344 | |
|---|
| | 345 | // if we get here, the filter was empty |
|---|
| | 346 | return new OpenLayers.Rule(); |
|---|
| | 347 | }, |
|---|
| | 348 | |
|---|
| | 349 | /** |
|---|
| | 350 | * Method: parseProperty |
|---|
| | 351 | * Convenience method to parse the different kinds of properties |
|---|
| | 352 | * found in the sld and ogc namespace. |
|---|
| | 353 | * Parses an ogc node that can either contain a value directly, |
|---|
| | 354 | * or inside a <Literal> property. The parsing can also be limited |
|---|
| | 355 | * to nodes with certain attribute names and/or values |
|---|
| | 356 | * |
|---|
| | 357 | * Parameters: |
|---|
| | 358 | * xmlNode - {<DOMElement>} |
|---|
| | 359 | * namespace - {String} namespace of the node to find |
|---|
| | 360 | * propertyName - {String} name of the property to parse |
|---|
| | 361 | * attributeName - {String} optional name of the property to match |
|---|
| | 362 | * attributeValue - {String} optional value of the specified attribute |
|---|
| | 363 | * |
|---|
| | 364 | * Returns: |
|---|
| | 365 | * {String} The value for the requested property |
|---|
| | 366 | */ |
|---|
| | 367 | parseProperty: function(xmlNode, namespace, propertyName, attributeName, |
|---|
| | 368 | attributeValue) { |
|---|
| | 369 | var result = null; |
|---|
| | 370 | var propertyNodeList = this.getElementsByTagNameNS( |
|---|
| | 371 | xmlNode, namespace, propertyName); |
|---|
| | 372 | |
|---|
| | 373 | if (propertyNodeList && propertyNodeList.length > 0) { |
|---|
| | 374 | var propertyNode = attributeName ? |
|---|
| | 375 | this.getNodeWithAttribute(propertyNodeList, |
|---|
| | 376 | attributeName) : |
|---|
| | 377 | propertyNodeList[0]; |
|---|
| | 378 | |
|---|
| | 379 | // strip namespace from attribute name for Opera browsers |
|---|
| | 380 | if (window.opera && attributeName) { |
|---|
| | 381 | var nsDelimiterPos = attributeName.indexOf(":"); |
|---|
| | 382 | if (nsDelimiterPos != -1) { |
|---|
| | 383 | attributeName = attributeName.substring(++nsDelimiterPos); |
|---|
| | 384 | } |
|---|
| | 385 | } |
|---|
| | 386 | |
|---|
| | 387 | // get the property value from the node matching attributeName |
|---|
| | 388 | // and attributeValue, eg.: |
|---|
| | 389 | // <CssParameter name="stroke"> |
|---|
| | 390 | // <ogc:Literal>red</ogc:Literal> |
|---|
| | 391 | // </CssParameter> |
|---|
| | 392 | // or: |
|---|
| | 393 | // <CssParameter name="stroke">red</CssParameter> |
|---|
| | 394 | if (attributeName && attributeValue) { |
|---|
| | 395 | propertyNode = this.getNodeWithAttribute(propertyNodeList, |
|---|
| | 396 | attributeName, attributeValue); |
|---|
| | 397 | result = this.parseParameter(propertyNode); |
|---|
| | 398 | } |
|---|
| | 399 | |
|---|
| | 400 | // get the attribute value and use it as result, eg.: |
|---|
| | 401 | // <sld:OnlineResource xlink:href="../img/marker.png"/> |
|---|
| | 402 | if (attributeName && !attributeValue) { |
|---|
| | 403 | var propertyNode = this.getNodeWithAttribute(propertyNodeList, |
|---|
| | 404 | attributeName); |
|---|
| | 405 | result = propertyNode.getAttribute(attributeName); |
|---|
| | 406 | } |
|---|
| | 407 | |
|---|
| | 408 | // get the property value directly or from an ogc:propertyName, |
|---|
| | 409 | // ogc:Literal or any other property at the level of the property |
|---|
| | 410 | // node, eg.: |
|---|
| | 411 | // <sld:Opacity>0.5</sld:Opacity> |
|---|
| | 412 | if (!attributeName) { |
|---|
| | 413 | var result = this.parseParameter(propertyNode); |
|---|
| | 414 | } |
|---|
| | 415 | } |
|---|
| | 416 | |
|---|
| | 417 | // adjust the result to be a trimmed string or a number |
|---|
| | 418 | if (result) { |
|---|
| | 419 | result = OpenLayers.String.trim(result); |
|---|
| | 420 | if (!isNaN(result)) { |
|---|
| | 421 | result = parseFloat(result); |
|---|
| | 422 | } |
|---|
| | 423 | } |
|---|
| | 424 | |
|---|
| | 425 | return result; |
|---|
| | 426 | }, |
|---|
| | 427 | |
|---|
| | 428 | /** |
|---|
| | 429 | * Method: parseParameter |
|---|
| | 430 | * parses a property for propertyNames, Literals and textContent and |
|---|
| | 431 | * creates the according value string. |
|---|
| | 432 | * |
|---|
| | 433 | * Parameters: |
|---|
| | 434 | * xmlNode - {<DOMElement>} |
|---|
| | 435 | * |
|---|
| | 436 | * Returns: |
|---|
| | 437 | * {String} a string holding a value suitable for OpenLayers.Style.value |
|---|
| | 438 | */ |
|---|
| | 439 | parseParameter: function(xmlNode) { |
|---|
| | 440 | if (!xmlNode) { |
|---|
| | 441 | return null; |
|---|
| | 442 | } |
|---|
| | 443 | var childNodes = xmlNode.childNodes; |
|---|
| | 444 | if (!childNodes) { |
|---|
| | 445 | return null; |
|---|
| | 446 | } |
|---|
| | 447 | |
|---|
| | 448 | var value = new Array(childNodes.length); |
|---|
| | 449 | for (var i=0; i<childNodes.length; i++) { |
|---|
| | 450 | if (childNodes[i].nodeName.indexOf("Literal") != -1) { |
|---|
| | 451 | value[i] = this.getChildValue(childNodes[i]); |
|---|
| | 452 | } else |
|---|
| | 453 | if (childNodes[i].nodeName.indexOf("propertyName") != -1) { |
|---|
| | 454 | value[i] = "${" + this.getChildValue(childNodes[i]) + "}"; |
|---|
| | 455 | } else |
|---|
| | 456 | if (childNodes[i].nodeType == 3) { |
|---|
| | 457 | value[i] = childNodes[i].text || childNodes[i].textContent; |
|---|
| | 458 | } |
|---|
| | 459 | } |
|---|
| | 460 | return value.join(""); |
|---|
| | 461 | }, |
|---|
| | 462 | |
|---|
| | 463 | /** |
|---|
| | 464 | * Method: getNodeWithAttribute |
|---|
| | 465 | * Walks through a list of xml nodes and returns the fist node that has an |
|---|
| | 466 | * attribute with the name and optional value specified. |
|---|
| | 467 | * |
|---|
| | 468 | * Parameters: |
|---|
| | 469 | * xmlNodeList - {Array(<DOMElement>)} list to search |
|---|
| | 470 | * attributeName - {String} name of the attribute to match |
|---|
| | 471 | * attributeValue - {String} optional value of the attribute |
|---|
| | 472 | */ |
|---|
| | 473 | getNodeWithAttribute: function(xmlNodeList, attributeName, attributeValue) { |
|---|
| | 474 | for (var i=0; i<xmlNodeList.length; i++) { |
|---|
| | 475 | var currentAttributeValue = |
|---|
| | 476 | xmlNodeList[i].getAttribute(attributeName); |
|---|
| | 477 | if (currentAttributeValue) { |
|---|
| | 478 | if (!attributeValue) { |
|---|
| | 479 | return xmlNodeList[i]; |
|---|
| | 480 | } else if (currentAttributeValue == attributeValue) { |
|---|
| | 481 | return xmlNodeList[i]; |
|---|
| | 482 | } |
|---|
| | 483 | } |
|---|
| | 484 | } |
|---|
| | 485 | }, |
|---|
| | 486 | |
|---|
| | 487 | CLASS_NAME: "OpenLayers.Format.SLD" |
|---|
| | 488 | }); |