Skip to content

Commit

Permalink
Don't append feature prefix twice in WFS requests
Browse files Browse the repository at this point in the history
Some WFS servers like tinyOWS require the feature prefix to be in the
feature type for the feature to be found (eg `prefix:layer`).

The problem was, the prefix was always added to the feature type which
gave us a type name like `prefix:prefix:feature` or
`feature:prefix:feature`. The requests were then rejected by the WFS
server.

We now check if the feature type starts with the prefix. If it does, we
don't append it again. If it doesn't we do.
  • Loading branch information
Julien Enselme committed Feb 21, 2017
1 parent b05136e commit d54fada
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions src/ol/format/wfs.js
Expand Up @@ -392,10 +392,9 @@ ol.format.WFS.writeDelete_ = function(node, feature, objectStack) {
ol.asserts.assert(feature.getId() !== undefined, 26); // Features must have an id set
var featureType = context['featureType'];
var featurePrefix = context['featurePrefix'];
featurePrefix = featurePrefix ? featurePrefix :
ol.format.WFS.FEATURE_PREFIX;
var featureNS = context['featureNS'];
node.setAttribute('typeName', featurePrefix + ':' + featureType);
var typeName = ol.format.WFS.getTypeName_(featurePrefix, featureType);
node.setAttribute('typeName', typeName);
ol.xml.setAttributeNS(node, ol.format.WFS.XMLNS, 'xmlns:' + featurePrefix,
featureNS);
var fid = feature.getId();
Expand All @@ -405,6 +404,25 @@ ol.format.WFS.writeDelete_ = function(node, feature, objectStack) {
};


/**
* @param {string|undefined} featurePrefix The prefix of the feature.
* @param {string} featureType The type of the feature.
* @returns {string} The value of the typeName property.
* @private
*/
ol.format.WFS.getTypeName_ = function(featurePrefix, featureType) {
featurePrefix = featurePrefix ? featurePrefix :
ol.format.WFS.FEATURE_PREFIX;
var prefix = featurePrefix + ':';
// The featureType already contains the prefix.
if (featureType.indexOf(prefix) === 0) {
return featureType;
} else {
return prefix + featureType;
}
};


/**
* @param {Node} node Node.
* @param {ol.Feature} feature Feature.
Expand All @@ -416,10 +434,9 @@ ol.format.WFS.writeUpdate_ = function(node, feature, objectStack) {
ol.asserts.assert(feature.getId() !== undefined, 27); // Features must have an id set
var featureType = context['featureType'];
var featurePrefix = context['featurePrefix'];
featurePrefix = featurePrefix ? featurePrefix :
ol.format.WFS.FEATURE_PREFIX;
var featureNS = context['featureNS'];
node.setAttribute('typeName', featurePrefix + ':' + featureType);
var typeName = ol.format.WFS.getTypeName_(featurePrefix, featureType);
node.setAttribute('typeName', typeName);
ol.xml.setAttributeNS(node, ol.format.WFS.XMLNS, 'xmlns:' + featurePrefix,
featureNS);
var fid = feature.getId();
Expand Down Expand Up @@ -512,8 +529,14 @@ ol.format.WFS.writeQuery_ = function(node, featureType, objectStack) {
var featureNS = context['featureNS'];
var propertyNames = context['propertyNames'];
var srsName = context['srsName'];
var prefix = featurePrefix ? featurePrefix + ':' : '';
node.setAttribute('typeName', prefix + featureType);
var typeName;
// If feature prefix is not defined, we must not use the default prefix.
if (featurePrefix) {
typeName = ol.format.WFS.getTypeName_(featurePrefix, featureType);
} else {
typeName = featureType;
}
node.setAttribute('typeName', typeName);
if (srsName) {
node.setAttribute('srsName', srsName);
}
Expand Down

0 comments on commit d54fada

Please sign in to comment.