Remove old ol.parser.GPX
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="chrome=1">
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
|
||||
<link rel="stylesheet" href="../css/ol.css" type="text/css">
|
||||
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap.min.css" type="text/css">
|
||||
<link rel="stylesheet" href="../resources/layout.css" type="text/css">
|
||||
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
|
||||
<title>GPX tracks example</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||
<div class="navbar-inner">
|
||||
<div class="container">
|
||||
<a class="brand" href="./"><img src="../resources/logo.png"> OpenLayers 3 Examples</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container-fluid">
|
||||
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
<div id="map" class="map"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row-fluid">
|
||||
|
||||
<div class="span4">
|
||||
<h4 id="title">GPX tracks example</h4>
|
||||
<p id="shortdesc">Example of using the GPX parser to display tracks.</p>
|
||||
<div id="docs">
|
||||
<p>See the <a href="gpx-trkpt.js" target="_blank">gpx-trkpt.js source</a> to see how this is done.</p>
|
||||
</div>
|
||||
<div id="tags">GPX trackpoint tracks</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="jquery.min.js" type="text/javascript"></script>
|
||||
<script src="loader.js?id=gpx-trkpt" type="text/javascript"></script>
|
||||
<script src="../resources/example-behaviour.js" type="text/javascript"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,40 +0,0 @@
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.RendererHint');
|
||||
goog.require('ol.View2D');
|
||||
goog.require('ol.layer.Tile');
|
||||
goog.require('ol.layer.Vector');
|
||||
goog.require('ol.parser.GPX');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.source.OSM');
|
||||
goog.require('ol.source.Vector');
|
||||
goog.require('ol.style.Stroke');
|
||||
goog.require('ol.style.Style');
|
||||
|
||||
var raster = new ol.layer.Tile({
|
||||
source: new ol.source.OSM()
|
||||
});
|
||||
|
||||
var vector = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({
|
||||
parser: new ol.parser.GPX(),
|
||||
url: 'data/gpx/gpx4j.xml'
|
||||
}),
|
||||
style: new ol.style.Style({
|
||||
symbolizers: [
|
||||
new ol.style.Stroke({
|
||||
color: 'red',
|
||||
opacity: 1
|
||||
})
|
||||
]
|
||||
})
|
||||
});
|
||||
|
||||
var map = new ol.Map({
|
||||
layers: [raster, vector],
|
||||
renderer: ol.RendererHint.CANVAS,
|
||||
target: 'map',
|
||||
view: new ol.View2D({
|
||||
center: ol.proj.transform([-0.425692, 39.114318], 'EPSG:4326', 'EPSG:3857'),
|
||||
zoom: 19
|
||||
})
|
||||
});
|
||||
@@ -1,55 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="chrome=1">
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
|
||||
<link rel="stylesheet" href="../css/ol.css" type="text/css">
|
||||
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap.min.css" type="text/css">
|
||||
<link rel="stylesheet" href="../resources/layout.css" type="text/css">
|
||||
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
|
||||
<title>GPX example</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||
<div class="navbar-inner">
|
||||
<div class="container">
|
||||
<a class="brand" href="./"><img src="../resources/logo.png"> OpenLayers 3 Examples</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container-fluid">
|
||||
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
<div id="map" class="map"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row-fluid">
|
||||
|
||||
<div class="span4">
|
||||
<h4 id="title">GPX example</h4>
|
||||
<p id="shortdesc">Example of using the GPX parser.</p>
|
||||
<div id="docs">
|
||||
<p>See the <a href="gpx.js" target="_blank">gpx.js source</a> to see how this is done.</p>
|
||||
</div>
|
||||
<div id="tags">GPX</div>
|
||||
</div>
|
||||
<div class="span4 offset4">
|
||||
<div id="info" class="alert alert-success">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="jquery.min.js" type="text/javascript"></script>
|
||||
<script src="loader.js?id=gpx" type="text/javascript"></script>
|
||||
<script src="../resources/example-behaviour.js" type="text/javascript"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,54 +0,0 @@
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.RendererHint');
|
||||
goog.require('ol.View2D');
|
||||
goog.require('ol.layer.Tile');
|
||||
goog.require('ol.layer.Vector');
|
||||
goog.require('ol.parser.GPX');
|
||||
goog.require('ol.source.OSM');
|
||||
goog.require('ol.source.Vector');
|
||||
|
||||
var raster = new ol.layer.Tile({
|
||||
source: new ol.source.OSM()
|
||||
});
|
||||
|
||||
var vector = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({
|
||||
parser: new ol.parser.GPX(),
|
||||
url: 'data/gpx/yahoo.xml'
|
||||
})
|
||||
});
|
||||
|
||||
var map = new ol.Map({
|
||||
layers: [raster, vector],
|
||||
renderer: ol.RendererHint.CANVAS,
|
||||
target: 'map',
|
||||
view: new ol.View2D({
|
||||
center: [-7916461.9312699, 5226343.9091441],
|
||||
zoom: 11
|
||||
})
|
||||
});
|
||||
|
||||
var displayFeatureInfo = function(pixel) {
|
||||
map.getFeatures({
|
||||
pixel: pixel,
|
||||
layers: [vector],
|
||||
success: function(featuresByLayer) {
|
||||
var features = featuresByLayer[0];
|
||||
var info = [];
|
||||
for (var i = 0, ii = features.length; i < ii; ++i) {
|
||||
info.push(features[i].get('name') + ': ' + features[i].get('type'));
|
||||
}
|
||||
document.getElementById('info').innerHTML = info.join(', ') || ' ';
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$(map.getViewport()).on('mousemove', function(evt) {
|
||||
var pixel = map.getEventPixel(evt.originalEvent);
|
||||
displayFeatureInfo(pixel);
|
||||
});
|
||||
|
||||
map.on('singleclick', function(evt) {
|
||||
var pixel = evt.getPixel();
|
||||
displayFeatureInfo(pixel);
|
||||
});
|
||||
@@ -1 +0,0 @@
|
||||
@exportSymbol ol.parser.GPX
|
||||
@@ -1,291 +0,0 @@
|
||||
goog.provide('ol.parser.GPX');
|
||||
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.parser.DomFeatureParser');
|
||||
goog.require('ol.parser.ObjectFeatureParser');
|
||||
goog.require('ol.parser.StringFeatureParser');
|
||||
goog.require('ol.parser.XML');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Read and write [GPX](http://www.topografix.com/gpx.asp) version 1.1
|
||||
*
|
||||
* @constructor
|
||||
* @implements {ol.parser.DomFeatureParser}
|
||||
* @implements {ol.parser.StringFeatureParser}
|
||||
* @implements {ol.parser.ObjectFeatureParser}
|
||||
* @param {olx.parser.GPXOptions=} opt_options Optional configuration object.
|
||||
* @extends {ol.parser.XML}
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.parser.GPX = function(opt_options) {
|
||||
var options = /** @type {olx.parser.GPXOptions} */
|
||||
(goog.isDef(opt_options) ? opt_options : {});
|
||||
this.extractAttributes = goog.isDef(options.extractAttributes) ?
|
||||
options.extractAttributes : true;
|
||||
this.extractWaypoints = goog.isDef(options.extractWaypoints) ?
|
||||
options.extractWaypoints : true;
|
||||
this.extractTracks = goog.isDef(options.extractTracks) ?
|
||||
options.extractTracks : true;
|
||||
this.extractRoutes = goog.isDef(options.extractRoutes) ?
|
||||
options.extractRoutes : true;
|
||||
this.creator = goog.isDef(options.creator) ?
|
||||
options.creator : 'OpenLayers';
|
||||
this.defaultDesc = goog.isDef(options.defaultDesc) ?
|
||||
options.defaultDesc : 'No description available';
|
||||
this.defaultNamespaceURI = 'http://www.topografix.com/GPX/1/1';
|
||||
this.schemaLocation = 'http://www.topografix.com/GPX/1/1 ' +
|
||||
'http://www.topografix.com/GPX/1/1/gpx.xsd';
|
||||
this.readers = {
|
||||
'http://www.topografix.com/GPX/1/1': {
|
||||
'gpx': function(node, obj) {
|
||||
if (!goog.isDef(obj.features)) {
|
||||
obj.features = [];
|
||||
}
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'wpt': function(node, obj) {
|
||||
if (this.extractWaypoints) {
|
||||
var properties = {};
|
||||
var coordinates = [parseFloat(node.getAttribute('lon')),
|
||||
parseFloat(node.getAttribute('lat'))];
|
||||
this.readChildNodes(node, properties);
|
||||
var feature = new ol.Feature(properties);
|
||||
var geometry = new ol.geom.Point(coordinates);
|
||||
feature.setGeometry(geometry);
|
||||
obj.features.push(feature);
|
||||
}
|
||||
},
|
||||
'rte': function(node, obj) {
|
||||
if (this.extractRoutes || obj.force) {
|
||||
var type = ol.geom.GeometryType.LINE_STRING;
|
||||
var container = {
|
||||
properties: {},
|
||||
geometry: {
|
||||
type: type,
|
||||
coordinates: []
|
||||
}
|
||||
};
|
||||
this.readChildNodes(node, container);
|
||||
var feature = new ol.Feature(container.properties);
|
||||
var geometry = new ol.geom.LineString(container.geometry.coordinates);
|
||||
feature.setGeometry(geometry);
|
||||
obj.features.push(feature);
|
||||
}
|
||||
},
|
||||
'rtept': function(node, container) {
|
||||
var coordinate = [parseFloat(node.getAttribute('lon')),
|
||||
parseFloat(node.getAttribute('lat'))];
|
||||
container.geometry.coordinates.push(coordinate);
|
||||
},
|
||||
'trk': function(node, obj) {
|
||||
if (this.extractTracks) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
obj.force = true;
|
||||
readers['rte'].apply(this, arguments);
|
||||
}
|
||||
},
|
||||
'trkseg': function(node, container) {
|
||||
this.readChildNodes(node, container);
|
||||
},
|
||||
'trkpt': function(node, container) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
readers['rtept'].apply(this, arguments);
|
||||
},
|
||||
'*': function(node, obj) {
|
||||
if (this.extractAttributes === true) {
|
||||
var len = node.childNodes.length;
|
||||
if ((len === 1 || len === 2) && (node.firstChild.nodeType === 3 ||
|
||||
node.firstChild.nodeType === 4)) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
readers['_attribute'].apply(this, arguments);
|
||||
}
|
||||
}
|
||||
},
|
||||
'_attribute': function(node, obj) {
|
||||
var local = node.localName || node.nodeName.split(':').pop();
|
||||
var value = this.getChildValue(node);
|
||||
if (obj.properties) {
|
||||
obj.properties[local] = value.replace(this.regExes.trimSpace, '');
|
||||
} else {
|
||||
obj[local] = value.replace(this.regExes.trimSpace, '');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
// create an alias for GXP 1.0
|
||||
this.readers['http://www.topografix.com/GPX/1/0'] =
|
||||
this.readers[this.defaultNamespaceURI];
|
||||
this.writers = {
|
||||
'http://www.topografix.com/GPX/1/1': {
|
||||
'_feature': function(feature) {
|
||||
var geom = feature.getGeometry();
|
||||
if (geom instanceof ol.geom.Point) {
|
||||
return this.writeNode('wpt', feature);
|
||||
} else if ((geom instanceof ol.geom.LineString) ||
|
||||
(geom instanceof ol.geom.MultiLineString) ||
|
||||
(geom instanceof ol.geom.Polygon)) {
|
||||
return this.writeNode('trk', feature);
|
||||
}
|
||||
},
|
||||
'wpt': function(feature) {
|
||||
var node = this.createElementNS('wpt');
|
||||
var geom = feature.getGeometry();
|
||||
var coordinates = geom.getCoordinates();
|
||||
node.setAttribute('lon', coordinates[0]);
|
||||
node.setAttribute('lat', coordinates[1]);
|
||||
var attributes = feature.getAttributes();
|
||||
var name = attributes['name'] || goog.getUid(feature).toString();
|
||||
this.writeNode('name', name, undefined, node);
|
||||
var desc = attributes['description'] || this.defaultDesc;
|
||||
this.writeNode('desc', desc, undefined, node);
|
||||
return node;
|
||||
},
|
||||
'trk': function(feature) {
|
||||
var attributes = feature.getAttributes();
|
||||
var node = this.createElementNS('trk');
|
||||
var name = attributes['name'] || goog.getUid(feature).toString();
|
||||
this.writeNode('name', name, undefined, node);
|
||||
var desc = attributes['description'] || this.defaultDesc;
|
||||
this.writeNode('desc', desc, undefined, node);
|
||||
var geom = feature.getGeometry();
|
||||
var i, ii, rings;
|
||||
if (geom instanceof ol.geom.LineString) {
|
||||
this.writeNode('trkseg', feature.getGeometry(), undefined, node);
|
||||
} else if (geom instanceof ol.geom.MultiLineString) {
|
||||
var components = geom.getComponents();
|
||||
for (i = 0, ii = components.length; i < ii; ++i) {
|
||||
this.writeNode('trkseg', components[i], undefined, node);
|
||||
}
|
||||
} else if (geom instanceof ol.geom.Polygon) {
|
||||
rings = geom.getRings();
|
||||
for (i = 0, ii = rings.length; i < ii; ++i) {
|
||||
this.writeNode('trkseg', rings[i], undefined, node);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'trkseg': function(geometry) {
|
||||
var node = this.createElementNS('trkseg');
|
||||
var coordinates = geometry.getCoordinates();
|
||||
for (var i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
this.writeNode('trkpt', coordinates[i], undefined, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'trkpt': function(coord) {
|
||||
var node = this.createElementNS('trkpt');
|
||||
node.setAttribute('lon', coord[0]);
|
||||
node.setAttribute('lat', coord[1]);
|
||||
return node;
|
||||
},
|
||||
'metadata': function(metadata) {
|
||||
var node = this.createElementNS('metadata');
|
||||
if (goog.isDef(metadata['name'])) {
|
||||
this.writeNode('name', metadata['name'], undefined, node);
|
||||
}
|
||||
if (goog.isDef(metadata['desc'])) {
|
||||
this.writeNode('desc', metadata['desc'], undefined, node);
|
||||
}
|
||||
if (goog.isDef(metadata['author'])) {
|
||||
this.writeNode('author', metadata['author'], undefined, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'name': function(name) {
|
||||
var node = this.createElementNS('name');
|
||||
node.appendChild(this.createTextNode(name));
|
||||
return node;
|
||||
},
|
||||
'desc': function(desc) {
|
||||
var node = this.createElementNS('desc');
|
||||
node.appendChild(this.createTextNode(desc));
|
||||
return node;
|
||||
},
|
||||
'author': function(author) {
|
||||
var node = this.createElementNS('author');
|
||||
node.appendChild(this.createTextNode(author));
|
||||
return node;
|
||||
}
|
||||
}
|
||||
};
|
||||
goog.base(this);
|
||||
};
|
||||
goog.inherits(ol.parser.GPX, ol.parser.XML);
|
||||
|
||||
|
||||
/**
|
||||
* @param {string|Document|Element|Object} data Data to read.
|
||||
* @return {ol.parser.ReadFeaturesResult} An object representing the document.
|
||||
*/
|
||||
ol.parser.GPX.prototype.read = function(data) {
|
||||
if (goog.isString(data)) {
|
||||
data = goog.dom.xml.loadXml(data);
|
||||
}
|
||||
if (data && data.nodeType == 9) {
|
||||
data = data.documentElement;
|
||||
}
|
||||
var obj = /** @type {ol.parser.ReadFeaturesResult} */
|
||||
({metadata: {projection: 'EPSG:4326'}});
|
||||
this.readNode(data, obj);
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse a GPX document provided as a string.
|
||||
* @param {string} str GPX document.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.GPX.prototype.readFeaturesFromString = function(str) {
|
||||
return this.read(str);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse a GPX document provided as a DOM structure.
|
||||
* @param {Element|Document} node Document or element node.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.GPX.prototype.readFeaturesFromNode = function(node) {
|
||||
return this.read(node);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Object} obj Object representing features.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.GPX.prototype.readFeaturesFromObject = function(obj) {
|
||||
return this.read(obj);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {olx.parser.GPXWriteOptions} obj Object structure to write out
|
||||
* as GPX.
|
||||
* @return {string} An string representing the GPX document.
|
||||
*/
|
||||
ol.parser.GPX.prototype.write = function(obj) {
|
||||
var features = goog.isArray(obj.features) ? obj.features : [obj.features];
|
||||
var root = this.createElementNS('gpx');
|
||||
root.setAttribute('version', '1.1');
|
||||
root.setAttribute('creator', this.creator);
|
||||
this.setAttributeNS(
|
||||
root, 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
'xsi:schemaLocation', this.schemaLocation);
|
||||
if (goog.isDef(obj.metadata)) {
|
||||
this.writeNode('metadata', obj.metadata, undefined, root);
|
||||
}
|
||||
for (var i = 0, ii = features.length; i < ii; i++) {
|
||||
this.writeNode('_feature', features[i], undefined, root);
|
||||
}
|
||||
return this.serialize(root);
|
||||
};
|
||||
@@ -1,130 +0,0 @@
|
||||
goog.provide('ol.test.parser.gpx');
|
||||
|
||||
describe('ol.parser.gpx', function() {
|
||||
|
||||
var parser = new ol.parser.GPX();
|
||||
|
||||
describe('Test GPX parser', function() {
|
||||
it('Read works correctly', function(done) {
|
||||
var url = 'spec/ol/parser/gpx/data.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
expect(obj.features.length).to.eql(3);
|
||||
// waypoint feature
|
||||
var feature = obj.features[0];
|
||||
var geom = feature.getGeometry();
|
||||
expect(geom.getType()).to.eql(ol.geom.GeometryType.POINT);
|
||||
expect(geom.getCoordinates()).to.eql([-0.1853562259, 51.3697845627]);
|
||||
// route feature
|
||||
feature = obj.features[1];
|
||||
geom = feature.getGeometry();
|
||||
var attributes = feature.getAttributes();
|
||||
expect(geom.getType()).to.eql(ol.geom.GeometryType.LINE_STRING);
|
||||
expect(geom.getCoordinates()).to.eql([[-0.1829991904, 51.3761803674],
|
||||
[-0.1758887005, 51.3697894659], [-0.1833202965, 51.3639790884],
|
||||
[-0.1751119509, 51.3567607069]]);
|
||||
expect(attributes['name']).to.eql('Route8');
|
||||
expect(attributes['type']).to.eql('Route');
|
||||
// track feature
|
||||
feature = obj.features[2];
|
||||
geom = feature.getGeometry();
|
||||
attributes = feature.getAttributes();
|
||||
expect(geom.getType()).to.eql(ol.geom.GeometryType.LINE_STRING);
|
||||
expect(geom.getCoordinates()).to.eql([[-0.1721292044, 51.3768216433],
|
||||
[-0.1649230916, 51.370833767], [-0.1736741378, 51.3644368725],
|
||||
[-0.166259525, 51.3576354272]]);
|
||||
expect(attributes['name']).to.eql('Track');
|
||||
expect(attributes['type']).to.eql('Track');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Write works correctly for points', function() {
|
||||
var feature1 = new ol.Feature({name: 'foo', description: 'bar'});
|
||||
feature1.setGeometry(new ol.geom.Point([-111.04, 45.68]));
|
||||
var feature2 = new ol.Feature({name: 'foo', description: 'bar'});
|
||||
feature2.setGeometry(new ol.geom.Point([-112.04, 45.68]));
|
||||
var output = parser.write({features: [feature1, feature2]});
|
||||
var expected = '<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
|
||||
'version="1.1" creator="OpenLayers" xsi:schemaLocation="' +
|
||||
'http://www.topografix.com/GPX/1/1 http://www.topografix.com/' +
|
||||
'GPX/1/1/gpx.xsd" xmlns:xsi="http://www.w3.org/2001/' +
|
||||
'XMLSchema-instance"><wpt lon="-111.04" lat="45.68"><name>foo' +
|
||||
'</name><desc>bar</desc></wpt><wpt lon="-112.04" lat="45.68">' +
|
||||
'<name>foo</name><desc>bar</desc></wpt></gpx>';
|
||||
expect(goog.dom.xml.loadXml(expected)).to.xmleql(
|
||||
goog.dom.xml.loadXml(output));
|
||||
});
|
||||
it('Write works correctly for lines', function() {
|
||||
var feature1 = new ol.Feature({name: 'foo', description: 'bar'});
|
||||
feature1.setGeometry(new ol.geom.LineString([[-111.04, 45.68],
|
||||
[-112.04, 45.68]]));
|
||||
var feature2 = new ol.Feature({name: 'dude', description: 'truite'});
|
||||
feature2.setGeometry(new ol.geom.LineString([[1, 2], [3, 4]]));
|
||||
var output = parser.write({features: [feature1, feature2]});
|
||||
var expected = '<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
|
||||
'version="1.1" creator="OpenLayers" xsi:schemaLocation="' +
|
||||
'http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/' +
|
||||
'1/1/gpx.xsd" xmlns:xsi="http://www.w3.org/2001/' +
|
||||
'XMLSchema-instance"><trk><name>foo</name><desc>bar</desc><trkseg>' +
|
||||
'<trkpt lon="-111.04" lat="45.68"/><trkpt lon="-112.04" lat="' +
|
||||
'45.68"/></trkseg></trk><trk><name>dude</name><desc>truite</desc>' +
|
||||
'<trkseg><trkpt lon="1" lat="2"/><trkpt lon="3" lat="4"/></trkseg>' +
|
||||
'</trk></gpx>';
|
||||
expect(goog.dom.xml.loadXml(expected)).to.xmleql(
|
||||
goog.dom.xml.loadXml(output));
|
||||
});
|
||||
it('Write works correctly for multilines', function() {
|
||||
var multi = new ol.geom.MultiLineString([[[-111.04, 45.68],
|
||||
[-112.04, 45.68]], [[1, 2], [3, 4]]]);
|
||||
var feature = new ol.Feature({name: 'foo', description: 'bar'});
|
||||
feature.setGeometry(multi);
|
||||
var output = parser.write({features: [feature]});
|
||||
var expected = '<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
|
||||
'version="1.1" creator="OpenLayers" xsi:schemaLocation="' +
|
||||
'http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/' +
|
||||
'1/1/gpx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-' +
|
||||
'instance"><trk><name>foo</name><desc>bar</desc><trkseg><trkpt' +
|
||||
' lon="-111.04" lat="45.68"/><trkpt lon="-112.04" lat="45.68"/>' +
|
||||
'</trkseg><trkseg><trkpt lon="1" lat="2"/><trkpt lon="3" lat="4"/>' +
|
||||
'</trkseg></trk></gpx>';
|
||||
expect(goog.dom.xml.loadXml(expected)).to.xmleql(
|
||||
goog.dom.xml.loadXml(output));
|
||||
});
|
||||
it('Write works correctly for polygon', function() {
|
||||
var polygon = new ol.geom.Polygon([[[-111.04, 45.68],
|
||||
[-112.04, 45.68], [-111.04, 45.68]]]);
|
||||
var feature = new ol.Feature({name: 'foo', description: 'bar'});
|
||||
feature.setGeometry(polygon);
|
||||
var output = parser.write({features: [feature]});
|
||||
var expected = '<gpx xmlns="http://www.topografix.com/GPX/1/1"' +
|
||||
' version="1.1" creator="OpenLayers" xsi:schemaLocation="http://' +
|
||||
'www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/' +
|
||||
'gpx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
|
||||
'<trk><name>foo</name><desc>bar</desc><trkseg><trkpt lon="-111.04"' +
|
||||
' lat="45.68"/><trkpt lon="-112.04" lat="45.68"/><trkpt lon="' +
|
||||
'-111.04" lat="45.68"/></trkseg></trk></gpx>';
|
||||
expect(goog.dom.xml.loadXml(expected)).to.xmleql(
|
||||
goog.dom.xml.loadXml(output));
|
||||
});
|
||||
it('Write works correctly for metadata', function() {
|
||||
var output = parser.write({features: [], metadata: {'name': 'foo',
|
||||
'desc': 'bar'}});
|
||||
var expected = '<gpx xmlns="http://www.topografix.com/GPX/1/1" ' +
|
||||
'version="1.1" creator="OpenLayers" xsi:schemaLocation="http://' +
|
||||
'www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/' +
|
||||
'gpx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
|
||||
'<metadata><name>foo</name><desc>bar</desc></metadata></gpx>';
|
||||
expect(goog.dom.xml.loadXml(expected)).to.xmleql(
|
||||
goog.dom.xml.loadXml(output));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.parser.GPX');
|
||||
@@ -1 +0,0 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?><gpx version="1.1" creator="Memory-Map 5.1.3.715 http://www.memory-map.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"><wpt lat="51.3697845627" lon="-0.1853562259"><name>Mark</name><sym><![CDATA[Flag]]></sym><type><![CDATA[Marks]]></type></wpt><rte><name><![CDATA[Route8]]></name><type><![CDATA[Route]]></type><rtept lat="51.3761803674" lon="-0.1829991904"><name><![CDATA[WP0801]]></name><sym><![CDATA[Dot]]></sym><type><![CDATA[Waypoints]]></type></rtept><rtept lat="51.3697894659" lon="-0.1758887005"><name><![CDATA[WP0802]]></name><sym><![CDATA[Dot]]></sym><type><![CDATA[Waypoints]]></type></rtept><rtept lat="51.3639790884" lon="-0.1833202965"><name><![CDATA[WP0803]]></name><sym><![CDATA[Dot]]></sym><type><![CDATA[Waypoints]]></type></rtept><rtept lat="51.3567607069" lon="-0.1751119509"><name><![CDATA[WP0804]]></name><sym><![CDATA[Dot]]></sym><type><![CDATA[Waypoints]]></type></rtept></rte><trk><name><![CDATA[Track]]></name><type><![CDATA[Track]]></type><trkseg><trkpt lat="51.3768216433" lon="-0.1721292044"></trkpt><trkpt lat="51.3708337670" lon="-0.1649230916"></trkpt><trkpt lat="51.3644368725" lon="-0.1736741378"></trkpt><trkpt lat="51.3576354272" lon="-0.1662595250"></trkpt></trkseg></trk></gpx>
|
||||
Reference in New Issue
Block a user