diff --git a/src/ol/format/gmlformat.js b/src/ol/format/gmlformat.js index 5810158b11..3da9e476a3 100644 --- a/src/ol/format/gmlformat.js +++ b/src/ol/format/gmlformat.js @@ -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.} */ (ol.xml.pushParseAndPop(null, + return /** @type {Array.} */ (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.|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) { diff --git a/test/spec/ol/format/gmlformat.test.js b/test/spec/ol/format/gmlformat.test.js index d2d7310b02..4698b4e009 100644 --- a/test/spec/ol/format/gmlformat.test.js +++ b/test/spec/ol/format/gmlformat.test.js @@ -38,6 +38,21 @@ describe('ol.format.GML', function() { }); + describe('linestring 3D', function() { + + it('can read a linestring 3D geometry', function() { + var text = + '' + + ' 1 2 3 4 5 6' + + ''; + 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() {