2 * @requires OpenLayers/Format/WMSCapabilities.js
3 * @requires OpenLayers/Format/XML.js
7 * Class: OpenLayers.Format.WMSCapabilities.v1_1
8 * Abstract class not to be instantiated directly.
11 * - <OpenLayers.Format.XML>
13 OpenLayers.Format.WMSCapabilities.v1_1 = OpenLayers.Class(
14 OpenLayers.Format.XML, {
17 * Constructor: OpenLayers.Format.WMSCapabilities.v1_1
18 * Create an instance of one of the subclasses.
21 * options - {Object} An optional object whose properties will be set on
24 initialize: function(options) {
25 OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
26 this.options = options;
31 * Read capabilities data from a string, and return a list of layers.
34 * data - {String} or {DOMElement} data to read/parse.
37 * {Array} List of named layers.
39 read: function(data) {
40 if(typeof data == "string") {
41 data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
43 var capabilities = {};
44 var root = data.documentElement;
45 this.runChildNodes(capabilities, root);
50 * Method: runChildNodes
52 runChildNodes: function(obj, node) {
53 var children = node.childNodes;
54 var childNode, processor;
55 for(var i=0; i<children.length; ++i) {
56 childNode = children[i];
57 if(childNode.nodeType == 1) {
58 processor = this["read_cap_" + childNode.nodeName];
60 processor.apply(this, [obj, childNode]);
67 * Method: read_cap_Capability
69 read_cap_Capability: function(capabilities, node) {
73 this.runChildNodes(capability, node);
74 capabilities.capability = capability;
78 * Method: read_cap_Request
80 read_cap_Request: function(obj, node) {
82 this.runChildNodes(request, node);
83 obj.request = request;
87 * Method: read_cap_GetMap
89 read_cap_GetMap: function(request, node) {
93 this.runChildNodes(getmap, node);
94 request.getmap = getmap;
98 * Method: read_cap_Format
100 read_cap_Format: function(obj, node) {
102 obj.formats.push(this.getChildValue(node));
107 * Method: read_cap_DCPType
108 * Super simplified HTTP href extractor. Assumes the first online resource
111 read_cap_DCPType: function(obj, node) {
112 var children = node.getElementsByTagName("OnlineResource");
113 if(children.length > 0) {
114 this.read_cap_OnlineResource(obj, children[0]);
119 * Method: read_cap_Service
121 read_cap_Service: function(capabilities, node) {
123 this.runChildNodes(service, node);
124 capabilities.service = service;
128 * Method: read_cap_Layer
130 read_cap_Layer: function(capability, node, parentLayer) {
132 formats: capability.request.getmap.formats || [],
134 queryable: (node.getAttribute("queryable") === "1"
135 || node.getAttribute("queryable") === "true")
137 // deal with property inheritance
140 layer.styles = layer.styles.concat(parentLayer.styles);
142 layer.llbbox = parentLayer.llbbox;
144 layer.minScale = parentLayer.minScale;
145 layer.maxScale = parentLayer.maxScale;
147 var children = node.childNodes;
148 var childNode, nodeName, processor;
149 for(var i=0; i<children.length; ++i) {
150 childNode = children[i];
151 nodeName = childNode.nodeName;
152 processor = this["read_cap_" + childNode.nodeName];
154 if(nodeName == "Layer") {
155 processor.apply(this, [capability, childNode, layer]);
157 processor.apply(this, [layer, childNode]);
162 var index = layer.name.indexOf(":");
164 layer.prefix = layer.name.substring(0, index);
166 capability.layers.push(layer);
171 * Method: read_cap_ScaleHint
172 * The Layer ScaleHint element has min and max attributes that relate to
173 * the minimum and maximum resolution that the server supports. The
174 * values are pixel diagonals measured in meters (on the ground).
176 read_cap_ScaleHint: function(layer, node) {
177 var min = node.getAttribute("min");
178 var max = node.getAttribute("max");
179 var rad2 = Math.pow(2, 0.5);
180 var ipm = OpenLayers.INCHES_PER_UNIT["m"];
181 layer.maxScale = parseFloat(
182 ((rad2 * min) * ipm * OpenLayers.DOTS_PER_INCH).toPrecision(13)
184 layer.minScale = parseFloat(
185 ((rad2 * max) * ipm * OpenLayers.DOTS_PER_INCH).toPrecision(13)
190 * Method: read_cap_Name
192 read_cap_Name: function(obj, node) {
193 var name = this.getChildValue(node);
200 * Method: read_cap_Title
202 read_cap_Title: function(obj, node) {
203 var title = this.getChildValue(node);
210 * Method: read_cap_Abstract
212 read_cap_Abstract: function(obj, node) {
213 var abst = this.getChildValue(node);
215 obj["abstract"] = abst;
220 * Method: read_cap_LatLonBoundingBox
222 read_cap_LatLonBoundingBox: function(layer, node) {
224 parseFloat(node.getAttribute("minx")),
225 parseFloat(node.getAttribute("miny")),
226 parseFloat(node.getAttribute("maxx")),
227 parseFloat(node.getAttribute("maxy"))
232 * Method: read_cap_Style
234 read_cap_Style: function(layer, node) {
236 this.runChildNodes(style, node);
237 layer.styles.push(style);
241 * Method: read_cap_LegendURL
243 read_cap_LegendURL: function(style, node) {
245 width: node.getAttribute('width'),
246 height: node.getAttribute('height')
248 var links = node.getElementsByTagName("OnlineResource");
249 if(links.length > 0) {
250 this.read_cap_OnlineResource(legend, links[0]);
252 style.legend = legend;
256 * Method: read_cap_OnlineResource
258 read_cap_OnlineResource: function(obj, node) {
259 obj.href = this.getAttributeNS(
260 node, "http://www.w3.org/1999/xlink", "href"
264 CLASS_NAME: "OpenLayers.Format.WMSCapabilities.v1_1"