diff --git a/examples/gpx.html b/examples/gpx.html index decc16d0b1..04f52f6889 100644 --- a/examples/gpx.html +++ b/examples/gpx.html @@ -25,6 +25,12 @@
+ + Export GPX +
diff --git a/examples/gpx.js b/examples/gpx.js index 5f4a84c6c4..f1d748dce0 100644 --- a/examples/gpx.js +++ b/examples/gpx.js @@ -1,7 +1,9 @@ goog.require('ol.Map'); goog.require('ol.View'); +goog.require('ol.format.GPX'); goog.require('ol.layer.Tile'); goog.require('ol.layer.Vector'); +goog.require('ol.proj'); goog.require('ol.source.BingMaps'); goog.require('ol.source.GPX'); goog.require('ol.style.Circle'); @@ -9,6 +11,8 @@ goog.require('ol.style.Fill'); goog.require('ol.style.Stroke'); goog.require('ol.style.Style'); +var projection = ol.proj.get('EPSG:3857'); + var raster = new ol.layer.Tile({ source: new ol.source.BingMaps({ imagerySet: 'Aerial', @@ -45,7 +49,7 @@ var style = { var vector = new ol.layer.Vector({ source: new ol.source.GPX({ - projection: 'EPSG:3857', + projection: projection, url: 'data/gpx/fells_loop.gpx' }), style: function(feature, resolution) { @@ -89,3 +93,30 @@ $(map.getViewport()).on('mousemove', function(evt) { map.on('click', function(evt) { displayFeatureInfo(evt.pixel); }); + +var exportGPXElement = document.getElementById('export-gpx'); +if ('download' in exportGPXElement) { + var vectorSource = /** @type {ol.source.Vector} */ (vector.getSource()); + exportGPXElement.addEventListener('click', function(e) { + if (!exportGPXElement.href) { + var features = []; + vectorSource.forEachFeature(function(feature) { + var clone = feature.clone(); + clone.getGeometry().transform(projection, 'EPSG:4326'); + features.push(clone); + }); + var node = new ol.format.GPX().writeFeatures(features); + var string = new XMLSerializer().serializeToString( + /** @type {Node} */ (node)); + var base64 = exampleNS.strToBase64(string); + exportGPXElement.href = + 'data:gpx+xml;base64,' + base64; + } + }, false); +} else { + var info = document.getElementById('no-download'); + /** + * display error message + */ + info.style.display = ''; +} diff --git a/src/ol/format/gpxformat.js b/src/ol/format/gpxformat.js index 7066c9559d..9097be5c5b 100644 --- a/src/ol/format/gpxformat.js +++ b/src/ol/format/gpxformat.js @@ -1,5 +1,4 @@ goog.provide('ol.format.GPX'); -goog.provide('ol.format.GPX.V1_1'); goog.require('goog.array'); goog.require('goog.asserts'); @@ -794,17 +793,6 @@ ol.format.GPX.GPX_SERIALIZERS_ = ol.xml.makeStructureNS( }); - -/** - * @constructor - * @extends {ol.format.GPX} - */ -ol.format.GPX.V1_1 = function() { - goog.base(this); -}; -goog.inherits(ol.format.GPX.V1_1, ol.format.GPX); - - /** * Encode an array of features in the GPX format. * @@ -819,7 +807,7 @@ ol.format.GPX.prototype.writeFeatures; /** * @inheritDoc */ -ol.format.GPX.V1_1.prototype.writeFeaturesNode = function(features) { +ol.format.GPX.prototype.writeFeaturesNode = function(features) { //FIXME Serialize metadata var gpx = ol.xml.createElementNS('http://www.topografix.com/GPX/1/1', 'gpx'); ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */ diff --git a/test/spec/ol/format/gpxformat.test.js b/test/spec/ol/format/gpxformat.test.js index 5428bae0ba..7d880ed391 100644 --- a/test/spec/ol/format/gpxformat.test.js +++ b/test/spec/ol/format/gpxformat.test.js @@ -5,7 +5,7 @@ describe('ol.format.GPX', function() { var format; beforeEach(function() { - format = new ol.format.GPX.V1_1(); + format = new ol.format.GPX(); }); describe('readFeatures', function() { @@ -401,7 +401,6 @@ describe('ol.format.GPX', function() { goog.require('ol.Feature'); goog.require('ol.format.GPX'); -goog.require('ol.format.GPX.V1_1'); goog.require('ol.geom.LineString'); goog.require('ol.geom.MultiLineString'); goog.require('ol.geom.Point');