Assert we have a feature id
This commit is contained in:
@@ -411,6 +411,7 @@ ol.format.WFS.writeOgcFidFilter_ = function(node, fid, objectStack) {
|
|||||||
ol.format.WFS.writeDelete_ = function(node, feature, objectStack) {
|
ol.format.WFS.writeDelete_ = function(node, feature, objectStack) {
|
||||||
var context = objectStack[objectStack.length - 1];
|
var context = objectStack[objectStack.length - 1];
|
||||||
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
|
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
|
||||||
|
goog.asserts.assert(feature.getId() !== undefined, 'feature should have an id');
|
||||||
var featureType = context['featureType'];
|
var featureType = context['featureType'];
|
||||||
var featurePrefix = context['featurePrefix'];
|
var featurePrefix = context['featurePrefix'];
|
||||||
featurePrefix = featurePrefix ? featurePrefix :
|
featurePrefix = featurePrefix ? featurePrefix :
|
||||||
@@ -420,7 +421,7 @@ ol.format.WFS.writeDelete_ = function(node, feature, objectStack) {
|
|||||||
ol.xml.setAttributeNS(node, ol.format.WFS.XMLNS, 'xmlns:' + featurePrefix,
|
ol.xml.setAttributeNS(node, ol.format.WFS.XMLNS, 'xmlns:' + featurePrefix,
|
||||||
featureNS);
|
featureNS);
|
||||||
var fid = feature.getId();
|
var fid = feature.getId();
|
||||||
if (fid) {
|
if (fid !== undefined) {
|
||||||
ol.format.WFS.writeOgcFidFilter_(node, fid, objectStack);
|
ol.format.WFS.writeOgcFidFilter_(node, fid, objectStack);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -435,6 +436,7 @@ ol.format.WFS.writeDelete_ = function(node, feature, objectStack) {
|
|||||||
ol.format.WFS.writeUpdate_ = function(node, feature, objectStack) {
|
ol.format.WFS.writeUpdate_ = function(node, feature, objectStack) {
|
||||||
var context = objectStack[objectStack.length - 1];
|
var context = objectStack[objectStack.length - 1];
|
||||||
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
|
goog.asserts.assert(goog.isObject(context), 'context should be an Object');
|
||||||
|
goog.asserts.assert(feature.getId() !== undefined, 'feature should have an id');
|
||||||
var featureType = context['featureType'];
|
var featureType = context['featureType'];
|
||||||
var featurePrefix = context['featurePrefix'];
|
var featurePrefix = context['featurePrefix'];
|
||||||
featurePrefix = featurePrefix ? featurePrefix :
|
featurePrefix = featurePrefix ? featurePrefix :
|
||||||
@@ -444,7 +446,7 @@ ol.format.WFS.writeUpdate_ = function(node, feature, objectStack) {
|
|||||||
ol.xml.setAttributeNS(node, ol.format.WFS.XMLNS, 'xmlns:' + featurePrefix,
|
ol.xml.setAttributeNS(node, ol.format.WFS.XMLNS, 'xmlns:' + featurePrefix,
|
||||||
featureNS);
|
featureNS);
|
||||||
var fid = feature.getId();
|
var fid = feature.getId();
|
||||||
if (fid) {
|
if (fid !== undefined) {
|
||||||
var keys = feature.getKeys();
|
var keys = feature.getKeys();
|
||||||
var values = [];
|
var values = [];
|
||||||
for (var i = 0, ii = keys.length; i < ii; i++) {
|
for (var i = 0, ii = keys.length; i < ii; i++) {
|
||||||
|
|||||||
@@ -328,6 +328,33 @@ describe('ol.format.WFS', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when writing out a Transaction request', function() {
|
||||||
|
|
||||||
|
it('does not create an update if no fid', function() {
|
||||||
|
var format = new ol.format.WFS();
|
||||||
|
var updateFeature = new ol.Feature();
|
||||||
|
updateFeature.setGeometryName('the_geom');
|
||||||
|
updateFeature.setGeometry(new ol.geom.MultiLineString([[
|
||||||
|
[-12279454, 6741885],
|
||||||
|
[-12064207, 6732101],
|
||||||
|
[-11941908, 6595126],
|
||||||
|
[-12240318, 6507071],
|
||||||
|
[-12416429, 6604910]
|
||||||
|
]]));
|
||||||
|
var error = false;
|
||||||
|
try {
|
||||||
|
format.writeTransaction(null, [updateFeature], null, {
|
||||||
|
featureNS: 'http://foo',
|
||||||
|
featureType: 'FAULTS',
|
||||||
|
featurePrefix: 'foo',
|
||||||
|
gmlOptions: {srsName: 'EPSG:900913'}
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
expect(error).to.be(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('when writing out a Transaction request', function() {
|
describe('when writing out a Transaction request', function() {
|
||||||
var text, filename = 'spec/ol/format/wfs/TransactionUpdateMultiGeoms.xml';
|
var text, filename = 'spec/ol/format/wfs/TransactionUpdateMultiGeoms.xml';
|
||||||
|
|||||||
Reference in New Issue
Block a user