overhaul gpx creation and usage
This commit is contained in:
@@ -7,3 +7,27 @@ test('parseGpx liest Beispielstrecke', () => {
|
||||
const parsed = parseGpx(fs.readFileSync(new URL('../examples/sample-route.gpx', import.meta.url), 'utf8'));
|
||||
assert.equal(parsed.name, 'Beispielweg'); assert.equal(parsed.points.length, 3); assert.ok(parsed.metrics.distanceM > 0);
|
||||
});
|
||||
|
||||
test('normalization separates waypoints and collapses stationary GPS drift', () => {
|
||||
const xml = '<gpx><metadata><name>Pause</name></metadata><wpt lat="51" lon="11"><name>Station</name></wpt><trk><trkseg>'
|
||||
+ '<trkpt lat="50" lon="10"><time>2026-10-03T10:00:00Z</time></trkpt>'
|
||||
+ '<trkpt lat="50.00001" lon="10.00001"/><trkpt lat="50.00002" lon="10.00002"/>'
|
||||
+ '<trkpt lat="50.001" lon="10.001"/></trkseg></trk></gpx>';
|
||||
const result = parseGpx(xml);
|
||||
assert.equal(result.points.length, 2);
|
||||
assert.equal(result.points[0].recordedAt, '2026-10-03T10:00:00Z');
|
||||
assert.match(result.normalizedXml, /<wpt /);
|
||||
assert.match(result.normalizedXml, /<rtept /);
|
||||
assert.doesNotMatch(result.normalizedXml, /<trkpt /);
|
||||
assert.deepEqual(parseGpx(result.normalizedXml).points, result.points);
|
||||
});
|
||||
|
||||
test('waypoint-only routes and missing-position recordings have no invented route coordinates', () => {
|
||||
const waypoint = parseGpx('<gpx><wpt lat="50" lon="10"/></gpx>');
|
||||
assert.equal(waypoint.points.length, 0); assert.equal(waypoint.metrics.distanceM, 0);
|
||||
const empty = parseGpx('<gpx xmlns:wegwichtel="urn:wegwichtel:poi"><extensions><wegwichtel:gpsGap time="2026-10-03T10:00:00Z"/></extensions></gpx>');
|
||||
assert.equal(empty.points.length, 0); assert.equal(empty.metrics.startLat, null);
|
||||
assert.match(empty.normalizedXml, /gpsGap/);
|
||||
assert.throws(() => parseGpx('<gpx><trk>'));
|
||||
assert.throws(() => parseGpx('<gpx><trk><trkseg><trkpt lat="100" lon="10"/></trkseg></trk></gpx>'));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user