Merge pull request #1874 from twpayne/wfs-fixes

Miscellaneous GML and WFS fixes
This commit is contained in:
Tom Payne
2014-03-19 12:54:49 +01:00
3 changed files with 47 additions and 5 deletions

View File

@@ -680,8 +680,18 @@ ol.format.GML.readFlatCoordinatesFromNode_ = function(node, objectStack) {
* @return {Array.<number>|undefined} Flat coordinates.
*/
ol.format.GML.readFlatPos_ = function(node, objectStack) {
var s = ol.xml.getAllTextContent(node, false).replace(/^\s*|\s*$/g, '');
var flatCoordinates = goog.array.map(s.split(/\s+/), parseFloat);
var s = ol.xml.getAllTextContent(node, false);
var re = /^\s*([+\-]?\d*\.?\d+(?:e[+\-]?\d+)?)\s*/;
/** @type {Array.<number>} */
var flatCoordinates = [];
var m;
while ((m = re.exec(s))) {
flatCoordinates.push(parseFloat(m[1]));
s = s.substr(m[0].length);
}
if (s !== '') {
return undefined;
}
var context = objectStack[0];
goog.asserts.assert(goog.isObject(context));
var containerSrs = goog.object.get(context, 'srsName');
@@ -691,7 +701,13 @@ ol.format.GML.readFlatPos_ = function(node, objectStack) {
axisOrientation = proj.getAxisOrientation();
}
if (axisOrientation === 'neu') {
flatCoordinates = flatCoordinates.reverse();
var i, ii;
for (i = 0, ii = flatCoordinates.length; i < ii; i += 3) {
var y = flatCoordinates[i];
var x = flatCoordinates[i + 1];
flatCoordinates[i] = x;
flatCoordinates[i + 1] = y;
}
}
var len = flatCoordinates.length;
if (len == 2) {

View File

@@ -547,7 +547,7 @@ ol.format.WFS.writeGetFeature_ = function(node, featureTypes, objectStack) {
/**
* @param {olx.format.WFSWriteGetFeatureOptions} options Options.
* @return {ArrayBuffer|Node|Object|string} Result.
* @return {Node} Result.
*/
ol.format.WFS.prototype.writeGetFeature = function(options) {
var node = ol.xml.createElementNS('http://www.opengis.net/wfs',
@@ -598,7 +598,7 @@ ol.format.WFS.prototype.writeGetFeature = function(options) {
* @param {Array.<ol.Feature>} updates The features to update.
* @param {Array.<ol.Feature>} deletes The features to delete.
* @param {olx.format.WFSWriteTransactionOptions} options Write options.
* @return {ArrayBuffer|Node|Object|string} Result.
* @return {Node} Result.
*/
ol.format.WFS.prototype.writeTransaction = function(inserts, updates, deletes,
options) {

View File

@@ -33,6 +33,19 @@ describe('ol.format.GML', function() {
expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text));
});
it('can read and write a point geometry in EPSG:4326', function() {
var text =
'<gml:Point xmlns:gml="http://www.opengis.net/gml" ' +
' srsName="urn:x-ogc:def:crs:EPSG:4326">' +
' <gml:pos>2 1</gml:pos>' +
'</gml:Point>';
var g = readGeometry(formatWGS84, text);
expect(g).to.be.an(ol.geom.Point);
expect(g.getCoordinates()).to.eql([1, 2, 0]);
var serialized = formatWGS84.writeGeometry(g);
expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text));
});
});
describe('linestring', function() {
@@ -50,6 +63,19 @@ describe('ol.format.GML', function() {
expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text));
});
it('can read and write a linestring geometry in EPSG:4326', function() {
var text =
'<gml:LineString xmlns:gml="http://www.opengis.net/gml" ' +
' srsName="urn:x-ogc:def:crs:EPSG:4326">' +
' <gml:posList>2 1 4 3</gml:posList>' +
'</gml:LineString>';
var g = readGeometry(formatWGS84, text);
expect(g).to.be.an(ol.geom.LineString);
expect(g.getCoordinates()).to.eql([[1, 2, 0], [3, 4, 0]]);
var serialized = formatWGS84.writeGeometry(g);
expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text));
});
});
describe('axis order', function() {