diff --git a/src/ol/format/gpxformat.js b/src/ol/format/gpxformat.js index 1c911e1d23..573d55d35d 100644 --- a/src/ol/format/gpxformat.js +++ b/src/ol/format/gpxformat.js @@ -432,6 +432,8 @@ ol.format.GPX.prototype.handleReadExtensions_ = function(features) { /** * Read the first feature from a GPX source. + * Routes (``) are converted into LineString geometries, and tracks (``) + * into MultiLineString. Any properties on route and track waypoints are ignored. * * @function * @param {Document|Node|Object|string} source Source. @@ -466,6 +468,8 @@ ol.format.GPX.prototype.readFeatureFromNode = function(node, opt_options) { /** * Read all features from a GPX source. + * Routes (``) are converted into LineString geometries, and tracks (``) + * into MultiLineString. Any properties on route and track waypoints are ignored. * * @function * @param {Document|Node|Object|string} source Source. @@ -569,7 +573,9 @@ ol.format.GPX.writeWptType_ = function(node, coordinate, objectStack) { default: // pass } - var orderedKeys = ol.format.GPX.WPT_TYPE_SEQUENCE_[namespaceURI]; + var orderedKeys = (node.nodeName == 'rtept') ? + ol.format.GPX.RTEPT_TYPE_SEQUENCE_[namespaceURI] : + ol.format.GPX.WPT_TYPE_SEQUENCE_[namespaceURI]; var values = ol.xml.makeSequence(properties, orderedKeys); ol.xml.pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */ ({node: node, 'properties': properties}), @@ -723,6 +729,17 @@ ol.format.GPX.RTE_SERIALIZERS_ = ol.xml.makeStructureNS( }); +/** + * @const + * @type {Object.>} + * @private + */ +ol.format.GPX.RTEPT_TYPE_SEQUENCE_ = ol.xml.makeStructureNS( + ol.format.GPX.NAMESPACE_URIS_, [ + 'ele', 'time' + ]); + + /** * @const * @type {Object.>} diff --git a/test/spec/ol/format/gpxformat.test.js b/test/spec/ol/format/gpxformat.test.js index eea926db2f..9a51fb5984 100644 --- a/test/spec/ol/format/gpxformat.test.js +++ b/test/spec/ol/format/gpxformat.test.js @@ -117,6 +117,20 @@ describe('ol.format.GPX', function() { expect(serialized).to.xmleql(ol.xml.parse(text)); }); + it('does not write rte attributes in rtepts', function() { + var text = + '' + + ' ' + + ' Name' + + ' ' + + ' ' + + ' ' + + ''; + var fs = format.readFeatures(text); + var serialized = format.writeFeaturesNode(fs); + expect(serialized).to.xmleql(ol.xml.parse(text)); + }); + }); describe('trk', function() { @@ -295,6 +309,38 @@ describe('ol.format.GPX', function() { expect(serialized).to.xmleql(ol.xml.parse(text)); }); + it('does not write trk attributes in trkpts', function() { + var text = + '' + + ' ' + + ' Name' + + ' ' + + ' ' + + ' 3' + + ' ' + + ' ' + + ' ' + + ' 7' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' 10' + + ' ' + + ' ' + + ' ' + + ' 13' + + ' ' + + ' ' + + ' ' + + ' ' + + ''; + var fs = format.readFeatures(text); + var serialized = format.writeFeaturesNode(fs); + expect(serialized).to.xmleql(ol.xml.parse(text)); + }); + }); describe('wpt', function() {