source:
trunk/workshop-routing-foss4g/web/OpenLayers/lib/OpenLayers/Format/WMSCapabilities.js
@
76
Revision 76, 2.4 KB checked in by djay, 12 years ago (diff) | |
---|---|
|
Rev | Line | |
---|---|---|
[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.WMSCapabilities | |
12 | * Read WMS Capabilities. | |
13 | * | |
14 | * Inherits from: | |
15 | * - <OpenLayers.Format.XML> | |
16 | */ | |
17 | OpenLayers.Format.WMSCapabilities = OpenLayers.Class(OpenLayers.Format.XML, { | |
18 | ||
19 | /** | |
20 | * APIProperty: defaultVersion | |
21 | * {String} Version number to assume if none found. Default is "1.1.1". | |
22 | */ | |
23 | defaultVersion: "1.1.1", | |
24 | ||
25 | /** | |
26 | * APIProperty: version | |
27 | * {String} Specify a version string if one is known. | |
28 | */ | |
29 | version: null, | |
30 | ||
31 | /** | |
32 | * Property: parser | |
33 | * {<OpenLayers.Format>} A cached versioned format used for reading. | |
34 | */ | |
35 | parser: null, | |
36 | ||
37 | /** | |
38 | * Constructor: OpenLayers.Format.WMSCapabilities | |
39 | * Create a new parser for WMS capabilities. | |
40 | * | |
41 | * Parameters: | |
42 | * options - {Object} An optional object whose properties will be set on | |
43 | * this instance. | |
44 | */ | |
45 | initialize: function(options) { | |
46 | OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); | |
47 | this.options = options; | |
48 | }, | |
49 | ||
50 | /** | |
51 | * APIMethod: read | |
52 | * Read capabilities data from a string, and return a list of layers. | |
53 | * | |
54 | * Parameters: | |
55 | * data - {String} or {DOMElement} data to read/parse. | |
56 | * | |
57 | * Returns: | |
58 | * {Array} List of named layers. | |
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 || root.getAttribute("version") || this.defaultVersion; | |
66 | if(!this.parser || this.parser.version !== version) { | |
67 | var constr = OpenLayers.Format.WMSCapabilities[ | |
68 | "v" + version.replace(/\./g, "_") | |
69 | ]; | |
70 | if(!constr) { | |
71 | throw "Can't find a WMS capabilities parser for version " + version; | |
72 | } | |
73 | this.parser = new constr(this.options); | |
74 | } | |
75 | var capabilities = this.parser.read(data); | |
76 | capabilities.version = version; | |
77 | return capabilities; | |
78 | }, | |
79 | ||
80 | CLASS_NAME: "OpenLayers.Format.WMSCapabilities" | |
81 | ||
82 | }); |
Note: See TracBrowser
for help on using the repository browser.