WCS 1.0.0 parsing now passing all tests

This commit is contained in:
Christopher Eykamp
2012-12-21 18:51:39 +01:00
parent 5c07ae47bb
commit d0986de775
3 changed files with 157 additions and 64 deletions

View File

@@ -28,6 +28,11 @@ OpenLayers.Format.WCSCapabilities.v1 = OpenLayers.Class(
ows: "http://www.opengis.net/ows"
},
regExes: {
trimSpace: (/^\s*|\s*$/g),
splitSpace: (/\s+/)
},
/**
* Property: defaultPrefix
*/
@@ -78,16 +83,6 @@ OpenLayers.Format.WCSCapabilities.v1 = OpenLayers.Class(
"WCS_Capabilities": function(node, obj) { // In 1.0.0, this was WCS_Capabilties, changed in 1.1.0
this.readChildNodes(node, obj);
},
"Name": function(node, obj) { //????
var name = this.getChildValue(node);
if(name) {
var parts = name.split(":");
obj.name = parts.pop();
if(parts.length > 0) {
obj.featureNS = this.lookupNamespaceURI(node, parts[0]);
}
}
},
"Title": function(node, obj) {
var title = this.getChildValue(node);
if(title) {

View File

@@ -36,59 +36,142 @@ OpenLayers.Format.WCSCapabilities.v1_0_0 = OpenLayers.Class(
*/
readers: {
"wcs": OpenLayers.Util.applyDefaults({
"Service": function(node, capabilities) {
capabilities.service = {};
this.readChildNodes(node, capabilities.service);
"Service": function(node, obj) {
obj.service = {};
this.readChildNodes(node, obj.service);
},
"Fees": function(node, service) {
var fees = this.getChildValue(node);
if (fees && fees.toLowerCase() != "none") {
service.fees = fees;
}
"name": function(node, service) {
service.name = this.getChildValue(node);
},
"AccessConstraints": function(node, service) {
var constraints = this.getChildValue(node);
if (constraints && constraints.toLowerCase() != "none") {
service.accessConstraints = constraints;
}
"label": function(node, service) {
service.label = this.getChildValue(node);
},
"OnlineResource": function(node, service) {
var onlineResource = this.getChildValue(node);
if (onlineResource && onlineResource.toLowerCase() != "none") {
service.onlineResource = onlineResource;
}
"keywords": function(node, service) {
service.keywords = [];
this.readChildNodes(node, service.keywords);
},
"Keywords": function(node, service) {
var keywords = this.getChildValue(node);
if (keywords && keywords.toLowerCase() != "none") {
service.keywords = keywords.split(', ');
}
"keyword": function(node, keywords) {
keywords.push(this.getChildValue(node)); // Append the keyword to the keywords list
},
"Capability": function(node, capabilities) {
capabilities.capability = {};
this.readChildNodes(node, capabilities.capability);
"responsibleParty": function(node, service) {
service.responsibleParty = {};
this.readChildNodes(node, service.responsibleParty);
},
"Request": function(node, obj) {
obj.request = {};
this.readChildNodes(node, obj.request);
"individualName": function(node, responsibleParty) {
responsibleParty.individualName = this.getChildValue(node);
},
"GetFeature": function(node, request) {
request.getfeature = {
href: {}, // DCPType
formats: [] // ResultFormat
};
this.readChildNodes(node, request.getfeature);
"organisationName": function(node, responsibleParty) {
responsibleParty.organisationName = this.getChildValue(node);
},
"ResultFormat": function(node, obj) {
var children = node.childNodes;
var childNode;
for(var i=0; i<children.length; i++) {
childNode = children[i];
if(childNode.nodeType == 1) {
obj.formats.push(childNode.nodeName);
"positionName": function(node, responsibleParty) {
responsibleParty.positionName = this.getChildValue(node);
},
"contactInfo": function(node, responsibleParty) {
responsibleParty.contactInfo = {};
this.readChildNodes(node, responsibleParty.contactInfo);
},
"phone": function(node, contactInfo) {
contactInfo.phone = {};
this.readChildNodes(node, contactInfo.phone);
},
"voice": function(node, phone) {
phone.voice = this.getChildValue(node);
},
"facsimile": function(node, phone) {
phone.facsimile = this.getChildValue(node);
},
"address": function(node, contactInfo) {
contactInfo.address = {};
this.readChildNodes(node, contactInfo.address);
},
"deliveryPoint": function(node, address) {
address.deliveryPoint = this.getChildValue(node);
},
"city": function(node, address) {
address.city = this.getChildValue(node);
},
"postalCode": function(node, address) {
address.postalCode = this.getChildValue(node);
},
"country": function(node, address) {
address.country = this.getChildValue(node);
},
"electronicMailAddress": function(node, address) {
address.electronicMailAddress = this.getChildValue(node);
},
"fees": function(node, service) {
service.fees = this.getChildValue(node);
},
"accessConstraints": function(node, service) {
service.accessConstraints = this.getChildValue(node);
},
"ContentMetadata": function(node, obj) {
obj.contentMetadata = [];
this.readChildNodes(node, obj.contentMetadata);
},
"CoverageOfferingBrief": function(node, contentMetadata) {
var coverageOfferingBrief = {};
this.readChildNodes(node, coverageOfferingBrief);
contentMetadata.push(coverageOfferingBrief);
},
"name": function(node, coverageOfferingBrief) {
coverageOfferingBrief.name = this.getChildValue(node);
},
"label": function(node, coverageOfferingBrief) {
coverageOfferingBrief.label = this.getChildValue(node);
},
"lonLatEnvelope": function(node, coverageOfferingBrief) {
// Look for <gml:pos>. Only write the data if everything parsed neatly.
// This works well for the data samples I have access to, but may need to be generalized to cover other possible use cases.
var nodeList = this.getElementsByTagNameNS(node, "http://www.opengis.net/gml", "pos");
// We expect two nodes here, to create the corners of a bounding box
if(nodeList.length == 2) {
var min = {},
max = {};
var ok = true;
// min
var coordString = nodeList[0].firstChild.nodeValue;
coordString = coordString.replace(this.regExes.trimSpace, "");
var coords = coordString.split(this.regExes.splitSpace);
if(coords.length == 2) {
min.lon = coords[0];
min.lat = coords[1];
} else {
ok = false;
}
// max
var coordString = nodeList[1].firstChild.nodeValue;
coordString = coordString.replace(this.regExes.trimSpace, "");
var coords = coordString.split(this.regExes.splitSpace);
if(coords.length == 2) {
max.lon = coords[0];
max.lat = coords[1];
} else {
ok = false;
}
if(ok) {
coverageOfferingBrief.lonLatEnvelope = {};
coverageOfferingBrief.lonLatEnvelope.srsName = node.getAttribute("srsName");
coverageOfferingBrief.lonLatEnvelope.min = min;
coverageOfferingBrief.lonLatEnvelope.max = max;
}
}
},
////////////////////////////////////////////////////////////////////////////////////////////
"DCPType": function(node, obj) {
this.readChildNodes(node, obj);
},

File diff suppressed because one or more lines are too long