Deal with srsDimension

This commit is contained in:
Bart van den Eijnden
2014-02-20 14:57:03 +01:00
parent 877d5a445e
commit 95bbb849bb
2 changed files with 23 additions and 3 deletions

View File

@@ -381,7 +381,8 @@ ol.format.GML.readEnvelope_ = function(node, objectStack) {
*/
ol.format.GML.readFlatCoordinatesFromNode_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
return /** @type {Array.<number>} */ (ol.xml.pushParseAndPop(null,
return /** @type {Array.<number>} */ (ol.xml.pushParseAndPop(
node.getAttribute('srsDimension'),
ol.format.GML.GEOMETRY_FLAT_COORDINATES_PARSERS_, node, objectStack));
};
@@ -408,15 +409,19 @@ ol.format.GML.readFlatPos_ = function(node) {
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
* @return {Array.<number>|undefined} Flat coordinates.
*/
ol.format.GML.readFlatPosList_ = function(node) {
ol.format.GML.readFlatPosList_ = function(node, objectStack) {
var containerDimension = objectStack[objectStack.length - 1];
var s = ol.xml.getAllTextContent(node, false).replace(/^\s*|\s*$/g, '');
var coords = s.split(/\s+/);
// The "dimension" attribute is from the GML 3.0.1 spec.
var dim = parseInt(node.getAttribute('srsDimension') ||
node.getAttribute('dimension'), 10) || 2;
node.getAttribute('dimension'), 10) ||
(goog.isString(containerDimension)) ?
parseInt(containerDimension, 10) : 2;
var x, y, z;
var flatCoordinates = [];
for (var i = 0, ii = coords.length; i < ii; i += dim) {

View File

@@ -38,6 +38,21 @@ describe('ol.format.GML', function() {
});
describe('linestring 3D', function() {
it('can read a linestring 3D geometry', function() {
var text =
'<gml:LineString xmlns:gml="http://www.opengis.net/gml" ' +
' srsName="foo" srsDimension="3">' +
' <gml:posList>1 2 3 4 5 6</gml:posList>' +
'</gml:LineString>';
var g = format.readGeometry(text);
expect(g).to.be.an(ol.geom.LineString);
expect(g.getCoordinates()).to.eql([[1, 2, 3], [4, 5, 6]]);
});
});
describe('polygon', function() {
it('can read a polygon geometry', function() {