Use correct axis order in write

This commit is contained in:
Bart van den Eijnden
2014-02-26 16:53:37 +01:00
parent 083d8d9890
commit 37a78dc753
2 changed files with 30 additions and 13 deletions
+14 -3
View File
@@ -1008,6 +1008,13 @@ ol.format.GML.writePos_ = function(node, value, objectStack) {
* @private * @private
*/ */
ol.format.GML.writePosList_ = function(node, value, objectStack) { ol.format.GML.writePosList_ = function(node, value, objectStack) {
var context = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(context));
var srsName = goog.object.get(context, 'srsName');
var axisOrientation = 'enu';
if (goog.isDefAndNotNull(srsName)) {
axisOrientation = ol.proj.get(srsName).getAxisOrientation();
}
// only 2d for simple features profile // only 2d for simple features profile
var points = value.getCoordinates(); var points = value.getCoordinates();
var len = points.length; var len = points.length;
@@ -1015,8 +1022,11 @@ ol.format.GML.writePosList_ = function(node, value, objectStack) {
var point; var point;
for (var i = 0; i < len; ++i) { for (var i = 0; i < len; ++i) {
point = points[i]; point = points[i];
// TODO axis orientation if (axisOrientation === 'enu') {
parts[i] = point[0] + ' ' + point[1]; parts[i] = point[0] + ' ' + point[1];
} else {
parts[i] = point[1] + ' ' + point[0];
}
} }
ol.format.XSD.writeStringTextNode(node, parts.join(' ')); ol.format.XSD.writeStringTextNode(node, parts.join(' '));
}; };
@@ -1088,7 +1098,8 @@ ol.format.GML.writeLineString_ = function(node, geometry, objectStack) {
if (goog.isDefAndNotNull(srsName)) { if (goog.isDefAndNotNull(srsName)) {
node.setAttribute('srsName', srsName); node.setAttribute('srsName', srsName);
} }
ol.xml.pushSerializeAndPop({node: node}, var context = {node: node, srsName: srsName};
ol.xml.pushSerializeAndPop(context,
ol.format.GML.FLAT_COORDINATES_SERIALIZERS_, ol.format.GML.FLAT_COORDINATES_SERIALIZERS_,
ol.format.GML.POSLIST_NODE_FACTORY_, [geometry], []); ol.format.GML.POSLIST_NODE_FACTORY_, [geometry], []);
}; };
+16 -10
View File
@@ -53,16 +53,22 @@ describe('ol.format.GML', function() {
describe('axis order', function() { describe('axis order', function() {
it('can read a linestring geometry with correct axis order', function() { it('can read and write a linestring geometry with ' +
var text = 'correct axis order', function() {
'<gml:LineString xmlns:gml="http://www.opengis.net/gml" ' + var text =
' srsName="urn:x-ogc:def:crs:EPSG:4326">' + '<gml:LineString xmlns:gml="http://www.opengis.net/gml" ' +
' <gml:posList>-90 -180 90 180</gml:posList>' + ' srsName="urn:x-ogc:def:crs:EPSG:4326">' +
'</gml:LineString>'; ' <gml:posList>-90 -180 90 180</gml:posList>' +
var g = readGeometry(format, text); '</gml:LineString>';
expect(g).to.be.an(ol.geom.LineString); format = new ol.format.GML({
expect(g.getCoordinates()).to.eql([[-180, -90, 0], [180, 90, 0]]); srsName: 'urn:x-ogc:def:crs:EPSG:4326'
}); });
var g = readGeometry(format, text);
expect(g).to.be.an(ol.geom.LineString);
expect(g.getCoordinates()).to.eql([[-180, -90, 0], [180, 90, 0]]);
var serialized = format.writeGeometry(g);
expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text));
});
it('can read a point geometry with correct axis order', function() { it('can read a point geometry with correct axis order', function() {
var text = var text =