Merge pull request #50 from ahocevar/wmscaps-singlepass
Process WMSCapabilities property inheritance and flat layers list in a single pass for increased performance.
This commit is contained in:
@@ -71,117 +71,10 @@ OpenLayers.Format.WMSCapabilities.v1 = OpenLayers.Class(
|
|||||||
// an exception must have occurred, so parse it
|
// an exception must have occurred, so parse it
|
||||||
var parser = new OpenLayers.Format.OGCExceptionReport();
|
var parser = new OpenLayers.Format.OGCExceptionReport();
|
||||||
capabilities.error = parser.read(raw);
|
capabilities.error = parser.read(raw);
|
||||||
} else {
|
|
||||||
// postprocess the layer list
|
|
||||||
this.postProcessLayers(capabilities);
|
|
||||||
}
|
}
|
||||||
return 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<len; ++i) {
|
|
||||||
var layer = layers[i];
|
|
||||||
this.processLayer(capabilities.capability, layer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method: processLayer
|
|
||||||
* Recursive submethod of postProcessLayers. This function will among
|
|
||||||
* others deal with property inheritance.
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* capability - {Object} The capability part of the capabilities object
|
|
||||||
* layer - {Object} The layer that needs processing
|
|
||||||
* parentLayer - {Object} The parent layer of the respective layer
|
|
||||||
*/
|
|
||||||
processLayer: function(capability, layer, parentLayer) {
|
|
||||||
if (layer.formats === undefined) {
|
|
||||||
layer.formats = capability.request.getmap.formats;
|
|
||||||
}
|
|
||||||
if (layer.infoFormats === undefined && capability.request.getfeatureinfo) {
|
|
||||||
layer.infoFormats = capability.request.getfeatureinfo.formats;
|
|
||||||
}
|
|
||||||
|
|
||||||
var i, len;
|
|
||||||
|
|
||||||
// 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 (i=0, len=attributes.length; i<len; i++) {
|
|
||||||
key = attributes[i];
|
|
||||||
if (key in parentLayer) {
|
|
||||||
// only take parent value if not present (null or undefined)
|
|
||||||
if (layer[key] == null) {
|
|
||||||
layer[key] = parentLayer[key];
|
|
||||||
}
|
|
||||||
// if attribute isn't present, and we haven't
|
|
||||||
// inherited anything from a parent layer
|
|
||||||
// set to default value
|
|
||||||
if (layer[key] == null) {
|
|
||||||
var intAttr = ["cascaded", "fixedWidth", "fixedHeight"];
|
|
||||||
var boolAttr = ["queryable", "opaque", "noSubsets"];
|
|
||||||
if (OpenLayers.Util.indexOf(intAttr, key) != -1) {
|
|
||||||
layer[key] = 0;
|
|
||||||
}
|
|
||||||
if (OpenLayers.Util.indexOf(boolAttr, key) != -1) {
|
|
||||||
layer[key] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i=0, len=complexAttr.length; i<len; i++) {
|
|
||||||
key = complexAttr[i];
|
|
||||||
layer[key] = OpenLayers.Util.applyDefaults(
|
|
||||||
layer[key], parentLayer[key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// process sublayers
|
|
||||||
for (i=0, len=layer.nestedLayers.length; i<len; i++) {
|
|
||||||
var childLayer = layer.nestedLayers[i];
|
|
||||||
this.processLayer(capability, childLayer, layer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (layer.name) {
|
|
||||||
capability.layers.push(layer);
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Property: readers
|
* Property: readers
|
||||||
* Contains public functions, grouped by namespace prefix, that will
|
* Contains public functions, grouped by namespace prefix, that will
|
||||||
@@ -290,7 +183,10 @@ OpenLayers.Format.WMSCapabilities.v1 = OpenLayers.Class(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Capability": function(node, obj) {
|
"Capability": function(node, obj) {
|
||||||
obj.capability = {nestedLayers: []};
|
obj.capability = {
|
||||||
|
nestedLayers: [],
|
||||||
|
layers: []
|
||||||
|
};
|
||||||
this.readChildNodes(node, obj.capability);
|
this.readChildNodes(node, obj.capability);
|
||||||
},
|
},
|
||||||
"Request": function(node, obj) {
|
"Request": function(node, obj) {
|
||||||
@@ -343,6 +239,13 @@ OpenLayers.Format.WMSCapabilities.v1 = OpenLayers.Class(
|
|||||||
this.readChildNodes(node, obj.exception);
|
this.readChildNodes(node, obj.exception);
|
||||||
},
|
},
|
||||||
"Layer": function(node, obj) {
|
"Layer": function(node, obj) {
|
||||||
|
var parentLayer, capability;
|
||||||
|
if (obj.capability) {
|
||||||
|
capability = obj.capability;
|
||||||
|
parentLayer = obj;
|
||||||
|
} else {
|
||||||
|
capability = obj;
|
||||||
|
}
|
||||||
var attrNode = node.getAttributeNode("queryable");
|
var attrNode = node.getAttributeNode("queryable");
|
||||||
var queryable = (attrNode && attrNode.specified) ?
|
var queryable = (attrNode && attrNode.specified) ?
|
||||||
node.getAttribute("queryable") : null;
|
node.getAttribute("queryable") : null;
|
||||||
@@ -355,28 +258,56 @@ OpenLayers.Format.WMSCapabilities.v1 = OpenLayers.Class(
|
|||||||
var noSubsets = node.getAttribute('noSubsets');
|
var noSubsets = node.getAttribute('noSubsets');
|
||||||
var fixedWidth = node.getAttribute('fixedWidth');
|
var fixedWidth = node.getAttribute('fixedWidth');
|
||||||
var fixedHeight = node.getAttribute('fixedHeight');
|
var fixedHeight = node.getAttribute('fixedHeight');
|
||||||
var layer = {nestedLayers: [], styles: [], srs: {},
|
var parent = parentLayer || {},
|
||||||
metadataURLs: [], bbox: {}, dimensions: {},
|
extend = OpenLayers.Util.extend;
|
||||||
authorityURLs: {}, identifiers: {}, keywords: [],
|
var layer = {
|
||||||
|
nestedLayers: [],
|
||||||
|
styles: parentLayer ? [].concat(parentLayer.styles) : [],
|
||||||
|
srs: parentLayer ? extend({}, parent.srs) : {},
|
||||||
|
metadataURLs: [],
|
||||||
|
bbox: parentLayer ? extend({}, parent.bbox) : {},
|
||||||
|
llbbox: parent.llbbox,
|
||||||
|
dimensions: parentLayer ? extend({}, parent.dimensions) : {},
|
||||||
|
authorityURLs: parentLayer ? extend({}, parent.authorityURLs) : {},
|
||||||
|
identifiers: {},
|
||||||
|
keywords: [],
|
||||||
queryable: (queryable && queryable !== "") ?
|
queryable: (queryable && queryable !== "") ?
|
||||||
( queryable === "1" || queryable === "true" ) : null,
|
(queryable === "1" || queryable === "true" ) :
|
||||||
cascaded: (cascaded !== null) ? parseInt(cascaded) : null,
|
(parent.queryable || false),
|
||||||
|
cascaded: (cascaded !== null) ? parseInt(cascaded) :
|
||||||
|
(parent.cascaded || 0),
|
||||||
opaque: opaque ?
|
opaque: opaque ?
|
||||||
(opaque === "1" || opaque === "true" ) : null,
|
(opaque === "1" || opaque === "true" ) :
|
||||||
|
(parent.opaque || false),
|
||||||
noSubsets: (noSubsets !== null) ?
|
noSubsets: (noSubsets !== null) ?
|
||||||
( noSubsets === "1" || noSubsets === "true" ) : null,
|
(noSubsets === "1" || noSubsets === "true" ) :
|
||||||
|
(parent.noSubsets || false),
|
||||||
fixedWidth: (fixedWidth != null) ?
|
fixedWidth: (fixedWidth != null) ?
|
||||||
parseInt(fixedWidth) : null,
|
parseInt(fixedWidth) : (parent.fixedWidth || 0),
|
||||||
fixedHeight: (fixedHeight != null) ?
|
fixedHeight: (fixedHeight != null) ?
|
||||||
parseInt(fixedHeight) : null
|
parseInt(fixedHeight) : (parent.fixedHeight || 0),
|
||||||
|
minScale: parent.minScale,
|
||||||
|
maxScale: parent.maxScale,
|
||||||
|
attribution: parent.attribution,
|
||||||
};
|
};
|
||||||
obj.nestedLayers.push(layer);
|
obj.nestedLayers.push(layer);
|
||||||
|
layer.capability = capability;
|
||||||
this.readChildNodes(node, layer);
|
this.readChildNodes(node, layer);
|
||||||
|
delete layer.capability;
|
||||||
if(layer.name) {
|
if(layer.name) {
|
||||||
var parts = layer.name.split(":");
|
var parts = layer.name.split(":"),
|
||||||
|
request = capability.request,
|
||||||
|
gfi = request.getfeatureinfo;
|
||||||
if(parts.length > 0) {
|
if(parts.length > 0) {
|
||||||
layer.prefix = parts[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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Attribution": function(node, obj) {
|
"Attribution": function(node, obj) {
|
||||||
|
|||||||
Reference in New Issue
Block a user