/** * @requires OpenLayers/Format/WMSCapabilities.js * @requires OpenLayers/Format/XML.js */ /** * Class: OpenLayers.Format.WMSCapabilities.v1_1 * Abstract class not to be instantiated directly. * * Inherits from: * - */ OpenLayers.Format.WMSCapabilities.v1_1 = OpenLayers.Class( OpenLayers.Format.XML, { /** * Constructor: OpenLayers.Format.WMSCapabilities.v1_1 * Create an instance of one of the subclasses. * * Parameters: * options - {Object} An optional object whose properties will be set on * this instance. */ initialize: function(options) { OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); this.options = options; }, /** * APIMethod: read * Read capabilities data from a string, and return a list of layers. * * Parameters: * data - {String} or {DOMElement} data to read/parse. * * Returns: * {Array} List of named layers. */ read: function(data) { if(typeof data == "string") { data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); } var capabilities = {}; var root = data.documentElement; this.runChildNodes(capabilities, root); return capabilities; }, /** * Method: runChildNodes */ runChildNodes: function(obj, node) { var children = node.childNodes; var childNode, processor; for(var i=0; i 0) { this.read_cap_OnlineResource(obj, children[0]); } }, /** * Method: read_cap_Exception */ read_cap_Exception: function(capability, node) { var exception = { formats: [] }; this.runChildNodes(exception, node); capability.exception = exception; }, /** * Method: read_cap_UserDefinedSymbolization */ read_cap_UserDefinedSymbolization: function(capability, node) { var userSymbols = { supportSLD: parseInt(node.getAttribute("SupportSLD")) == 1, userLayer: parseInt(node.getAttribute("UserLayer")) == 1, userStyle: parseInt(node.getAttribute("UserStyle")) == 1, remoteWFS: parseInt(node.getAttribute("RemoteWFS")) == 1 }; capability.userSymbols = userSymbols; }, /** * Method: read_cap_Layer */ read_cap_Layer: function(capability, node, parentLayer) { var layer = { formats: capability.request.getmap.formats || [], styles: [], srs: {}, bbox: {}, dimensions: {}, metadataURLs: [], authorityURLs: {}, identifiers: {}, keywords: [] }; // deal with property inheritance if(parentLayer) { // add style layer.styles = layer.styles.concat(parentLayer.styles); var attributes = ["queryable", "cascaded", "fixedWidth", "fixedHeight", "opaque", "noSubsets", "llbbox", "minScale", "maxScale", "attribution"]; var complexAttr = ["srs", "bbox", "dimensions", "authorityURLs"]; var key; for (var i=0; i 0) { layer.prefix = layer.name.substring(0, index); } capability.layers.push(layer); } }, /** * Method: read_cap_ScaleHint * The Layer ScaleHint element has min and max attributes that relate to * the minimum and maximum resolution that the server supports. The * values are pixel diagonals measured in meters (on the ground). */ read_cap_ScaleHint: function(layer, node) { var min = node.getAttribute("min"); var max = node.getAttribute("max"); var rad2 = Math.pow(2, 0.5); var ipm = OpenLayers.INCHES_PER_UNIT["m"]; layer.maxScale = parseFloat( ((min / rad2) * ipm * OpenLayers.DOTS_PER_INCH).toPrecision(13) ); layer.minScale = parseFloat( ((max / rad2) * ipm * OpenLayers.DOTS_PER_INCH).toPrecision(13) ); }, /** * Method: read_cap_Name */ read_cap_Name: function(obj, node) { var name = this.getChildValue(node); if(name) { obj.name = name; } }, /** * Method: read_cap_Title */ read_cap_Title: function(obj, node) { var title = this.getChildValue(node); if(title) { obj.title = title; } }, /** * Method: read_cap_Abstract */ read_cap_Abstract: function(obj, node) { var abst = this.getChildValue(node); if(abst) { obj["abstract"] = abst; } }, /** * Method: read_cap_Attribution */ read_cap_Attribution: function(obj, node) { var attribution = {}; this.runChildNodes(attribution, node); obj.attribution = attribution; }, /** * Method: read_cap_LogoURL */ read_cap_LogoURL: function(obj, node) { obj.logo = { width: node.getAttribute("width"), height: node.getAttribute("height") }; this.runChildNodes(obj.logo, node); }, /** * Method: read_cap_MetadataURL */ read_cap_MetadataURL: function(layer, node) { var metadataURL = {}; this.runChildNodes(metadataURL, node); metadataURL.type = node.getAttribute("type"); layer.metadataURLs.push(metadataURL); }, /** * Method: read_cap_DataURL */ read_cap_DataURL: function(layer, node) { layer.dataURL = {}; this.runChildNodes(layer.dataURL, node); }, /** * Method: read_cap_FeatureListURL */ read_cap_FeatureListURL: function(layer, node) { layer.featureListURL = {}; this.runChildNodes(layer.featureListURL, node); }, /** * Method: read_cap_AuthorityURL */ read_cap_AuthorityURL: function(layer, node) { var name = node.getAttribute("name"); if (! (name in layer.authorityURLs)) { var authority = {}; this.runChildNodes(authority, node); layer.authorityURLs[name] = authority.href; } else { // A child Layer SHALL NOT define an AuthorityURL with the // same name attribute as one inherited from a parent return; } }, /** * Method: read_cap_Identifier */ read_cap_Identifier: function(layer, node) { var authority = node.getAttribute("authority"); if (authority in layer.authorityURLs) { layer.identifiers[authority] = this.getChildValue(node); } else { // A layer SHALL NOT declare an Identifier unless a // corresponding authorityURL has been declared or // inherited earlier in the Capabilities XML return; } }, /** * Method: read_cap_KeywordList */ read_cap_KeywordList: function(layer, node) { var obj = layer; this.runChildNodes(obj, node); }, /** * Method: read_cap_Keyword */ read_cap_Keyword: function(obj, node) { if(obj.keywords) { obj.keywords.push(this.getChildValue(node)); } }, /** * Method: read_cap_LatLonBoundingBox */ read_cap_LatLonBoundingBox: function(layer, node) { layer.llbbox = [ parseFloat(node.getAttribute("minx")), parseFloat(node.getAttribute("miny")), parseFloat(node.getAttribute("maxx")), parseFloat(node.getAttribute("maxy")) ]; }, /** * Method: read_cap_BoundingBox */ read_cap_BoundingBox: function(layer, node) { var bbox = {}; bbox.srs = node.getAttribute("SRS"); bbox.bbox = [ parseFloat(node.getAttribute("minx")), parseFloat(node.getAttribute("miny")), parseFloat(node.getAttribute("maxx")), parseFloat(node.getAttribute("maxy")) ]; var res = { x: parseFloat(node.getAttribute("resx")), y: parseFloat(node.getAttribute("resy")) }; if (! (isNaN(res.x) && isNaN(res.y))) { bbox.res = res; } layer.bbox[bbox.srs] = bbox; }, /** * Method: read_cap_Style */ read_cap_Style: function(layer, node) { var style = {}; this.runChildNodes(style, node); layer.styles.push(style); }, /** * Method: read_cap_Dimension */ read_cap_Dimension: function(layer, node) { var name = node.getAttribute("name").toLowerCase(); if (name in layer["dimensions"]) { // "A child SHALL NOT redefine a Dimension with the same // name attribute as one that was inherited" return; } var dim = { name: name, units: node.getAttribute("units"), unitsymbol: node.getAttribute("unitSymbol") }; layer.dimensions[dim.name] = dim; }, /** * Method: read_cap_Extent */ read_cap_Extent: function(layer, node) { var name = node.getAttribute("name").toLowerCase(); if (name in layer["dimensions"]) { var extent = layer.dimensions[name]; extent.nearestVal = node.getAttribute("nearestValue") === "1"; extent.multipleVal = node.getAttribute("multipleValues") === "1"; extent.current = node.getAttribute("current") === "1"; extent["default"] = node.getAttribute("default") || ""; var values = this.getChildValue(node); extent.values = values.split(","); } else { // A layer SHALL NOT declare an Extent unless a Dimension // with the same name has been declared or inherited // earlier in the Capabilities XML return; } }, /** * Method: read_cap_LegendURL */ read_cap_LegendURL: function(style, node) { style.legend = { width: node.getAttribute("width"), height: node.getAttribute("height") }; this.runChildNodes(style.legend, node); }, /** * Method: read_cap_OnlineResource */ read_cap_OnlineResource: function(obj, node) { obj.href = this.getAttributeNS( node, "http://www.w3.org/1999/xlink", "href" ); }, CLASS_NAME: "OpenLayers.Format.WMSCapabilities.v1_1" });