diff --git a/lib/OpenLayers/Format/GPX.js b/lib/OpenLayers/Format/GPX.js index c6a67f9953..f3f0fce313 100644 --- a/lib/OpenLayers/Format/GPX.js +++ b/lib/OpenLayers/Format/GPX.js @@ -57,11 +57,20 @@ OpenLayers.Format.GPX = OpenLayers.Class(OpenLayers.Format.XML, { extractAttributes: true, /** - * APIProperty: gpxns - * {String} GPX namespace to use. Defaults to - * "http://www.topografix.com/GPX/1/1" + * Property: namespaces + * {Object} Mapping of namespace aliases to namespace URIs. */ - gpxns: "http://www.topografix.com/GPX/1/1", + namespaces: { + gpx: "http://www.topografix.com/GPX/1/1", + xsi: "http://www.w3.org/2001/XMLSchema-instance" + }, + + /** + * Property: schemaLocation + * {String} Schema location. Defaults to + * "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" + */ + schemaLocation: "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd", /** * Constructor: OpenLayers.Format.GPX @@ -207,17 +216,20 @@ OpenLayers.Format.GPX = OpenLayers.Class(OpenLayers.Format.XML, { * add to the gpx. Supported keys are 'name', 'desc', 'author'. */ write: function(features, metadata) { - var gpx; features = OpenLayers.Util.isArray(features) ? features : [features]; - gpx = this.createElementNS(this.gpxns, "gpx"); + var gpx = this.createElementNSPlus("gpx:gpx"); + gpx.setAttribute("version", "1.1"); + this.setAttributes(gpx, { + "xsi:schemaLocation": this.schemaLocation + }); - for(var i=0, len=features.length; i} */ appendAttributesNode: function(node, feature) { - var name = this.createElementNS(this.gpxns, 'name'); + var name = this.createElementNSPlus('gpx:name'); name.appendChild(this.createTextNode( feature.attributes.name || feature.id)); node.appendChild(name); - var desc = this.createElementNS(this.gpxns, 'desc'); + var desc = this.createElementNSPlus('gpx:desc'); desc.appendChild(this.createTextNode( feature.attributes.description || this.defaultDesc)); node.appendChild(desc); diff --git a/notes/2.12.md b/notes/2.12.md index a02c465a7a..2182009676 100644 --- a/notes/2.12.md +++ b/notes/2.12.md @@ -22,6 +22,10 @@ People can override this rule to use other transition settings. To remove tile a # Behavior Changes from Past Releases +## GPX API change + +The `gpxns` API property has been removed. The GPX namespace is now defined in the `namespaces` property but is not intended to be overriden. + ## Function return values [Previously][prev] a few functions in the library displayed error messages and returned `undefined`, `null` or `false` if the parameters passed in were bad. In 2.12 these functions now just throw an error/exception. People relying on return values to know if a function call is successful may need to change their code. Here are the modified functions: diff --git a/tests/Format/GPX.html b/tests/Format/GPX.html index 2b88e7a9de..6a86ca6774 100644 --- a/tests/Format/GPX.html +++ b/tests/Format/GPX.html @@ -46,7 +46,7 @@ new OpenLayers.Feature.Vector(point2, {name: 'foo', description: 'bar'}) ]; var data = parser.write(features); - t.xml_eq(data, 'foobarfoobar', 'GPX serializes points correctly'); + t.xml_eq(data, 'foobarfoobar', 'GPX serializes points correctly'); } function test_Format_GPX_serialize_line(t) { t.plan(1); @@ -58,7 +58,7 @@ var line = new OpenLayers.Geometry.LineString([point, point2]); var f = new OpenLayers.Feature.Vector(line, {name: 'foo', description: 'bar'}); var data = parser.write(f); - t.xml_eq(data, 'foobar', 'GPX serializes line correctly'); + t.xml_eq(data, 'foobar', 'GPX serializes line correctly'); } function test_Format_GPX_serialize_lines(t) { t.plan(1); @@ -74,7 +74,7 @@ var f = new OpenLayers.Feature.Vector(line, {name: 'foo', description: 'bar'}); var f2 = new OpenLayers.Feature.Vector(line2, {name: 'dude', description: 'truite'}); var data = parser.write([f, f2]); - t.xml_eq(data, 'foobardudetruite', 'GPX serializes lines correctly'); + t.xml_eq(data, 'foobardudetruite', 'GPX serializes lines correctly'); } function test_Format_GPX_serialize_multiline(t) { t.plan(1); @@ -90,7 +90,7 @@ var multiline = new OpenLayers.Geometry.MultiLineString([line, line2]); var f = new OpenLayers.Feature.Vector(multiline, {name: 'foo', description: 'bar'}); var data = parser.write([f]); - t.xml_eq(data, 'foobar', 'GPX serializes multiline correctly'); + t.xml_eq(data, 'foobar', 'GPX serializes multiline correctly'); } function test_Format_GPX_serialize_polygon(t) { t.plan(1); @@ -103,7 +103,7 @@ var polygon = new OpenLayers.Geometry.Polygon([linearRing]); var f = new OpenLayers.Feature.Vector(polygon, {name: 'foo', description: 'bar'}); var data = parser.write([f]); - t.xml_eq(data, 'foobar', 'GPX serializes polygon correctly'); + t.xml_eq(data, 'foobar', 'GPX serializes polygon correctly'); } function test_Format_GPX_serialize_metadata(t) { t.plan(1); @@ -111,7 +111,7 @@ var parser = new OpenLayers.Format.GPX(); var data = parser.write([], {name: 'foo', desc: 'bar'}); - t.xml_eq(data, 'foobar', 'GPX serializes metadata correctly'); + t.xml_eq(data, 'foobar', 'GPX serializes metadata correctly'); }