add Protocol for Sensor Observation Service r=ahocevar (closes #2373)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9912 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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 - {<OpenLayers.Protocol.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"
|
||||
});
|
||||
|
||||
|
||||
@@ -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 - {<OpenLayers.Protocol.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.
|
||||
|
||||
@@ -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:
|
||||
* {<OpenLayers.Protocol>} 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"
|
||||
};
|
||||
@@ -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
|
||||
* <OpenLayers.Protocol.SOS.v1_0_0> constructor.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Protocol>
|
||||
*/
|
||||
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 - {<OpenLayers.Protocol.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({<OpenLayers.Feature.Vector>})} 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"
|
||||
});
|
||||
@@ -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 - {<OpenLayers.Protocol.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
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_constructor(t) {
|
||||
t.plan(4);
|
||||
var a = new OpenLayers.Protocol.SOS({
|
||||
url: "foo",
|
||||
fois: ["a", "b", "c"]
|
||||
});
|
||||
|
||||
t.eq(a.url, "foo", "constructor sets url");
|
||||
t.eq(a.options.url, a.url, "constructor copies url to options.url");
|
||||
t.eq(a.fois[0], "a", "constructor sets the fois correctly");
|
||||
t.eq((a.format instanceof OpenLayers.Format.SOSGetFeatureOfInterest), true, "Constructor sets format correctly");
|
||||
}
|
||||
|
||||
function test_read(t) {
|
||||
t.plan(4);
|
||||
|
||||
var protocol = new OpenLayers.Protocol.SOS({
|
||||
url: "http://some.url.org/sos?",
|
||||
fois: ["foi1", "foi2"],
|
||||
parseFeatures: function(request) {
|
||||
t.eq(request.responseText, "foo", "parseFeatures called properly");
|
||||
return "foo";
|
||||
}
|
||||
});
|
||||
|
||||
var _POST = OpenLayers.Request.POST;
|
||||
|
||||
var expected, status;
|
||||
OpenLayers.Request.POST = function(obj) {
|
||||
t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "GetFeatureOfInterest request is correct");
|
||||
obj.status = status;
|
||||
obj.responseText = "foo";
|
||||
obj.options = {};
|
||||
t.delay_call(0.1, function() {obj.callback.call(this)});
|
||||
return obj;
|
||||
};
|
||||
|
||||
var xml = '<GetFeatureOfInterest xmlns="http://www.opengis.net/sos/1.0" version="1.0.0" service="SOS" xsi:schemaLocation="http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosAll.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><FeatureOfInterestId>foi1</FeatureOfInterestId><FeatureOfInterestId>foi2</FeatureOfInterestId></GetFeatureOfInterest>';
|
||||
expected = new OpenLayers.Format.XML().read(xml).documentElement;
|
||||
status = 200;
|
||||
var response = protocol.read({callback: function(response) {
|
||||
t.eq(response.features, "foo", "user callback properly called with features");
|
||||
t.eq(response.code, OpenLayers.Protocol.Response.SUCCESS, "success reported properly");
|
||||
}});
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -157,6 +157,7 @@
|
||||
<li>Protocol/SQL.html</li>
|
||||
<li>Protocol/SQL/Gears.html</li>
|
||||
<li>Protocol/WFS.html</li>
|
||||
<li>Protocol/SOS.html</li>
|
||||
<li>Renderer.html</li>
|
||||
<li>Renderer/Canvas.html</li>
|
||||
<li>Renderer/Elements.html</li>
|
||||
|
||||
Reference in New Issue
Block a user