diff --git a/src/ol/format/gml2.js b/src/ol/format/gml2.js index 134e208353..f90f07b016 100644 --- a/src/ol/format/gml2.js +++ b/src/ol/format/gml2.js @@ -471,7 +471,9 @@ ol.format.GML2.prototype.getCoords_ = function(point, opt_srsName, opt_is3D) { point[0] + ',' + point[1] : point[1] + ',' + point[0]); if (opt_is3D) { - coords += ',' + point[2]; + // For newly created points, Z can be undefined. + var z = point[2] || 0; + coords += ',' + z; } return coords; diff --git a/src/ol/format/gml3.js b/src/ol/format/gml3.js index be9a256d23..2e77ea67b7 100644 --- a/src/ol/format/gml3.js +++ b/src/ol/format/gml3.js @@ -580,7 +580,9 @@ ol.format.GML3.prototype.writePos_ = function(node, value, objectStack) { coords = (point[1] + ' ' + point[0]); } if (is3D) { - coords += ' ' + point[2]; + // For newly created points, Z can be undefined. + var z = point[2] || 0; + coords += ' ' + z; } ol.format.XSD.writeStringTextNode(node, coords); }; @@ -602,7 +604,9 @@ ol.format.GML3.prototype.getCoords_ = function(point, opt_srsName, opt_is3D) { point[0] + ' ' + point[1] : point[1] + ' ' + point[0]); if (opt_is3D) { - coords += ' ' + point[2]; + // For newly created points, Z can be undefined. + var z = point[2] || 0; + coords += ' ' + z; } return coords;