Cache of DescribeProcess responses on the client.

This commit is contained in:
ahocevar
2012-08-06 23:17:04 +02:00
parent 9bc7bb8115
commit b61120d3b5
2 changed files with 35 additions and 14 deletions
+5 -3
View File
@@ -18,8 +18,9 @@ OpenLayers.WPSClient = OpenLayers.Class({
* *
* Properties: * Properties:
* url - {String} the url of the server * url - {String} the url of the server
* knownProcesses: {Object} Cache of DescribeProcess responses, keyed by * version - {String} WPS version of the server
* process identifier. * describeProcessResponse - {Object} Cache of DescribeProcess responses,
* keyed by process identifier.
*/ */
servers: null, servers: null,
@@ -61,7 +62,8 @@ OpenLayers.WPSClient = OpenLayers.Class({
for (var s in options.servers) { for (var s in options.servers) {
this.servers[s] = typeof options.servers[s] == 'string' ? { this.servers[s] = typeof options.servers[s] == 'string' ? {
url: options.servers[s], url: options.servers[s],
version: '1.0.0' version: '1.0.0',
describeProcessResponse: {}
} : options.servers[s]; } : options.servers[s];
} }
}, },
+30 -11
View File
@@ -84,15 +84,23 @@ OpenLayers.WPSProcess = OpenLayers.Class({
/** /**
* Method: describe * Method: describe
* Issues a DescribeProcess request asynchronously and fires the * Issues a DescribeProcess request asynchronously and fires the
* 'describeProcess' event as soon as the response is available in * 'describeprocess' event as soon as the response is available in
* <description>. * <description>.
*/ */
describe: function() { describe: function() {
if (this._describePending || this.description) { var server = this.client.servers[this.server];
if (this.description !== null) {
return;
} else if (server.describeProcessResponse[this.identifier] === null) {
// pending request
return;
} else if (this.identifier in server.describeProcessResponse) {
// process description already cached on client
this.parseDescription();
return; return;
} }
this._describePending = true; // set to null so we know a describeFeature request is pending
var server = this.client.servers[this.server]; server.describeProcessResponse[this.identifier] = null;
OpenLayers.Request.GET({ OpenLayers.Request.GET({
url: server.url, url: server.url,
params: { params: {
@@ -101,13 +109,7 @@ OpenLayers.WPSProcess = OpenLayers.Class({
REQUEST: 'DescribeProcess', REQUEST: 'DescribeProcess',
IDENTIFIER: this.identifier IDENTIFIER: this.identifier
}, },
success: function(response) { success: this.parseDescription,
this.description = new OpenLayers.Format.WPSDescribeProcess()
.read(response.responseText)
.processDescriptions[this.identifier];
delete this._describePending;
this.events.triggerEvent('describeprocess');
},
scope: this scope: this
}); });
}, },
@@ -165,6 +167,23 @@ OpenLayers.WPSProcess = OpenLayers.Class({
}); });
}, },
/**
* Method: parseDescription
*
* Parameters:
* response - {Object}
*/
parseDescription: function(response) {
var server = this.client.servers[this.server];
if (response) {
server.describeProcessResponse[this.identifier] = response.responseText;
}
this.description = new OpenLayers.Format.WPSDescribeProcess()
.read(server.describeProcessResponse[this.identifier])
.processDescriptions[this.identifier];
this.events.triggerEvent('describeprocess');
},
/** /**
* Method: setInputData * Method: setInputData
* Sets the data for a single input * Sets the data for a single input