| 39 | | gmlns: "http://www.opengis.net/gml", |
|---|
| 40 | | |
|---|
| 41 | | /** |
|---|
| 42 | | * APIProperty: defaultStyle. |
|---|
| 43 | | * {Object} |
|---|
| 44 | | * A simple style, preset with the SLD defaults. |
|---|
| 45 | | */ |
|---|
| 46 | | defaultStyle: { |
|---|
| 47 | | fillColor: "#808080", |
|---|
| 48 | | fillOpacity: 1, |
|---|
| 49 | | strokeColor: "#000000", |
|---|
| 50 | | strokeOpacity: 1, |
|---|
| 51 | | strokeWidth: 1, |
|---|
| 52 | | pointRadius: 6 |
|---|
| 53 | | }, |
|---|
| 54 | | |
|---|
| 55 | | /** |
|---|
| 56 | | * Property: withNamedLayer |
|---|
| 57 | | * {Boolean} Option set during <read>. Default is false. If true, the |
|---|
| 58 | | * return from <read> will be a two item array ([styles, namedLayer]): |
|---|
| 59 | | * - styles - {Array(<OpenLayers.Style>)} |
|---|
| 60 | | * - namedLayer - {Object} hash of userStyles, keyed by |
|---|
| 61 | | * sld:NamedLayer/Name, each again keyed by |
|---|
| 62 | | * sld:UserStyle/Name. Each entry of namedLayer is a |
|---|
| 63 | | * StyleMap for a layer, with the userStyle names as style |
|---|
| 64 | | * keys. |
|---|
| 65 | | */ |
|---|
| 66 | | withNamedLayer: false, |
|---|
| 67 | | |
|---|
| 68 | | /** |
|---|
| 69 | | * APIProperty: overrideDefaultStyleKey |
|---|
| 70 | | * {Boolean} Store styles with key of "default" instead of user style name. |
|---|
| 71 | | * If true, userStyles with sld:IsDefault==1 will be stored with |
|---|
| 72 | | * key "default" instead of the sld:UserStyle/Name in the style map. |
|---|
| 73 | | * Default is true. |
|---|
| 74 | | */ |
|---|
| 75 | | overrideDefaultStyleKey: true, |
|---|
| | 40 | parser: null, |
|---|
| 99 | | * Returns: |
|---|
| 100 | | * {Array(<OpenLayers.Style>)} List of styles. If <withNamedLayer> is |
|---|
| 101 | | * true, return will be a two item array where the first item is |
|---|
| 102 | | * a list of styles and the second is the namedLayer object. |
|---|
| 103 | | */ |
|---|
| 104 | | read: function(data, options) { |
|---|
| 105 | | if (typeof data == "string") { |
|---|
| 106 | | data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); |
|---|
| 107 | | } |
|---|
| 108 | | |
|---|
| 109 | | options = options || {}; |
|---|
| 110 | | OpenLayers.Util.applyDefaults(options, { |
|---|
| 111 | | withNamedLayer: false, |
|---|
| 112 | | overrideDefaultStyleKey: true |
|---|
| 113 | | }); |
|---|
| 114 | | |
|---|
| 115 | | var userStyles = this.getElementsByTagNameNS( |
|---|
| 116 | | data, this.sldns, "UserStyle" |
|---|
| 117 | | ); |
|---|
| 118 | | var result = {}; |
|---|
| 119 | | if (userStyles.length > 0) { |
|---|
| 120 | | var namedLayer = {}; |
|---|
| 121 | | var styles = new Array(userStyles.length); |
|---|
| 122 | | var styleName, userStyle, style; |
|---|
| 123 | | for (var i=0; i<userStyles.length; i++) { |
|---|
| 124 | | userStyle = userStyles[i]; |
|---|
| 125 | | styleName = this.parseProperty( |
|---|
| 126 | | userStyle, this.sldns, "Name" |
|---|
| 127 | | ); |
|---|
| 128 | | style = this.parseUserStyle(userStyle, styleName); |
|---|
| 129 | | |
|---|
| 130 | | if (options.overrideDefaultStyleKey && style.isDefault == true) { |
|---|
| 131 | | styleName = "default"; |
|---|
| 132 | | } |
|---|
| 133 | | |
|---|
| 134 | | if (!namedLayer[style.layerName]) { |
|---|
| 135 | | namedLayer[style.layerName] = {}; |
|---|
| 136 | | } |
|---|
| 137 | | namedLayer[style.layerName][styleName] = style; |
|---|
| 138 | | styles[i] = style; |
|---|
| 139 | | } |
|---|
| 140 | | result = options.withNamedLayer ? [styles, namedLayer] : styles; |
|---|
| 141 | | } |
|---|
| 142 | | return result; |
|---|
| 143 | | }, |
|---|
| 144 | | |
|---|
| 145 | | /** |
|---|
| 146 | | * Method: parseUserStyle |
|---|
| 147 | | * parses a sld userStyle for rules |
|---|
| 148 | | * |
|---|
| 150 | | * xmlNode - {DOMElement} xml node to read the style from |
|---|
| 151 | | * name - {String} name of the style |
|---|
| 152 | | * |
|---|
| 153 | | * Returns: |
|---|
| 154 | | * {<OpenLayers.Style>} |
|---|
| 155 | | */ |
|---|
| 156 | | parseUserStyle: function(xmlNode, name) { |
|---|
| 157 | | var userStyle = new OpenLayers.Style(this.defaultStyle, {name: name}); |
|---|
| 158 | | |
|---|
| 159 | | userStyle.isDefault = ( |
|---|
| 160 | | this.parseProperty(xmlNode, this.sldns, "IsDefault") == 1 |
|---|
| 161 | | ); |
|---|
| 162 | | |
|---|
| 163 | | // get the name of the layer if we have a NamedLayer |
|---|
| 164 | | var namedLayerNode = xmlNode.parentNode; |
|---|
| 165 | | var nameNodes = this.getElementsByTagNameNS( |
|---|
| 166 | | namedLayerNode, this.sldns, "Name" |
|---|
| 167 | | ); |
|---|
| 168 | | if (namedLayerNode.nodeName.indexOf("NamedLayer") != -1 && |
|---|
| 169 | | nameNodes && |
|---|
| 170 | | nameNodes.length > 0 && |
|---|
| 171 | | nameNodes[0].parentNode == namedLayerNode) { |
|---|
| 172 | | userStyle.layerName = this.getChildValue(nameNodes[0]); |
|---|
| 173 | | } |
|---|
| 174 | | |
|---|
| 175 | | var ruleNodes = this.getElementsByTagNameNS( |
|---|
| 176 | | xmlNode, this.sldns, "Rule" |
|---|
| 177 | | ); |
|---|
| 178 | | |
|---|
| 179 | | if (ruleNodes.length > 0) { |
|---|
| 180 | | var rules = userStyle.rules; |
|---|
| 181 | | var ruleName; |
|---|
| 182 | | for (var i=0; i<ruleNodes.length; i++) { |
|---|
| 183 | | ruleName = this.parseProperty(ruleNodes[i], this.sldns, "Name"); |
|---|
| 184 | | rules.push(this.parseRule(ruleNodes[i], ruleName)); |
|---|
| 185 | | } |
|---|
| 186 | | } |
|---|
| 187 | | |
|---|
| 188 | | return userStyle; |
|---|
| 189 | | }, |
|---|
| 190 | | |
|---|
| 191 | | /** |
|---|
| 192 | | * Method: parseRule |
|---|
| 193 | | * This function is the core of the SLD parsing code in OpenLayers. |
|---|
| 194 | | * It creates the rule with its constraints and symbolizers. |
|---|
| | 59 | * sld - {Object} An object representing the SLD. |
|---|
| | 60 | * options - {Object} Optional configuration object. |
|---|
| 202 | | parseRule: function(xmlNode, name) { |
|---|
| 203 | | |
|---|
| 204 | | // FILTERS |
|---|
| 205 | | |
|---|
| 206 | | var filter = this.getElementsByTagNameNS(xmlNode, this.ogcns, "Filter"); |
|---|
| 207 | | if (filter && filter.length > 0) { |
|---|
| 208 | | var rule = this.parseFilter(filter[0]); |
|---|
| 209 | | } else { |
|---|
| 210 | | // start with an empty rule that always applies |
|---|
| 211 | | var rule = new OpenLayers.Rule(); |
|---|
| 212 | | // and check if the rule is an ElseFilter |
|---|
| 213 | | var elseFilter = this.getElementsByTagNameNS(xmlNode, this.ogcns, |
|---|
| 214 | | "ElseFilter"); |
|---|
| 215 | | if (elseFilter && elseFilter.length > 0) { |
|---|
| 216 | | rule.elseFilter = true; |
|---|
| | 65 | write: function(sld, options) { |
|---|
| | 66 | var version = (options && options.version) || |
|---|
| | 67 | this.version || this.defaultVersion; |
|---|
| | 68 | if(!this.parser || this.parser.VERSION != version) { |
|---|
| | 69 | var format = OpenLayers.Format.SLD[ |
|---|
| | 70 | "v" + version.replace(/\./g, "_") |
|---|
| | 71 | ]; |
|---|
| | 72 | if(!format) { |
|---|
| | 73 | throw "Can't find a SLD parser for version " + |
|---|
| | 74 | version; |
|---|
| 219 | | |
|---|
| 220 | | rule.name = name; |
|---|
| 221 | | |
|---|
| 222 | | // SCALE DENOMINATORS |
|---|
| 223 | | |
|---|
| 224 | | // MinScaleDenominator |
|---|
| 225 | | var minScale = this.getElementsByTagNameNS( |
|---|
| 226 | | xmlNode, this.sldns, "MinScaleDenominator" |
|---|
| 227 | | ); |
|---|
| 228 | | if (minScale && minScale.length > 0) { |
|---|
| 229 | | rule.minScaleDenominator = |
|---|
| 230 | | parseFloat(this.getChildValue(minScale[0])); |
|---|
| 231 | | } |
|---|
| 232 | | |
|---|
| 233 | | // MaxScaleDenominator |
|---|
| 234 | | var maxScale = this.getElementsByTagNameNS( |
|---|
| 235 | | xmlNode, this.sldns, "MaxScaleDenominator" |
|---|
| 236 | | ); |
|---|
| 237 | | if (maxScale && maxScale.length > 0) { |
|---|
| 238 | | rule.maxScaleDenominator = |
|---|
| 239 | | parseFloat(this.getChildValue(maxScale[0])); |
|---|
| 240 | | } |
|---|
| 241 | | |
|---|
| 242 | | // STYLES |
|---|
| 243 | | |
|---|
| 244 | | // walk through all symbolizers |
|---|
| 245 | | var prefixes = OpenLayers.Style.SYMBOLIZER_PREFIXES; |
|---|
| 246 | | for (var s=0; s<prefixes.length; s++) { |
|---|
| 247 | | |
|---|
| 248 | | // symbolizer type |
|---|
| 249 | | var symbolizer = this.getElementsByTagNameNS( |
|---|
| 250 | | xmlNode, this.sldns, prefixes[s]+"Symbolizer" |
|---|
| 251 | | ); |
|---|
| 252 | | |
|---|
| 253 | | if (symbolizer && symbolizer.length > 0) { |
|---|
| 254 | | |
|---|
| 255 | | var style = {}; |
|---|
| 256 | | |
|---|
| 257 | | // externalGraphic |
|---|
| 258 | | var graphic = this.getElementsByTagNameNS( |
|---|
| 259 | | symbolizer[0], this.sldns, "Graphic" |
|---|
| 260 | | ); |
|---|
| 261 | | if (graphic && graphic.length > 0) { |
|---|
| 262 | | style.externalGraphic = this.parseProperty( |
|---|
| 263 | | graphic[0], this.sldns, "OnlineResource", "xlink:href" |
|---|
| 264 | | ); |
|---|
| 265 | | style.pointRadius = this.parseProperty( |
|---|
| 266 | | graphic[0], this.sldns, "Size" |
|---|
| 267 | | ); |
|---|
| 268 | | style.graphicOpacity = this.parseProperty( |
|---|
| 269 | | graphic[0], this.sldns, "Opacity" |
|---|
| 270 | | ); |
|---|
| 271 | | } |
|---|
| 272 | | |
|---|
| 273 | | // fill |
|---|
| 274 | | var fill = this.getElementsByTagNameNS( |
|---|
| 275 | | symbolizer[0], this.sldns, "Fill" |
|---|
| 276 | | ); |
|---|
| 277 | | if (fill && fill.length > 0) { |
|---|
| 278 | | style.fillColor = this.parseProperty( |
|---|
| 279 | | fill[0], this.sldns, "CssParameter", "name", "fill" |
|---|
| 280 | | ); |
|---|
| 281 | | style.fillOpacity = this.parseProperty( |
|---|
| 282 | | fill[0], this.sldns, "CssParameter", |
|---|
| 283 | | "name", "fill-opacity" |
|---|
| 284 | | ) || 1; |
|---|
| 285 | | } |
|---|
| 286 | | |
|---|
| 287 | | // stroke |
|---|
| 288 | | var stroke = this.getElementsByTagNameNS( |
|---|
| 289 | | symbolizer[0], this.sldns, "Stroke" |
|---|
| 290 | | ); |
|---|
| 291 | | if (stroke && stroke.length > 0) { |
|---|
| 292 | | style.strokeColor = this.parseProperty( |
|---|
| 293 | | stroke[0], this.sldns, "CssParameter", "name", "stroke" |
|---|
| 294 | | ); |
|---|
| 295 | | style.strokeOpacity = this.parseProperty( |
|---|
| 296 | | stroke[0], this.sldns, "CssParameter", |
|---|
| 297 | | "name", "stroke-opacity" |
|---|
| 298 | | ) || 1; |
|---|
| 299 | | style.strokeWidth = this.parseProperty( |
|---|
| 300 | | stroke[0], this.sldns, "CssParameter", |
|---|
| 301 | | "name", "stroke-width" |
|---|
| 302 | | ); |
|---|
| 303 | | style.strokeLinecap = this.parseProperty( |
|---|
| 304 | | stroke[0], this.sldns, "CssParameter", |
|---|
| 305 | | "name", "stroke-linecap" |
|---|
| 306 | | ); |
|---|
| 307 | | } |
|---|
| 308 | | |
|---|
| 309 | | // set the [point|line|polygon]Symbolizer property of the rule |
|---|
| 310 | | rule.symbolizer[prefixes[s]] = style; |
|---|
| 311 | | } |
|---|
| 312 | | } |
|---|
| 313 | | |
|---|
| 314 | | return rule; |
|---|
| | 78 | var root = this.parser.write(sld); |
|---|
| | 79 | return OpenLayers.Format.XML.prototype.write.apply(this, [root]); |
|---|
| 322 | | * xmlNode - {<DOMElement>} |
|---|
| 323 | | * |
|---|
| 324 | | * Returns: |
|---|
| 325 | | * {<OpenLayers.Rule>} rule representing the filter |
|---|
| 326 | | */ |
|---|
| 327 | | parseFilter: function(xmlNode) { |
|---|
| 328 | | // ogc:FeatureId filter |
|---|
| 329 | | var filter = this.getNodeOrChildrenByTagName(xmlNode, "FeatureId"); |
|---|
| 330 | | if (filter) { |
|---|
| 331 | | var rule = new OpenLayers.Rule.FeatureId(); |
|---|
| 332 | | for (var i=0; i<filter.length; i++) { |
|---|
| 333 | | rule.fids.push(filter[i].getAttribute("fid")); |
|---|
| 334 | | } |
|---|
| 335 | | return rule; |
|---|
| 336 | | } |
|---|
| 337 | | |
|---|
| 338 | | // ogc:And filter |
|---|
| 339 | | filter = this.getNodeOrChildrenByTagName(xmlNode, "And"); |
|---|
| 340 | | if (filter) { |
|---|
| 341 | | var rule = new OpenLayers.Rule.Logical( |
|---|
| 342 | | {type: OpenLayers.Rule.Logical.AND}); |
|---|
| 343 | | var filters = filter[0].childNodes; |
|---|
| 344 | | for (var i=0; i<filters.length; i++) { |
|---|
| 345 | | if (filters[i].nodeType == 1) { |
|---|
| 346 | | rule.rules.push(this.parseFilter(filters[i])); |
|---|
| 347 | | } |
|---|
| 348 | | } |
|---|
| 349 | | return rule; |
|---|
| 350 | | } |
|---|
| 351 | | |
|---|
| 352 | | // ogc:Or filter |
|---|
| 353 | | filter = this.getNodeOrChildrenByTagName(xmlNode, "Or"); |
|---|
| 354 | | if (filter) { |
|---|
| 355 | | var rule = new OpenLayers.Rule.Logical( |
|---|
| 356 | | {type: OpenLayers.Rule.Logical.OR}) |
|---|
| 357 | | var filters = filter[0].childNodes; |
|---|
| 358 | | for (var i=0; i<filters.length; i++) { |
|---|
| 359 | | if (filters[i].nodeType == 1) { |
|---|
| 360 | | rule.rules.push(this.parseFilter(filters[i])); |
|---|
| 361 | | } |
|---|
| 362 | | } |
|---|
| 363 | | return rule; |
|---|
| 364 | | } |
|---|
| 365 | | |
|---|
| 366 | | // ogc:Not filter |
|---|
| 367 | | filter = this.getNodeOrChildrenByTagName(xmlNode, "Not"); |
|---|
| 368 | | if (filter) { |
|---|
| 369 | | var rule = new OpenLayers.Rule.Logical( |
|---|
| 370 | | {type: OpenLayers.Rule.Logical.NOT}); |
|---|
| 371 | | var filters = filter[0].childNodes; |
|---|
| 372 | | for (var i=0; i<filters.length; i++) { |
|---|
| 373 | | if (filters[i].nodeType == 1) { |
|---|
| 374 | | rule.rules.push(this.parseFilter(filters[i])); |
|---|
| 375 | | } |
|---|
| 376 | | } |
|---|
| 377 | | return rule; |
|---|
| 378 | | } |
|---|
| 379 | | |
|---|
| 380 | | // Comparison filters |
|---|
| 381 | | for (var type in this.TYPES) { |
|---|
| 382 | | var filter = this.getNodeOrChildrenByTagName(xmlNode, type); |
|---|
| 383 | | if (filter) { |
|---|
| 384 | | filter = filter[0]; |
|---|
| 385 | | var rule = new OpenLayers.Rule.Comparison({ |
|---|
| 386 | | type: OpenLayers.Rule.Comparison[this.TYPES[type]], |
|---|
| 387 | | property: this.parseProperty( |
|---|
| 388 | | filter, this.ogcns, "PropertyName")}); |
|---|
| 389 | | // ogc:PropertyIsBetween |
|---|
| 390 | | if (this.TYPES[type] == "BETWEEN") { |
|---|
| 391 | | rule.lowerBoundary = this.parseProperty( |
|---|
| 392 | | filter, this.ogcns, "LowerBoundary"); |
|---|
| 393 | | rule.upperBoudary = this.parseProperty( |
|---|
| 394 | | filter, this.ogcns, "UpperBoundary"); |
|---|
| 395 | | } else { |
|---|
| 396 | | rule.value = this.parseProperty( |
|---|
| 397 | | filter, this.ogcns, "Literal"); |
|---|
| 398 | | // ogc:PropertyIsLike |
|---|
| 399 | | if (this.TYPES[type] == "LIKE") { |
|---|
| 400 | | var wildCard = filter.getAttribute("wildCard"); |
|---|
| 401 | | var singleChar = filter.getAttribute("singleChar"); |
|---|
| 402 | | var escape = filter.getAttribute("escape"); |
|---|
| 403 | | rule.value2regex(wildCard, singleChar, escape); |
|---|
| 404 | | } |
|---|
| 405 | | } |
|---|
| 406 | | return rule; |
|---|
| 407 | | } |
|---|
| 408 | | } |
|---|
| 409 | | |
|---|
| 410 | | // if we get here, the filter was empty |
|---|
| 411 | | return new OpenLayers.Rule(); |
|---|
| 412 | | }, |
|---|
| 413 | | |
|---|
| 414 | | /** |
|---|
| 415 | | * Method: getNodeOrChildrenByTagName |
|---|
| 416 | | * Convenience method to get a node or its child nodes, but only |
|---|
| 417 | | * those matching a tag name. |
|---|
| 418 | | * |
|---|
| 419 | | * Returns: |
|---|
| 420 | | * {Array(<DOMElement>)} or null if no matching content is found |
|---|
| 421 | | */ |
|---|
| 422 | | getNodeOrChildrenByTagName: function(xmlNode, tagName) { |
|---|
| 423 | | var nodeName = (xmlNode.prefix) ? |
|---|
| 424 | | xmlNode.nodeName.split(":")[1] : |
|---|
| 425 | | xmlNode.nodeName; |
|---|
| 426 | | |
|---|
| 427 | | if (nodeName == tagName) { |
|---|
| 428 | | return [xmlNode]; |
|---|
| 429 | | } else { |
|---|
| 430 | | var nodelist = this.getElementsByTagNameNS( |
|---|
| 431 | | xmlNode, this.ogcns, tagName); |
|---|
| 432 | | } |
|---|
| 433 | | |
|---|
| 434 | | // make a new list which only contains matching child nodes |
|---|
| 435 | | if (nodelist.length > 0) { |
|---|
| 436 | | var node; |
|---|
| 437 | | var list = []; |
|---|
| 438 | | for (var i=0; i<nodelist.length; i++) { |
|---|
| 439 | | node = nodelist[i]; |
|---|
| 440 | | if (node.parentNode == xmlNode) { |
|---|
| 441 | | list.push(node); |
|---|
| 442 | | } |
|---|
| 443 | | } |
|---|
| 444 | | return list.length > 0 ? list : null; |
|---|
| 445 | | } |
|---|
| 446 | | |
|---|
| 447 | | return null; |
|---|
| 448 | | }, |
|---|
| 449 | | |
|---|
| 450 | | /** |
|---|
| 451 | | * Method: parseProperty |
|---|
| 452 | | * Convenience method to parse the different kinds of properties |
|---|
| 453 | | * found in the sld and ogc namespace. |
|---|
| | 87 | * data - {String | DOMElement} Data to read. |
|---|
| 467 | | * {String} The value for the requested property. |
|---|
| 468 | | */ |
|---|
| 469 | | parseProperty: function(xmlNode, namespace, propertyName, attributeName, |
|---|
| 470 | | attributeValue) { |
|---|
| 471 | | var result = null; |
|---|
| 472 | | var propertyNodeList = this.getElementsByTagNameNS( |
|---|
| 473 | | xmlNode, namespace, propertyName); |
|---|
| 474 | | |
|---|
| 475 | | if (propertyNodeList && propertyNodeList.length > 0) { |
|---|
| 476 | | var propertyNode = attributeName ? |
|---|
| 477 | | this.getNodeWithAttribute(propertyNodeList, |
|---|
| 478 | | attributeName) : |
|---|
| 479 | | propertyNodeList[0]; |
|---|
| 480 | | |
|---|
| 481 | | // strip namespace from attribute name for Opera browsers |
|---|
| 482 | | if (window.opera && attributeName) { |
|---|
| 483 | | var nsDelimiterPos = attributeName.indexOf(":"); |
|---|
| 484 | | if (nsDelimiterPos != -1) { |
|---|
| 485 | | attributeName = attributeName.substring(++nsDelimiterPos); |
|---|
| 486 | | } |
|---|
| 487 | | } |
|---|
| 488 | | |
|---|
| 489 | | // get the property value from the node matching attributeName |
|---|
| 490 | | // and attributeValue, eg.: |
|---|
| 491 | | // <CssParameter name="stroke"> |
|---|
| 492 | | // <ogc:Literal>red</ogc:Literal> |
|---|
| 493 | | // </CssParameter> |
|---|
| 494 | | // or: |
|---|
| 495 | | // <CssParameter name="stroke">red</CssParameter> |
|---|
| 496 | | if (attributeName && attributeValue) { |
|---|
| 497 | | propertyNode = this.getNodeWithAttribute(propertyNodeList, |
|---|
| 498 | | attributeName, attributeValue); |
|---|
| 499 | | result = this.parseParameter(propertyNode); |
|---|
| 500 | | } |
|---|
| 501 | | |
|---|
| 502 | | // get the attribute value and use it as result, eg.: |
|---|
| 503 | | // <sld:OnlineResource xlink:href="../img/marker.png"/> |
|---|
| 504 | | if (attributeName && !attributeValue) { |
|---|
| 505 | | var propertyNode = this.getNodeWithAttribute(propertyNodeList, |
|---|
| 506 | | attributeName); |
|---|
| 507 | | result = propertyNode.getAttribute(attributeName); |
|---|
| 508 | | } |
|---|
| 509 | | |
|---|
| 510 | | // get the property value directly or from an ogc:propertyName, |
|---|
| 511 | | // ogc:Literal or any other property at the level of the property |
|---|
| 512 | | // node, eg.: |
|---|
| 513 | | // <sld:Opacity>0.5</sld:Opacity> |
|---|
| 514 | | if (!attributeName) { |
|---|
| 515 | | var result = this.parseParameter(propertyNode); |
|---|
| 516 | | } |
|---|
| 517 | | } |
|---|
| 518 | | |
|---|
| 519 | | // adjust the result to be a trimmed string or a number |
|---|
| 520 | | if (result) { |
|---|
| 521 | | result = OpenLayers.String.trim(result); |
|---|
| 522 | | if (!isNaN(result)) { |
|---|
| 523 | | result = parseFloat(result); |
|---|
| 524 | | } |
|---|
| 525 | | } |
|---|
| 526 | | |
|---|
| 527 | | return result; |
|---|
| 528 | | }, |
|---|
| 529 | | |
|---|
| 530 | | /** |
|---|
| 531 | | * Method: parseParameter |
|---|
| 532 | | * parses a property for propertyNames, Literals and textContent and |
|---|
| 533 | | * creates the according value string. |
|---|
| 534 | | * |
|---|
| 535 | | * Parameters: |
|---|
| 536 | | * xmlNode - {<DOMElement>} |
|---|
| 537 | | * |
|---|
| 538 | | * Returns: |
|---|
| 539 | | * {String} a string holding a value suitable for OpenLayers.Style.value |
|---|
| | 90 | * {Object} An object representing the SLD. |
|---|
| 562 | | return value.join(""); |
|---|
| 563 | | }, |
|---|
| 564 | | |
|---|
| 565 | | /** |
|---|
| 566 | | * Method: getNodeWithAttribute |
|---|
| 567 | | * Walks through a list of xml nodes and returns the fist node that has an |
|---|
| 568 | | * attribute with the name and optional value specified. |
|---|
| 569 | | * |
|---|
| 570 | | * Parameters: |
|---|
| 571 | | * xmlNodeList - {Array(<DOMElement>)} list to search |
|---|
| 572 | | * attributeName - {String} name of the attribute to match |
|---|
| 573 | | * attributeValue - {String} optional value of the attribute |
|---|
| 574 | | */ |
|---|
| 575 | | getNodeWithAttribute: function(xmlNodeList, attributeName, attributeValue) { |
|---|
| 576 | | for (var i=0; i<xmlNodeList.length; i++) { |
|---|
| 577 | | var currentAttributeValue = |
|---|
| 578 | | xmlNodeList[i].getAttribute(attributeName); |
|---|
| 579 | | if (currentAttributeValue) { |
|---|
| 580 | | if (!attributeValue) { |
|---|
| 581 | | return xmlNodeList[i]; |
|---|
| 582 | | } else if (currentAttributeValue == attributeValue) { |
|---|
| 583 | | return xmlNodeList[i]; |
|---|
| 584 | | } |
|---|
| | 104 | if(!this.parser || this.parser.VERSION != version) { |
|---|
| | 105 | var format = OpenLayers.Format.SLD[ |
|---|
| | 106 | "v" + version.replace(/\./g, "_") |
|---|
| | 107 | ]; |
|---|
| | 108 | if(!format) { |
|---|
| | 109 | throw "Can't find a SLD parser for version " + |
|---|
| | 110 | version; |
|---|