diff --git a/lib/OpenLayers.js b/lib/OpenLayers.js index 1fc546d007..a27cdadfef 100644 --- a/lib/OpenLayers.js +++ b/lib/OpenLayers.js @@ -203,6 +203,8 @@ "OpenLayers/Protocol/WFS/v1.js", "OpenLayers/Protocol/WFS/v1_0_0.js", "OpenLayers/Protocol/WFS/v1_1_0.js", + "OpenLayers/Protocol/SOS.js", + "OpenLayers/Protocol/SOS/v1_0_0.js", "OpenLayers/Layer/PointTrack.js", "OpenLayers/Layer/GML.js", "OpenLayers/Style.js", diff --git a/lib/OpenLayers/Protocol.js b/lib/OpenLayers/Protocol.js index 9a2829bc1a..7b92df97bb 100755 --- a/lib/OpenLayers/Protocol.js +++ b/lib/OpenLayers/Protocol.js @@ -180,6 +180,22 @@ OpenLayers.Protocol = OpenLayers.Class({ abort: function(response) { }, + /** + * Method: createCallback + * Returns a function that applies the given public method with resp and + * options arguments. + * + * Parameters: + * method - {Function} The method to be applied by the callback. + * response - {} The protocol response object. + * options - {Object} Options sent to the protocol method + */ + createCallback: function(method, response, options) { + return OpenLayers.Function.bind(function() { + method.apply(this, [response, options]); + }, this); + }, + CLASS_NAME: "OpenLayers.Protocol" }); diff --git a/lib/OpenLayers/Protocol/HTTP.js b/lib/OpenLayers/Protocol/HTTP.js index 337c9aa1d9..01d52c15cf 100644 --- a/lib/OpenLayers/Protocol/HTTP.js +++ b/lib/OpenLayers/Protocol/HTTP.js @@ -94,23 +94,6 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, { OpenLayers.Protocol.prototype.destroy.apply(this); }, - /** - * Method: createCallback - * Returns a function that applies the given public method with resp and - * options arguments. - * - * Parameters: - * method - {Function} The method to be applied by the callback. - * response - {} The protocol response object. - * options - {Object} Options sent to the protocol method (read, create, - * update, or delete). - */ - createCallback: function(method, response, options) { - return OpenLayers.Function.bind(function() { - method.apply(this, [response, options]); - }, this); - }, - /** * APIMethod: read * Construct a request for reading new features. diff --git a/lib/OpenLayers/Protocol/SOS.js b/lib/OpenLayers/Protocol/SOS.js new file mode 100644 index 0000000000..0e7b210735 --- /dev/null +++ b/lib/OpenLayers/Protocol/SOS.js @@ -0,0 +1,32 @@ +/* Copyright (c) 2006-2009 MetaCarta, Inc., published under the Clear BSD + * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the + * full text of the license. */ + +/** + * @requires OpenLayers/Protocol.js + */ + +/** + * Function: OpenLayers.Protocol.SOS + * Used to create a versioned SOS protocol. Default version is 1.0.0. + * + * Returns: + * {} An SOS protocol for the given version. + */ +OpenLayers.Protocol.SOS = function(options) { + options = OpenLayers.Util.applyDefaults( + options, OpenLayers.Protocol.SOS.DEFAULTS + ); + var cls = OpenLayers.Protocol.SOS["v"+options.version.replace(/\./g, "_")]; + if(!cls) { + throw "Unsupported SOS version: " + options.version; + } + return new cls(options); +}; + +/** + * Constant: OpenLayers.Protocol.SOS.DEFAULTS + */ +OpenLayers.Protocol.SOS.DEFAULTS = { + "version": "1.0.0" +}; diff --git a/lib/OpenLayers/Protocol/SOS/v1_0_0.js b/lib/OpenLayers/Protocol/SOS/v1_0_0.js new file mode 100644 index 0000000000..87e0060178 --- /dev/null +++ b/lib/OpenLayers/Protocol/SOS/v1_0_0.js @@ -0,0 +1,131 @@ +/* Copyright (c) 2006-2009 MetaCarta, Inc., published under the Clear BSD + * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the + * full text of the license. */ + +/** + * @requires OpenLayers/Protocol/SOS.js + * @requires OpenLayers/Format/SOSGetFeatureOfInterest.js + */ + +/** + * Class: OpenLayers.Protocol.SOS.v1_0_0 + * An SOS v1.0.0 Protocol for vector layers. Create a new instance with the + * constructor. + * + * Inherits from: + * - + */ + OpenLayers.Protocol.SOS.v1_0_0 = OpenLayers.Class(OpenLayers.Protocol, { + + /** + * APIProperty: fois + * {Array(String)} Array of features of interest (foi) + */ + fois: null, + + /** + * Property: formatOptions + * {Object} Optional options for the format. If a format is not provided, + * this property can be used to extend the default format options. + */ + formatOptions: null, + + /** + * Constructor: OpenLayers.Protocol.SOS + * A class for giving layers an SOS protocol. + * + * Parameters: + * options - {Object} Optional object whose properties will be set on the + * instance. + * Valid options properties: + * url - {String} URL to send requests to (required). + * fois - {Array} The features of interest (required). + */ + initialize: function(options) { + OpenLayers.Protocol.prototype.initialize.apply(this, [options]); + if(!options.format) { + this.format = new OpenLayers.Format.SOSGetFeatureOfInterest( + this.formatOptions); + } + }, + + /** + * APIMethod: destroy + * Clean up the protocol. + */ + destroy: function() { + if(this.options && !this.options.format) { + this.format.destroy(); + } + this.format = null; + OpenLayers.Protocol.prototype.destroy.apply(this); + }, + + /** + * APIMethod: read + * Construct a request for reading new sensor positions. This is done by + * issuing one GetFeatureOfInterest request. + */ + read: function(options) { + options = OpenLayers.Util.extend({}, options); + OpenLayers.Util.applyDefaults(options, this.options || {}); + var response = new OpenLayers.Protocol.Response({requestType: "read"}); + var format = this.format; + var data = OpenLayers.Format.XML.prototype.write.apply(format, + [format.writeNode("sos:GetFeatureOfInterest", {fois: this.fois})] + ); + response.priv = OpenLayers.Request.POST({ + url: options.url, + callback: this.createCallback(this.handleRead, response, options), + data: data + }); + return response; + }, + + /** + * Method: handleRead + * Deal with response from the read request. + * + * Parameters: + * response - {} The response object to pass + * to the user callback. + * options - {Object} The user options passed to the read call. + */ + handleRead: function(response, options) { + if(options.callback) { + var request = response.priv; + if(request.status >= 200 && request.status < 300) { + // success + response.features = this.parseFeatures(request); + response.code = OpenLayers.Protocol.Response.SUCCESS; + } else { + // failure + response.code = OpenLayers.Protocol.Response.FAILURE; + } + options.callback.call(options.scope, response); + } + }, + + /** + * Method: parseFeatures + * Read HTTP response body and return features + * + * Parameters: + * request - {XMLHttpRequest} The request object + * + * Returns: + * {Array({})} Array of features + */ + parseFeatures: function(request) { + var doc = request.responseXML; + if(!doc || !doc.documentElement) { + doc = request.responseText; + } + if(!doc || doc.length <= 0) { + return null; + } + return this.format.read(doc); + }, + + CLASS_NAME: "OpenLayers.Protocol.SOS.v1_0_0" +}); diff --git a/lib/OpenLayers/Protocol/WFS/v1.js b/lib/OpenLayers/Protocol/WFS/v1.js index 0cbc4c887c..d64ac54aa8 100644 --- a/lib/OpenLayers/Protocol/WFS/v1.js +++ b/lib/OpenLayers/Protocol/WFS/v1.js @@ -130,23 +130,6 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, { OpenLayers.Protocol.prototype.destroy.apply(this); }, - /** - * Method: createCallback - * Returns a function that applies the given public method with resp and - * options arguments. - * - * Parameters: - * method - {Function} The method to be applied by the callback. - * response - {} The protocol response object. - * options - {Object} Options sent to the protocol method (read, create, - * update, or delete). - */ - createCallback: function(method, response, options) { - return OpenLayers.Function.bind(function() { - method.apply(this, [response, options]); - }, this); - }, - /** * Method: read * Construct a request for reading new features. Since WFS splits the diff --git a/tests/Protocol/SOS.html b/tests/Protocol/SOS.html new file mode 100644 index 0000000000..4e4277b889 --- /dev/null +++ b/tests/Protocol/SOS.html @@ -0,0 +1,57 @@ + + + + + + + + diff --git a/tests/list-tests.html b/tests/list-tests.html index 4711aef99f..c458376af2 100644 --- a/tests/list-tests.html +++ b/tests/list-tests.html @@ -157,6 +157,7 @@
  • Protocol/SQL.html
  • Protocol/SQL/Gears.html
  • Protocol/WFS.html
  • +
  • Protocol/SOS.html
  • Renderer.html
  • Renderer/Canvas.html
  • Renderer/Elements.html