|
/* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for |
|
* full list of contributors). Published under the Clear BSD license. |
|
* See http://svn.openlayers.org/trunk/openlayers/license.txt 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.XML> |
|
*/ |
|
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 <namespaces> 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 |
|
* <OpenLayers.Format.WMC> 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<len; ++i) { |
|
childNode = children[i]; |
|
if(childNode.nodeType == 1) { |
|
prefix = this.getNamespacePrefix(childNode.namespaceURI); |
|
local = childNode.nodeName.split(":").pop(); |
|
processor = this["read_" + prefix + "_" + local]; |
|
if(processor) { |
|
processor.apply(this, [obj, childNode]); |
|
} |
|
} |
|
} |
|
}, |
|
|
|
/** |
|
* Method: read_wmc_General |
|
*/ |
|
read_wmc_General: function(context, node) { |
|
this.runChildNodes(context, node); |
|
}, |
|
|
|
/** |
|
* Method: read_wmc_BoundingBox |
|
*/ |
|
read_wmc_BoundingBox: function(context, node) { |
|
context.projection = node.getAttribute("SRS"); |
|
context.bounds = new OpenLayers.Bounds( |
|
parseFloat(node.getAttribute("minx")), |
|
parseFloat(node.getAttribute("miny")), |
|
parseFloat(node.getAttribute("maxx")), |
|
parseFloat(node.getAttribute("maxy")) |
|
); |
|
}, |
|
|
|
/** |
|
* Method: read_wmc_LayerList |
|
*/ |
|
read_wmc_LayerList: function(context, node) { |
|
// layersContext is an array containing info for each layer |
|
context.layersContext = []; |
|
this.runChildNodes(context, node); |
|
}, |
|
|
|
/** |
|
* Method: read_wmc_Layer |
|
*/ |
|
read_wmc_Layer: function(context, node) { |
|
var layerContext = { |
|
visibility: (node.getAttribute("hidden") != "1"), |
|
queryable: (node.getAttribute("queryable") == "1"), |
|
formats: [], |
|
styles: [] |
|
}; |
|
|
|
this.runChildNodes(layerContext, node); |
|
// set properties common to multiple objects on layer options/params |
|
context.layersContext.push(layerContext); |
|
}, |
|
|
|
/** |
|
* Method: read_wmc_Extension |
|
*/ |
|
read_wmc_Extension: function(obj, node) { |
|
this.runChildNodes(obj, node); |
|
}, |
|
|
|
/** |
|
* Method: read_ol_units |
|
*/ |
|
read_ol_units: function(layerContext, node) { |
|
layerContext.units = this.getChildValue(node); |
|
}, |
|
|
|
/** |
|
* Method: read_ol_maxExtent |
|
*/ |
|
read_ol_maxExtent: function(obj, node) { |
|
var bounds = new OpenLayers.Bounds( |
|
node.getAttribute("minx"), node.getAttribute("miny"), |
|
node.getAttribute("maxx"), node.getAttribute("maxy") |
|
); |
|
obj.maxExtent = bounds; |
|
}, |
|
|
|
/** |
|
* Method: read_ol_transparent |
|
*/ |
|
read_ol_transparent: function(layerContext, node) { |
|
layerContext.transparent = this.getChildValue(node); |
|
}, |
|
|
|
/** |
|
* Method: read_ol_numZoomLevels |
|
*/ |
|
read_ol_numZoomLevels: function(layerContext, node) { |
|
layerContext.numZoomLevels = parseInt(this.getChildValue(node)); |
|
}, |
|
|
|
/** |
|
* Method: read_ol_opacity |
|
*/ |
|
read_ol_opacity: function(layerContext, node) { |
|
layerContext.opacity = parseFloat(this.getChildValue(node)); |
|
}, |
|
|
|
/** |
|
* Method: read_ol_singleTile |
|
*/ |
|
read_ol_singleTile: function(layerContext, node) { |
|
layerContext.singleTile = (this.getChildValue(node) == "true"); |
|
}, |
|
|
|
/** |
|
* Method: read_ol_tileSize |
|
*/ |
|
read_ol_tileSize: function(layerContext, node) { |
|
var obj = {"width": node.getAttribute("width"), "height": node.getAttribute("height")}; |
|
layerContext.tileSize = obj; |
|
}, |
|
|
|
/** |
|
* Method: read_ol_isBaseLayer |
|
*/ |
|
read_ol_isBaseLayer: function(layerContext, node) { |
|
layerContext.isBaseLayer = (this.getChildValue(node) == "true"); |
|
}, |
|
|
|
/** |
|
* Method: read_ol_displayInLayerSwitcher |
|
*/ |
|
read_ol_displayInLayerSwitcher: function(layerContext, node) { |
|
layerContext.displayInLayerSwitcher = (this.getChildValue(node) == "true"); |
|
}, |
|
|
|
/** |
|
* Method: read_wmc_Server |
|
*/ |
|
read_wmc_Server: function(layerContext, node) { |
|
layerContext.version = node.getAttribute("version"); |
|
var server = {}; |
|
var links = node.getElementsByTagName("OnlineResource"); |
|
if(links.length > 0) { |
|
this.read_wmc_OnlineResource(server, links[0]); |
|
} |
|
layerContext.url = server.href; |
|
}, |
|
|
|
/** |
|
* Method: read_wmc_FormatList |
|
*/ |
|
read_wmc_FormatList: function(layerContext, node) { |
|
this.runChildNodes(layerContext, node); |
|
}, |
|
|
|
/** |
|
* Method: read_wmc_Format |
|
*/ |
|
read_wmc_Format: function(layerContext, node) { |
|
var format = { |
|
value: this.getChildValue(node) |
|
}; |
|
if(node.getAttribute("current") == "1") { |
|
format.current = true; |
|
} |
|
layerContext.formats.push(format); |
|
}, |
|
|
|
/** |
|
* Method: read_wmc_StyleList |
|
*/ |
|
read_wmc_StyleList: function(layerContext, node) { |
|
this.runChildNodes(layerContext, node); |
|
}, |
|
|
|
/** |
|
* Method: read_wmc_Style |
|
*/ |
|
read_wmc_Style: function(layerContext, node) { |
|
var style = {}; |
|
this.runChildNodes(style, node); |
|
if(node.getAttribute("current") == "1") { |
|
style.current = true; |
|
} |
|
layerContext.styles.push(style); |
|
}, |
|
|
|
/** |
|
* Method: read_wmc_SLD |
|
*/ |
|
read_wmc_SLD: function(style, node) { |
|
this.runChildNodes(style, node); |
|
// style either comes back with an href or a body property |
|
}, |
|
|
|
/** |
|
* Method: read_sld_StyledLayerDescriptor |
|
*/ |
|
read_sld_StyledLayerDescriptor: function(sld, node) { |
|
var xml = OpenLayers.Format.XML.prototype.write.apply(this, [node]); |
|
sld.body = xml; |
|
}, |
|
|
|
/** |
|
* Method: read_wmc_OnlineResource |
|
*/ |
|
read_wmc_OnlineResource: function(obj, node) { |
|
obj.href = this.getAttributeNS( |
|
node, this.namespaces.xlink, "href" |
|
); |
|
}, |
|
|
|
/** |
|
* Method: read_wmc_Name |
|
*/ |
|
read_wmc_Name: function(obj, node) { |
|
var name = this.getChildValue(node); |
|
if(name) { |
|
obj.name = name; |
|
} |
|
}, |
|
|
|
/** |
|
* Method: read_wmc_Title |
|
*/ |
|
read_wmc_Title: function(obj, node) { |
|
var title = this.getChildValue(node); |
|
if(title) { |
|
obj.title = title; |
|
} |
|
}, |
|
|
|
/** |
|
* Method: read_wmc_MetadataURL |
|
*/ |
|
read_wmc_MetadataURL: function(layerContext, node) { |
|
var metadataURL = {}; |
|
var links = node.getElementsByTagName("OnlineResource"); |
|
if(links.length > 0) { |
|
this.read_wmc_OnlineResource(metadataURL, links[0]); |
|
} |
|
layerContext.metadataURL = metadataURL.href; |
|
|
|
}, |
|
|
|
/** |
|
* Method: read_wmc_Abstract |
|
*/ |
|
read_wmc_Abstract: function(obj, node) { |
|
var abst = this.getChildValue(node); |
|
if(abst) { |
|
obj["abstract"] = abst; |
|
} |
|
}, |
|
|
|
/** |
|
* Method: read_wmc_LegendURL |
|
*/ |
|
read_wmc_LegendURL: function(style, node) { |
|
var legend = { |
|
width: node.getAttribute('width'), |
|
height: node.getAttribute('height') |
|
}; |
|
var links = node.getElementsByTagName("OnlineResource"); |
|
if(links.length > 0) { |
|