diff --git a/src/ol/format/gpxformat.js b/src/ol/format/gpxformat.js index bb83768e7d..8f1d8fa72c 100644 --- a/src/ol/format/gpxformat.js +++ b/src/ol/format/gpxformat.js @@ -839,11 +839,13 @@ ol.format.GPX.GPX_NODE_FACTORY_ = function(value, objectStack, opt_nodeName) { 'value should be an ol.Feature'); var geometry = value.getGeometry(); if (geometry) { - var parentNode = objectStack[objectStack.length - 1].node; - goog.asserts.assert(ol.xml.isNode(parentNode), - 'parentNode should be an XML node'); - return ol.xml.createElementNS(parentNode.namespaceURI, - ol.format.GPX.GEOMETRY_TYPE_TO_NODENAME_[geometry.getType()]); + var nodeName = ol.format.GPX.GEOMETRY_TYPE_TO_NODENAME_[geometry.getType()]; + if (nodeName) { + var parentNode = objectStack[objectStack.length - 1].node; + goog.asserts.assert(ol.xml.isNode(parentNode), + 'parentNode should be an XML node'); + return ol.xml.createElementNS(parentNode.namespaceURI, nodeName); + } } }; diff --git a/test/spec/ol/format/gpxformat.test.js b/test/spec/ol/format/gpxformat.test.js index ff09580aca..bf5c4eaca0 100644 --- a/test/spec/ol/format/gpxformat.test.js +++ b/test/spec/ol/format/gpxformat.test.js @@ -557,6 +557,23 @@ describe('ol.format.GPX', function() { }); + describe('write unsupported geometries', function() { + beforeEach(function() { + format = new ol.format.GPX(); + }); + + it('does not fail', function() { + var polygon = new ol.geom.Polygon( + [[[0, 0], [2, 2], [4, 0], [0, 0]]]); + var feature = new ol.Feature(polygon); + var features = [feature]; + var gpx = format.writeFeatures(features); + var expected = + ''; + expect(gpx).to.be(expected); + }); + }); + }); @@ -566,5 +583,6 @@ goog.require('ol.geom.GeometryLayout'); goog.require('ol.geom.LineString'); goog.require('ol.geom.MultiLineString'); goog.require('ol.geom.Point'); +goog.require('ol.geom.Polygon'); goog.require('ol.proj'); goog.require('ol.xml');