From 7d210948e89d7efce377f1e5eda2a4c7edcd711c Mon Sep 17 00:00:00 2001 From: Peter Robins Date: Tue, 14 Jun 2016 09:04:26 +0000 Subject: [PATCH] Fix GPX write of xsi ns Also add version/creator attributes to node. --- src/ol/format/gpxformat.js | 16 +++++ test/spec/ol/format/gpxformat.test.js | 86 +++++++++++++++++++++------ 2 files changed, 85 insertions(+), 17 deletions(-) diff --git a/src/ol/format/gpxformat.js b/src/ol/format/gpxformat.js index 573d55d35d..8c31c9e11c 100644 --- a/src/ol/format/gpxformat.js +++ b/src/ol/format/gpxformat.js @@ -56,6 +56,15 @@ ol.format.GPX.NAMESPACE_URIS_ = [ ]; +/** + * @const + * @type {string} + * @private + */ +ol.format.GPX.SCHEMA_LOCATION_ = 'http://www.topografix.com/GPX/1/1 ' + + 'http://www.topografix.com/GPX/1/1/gpx.xsd'; + + /** * @param {Array.} flatCoordinates Flat coordinates. * @param {Node} node Node. @@ -911,6 +920,13 @@ ol.format.GPX.prototype.writeFeaturesNode = function(features, opt_options) { opt_options = this.adaptOptions(opt_options); //FIXME Serialize metadata var gpx = ol.xml.createElementNS('http://www.topografix.com/GPX/1/1', 'gpx'); + var xmlnsUri = 'http://www.w3.org/2000/xmlns/'; + var xmlSchemaInstanceUri = 'http://www.w3.org/2001/XMLSchema-instance'; + ol.xml.setAttributeNS(gpx, xmlnsUri, 'xmlns:xsi', xmlSchemaInstanceUri); + ol.xml.setAttributeNS(gpx, xmlSchemaInstanceUri, 'xsi:schemaLocation', + ol.format.GPX.SCHEMA_LOCATION_); + gpx.setAttribute('version', '1.1'); + gpx.setAttribute('creator', 'OpenLayers 3'); ol.xml.pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */ ({node: gpx}), ol.format.GPX.GPX_SERIALIZERS_, diff --git a/test/spec/ol/format/gpxformat.test.js b/test/spec/ol/format/gpxformat.test.js index 9a51fb5984..aab4c026ba 100644 --- a/test/spec/ol/format/gpxformat.test.js +++ b/test/spec/ol/format/gpxformat.test.js @@ -38,7 +38,10 @@ describe('ol.format.GPX', function() { it('can read and write various rte attributes', function() { var text = - '' + + '' + ' ' + ' Name' + ' Comment' + @@ -71,7 +74,10 @@ describe('ol.format.GPX', function() { it('can read and write a rte with multiple rtepts', function() { var text = - '' + + '' + ' ' + ' ' + ' ' + @@ -91,7 +97,10 @@ describe('ol.format.GPX', function() { it('can transform, read and write a rte', function() { var text = - '' + + '' + ' ' + ' ' + ' ' + @@ -119,7 +128,10 @@ describe('ol.format.GPX', function() { it('does not write rte attributes in rtepts', function() { var text = - '' + + '' + ' ' + ' Name' + ' ' + @@ -152,7 +164,10 @@ describe('ol.format.GPX', function() { it('can read and write various trk attributes', function() { var text = - '' + + '' + ' ' + ' Name' + ' Comment' + @@ -185,7 +200,10 @@ describe('ol.format.GPX', function() { it('can read and write a trk with an empty trkseg', function() { var text = - '' + + '' + ' ' + ' ' + ' ' + @@ -204,7 +222,10 @@ describe('ol.format.GPX', function() { it('can read/write a trk with a trkseg with multiple trkpts', function() { var text = - '' + + '' + ' ' + ' ' + ' ' + @@ -234,7 +255,10 @@ describe('ol.format.GPX', function() { it('can transform, read and write a trk with a trkseg', function() { var text = - '' + + '' + ' ' + ' ' + ' ' + @@ -270,7 +294,10 @@ describe('ol.format.GPX', function() { it('can read and write a trk with multiple trksegs', function() { var text = - '' + + '' + ' ' + ' ' + ' ' + @@ -311,7 +338,10 @@ describe('ol.format.GPX', function() { it('does not write trk attributes in trkpts', function() { var text = - '' + + '' + ' ' + ' Name' + ' ' + @@ -347,7 +377,10 @@ describe('ol.format.GPX', function() { it('can read and write a wpt', function() { var text = - '' + + '' + ' ' + ''; var fs = format.readFeatures(text); @@ -364,7 +397,10 @@ describe('ol.format.GPX', function() { it('can transform, read and write a wpt', function() { var text = - '' + + '' + ' ' + ''; var fs = format.readFeatures(text, { @@ -387,7 +423,10 @@ describe('ol.format.GPX', function() { it('can read and write a wpt with ele', function() { var text = - '' + + '' + ' ' + ' 3' + ' ' + @@ -406,7 +445,10 @@ describe('ol.format.GPX', function() { it('can read and write a wpt with time', function() { var text = - '' + + '' + ' ' + ' ' + ' ' + @@ -425,7 +467,10 @@ describe('ol.format.GPX', function() { it('can read and write a wpt with ele and time', function() { var text = - '' + + '' + ' ' + ' 3' + ' ' + @@ -445,7 +490,10 @@ describe('ol.format.GPX', function() { it('can read and write various wpt attributes', function() { var text = - '' + + '' + ' ' + ' 11' + ' 4' + @@ -615,7 +663,11 @@ describe('ol.format.GPX', function() { var features = [feature]; var gpx = format.writeFeaturesNode(features); var expected = - ''; + ''; expect(gpx).to.xmleql(ol.xml.parse(expected)); }); });