no way to pass read options from protocol to format, r=ahocevar,elemoine (closes #2656)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10703 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -74,6 +74,12 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, {
|
|||||||
*/
|
*/
|
||||||
readFormat: null,
|
readFormat: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: readOptions
|
||||||
|
* {Object} Optional object to pass to format's read.
|
||||||
|
*/
|
||||||
|
readOptions: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor: OpenLayers.Protocol.WFS
|
* Constructor: OpenLayers.Protocol.WFS
|
||||||
* A class for giving layers WFS protocol.
|
* A class for giving layers WFS protocol.
|
||||||
@@ -173,7 +179,12 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, {
|
|||||||
var request = response.priv;
|
var request = response.priv;
|
||||||
if(request.status >= 200 && request.status < 300) {
|
if(request.status >= 200 && request.status < 300) {
|
||||||
// success
|
// success
|
||||||
response.features = this.parseFeatures(request);
|
if (this.readOptions && this.readOptions.output == "object") {
|
||||||
|
OpenLayers.Util.extend(response,
|
||||||
|
this.parseResponse(request, this.readOptions));
|
||||||
|
} else {
|
||||||
|
response.features = this.parseResponse(request);
|
||||||
|
}
|
||||||
response.code = OpenLayers.Protocol.Response.SUCCESS;
|
response.code = OpenLayers.Protocol.Response.SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
// failure
|
// failure
|
||||||
@@ -184,17 +195,20 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: parseFeatures
|
* Method: parseResponse
|
||||||
* Read HTTP response body and return features
|
* Read HTTP response body and return features
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* request - {XMLHttpRequest} The request object
|
* request - {XMLHttpRequest} The request object
|
||||||
|
* options - {Object} Optional object to pass to format's read
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* {Array({<OpenLayers.Feature.Vector>})} or
|
* {Object} or {Array({<OpenLayers.Feature.Vector>})} or
|
||||||
* {<OpenLayers.Feature.Vector>} Array of features or a single feature.
|
* {<OpenLayers.Feature.Vector>}
|
||||||
|
* An object with a features property, an array of features or a single
|
||||||
|
* feature.
|
||||||
*/
|
*/
|
||||||
parseFeatures: function(request) {
|
parseResponse: function(request, options) {
|
||||||
var doc = request.responseXML;
|
var doc = request.responseXML;
|
||||||
if(!doc || !doc.documentElement) {
|
if(!doc || !doc.documentElement) {
|
||||||
doc = request.responseText;
|
doc = request.responseText;
|
||||||
@@ -203,7 +217,7 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (this.readFormat !== null) ? this.readFormat.read(doc) :
|
return (this.readFormat !== null) ? this.readFormat.read(doc) :
|
||||||
this.format.read(doc);
|
this.format.read(doc, options);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,8 +31,8 @@
|
|||||||
url: "http://some.url.org",
|
url: "http://some.url.org",
|
||||||
featureNS: "http://namespace.org",
|
featureNS: "http://namespace.org",
|
||||||
featureType: "type",
|
featureType: "type",
|
||||||
parseFeatures: function(request) {
|
parseResponse: function(request) {
|
||||||
t.eq(request.responseText, "foo", "parseFeatures called properly");
|
t.eq(request.responseText, "foo", "parseResponse called properly");
|
||||||
return "foo";
|
return "foo";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -225,10 +225,41 @@
|
|||||||
|
|
||||||
var request = {};
|
var request = {};
|
||||||
request.responseText = '{"type":"FeatureCollection","features":[{"type":"Feature","id":"V_HECTOPUNTEN.108411","geometry":{"type":"MultiPoint","coordinates":[[190659.467,349576.19]]},"geometry_name":"ORA_GEOMETRY","properties":{"WEGNUMMER":"002","HECTOMTRNG_ORG":2200,"HECTOMTRNG":"220.00","bbox":[190659.467,349576.19,190659.467,349576.19]}}]}';
|
request.responseText = '{"type":"FeatureCollection","features":[{"type":"Feature","id":"V_HECTOPUNTEN.108411","geometry":{"type":"MultiPoint","coordinates":[[190659.467,349576.19]]},"geometry_name":"ORA_GEOMETRY","properties":{"WEGNUMMER":"002","HECTOMTRNG_ORG":2200,"HECTOMTRNG":"220.00","bbox":[190659.467,349576.19,190659.467,349576.19]}}]}';
|
||||||
var features = protocol.parseFeatures(request);
|
var features = protocol.parseResponse(request);
|
||||||
t.eq(features.length, 1, "the right format is used to read the request (GeoJSON)");
|
t.eq(features.length, 1, "the right format is used to read the request (GeoJSON)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_readOptions(t) {
|
||||||
|
t.plan(1);
|
||||||
|
|
||||||
|
var protocol = new OpenLayers.Protocol.WFS({
|
||||||
|
url: "http://some.url.org",
|
||||||
|
version: "1.1.0",
|
||||||
|
featureNS: "http://namespace.org",
|
||||||
|
featureType: "type",
|
||||||
|
readOptions: {'output': 'object'},
|
||||||
|
parseResponse: function(request, options) {
|
||||||
|
t.eq(options.output, "object", "Options object correctly set to pass on to Format's read");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var _POST = OpenLayers.Request.POST;
|
||||||
|
|
||||||
|
OpenLayers.Request.POST = function(obj) {
|
||||||
|
obj.status = 200;
|
||||||
|
obj.responseText = "foo";
|
||||||
|
obj.options = {};
|
||||||
|
t.delay_call(0.1, function() {obj.callback.call(this)});
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
|
|
||||||
|
protocol.read({
|
||||||
|
callback: function() {}
|
||||||
|
});
|
||||||
|
|
||||||
|
OpenLayers.Request.POST = _POST;
|
||||||
|
}
|
||||||
|
|
||||||
function readXML(id) {
|
function readXML(id) {
|
||||||
var xml = document.getElementById(id).firstChild.nodeValue;
|
var xml = document.getElementById(id).firstChild.nodeValue;
|
||||||
return new OpenLayers.Format.XML().read(xml).documentElement;
|
return new OpenLayers.Format.XML().read(xml).documentElement;
|
||||||
|
|||||||
Reference in New Issue
Block a user