Merge pull request #814 from eykamp/wcsdev
Add WCS GetCapabilities parsing for WCS 1.0.0 and 1.1.0 (r=@bartvde)
This commit is contained in:
47
lib/OpenLayers/Format/WCSCapabilities.js
Normal file
47
lib/OpenLayers/Format/WCSCapabilities.js
Normal file
@@ -0,0 +1,47 @@
|
||||
/* Copyright (c) 2006-2012 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/XML/VersionedOGC.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Format.WCSCapabilities
|
||||
* Read WCS Capabilities.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Format.XML.VersionedOGC>
|
||||
*/
|
||||
OpenLayers.Format.WCSCapabilities = OpenLayers.Class(OpenLayers.Format.XML.VersionedOGC, {
|
||||
|
||||
/**
|
||||
* APIProperty: defaultVersion
|
||||
* {String} Version number to assume if none found. Default is "1.1.0".
|
||||
*/
|
||||
defaultVersion: "1.1.0",
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Format.WCSCapabilities
|
||||
* Create a new parser for WCS capabilities.
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} An optional object whose properties will be set on
|
||||
* this instance.
|
||||
*/
|
||||
|
||||
/**
|
||||
* APIMethod: read
|
||||
* Read capabilities data from a string, and return a list of coverages.
|
||||
*
|
||||
* Parameters:
|
||||
* data - {String} or {DOMElement} data to read/parse.
|
||||
*
|
||||
* Returns:
|
||||
* {Array} List of named coverages.
|
||||
*/
|
||||
|
||||
CLASS_NAME: "OpenLayers.Format.WCSCapabilities"
|
||||
|
||||
});
|
||||
55
lib/OpenLayers/Format/WCSCapabilities/v1.js
Normal file
55
lib/OpenLayers/Format/WCSCapabilities/v1.js
Normal file
@@ -0,0 +1,55 @@
|
||||
/* Copyright (c) 2006-2012 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/WCSCapabilities.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Format.WCSCapabilities.v1
|
||||
* Abstract class not to be instantiated directly.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Format.XML>
|
||||
*/
|
||||
OpenLayers.Format.WCSCapabilities.v1 = OpenLayers.Class(
|
||||
OpenLayers.Format.XML, {
|
||||
|
||||
regExes: {
|
||||
trimSpace: (/^\s*|\s*$/g),
|
||||
splitSpace: (/\s+/)
|
||||
},
|
||||
|
||||
/**
|
||||
* Property: defaultPrefix
|
||||
*/
|
||||
defaultPrefix: "wcs",
|
||||
|
||||
/**
|
||||
* APIMethod: read
|
||||
* Read capabilities data from a string, and return a list of coverages.
|
||||
*
|
||||
* Parameters:
|
||||
* data - {String} or {DOMElement} data to read/parse.
|
||||
*
|
||||
* Returns:
|
||||
* {Array} List of named coverages.
|
||||
*/
|
||||
read: function(data) {
|
||||
if(typeof data == "string") {
|
||||
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
|
||||
}
|
||||
var raw = data;
|
||||
if(data && data.nodeType == 9) {
|
||||
data = data.documentElement;
|
||||
}
|
||||
var capabilities = {};
|
||||
this.readNode(data, capabilities);
|
||||
return capabilities;
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Format.WCSCapabilities.v1"
|
||||
|
||||
});
|
||||
170
lib/OpenLayers/Format/WCSCapabilities/v1_0_0.js
Normal file
170
lib/OpenLayers/Format/WCSCapabilities/v1_0_0.js
Normal file
@@ -0,0 +1,170 @@
|
||||
/* Copyright (c) 2006-2012 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/WCSCapabilities/v1.js
|
||||
* @requires OpenLayers/Format/GML/v3.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Format.WCSCapabilities/v1_0_0
|
||||
* Read WCS Capabilities version 1.0.0.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Format.WCSCapabilities.v1>
|
||||
*/
|
||||
OpenLayers.Format.WCSCapabilities.v1_0_0 = OpenLayers.Class(
|
||||
OpenLayers.Format.WCSCapabilities.v1, {
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Format.WCSCapabilities.v1_0_0
|
||||
* Create a new parser for WCS capabilities version 1.0.0.
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} An optional object whose properties will be set on
|
||||
* this instance.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Property: namespaces
|
||||
* {Object} Mapping of namespace aliases to namespace URIs.
|
||||
*/
|
||||
namespaces: {
|
||||
wcs: "http://www.opengis.net/wcs",
|
||||
xlink: "http://www.w3.org/1999/xlink",
|
||||
xsi: "http://www.w3.org/2001/XMLSchema-instance",
|
||||
ows: "http://www.opengis.net/ows"
|
||||
},
|
||||
|
||||
/**
|
||||
* Property: errorProperty
|
||||
* {String} Which property of the returned object to check for in order to
|
||||
* determine whether or not parsing has failed. In the case that the
|
||||
* errorProperty is undefined on the returned object, the document will be
|
||||
* run through an OGCExceptionReport parser.
|
||||
*/
|
||||
errorProperty: "service",
|
||||
|
||||
/**
|
||||
* Property: readers
|
||||
* Contains public functions, grouped by namespace prefix, that will
|
||||
* be applied when a namespaced node is found matching the function
|
||||
* name. The function will be applied in the scope of this parser
|
||||
* with two arguments: the node being read and a context object passed
|
||||
* from the parent.
|
||||
*/
|
||||
readers: {
|
||||
"wcs": {
|
||||
"WCS_Capabilities": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
"Service": function(node, obj) {
|
||||
obj.service = {};
|
||||
this.readChildNodes(node, obj.service);
|
||||
},
|
||||
"name": function(node, service) {
|
||||
service.name = this.getChildValue(node);
|
||||
},
|
||||
"label": function(node, service) {
|
||||
service.label = this.getChildValue(node);
|
||||
},
|
||||
"keywords": function(node, service) {
|
||||
service.keywords = [];
|
||||
this.readChildNodes(node, service.keywords);
|
||||
},
|
||||
"keyword": function(node, keywords) {
|
||||
// Append the keyword to the keywords list
|
||||
keywords.push(this.getChildValue(node));
|
||||
},
|
||||
"responsibleParty": function(node, service) {
|
||||
service.responsibleParty = {};
|
||||
this.readChildNodes(node, service.responsibleParty);
|
||||
},
|
||||
"individualName": function(node, responsibleParty) {
|
||||
responsibleParty.individualName = this.getChildValue(node);
|
||||
},
|
||||
"organisationName": function(node, responsibleParty) {
|
||||
responsibleParty.organisationName = this.getChildValue(node);
|
||||
},
|
||||
"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) {
|
||||
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 = {};
|
||||
var max = {};
|
||||
|
||||
OpenLayers.Format.GML.v3.prototype.readers["gml"].pos.apply(this, [nodeList[0], min]);
|
||||
OpenLayers.Format.GML.v3.prototype.readers["gml"].pos.apply(this, [nodeList[1], max]);
|
||||
|
||||
coverageOfferingBrief.lonLatEnvelope = {};
|
||||
coverageOfferingBrief.lonLatEnvelope.srsName = node.getAttribute("srsName");
|
||||
coverageOfferingBrief.lonLatEnvelope.min = min.points[0];
|
||||
coverageOfferingBrief.lonLatEnvelope.max = max.points[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Format.WCSCapabilities.v1_0_0"
|
||||
|
||||
});
|
||||
109
lib/OpenLayers/Format/WCSCapabilities/v1_1_0.js
Normal file
109
lib/OpenLayers/Format/WCSCapabilities/v1_1_0.js
Normal file
@@ -0,0 +1,109 @@
|
||||
/* Copyright (c) 2006-2012 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/WCSCapabilities/v1.js
|
||||
* @requires OpenLayers/Format/OWSCommon/v1_1_0.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class: OpenLayers.Format.WCSCapabilities/v1_1_0
|
||||
* Read WCS Capabilities version 1.1.0.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Format.WCSCapabilities.v1>
|
||||
*/
|
||||
OpenLayers.Format.WCSCapabilities.v1_1_0 = OpenLayers.Class(
|
||||
OpenLayers.Format.WCSCapabilities.v1, {
|
||||
|
||||
/**
|
||||
* Property: namespaces
|
||||
* {Object} Mapping of namespace aliases to namespace URIs.
|
||||
*/
|
||||
namespaces: {
|
||||
wcs: "http://www.opengis.net/wcs/1.1",
|
||||
xlink: "http://www.w3.org/1999/xlink",
|
||||
xsi: "http://www.w3.org/2001/XMLSchema-instance",
|
||||
ows: "http://www.opengis.net/ows/1.1"
|
||||
},
|
||||
|
||||
/**
|
||||
* APIProperty: errorProperty
|
||||
* {String} Which property of the returned object to check for in order to
|
||||
* determine whether or not parsing has failed. In the case that the
|
||||
* errorProperty is undefined on the returned object, the document will be
|
||||
* run through an OGCExceptionReport parser.
|
||||
*/
|
||||
errorProperty: "operationsMetadata",
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Format.WCSCapabilities.v1_1_0
|
||||
* Create a new parser for WCS capabilities version 1.1.0.
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} An optional object whose properties will be set on
|
||||
* this instance.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Property: readers
|
||||
* Contains public functions, grouped by namespace prefix, that will
|
||||
* be applied when a namespaced node is found matching the function
|
||||
* name. The function will be applied in the scope of this parser
|
||||
* with two arguments: the node being read and a context object passed
|
||||
* from the parent.
|
||||
*/
|
||||
readers: {
|
||||
"wcs": OpenLayers.Util.applyDefaults({
|
||||
// In 1.0.0, this was WCS_Capabilties, in 1.1.0, it's Capabilities
|
||||
"Capabilities": function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
"Contents": function(node, request) {
|
||||
request.contentMetadata = [];
|
||||
this.readChildNodes(node, request.contentMetadata);
|
||||
},
|
||||
"CoverageSummary": function(node, contentMetadata) {
|
||||
var coverageSummary = {};
|
||||
// Read the summary:
|
||||
this.readChildNodes(node, coverageSummary);
|
||||
|
||||
// Add it to the contentMetadata array:
|
||||
contentMetadata.push(coverageSummary);
|
||||
},
|
||||
"Identifier": function(node, coverageSummary) {
|
||||
coverageSummary.identifier = this.getChildValue(node);
|
||||
},
|
||||
"Title": function(node, coverageSummary) {
|
||||
coverageSummary.title = this.getChildValue(node);
|
||||
},
|
||||
"Abstract": function(node, coverageSummary) {
|
||||
coverageSummary["abstract"] = this.getChildValue(node);
|
||||
},
|
||||
"SupportedCRS": function(node, coverageSummary) {
|
||||
var crs = this.getChildValue(node);
|
||||
if(crs) {
|
||||
if(!coverageSummary.supportedCRS) {
|
||||
coverageSummary.supportedCRS = [];
|
||||
}
|
||||
coverageSummary.supportedCRS.push(crs);
|
||||
}
|
||||
},
|
||||
"SupportedFormat": function(node, coverageSummary) {
|
||||
var format = this.getChildValue(node);
|
||||
if(format) {
|
||||
if(!coverageSummary.supportedFormat) {
|
||||
coverageSummary.supportedFormat = [];
|
||||
}
|
||||
coverageSummary.supportedFormat.push(format);
|
||||
}
|
||||
}
|
||||
}, OpenLayers.Format.WCSCapabilities.v1.prototype.readers["wcs"]),
|
||||
"ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.readers["ows"]
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Format.WCSCapabilities.v1_1_0"
|
||||
|
||||
});
|
||||
@@ -21,15 +21,6 @@ OpenLayers.Format.WFSCapabilities = OpenLayers.Class(OpenLayers.Format.XML.Versi
|
||||
* {String} Version number to assume if none found. Default is "1.1.0".
|
||||
*/
|
||||
defaultVersion: "1.1.0",
|
||||
|
||||
/**
|
||||
* APIProperty: errorProperty
|
||||
* {String} Which property of the returned object to check for in order to
|
||||
* determine whether or not parsing has failed. In the case that the
|
||||
* errorProperty is undefined on the returned object, the document will be
|
||||
* run through an OGCExceptionReport parser.
|
||||
*/
|
||||
errorProperty: "featureTypeList",
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Format.WFSCapabilities
|
||||
|
||||
@@ -28,6 +28,16 @@ OpenLayers.Format.WFSCapabilities.v1 = OpenLayers.Class(
|
||||
ows: "http://www.opengis.net/ows"
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* APIProperty: errorProperty
|
||||
* {String} Which property of the returned object to check for in order to
|
||||
* determine whether or not parsing has failed. In the case that the
|
||||
* errorProperty is undefined on the returned object, the document will be
|
||||
* run through an OGCExceptionReport parser.
|
||||
*/
|
||||
errorProperty: "featureTypeList",
|
||||
|
||||
/**
|
||||
* Property: defaultPrefix
|
||||
*/
|
||||
|
||||
@@ -12,6 +12,17 @@
|
||||
* Class: OpenLayers.Format.XML.VersionedOGC
|
||||
* Base class for versioned formats, i.e. a format which supports multiple
|
||||
* versions.
|
||||
*
|
||||
* To enable checking if parsing succeeded, you will need to define a property
|
||||
* called errorProperty on the parser you want to check. The parser will then
|
||||
* check the returned object to see if that property is present. If it is, it
|
||||
* assumes the parsing was successful. If it is not present (or is null), it will
|
||||
* pass the document through an OGCExceptionReport parser.
|
||||
*
|
||||
* If errorProperty is undefined for the parser, this error checking mechanism
|
||||
* will be disabled.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Format.XML>
|
||||
@@ -45,15 +56,6 @@ OpenLayers.Format.XML.VersionedOGC = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
*/
|
||||
allowFallback: false,
|
||||
|
||||
/**
|
||||
* APIProperty: errorProperty
|
||||
* {String} Which property of the returned object to check for in order to
|
||||
* determine whether or not parsing has failed. In the case that the
|
||||
* errorProperty is undefined on the returned object, the document will be
|
||||
* run through an OGCExceptionReport parser.
|
||||
*/
|
||||
errorProperty: null,
|
||||
|
||||
/**
|
||||
* Property: name
|
||||
* {String} The name of this parser, this is the part of the CLASS_NAME
|
||||
@@ -193,9 +195,11 @@ OpenLayers.Format.XML.VersionedOGC = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
}
|
||||
var root = data.documentElement;
|
||||
var version = this.getVersion(root);
|
||||
this.parser = this.getParser(version);
|
||||
var obj = this.parser.read(data, options);
|
||||
if (this.errorProperty !== null && obj[this.errorProperty] === undefined) {
|
||||
this.parser = this.getParser(version); // Select the parser
|
||||
var obj = this.parser.read(data, options); // Parse the data
|
||||
|
||||
var errorProperty = this.parser.errorProperty || null;
|
||||
if (errorProperty !== null && obj[errorProperty] === undefined) {
|
||||
// an error must have happened, so parse it and report back
|
||||
var format = new OpenLayers.Format.OGCExceptionReport();
|
||||
obj.error = format.read(data);
|
||||
|
||||
Reference in New Issue
Block a user