[76] | 1 | /* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for |
---|
| 2 | * full list of contributors). Published under the Clear BSD license. |
---|
| 3 | * See http://svn.openlayers.org/trunk/openlayers/license.txt for the |
---|
| 4 | * full text of the license. */ |
---|
| 5 | |
---|
| 6 | /** |
---|
| 7 | * @requires OpenLayers/Format/XML.js |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | /** |
---|
| 11 | * Class: OpenLayers.Format.WMSDescribeLayer |
---|
| 12 | * Read SLD WMS DescribeLayer response |
---|
| 13 | * DescribeLayer is meant to couple WMS to WFS and WCS |
---|
| 14 | * |
---|
| 15 | * Inherits from: |
---|
| 16 | * - <OpenLayers.Format.XML> |
---|
| 17 | */ |
---|
| 18 | OpenLayers.Format.WMSDescribeLayer = OpenLayers.Class(OpenLayers.Format.XML, { |
---|
| 19 | |
---|
| 20 | /** |
---|
| 21 | * APIProperty: defaultVersion |
---|
| 22 | * {String} Version number to assume if none found. Default is "1.1.1". |
---|
| 23 | */ |
---|
| 24 | defaultVersion: "1.1.1", |
---|
| 25 | |
---|
| 26 | /** |
---|
| 27 | * APIProperty: version |
---|
| 28 | * {String} Specify a version string if one is known. |
---|
| 29 | */ |
---|
| 30 | version: null, |
---|
| 31 | |
---|
| 32 | /** |
---|
| 33 | * Constructor: OpenLayers.Format.WMSDescribeLayer |
---|
| 34 | * Create a new parser for WMS DescribeLayer responses. |
---|
| 35 | * |
---|
| 36 | * Parameters: |
---|
| 37 | * options - {Object} An optional object whose properties will be set on |
---|
| 38 | * this instance. |
---|
| 39 | */ |
---|
| 40 | initialize: function(options) { |
---|
| 41 | OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); |
---|
| 42 | this.options = options; |
---|
| 43 | }, |
---|
| 44 | |
---|
| 45 | /** |
---|
| 46 | * APIMethod: read |
---|
| 47 | * Read DescribeLayer data from a string, and return the response. |
---|
| 48 | * The OGC currently defines 2 formats which are allowed for output, |
---|
| 49 | * so we need to parse these 2 types |
---|
| 50 | * |
---|
| 51 | * Parameters: |
---|
| 52 | * data - {String} or {DOMElement} data to read/parse. |
---|
| 53 | * |
---|
| 54 | * Returns: |
---|
| 55 | * {Array} Array of {<LayerDescription>} objects which have: |
---|
| 56 | * - {String} owsType: WFS/WCS |
---|
| 57 | * - {String} owsURL: the online resource |
---|
| 58 | * - {String} typeName: the name of the typename on the service |
---|
| 59 | */ |
---|
| 60 | read: function(data) { |
---|
| 61 | if(typeof data == "string") { |
---|
| 62 | data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); |
---|
| 63 | } |
---|
| 64 | var root = data.documentElement; |
---|
| 65 | var version = this.version; |
---|
| 66 | if(!version) { |
---|
| 67 | version = root.getAttribute("version"); |
---|
| 68 | if(!version) { |
---|
| 69 | version = this.defaultVersion; |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | // these are identical to us, but some WMS use 1.1.1 and some use 1.1.0 |
---|
| 73 | if (version == "1.1.1" || version == "1.1.0") { |
---|
| 74 | version = "1.1"; |
---|
| 75 | } |
---|
| 76 | var constructor = OpenLayers.Format.WMSDescribeLayer[ |
---|
| 77 | "v" + version.replace(/\./g, "_") |
---|
| 78 | ]; |
---|
| 79 | if(!constructor) { |
---|
| 80 | throw "Can't find a WMS DescribeLayer parser for version " + |
---|
| 81 | version; |
---|
| 82 | } |
---|
| 83 | var parser = new constructor(this.options); |
---|
| 84 | var describelayer = parser.read(data); |
---|
| 85 | describelayer.version = version; |
---|
| 86 | return describelayer; |
---|
| 87 | }, |
---|
| 88 | |
---|
| 89 | CLASS_NAME: "OpenLayers.Format.WMSDescribeLayer" |
---|
| 90 | |
---|
| 91 | }); |
---|