From b563989985217eefd7b723fd19380de4f81309f3 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Sun, 13 Nov 2011 17:14:13 +0100 Subject: [PATCH] no second pass to handle inheritance and nested layer --- lib/OpenLayers/Format/WMSCapabilities/v1.js | 243 ++++++++------------ 1 file changed, 100 insertions(+), 143 deletions(-) diff --git a/lib/OpenLayers/Format/WMSCapabilities/v1.js b/lib/OpenLayers/Format/WMSCapabilities/v1.js index dd3c498b6c..eeb4b76310 100644 --- a/lib/OpenLayers/Format/WMSCapabilities/v1.js +++ b/lib/OpenLayers/Format/WMSCapabilities/v1.js @@ -71,117 +71,10 @@ OpenLayers.Format.WMSCapabilities.v1 = OpenLayers.Class( // an exception must have occurred, so parse it var parser = new OpenLayers.Format.OGCExceptionReport(); capabilities.error = parser.read(raw); - } else { - // postprocess the layer list - this.postProcessLayers(capabilities); } return capabilities; }, - /** - * Method: postProcessLayers - * Post process the layers, so that the nested layer structure is converted - * to a flat layer list with only named layers. - * - * Parameters: - * capabilities - {Object} The object (structure) returned by the parser with - * all the info from the GetCapabilities response. - */ - postProcessLayers: function(capabilities) { - if (capabilities.capability) { - capabilities.capability.layers = []; - var layers = capabilities.capability.nestedLayers; - for (var i=0, len = layers.length; i 0) { - layer.prefix = parts[0]; + "Layer": (function() { + var defaults = { + cascaded: 0, + fixedWidth: 0, + fixedHeight: 0, + queryable: false, + opaque: false, + noSubsets: false + }, + attributes = ["queryable", "cascaded", "fixedWidth", + "fixedHeight", "opaque", "noSubsets", "llbbox", + "minScale", "maxScale", "attribution"], + complexAttr = ["srs", "bbox", "dimensions", "authorityURLs"]; + + return function(node, obj) { + var parentLayer, capability; + if (obj.capability) { + capability = obj.capability; + parentLayer = obj; + } else { + capability = obj; + } + var attrNode = node.getAttributeNode("queryable"); + var queryable = (attrNode && attrNode.specified) ? + node.getAttribute("queryable") : null; + attrNode = node.getAttributeNode("cascaded"); + var cascaded = (attrNode && attrNode.specified) ? + node.getAttribute("cascaded") : null; + attrNode = node.getAttributeNode("opaque"); + var opaque = (attrNode && attrNode.specified) ? + node.getAttribute('opaque') : null; + var noSubsets = node.getAttribute('noSubsets'); + var fixedWidth = node.getAttribute('fixedWidth'); + var fixedHeight = node.getAttribute('fixedHeight'); + var layer = {nestedLayers: [], styles: [], srs: {}, + metadataURLs: [], bbox: {}, dimensions: {}, + authorityURLs: {}, identifiers: {}, keywords: [], + queryable: (queryable && queryable !== "") ? + ( queryable === "1" || queryable === "true" ) : null, + cascaded: (cascaded !== null) ? parseInt(cascaded) : null, + opaque: opaque ? + (opaque === "1" || opaque === "true" ) : null, + noSubsets: (noSubsets !== null) ? + ( noSubsets === "1" || noSubsets === "true" ) : null, + fixedWidth: (fixedWidth != null) ? + parseInt(fixedWidth) : null, + fixedHeight: (fixedHeight != null) ? + parseInt(fixedHeight) : null + }; + obj.nestedLayers.push(layer); + layer.capability = capability; + this.readChildNodes(node, layer); + delete layer.capability; + if(layer.name) { + var parts = layer.name.split(":"), + request = capability.request, + gfi = request.getfeatureinfo; + if(parts.length > 0) { + layer.prefix = parts[0]; + } + capability.layers.push(layer); + if (layer.formats === undefined) { + layer.formats = request.getmap.formats; + } + if (layer.infoFormats === undefined && gfi) { + layer.infoFormats = gfi.formats; + } + + // deal with property inheritance + if(parentLayer) { + // add style + layer.styles = layer.styles.concat(parentLayer.styles); + var parentValue, key, i, len; + + for (i=0, len=attributes.length; i