Merge pull request #1874 from twpayne/wfs-fixes
Miscellaneous GML and WFS fixes
This commit is contained in:
@@ -680,8 +680,18 @@ ol.format.GML.readFlatCoordinatesFromNode_ = function(node, objectStack) {
|
|||||||
* @return {Array.<number>|undefined} Flat coordinates.
|
* @return {Array.<number>|undefined} Flat coordinates.
|
||||||
*/
|
*/
|
||||||
ol.format.GML.readFlatPos_ = function(node, objectStack) {
|
ol.format.GML.readFlatPos_ = function(node, objectStack) {
|
||||||
var s = ol.xml.getAllTextContent(node, false).replace(/^\s*|\s*$/g, '');
|
var s = ol.xml.getAllTextContent(node, false);
|
||||||
var flatCoordinates = goog.array.map(s.split(/\s+/), parseFloat);
|
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];
|
var context = objectStack[0];
|
||||||
goog.asserts.assert(goog.isObject(context));
|
goog.asserts.assert(goog.isObject(context));
|
||||||
var containerSrs = goog.object.get(context, 'srsName');
|
var containerSrs = goog.object.get(context, 'srsName');
|
||||||
@@ -691,7 +701,13 @@ ol.format.GML.readFlatPos_ = function(node, objectStack) {
|
|||||||
axisOrientation = proj.getAxisOrientation();
|
axisOrientation = proj.getAxisOrientation();
|
||||||
}
|
}
|
||||||
if (axisOrientation === 'neu') {
|
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;
|
var len = flatCoordinates.length;
|
||||||
if (len == 2) {
|
if (len == 2) {
|
||||||
|
|||||||
@@ -547,7 +547,7 @@ ol.format.WFS.writeGetFeature_ = function(node, featureTypes, objectStack) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {olx.format.WFSWriteGetFeatureOptions} options Options.
|
* @param {olx.format.WFSWriteGetFeatureOptions} options Options.
|
||||||
* @return {ArrayBuffer|Node|Object|string} Result.
|
* @return {Node} Result.
|
||||||
*/
|
*/
|
||||||
ol.format.WFS.prototype.writeGetFeature = function(options) {
|
ol.format.WFS.prototype.writeGetFeature = function(options) {
|
||||||
var node = ol.xml.createElementNS('http://www.opengis.net/wfs',
|
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>} updates The features to update.
|
||||||
* @param {Array.<ol.Feature>} deletes The features to delete.
|
* @param {Array.<ol.Feature>} deletes The features to delete.
|
||||||
* @param {olx.format.WFSWriteTransactionOptions} options Write options.
|
* @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,
|
ol.format.WFS.prototype.writeTransaction = function(inserts, updates, deletes,
|
||||||
options) {
|
options) {
|
||||||
|
|||||||
@@ -33,6 +33,19 @@ describe('ol.format.GML', function() {
|
|||||||
expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text));
|
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() {
|
describe('linestring', function() {
|
||||||
@@ -50,6 +63,19 @@ describe('ol.format.GML', function() {
|
|||||||
expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text));
|
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() {
|
describe('axis order', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user