Correct axis order for gml:pos
This commit is contained in:
@@ -694,7 +694,7 @@ ol.format.GML.readFlatPosList_ = function(node, objectStack) {
|
|||||||
x = parseFloat(coords[i]);
|
x = parseFloat(coords[i]);
|
||||||
y = parseFloat(coords[i + 1]);
|
y = parseFloat(coords[i + 1]);
|
||||||
z = (dim === 3) ? parseFloat(coords[i + 2]) : 0;
|
z = (dim === 3) ? parseFloat(coords[i + 2]) : 0;
|
||||||
if (axisOrientation === 'enu') {
|
if (axisOrientation.substr(0, 2) === 'en') {
|
||||||
flatCoordinates.push(x, y, z);
|
flatCoordinates.push(x, y, z);
|
||||||
} else {
|
} else {
|
||||||
flatCoordinates.push(y, x, z);
|
flatCoordinates.push(y, x, z);
|
||||||
@@ -994,10 +994,22 @@ ol.format.GML.prototype.readFeaturesFromNode = function(node) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.format.GML.writePos_ = function(node, value, objectStack) {
|
ol.format.GML.writePos_ = function(node, value, objectStack) {
|
||||||
var layout = value.getLayout();
|
var context = objectStack[objectStack.length - 1];
|
||||||
node.setAttribute('srsDimension',
|
goog.asserts.assert(goog.isObject(context));
|
||||||
(layout == ol.geom.GeometryLayout.XYZ) ? '3' : '2');
|
var srsName = goog.object.get(context, 'srsName');
|
||||||
ol.format.XSD.writeStringTextNode(node, value.getCoordinates().join(' '));
|
var axisOrientation = 'enu';
|
||||||
|
if (goog.isDefAndNotNull(srsName)) {
|
||||||
|
axisOrientation = ol.proj.get(srsName).getAxisOrientation();
|
||||||
|
}
|
||||||
|
var point = value.getCoordinates();
|
||||||
|
var coords;
|
||||||
|
// only 2d for simple features profile
|
||||||
|
if (axisOrientation.substr(0, 2) === 'en') {
|
||||||
|
coords = (point[0] + ' ' + point[1]);
|
||||||
|
} else {
|
||||||
|
coords = (point[1] + ' ' + point[0]);
|
||||||
|
}
|
||||||
|
ol.format.XSD.writeStringTextNode(node, coords);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -1022,7 +1034,7 @@ 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];
|
||||||
if (axisOrientation === 'enu') {
|
if (axisOrientation.substr(0, 2) === 'en') {
|
||||||
parts[i] = point[0] + ' ' + point[1];
|
parts[i] = point[0] + ' ' + point[1];
|
||||||
} else {
|
} else {
|
||||||
parts[i] = point[1] + ' ' + point[0];
|
parts[i] = point[1] + ' ' + point[0];
|
||||||
@@ -1079,7 +1091,8 @@ ol.format.GML.writePoint_ = 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.POS_NODE_FACTORY_, [geometry], []);
|
ol.format.GML.POS_NODE_FACTORY_, [geometry], []);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ describe('ol.format.GML', function() {
|
|||||||
var text =
|
var text =
|
||||||
'<gml:Point xmlns:gml="http://www.opengis.net/gml" ' +
|
'<gml:Point xmlns:gml="http://www.opengis.net/gml" ' +
|
||||||
' srsName="CRS:84">' +
|
' srsName="CRS:84">' +
|
||||||
' <gml:pos srsDimension="3">1 2 0</gml:pos>' +
|
' <gml:pos>1 2</gml:pos>' +
|
||||||
'</gml:Point>';
|
'</gml:Point>';
|
||||||
var g = readGeometry(format, text);
|
var g = readGeometry(format, text);
|
||||||
expect(g).to.be.an(ol.geom.Point);
|
expect(g).to.be.an(ol.geom.Point);
|
||||||
@@ -70,16 +70,22 @@ 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 a point geometry with correct axis order', function() {
|
it('can read and write a point geometry with correct axis order',
|
||||||
var text =
|
function() {
|
||||||
'<gml:Point xmlns:gml="http://www.opengis.net/gml" ' +
|
var text =
|
||||||
' srsName="urn:x-ogc:def:crs:EPSG:4326">' +
|
'<gml:Point xmlns:gml="http://www.opengis.net/gml" ' +
|
||||||
' <gml:pos>-90 -180</gml:pos>' +
|
' srsName="urn:x-ogc:def:crs:EPSG:4326">' +
|
||||||
'</gml:Point>';
|
' <gml:pos>-90 -180</gml:pos>' +
|
||||||
var g = readGeometry(format, text);
|
'</gml:Point>';
|
||||||
expect(g).to.be.an(ol.geom.Point);
|
format = new ol.format.GML({
|
||||||
expect(g.getCoordinates()).to.eql([-180, -90, 0]);
|
srsName: 'urn:x-ogc:def:crs:EPSG:4326'
|
||||||
});
|
});
|
||||||
|
var g = readGeometry(format, text);
|
||||||
|
expect(g).to.be.an(ol.geom.Point);
|
||||||
|
expect(g.getCoordinates()).to.eql([-180, -90, 0]);
|
||||||
|
var serialized = format.writeGeometry(g);
|
||||||
|
expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text));
|
||||||
|
});
|
||||||
|
|
||||||
it('can read multi surface geometry with right axis order', function() {
|
it('can read multi surface geometry with right axis order', function() {
|
||||||
var text =
|
var text =
|
||||||
|
|||||||
Reference in New Issue
Block a user