/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for * full list of contributors). Published under the 2-clause BSD license. * See license.txt in the OpenLayers distribution or repository for the * full text of the license. */ /** * @requires OpenLayers/Format/WMC.js * @requires OpenLayers/Format/XML.js */ /** * Class: OpenLayers.Format.WMC.v1 * Superclass for WMC version 1 parsers. * * Inherits from: * - */ OpenLayers.Format.WMC.v1 = OpenLayers.Class(OpenLayers.Format.XML, { /** * Property: namespaces * {Object} Mapping of namespace aliases to namespace URIs. */ namespaces: { ol: "http://openlayers.org/context", wmc: "http://www.opengis.net/context", sld: "http://www.opengis.net/sld", xlink: "http://www.w3.org/1999/xlink", xsi: "http://www.w3.org/2001/XMLSchema-instance" }, /** * Property: schemaLocation * {String} Schema location for a particular minor version. */ schemaLocation: "", /** * Method: getNamespacePrefix * Get the namespace prefix for a given uri from the object. * * Returns: * {String} A namespace prefix or null if none found. */ getNamespacePrefix: function(uri) { var prefix = null; if(uri == null) { prefix = this.namespaces[this.defaultPrefix]; } else { for(prefix in this.namespaces) { if(this.namespaces[prefix] == uri) { break; } } } return prefix; }, /** * Property: defaultPrefix */ defaultPrefix: "wmc", /** * Property: rootPrefix * {String} Prefix on the root node that maps to the context namespace URI. */ rootPrefix: null, /** * Property: defaultStyleName * {String} Style name used if layer has no style param. Default is "". */ defaultStyleName: "", /** * Property: defaultStyleTitle * {String} Default style title. Default is "Default". */ defaultStyleTitle: "Default", /** * Constructor: OpenLayers.Format.WMC.v1 * Instances of this class are not created directly. Use the * constructor instead. * * 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]); }, /** * Method: 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 root = data.documentElement; this.rootPrefix = root.prefix; var context = { version: root.getAttribute("version") }; this.runChildNodes(context, root); return context; }, /** * Method: runChildNodes */ runChildNodes: function(obj, node) { var children = node.childNodes; var childNode, processor, prefix, local; for(var i=0, len=children.length; i. * Can optionally be used to set attributes and a text child value. * * Parameters: * name - {String} The qualified node name. * childValue - {String} Optional value for text child node. * attributes - {Object} Optional object representing attributes. * * Returns: * {Element} An element node. */ createElementDefaultNS: function(name, childValue, attributes) { var node = this.createElementNS( this.namespaces[this.defaultPrefix], name ); if(childValue) { node.appendChild(this.createTextNode(childValue)); } if(attributes) { this.setAttributes(node, attributes); } return node; }, /** * Method: setAttributes * Set multiple attributes given key value pairs from an object. * * Parameters: * node - {Element} An element node. * obj - {Object} An object whose properties represent attribute names and * values represent attribute values. */ setAttributes: function(node, obj) { var value; for(var name in obj) { value = obj[name].toString(); if(value.match(/[A-Z]/)) { // safari lowercases attributes with setAttribute this.setAttributeNS(node, null, name, value); } else { node.setAttribute(name, value); } } }, /** * Method: write_wmc_General * Create a General node given an context object. * * Parameters: * context - {Object} Context object. * * Returns: * {Element} A WMC General element node. */ write_wmc_General: function(context) { var node = this.createElementDefaultNS("General"); // optional Window element if(context.size) { node.appendChild(this.createElementDefaultNS( "Window", null, { width: context.size.w, height: context.size.h } )); } // required BoundingBox element var bounds = context.bounds; node.appendChild(this.createElementDefaultNS( "BoundingBox", null, { minx: bounds.left.toPrecision(18), miny: bounds.bottom.toPrecision(18), maxx: bounds.right.toPrecision(18), maxy: bounds.top.toPrecision(18), SRS: context.projection } )); // required Title element node.appendChild(this.createElementDefaultNS( "Title", context.title )); // optional KeywordList element if (context.keywords) { node.appendChild(this.write_wmc_KeywordList(context.keywords)); } // optional Abstract element if (context["abstract"]) { node.appendChild(this.createElementDefaultNS( "Abstract", context["abstract"] )); } // Optional LogoURL element if (context.logo) { node.appendChild(this.write_wmc_URLType("LogoURL", context.logo.href, context.logo)); } // Optional DescriptionURL element if (context.descriptionURL) { node.appendChild(this.write_wmc_URLType("DescriptionURL", context.descriptionURL)); } // Optional ContactInformation element if (context.contactInformation) { node.appendChild(this.write_wmc_ContactInformation(context.contactInformation)); } // OpenLayers specific map properties node.appendChild(this.write_ol_MapExtension(context)); return node; }, /** * Method: write_wmc_KeywordList */ write_wmc_KeywordList: function(keywords) { var node = this.createElementDefaultNS("KeywordList"); for (var i=0, len=keywords.length; i 0) { this.read_wmc_OnlineResource(object, links[0]); } return object.href; }, CLASS_NAME: "OpenLayers.Format.WMC.v1" });