allow WFS protocol to use a different outputFormat, for instance json, patch by rdewit, r=me (closes #2107)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9725 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -181,6 +181,7 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
attributes: {
|
||||
service: "WFS",
|
||||
version: this.version,
|
||||
outputFormat: options && options.outputFormat,
|
||||
maxFeatures: options && options.maxFeatures,
|
||||
"xsi:schemaLocation": this.schemaLocationAttr(options)
|
||||
}
|
||||
|
||||
@@ -65,6 +65,15 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, {
|
||||
*/
|
||||
formatOptions: null,
|
||||
|
||||
/**
|
||||
* Property: readFormat
|
||||
* {<OpenLayers.Format>} For WFS requests it is possible to get a
|
||||
* different output format than GML. In that case, we cannot parse
|
||||
* the response with the default format (WFST) and we need a different
|
||||
* format for reading.
|
||||
*/
|
||||
readFormat: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Protocol.WFS
|
||||
* A class for giving layers WFS protocol.
|
||||
@@ -105,7 +114,7 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, {
|
||||
this.setNamespace("feature", this.featureNS);
|
||||
}
|
||||
return readNode.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
@@ -188,7 +197,7 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, {
|
||||
response.code = OpenLayers.Protocol.Response.FAILURE;
|
||||
}
|
||||
options.callback.call(options.scope, response);
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -210,7 +219,8 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, {
|
||||
if(!doc || doc.length <= 0) {
|
||||
return null;
|
||||
}
|
||||
return this.format.read(doc);
|
||||
return (this.readFormat !== null) ? this.readFormat.read(doc) :
|
||||
this.format.read(doc);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
|
||||
t.plan(5);
|
||||
var snippets = {
|
||||
"GetFeature": {maxFeatures: 1},
|
||||
"GetFeature": {maxFeatures: 1, outputFormat: 'json'},
|
||||
"Transaction": null,
|
||||
"Insert": insertFeature,
|
||||
"Update": updateFeature,
|
||||
@@ -118,7 +118,7 @@
|
||||
--></div>
|
||||
|
||||
<div id="GetFeature"><!--
|
||||
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" maxFeatures="1" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" outputFormat="json" maxFeatures="1" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<wfs:Query typeName="topp:states" xmlns:topp="http://www.openplans.org/topp"/>
|
||||
</wfs:GetFeature>
|
||||
--></div>
|
||||
|
||||
@@ -212,6 +212,23 @@
|
||||
t.eq(protocol.srsName, "EPSG:900913", "projection from layer preferred");
|
||||
}
|
||||
|
||||
function test_readFormat(t) {
|
||||
t.plan(1);
|
||||
|
||||
var protocol = new OpenLayers.Protocol.WFS({
|
||||
url: "http://some.url.org",
|
||||
featureNS: "http://namespace.org",
|
||||
featureType: "type",
|
||||
formatOptions: {outputFormat: 'json'},
|
||||
readFormat: new OpenLayers.Format.GeoJSON()
|
||||
});
|
||||
|
||||
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]}}]}';
|
||||
var features = protocol.parseFeatures(request);
|
||||
t.eq(features.length, 1, "the right format is used to read the request (GeoJSON)");
|
||||
}
|
||||
|
||||
function readXML(id) {
|
||||
var xml = document.getElementById(id).firstChild.nodeValue;
|
||||
return new OpenLayers.Format.XML().read(xml).documentElement;
|
||||
|
||||
Reference in New Issue
Block a user