add support for WFS hit count (1.1) in WFST Format, r=ahocevar (closes #2131)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10268 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -105,13 +105,31 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: read
|
* APIMethod: read
|
||||||
* Parse the response from a transaction. Because WFS is split into
|
* Parse the response from a transaction. Because WFS is split into
|
||||||
* Transaction requests (create, update, and delete) and GetFeature
|
* Transaction requests (create, update, and delete) and GetFeature
|
||||||
* requests (read), this method handles parsing of both types of
|
* requests (read), this method handles parsing of both types of
|
||||||
* responses.
|
* responses.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* data - {String | Document} The WFST document to read
|
||||||
|
* options - {Object} Options for the reader
|
||||||
|
*
|
||||||
|
* Valid options properties:
|
||||||
|
* output - {String} either "features" or "object". The default is
|
||||||
|
* "features", which means that the method will return an array of
|
||||||
|
* features. If set to "object", an object with a "features" property
|
||||||
|
* and other properties read by the parser will be returned.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Array | Object} Output depending on the output option.
|
||||||
*/
|
*/
|
||||||
read: function(data) {
|
read: function(data, options) {
|
||||||
|
options = options || {};
|
||||||
|
OpenLayers.Util.applyDefaults(options, {
|
||||||
|
output: "features"
|
||||||
|
});
|
||||||
|
|
||||||
if(typeof data == "string") {
|
if(typeof data == "string") {
|
||||||
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
|
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
|
||||||
}
|
}
|
||||||
@@ -122,7 +140,7 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
if(data) {
|
if(data) {
|
||||||
this.readNode(data, obj);
|
this.readNode(data, obj);
|
||||||
}
|
}
|
||||||
if(obj.features) {
|
if(obj.features && options.output === "features") {
|
||||||
obj = obj.features;
|
obj = obj.features;
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
|||||||
@@ -33,6 +33,12 @@ OpenLayers.Format.WFST.v1_1_0 = OpenLayers.Class(
|
|||||||
* Constructor: OpenLayers.Format.WFST.v1_1_0
|
* Constructor: OpenLayers.Format.WFST.v1_1_0
|
||||||
* A class for parsing and generating WFS v1.1.0 transactions.
|
* A class for parsing and generating WFS v1.1.0 transactions.
|
||||||
*
|
*
|
||||||
|
* To read additional information like hit count (numberOfFeatures) from
|
||||||
|
* the FeatureCollection, call the <OpenLayers.Format.WFST.v1.read> method
|
||||||
|
* with {output: "object"} as 2nd argument. Note that it is possible to
|
||||||
|
* just request the hit count from a WFS 1.1.0 server with the
|
||||||
|
* resultType="hits" request parameter.
|
||||||
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* options - {Object} Optional object whose properties will be set on the
|
* options - {Object} Optional object whose properties will be set on the
|
||||||
* instance.
|
* instance.
|
||||||
@@ -59,6 +65,12 @@ OpenLayers.Format.WFST.v1_1_0 = OpenLayers.Class(
|
|||||||
*/
|
*/
|
||||||
readers: {
|
readers: {
|
||||||
"wfs": OpenLayers.Util.applyDefaults({
|
"wfs": OpenLayers.Util.applyDefaults({
|
||||||
|
"FeatureCollection": function(node, obj) {
|
||||||
|
obj.numberOfFeatures = parseInt(node.getAttribute(
|
||||||
|
"numberOfFeatures"));
|
||||||
|
OpenLayers.Format.WFST.v1.prototype.readers["wfs"]["FeatureCollection"].apply(
|
||||||
|
this, arguments);
|
||||||
|
},
|
||||||
"TransactionResponse": function(node, obj) {
|
"TransactionResponse": function(node, obj) {
|
||||||
obj.insertIds = [];
|
obj.insertIds = [];
|
||||||
obj.success = false;
|
obj.success = false;
|
||||||
|
|||||||
@@ -23,6 +23,17 @@
|
|||||||
t.eq(result.success, true, "Success read correctly");
|
t.eq(result.success, true, "Success read correctly");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_read_hits(t) {
|
||||||
|
t.plan(1);
|
||||||
|
var data = readXML("NumberOfFeatures");
|
||||||
|
var format = new OpenLayers.Format.WFST.v1_1_0({
|
||||||
|
featureNS: "http://mapserver.gis.umn.edu/mapserver",
|
||||||
|
featureType: "AAA64"
|
||||||
|
});
|
||||||
|
var result = format.read(data, {output: "object"});
|
||||||
|
t.eq(result.numberOfFeatures, 625, "numberOfFeatures of FeatureCollection correctly read");
|
||||||
|
}
|
||||||
|
|
||||||
function test_write(t) {
|
function test_write(t) {
|
||||||
|
|
||||||
var format = new OpenLayers.Format.WFST.v1_1_0({
|
var format = new OpenLayers.Format.WFST.v1_1_0({
|
||||||
@@ -70,6 +81,17 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="map" style="width:512px; height:256px"> </div>
|
<div id="map" style="width:512px; height:256px"> </div>
|
||||||
|
<div id="NumberOfFeatures"><!--
|
||||||
|
<?xml version='1.0' encoding="ISO-8859-1" ?>
|
||||||
|
<wfs:FeatureCollection
|
||||||
|
xmlns:rws="http://mapserver.gis.umn.edu/mapserver"
|
||||||
|
xmlns:gml="http://www.opengis.net/gml"
|
||||||
|
xmlns:wfs="http://www.opengis.net/wfs"
|
||||||
|
xmlns:ogc="http://www.opengis.net/ogc"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://mapserver.gis.umn.edu/mapserver http://intranet.rijkswaterstaat.nl/services/geoservices/nwb_wegen?SERVICE=WFS&VERSION=1.1.0&REQUEST=DescribeFeatureType&TYPENAME=feature:AAA64&OUTPUTFORMAT=text/xml; subtype=gml/3.1.1 http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" numberOfFeatures="625">
|
||||||
|
</wfs:FeatureCollection>
|
||||||
|
--></div>
|
||||||
<div id="TransactionResponse"><!--
|
<div id="TransactionResponse"><!--
|
||||||
<wfs:TransactionResponse version="1.1.0" xmlns:ogc="http://www.opengis.net/ogc" xmlns:tiger="http://www.census.gov" xmlns:wfs="http://www.opengis.net/wfs" xmlns:topp="http://www.openplans.org/topp" xmlns:sf="http://www.openplans.org/spearfish" xmlns:ows="http://www.opengis.net/ows" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink">
|
<wfs:TransactionResponse version="1.1.0" xmlns:ogc="http://www.opengis.net/ogc" xmlns:tiger="http://www.census.gov" xmlns:wfs="http://www.opengis.net/wfs" xmlns:topp="http://www.openplans.org/topp" xmlns:sf="http://www.openplans.org/spearfish" xmlns:ows="http://www.opengis.net/ows" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||||
<wfs:TransactionSummary>
|
<wfs:TransactionSummary>
|
||||||
|
|||||||
Reference in New Issue
Block a user