more tests and typedefs.
Once feature editing is more stable, this format can be extended with Update, Delete and Insert
This commit is contained in:
@@ -597,9 +597,16 @@
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.parser.WFSOptions
|
||||
* @property {string} featureNS The feature namespace to use.
|
||||
* @property {string} featurePrefix The prefix for the namespace.
|
||||
* @property {Array.<string>} featureTypes The feature types to use.
|
||||
* @property {string} featureNS The featureNS to use.
|
||||
* @property {string} featurePrefix The prefix to use for the featureNS.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.parser.WFSNative
|
||||
* @property {string} vendorId The vendor id to use.
|
||||
* @property {boolean} safeToIgnore Is it safe to ignore?
|
||||
* @property {string} value The value of the Native element.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,6 +21,7 @@ ol.parser.ogc.WFS_v1 = function() {
|
||||
this.writers = {};
|
||||
this.writers[this.defaultNamespaceURI] = {
|
||||
'GetFeature': function(options) {
|
||||
options = /** @type {ol.parser.WFSOptions} */(options);
|
||||
var node = this.createElementNS('wfs:GetFeature');
|
||||
node.setAttribute('service', 'WFS');
|
||||
node.setAttribute('version', this.version);
|
||||
@@ -43,6 +44,46 @@ ol.parser.ogc.WFS_v1 = function() {
|
||||
node, 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
'xsi:schemaLocation', this.schemaLocation);
|
||||
return {node: node, options: options};
|
||||
},
|
||||
'Transaction': function(obj) {
|
||||
obj = obj || {};
|
||||
var options = obj.options || {};
|
||||
var node = this.createElementNS('wfs:Transaction');
|
||||
node.setAttribute('service', 'WFS');
|
||||
node.setAttribute('version', this.version);
|
||||
if (goog.isDef(options.handle)) {
|
||||
node.setAttribute('handle', options.handle);
|
||||
}
|
||||
var i, ii;
|
||||
var features = obj.features;
|
||||
if (goog.isDefAndNotNull(features)) {
|
||||
// TODO implement multi option for geometry types
|
||||
var name, feature;
|
||||
for (i = 0, ii = features.length; i < ii; ++i) {
|
||||
feature = features[i];
|
||||
// TODO Update (use feature.getOriginal())
|
||||
// TODO Insert and Delete
|
||||
if (goog.isDef(name)) {
|
||||
this.writeNode(name, {
|
||||
feature: feature,
|
||||
options: options
|
||||
}, null, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (goog.isDef(options.nativeElements)) {
|
||||
for (i = 0, ii = options.nativeElements.length; i < ii; ++i) {
|
||||
this.writeNode('Native', options.nativeElements[i], null, node);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'Native': function(nativeElement) {
|
||||
var node = this.createElementNS('wfs:Native');
|
||||
node.setAttribute('vendorId', nativeElement.vendorId);
|
||||
node.setAttribute('safeToIgnore', nativeElement.safeToIgnore);
|
||||
node.appendChild(this.createTextNode(nativeElement.value));
|
||||
return node;
|
||||
}
|
||||
};
|
||||
goog.base(this);
|
||||
@@ -115,7 +156,7 @@ ol.parser.ogc.WFS_v1.prototype.read = function(data) {
|
||||
* @return {string} A serialized WFS transaction.
|
||||
*/
|
||||
ol.parser.ogc.WFS_v1.prototype.write = function(features, options) {
|
||||
var root = this.writeNode('wfs:Transaction', {features: features,
|
||||
var root = this.writeNode('Transaction', {features: features,
|
||||
options: options});
|
||||
this.setAttributeNS(
|
||||
root, 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
|
||||
@@ -15,9 +15,80 @@ describe('ol.parser.ogc.WFS', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('handles writing out GetFeature with a handle', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wfs_v1/GetFeature.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.ogc.WFS_v1_0_0();
|
||||
var output = p.writers[p.defaultNamespaceURI]['GetFeature'].
|
||||
apply(p, [{
|
||||
featureNS: 'http://www.openplans.org/topp',
|
||||
featureTypes: ['states'],
|
||||
featurePrefix: 'topp',
|
||||
handle: 'handle_g',
|
||||
maxFeatures: 1,
|
||||
outputFormat: 'json'
|
||||
}
|
||||
]);
|
||||
expect(goog.dom.xml.loadXml(p.serialize(output))).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles writing out Transaction with a handle', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wfs_v1/Transaction.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.ogc.WFS_v1_0_0();
|
||||
var output = p.writers[p.defaultNamespaceURI]['Transaction'].
|
||||
apply(p, [{
|
||||
options: {handle: 'handle_t'}
|
||||
}
|
||||
]);
|
||||
expect(goog.dom.xml.loadXml(p.serialize(output))).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles writing out Native', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wfs_v1/Native.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.ogc.WFS_v1_1_0();
|
||||
var output = p.write(null, {
|
||||
nativeElements: [{
|
||||
vendorId: 'ORACLE',
|
||||
safeToIgnore: true,
|
||||
value: 'ALTER SESSION ENABLE PARALLEL DML'
|
||||
}, {
|
||||
vendorId: 'ORACLE',
|
||||
safeToIgnore: false,
|
||||
value: 'Another native line goes here'
|
||||
}]
|
||||
});
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles writing out GetFeature with > 1 typename', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wfs_v1/GetFeatureMultiple.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var p = new ol.parser.ogc.WFS_v1_0_0();
|
||||
var output = p.writers[p.defaultNamespaceURI]['GetFeature'].
|
||||
apply(p, [{
|
||||
featureNS: 'http://www.openplans.org/topp',
|
||||
featureTypes: ['states', 'cities'],
|
||||
featurePrefix: 'topp'
|
||||
}
|
||||
]);
|
||||
expect(goog.dom.xml.loadXml(p.serialize(output))).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.parser.ogc.WFS');
|
||||
goog.require('ol.parser.ogc.WFS_v1_0_0');
|
||||
goog.require('ol.parser.ogc.WFS_v1_1_0');
|
||||
|
||||
3
test/spec/ol/parser/ogc/xml/wfs_v1/GetFeature.xml
Normal file
3
test/spec/ol/parser/ogc/xml/wfs_v1/GetFeature.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" handle="handle_g" 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>
|
||||
@@ -0,0 +1,4 @@
|
||||
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" 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:Query typeName="topp:cities" xmlns:topp="http://www.openplans.org/topp"/>
|
||||
</wfs:GetFeature>
|
||||
1
test/spec/ol/parser/ogc/xml/wfs_v1/Native.xml
Normal file
1
test/spec/ol/parser/ogc/xml/wfs_v1/Native.xml
Normal file
@@ -0,0 +1 @@
|
||||
<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><wfs:Native vendorId="ORACLE" safeToIgnore="true">ALTER SESSION ENABLE PARALLEL DML</wfs:Native><wfs:Native vendorId="ORACLE" safeToIgnore="false">Another native line goes here</wfs:Native></wfs:Transaction>
|
||||
1
test/spec/ol/parser/ogc/xml/wfs_v1/Transaction.xml
Normal file
1
test/spec/ol/parser/ogc/xml/wfs_v1/Transaction.xml
Normal file
@@ -0,0 +1 @@
|
||||
<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" handle="handle_t" />
|
||||
Reference in New Issue
Block a user