1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tools_1 = require("@toba/tools");
|
4 | const index_1 = require("./index");
|
5 | const xml_1 = require("./xml");
|
6 | const defaultConfig = {
|
7 | checkPrivacy: false,
|
8 | privacyMiles: 1
|
9 | };
|
10 | function location(node, config = null) {
|
11 | const location = new Array(5);
|
12 | const elevation = xml_1.xml.firstNode(node, 'ele');
|
13 | const t = xml_1.xml.firstNode(node, 'time');
|
14 | config = config === null ? defaultConfig : tools_1.merge(config, defaultConfig);
|
15 | location[0] = xml_1.xml.numberAttribute(node, 'lon');
|
16 | location[1] = xml_1.xml.numberAttribute(node, 'lat');
|
17 | if (config.checkPrivacy &&
|
18 | index_1.measure.pointDistance(location, config.privacyCenter) <
|
19 | config.privacyMiles) {
|
20 | return null;
|
21 | }
|
22 | if (tools_1.is.value(elevation)) {
|
23 | const v = xml_1.xml.value(elevation);
|
24 | if (v !== null) {
|
25 | const m = parseFloat(v);
|
26 | location[2] = Math.round(m * 3.28084);
|
27 | }
|
28 | }
|
29 | if (tools_1.is.value(t)) {
|
30 | const v = xml_1.xml.value(t);
|
31 | if (v !== null) {
|
32 | const d = new Date(v);
|
33 | location[3] = d.getTime();
|
34 | }
|
35 | }
|
36 | location[4] = 0;
|
37 | return location;
|
38 | }
|
39 | function properties(node, extras = []) {
|
40 | const names = extras.concat([
|
41 | 'name',
|
42 | 'desc',
|
43 | 'author',
|
44 | 'copyright',
|
45 | 'link',
|
46 | 'time',
|
47 | 'keywords'
|
48 | ]);
|
49 | const properties = {};
|
50 | for (const key of names) {
|
51 | const value = xml_1.xml.firstValue(node, key);
|
52 | if (!tools_1.is.empty(value)) {
|
53 | properties[key] = value;
|
54 | }
|
55 | }
|
56 | return properties;
|
57 | }
|
58 | const line = (node, name) => {
|
59 | const points = Array.from(node.getElementsByTagName(name))
|
60 | .map(p => location(p))
|
61 | .filter(p => tools_1.is.value(p));
|
62 | const speed = points.map((p, i, line) => {
|
63 | if (i > 0) {
|
64 | p[4] = index_1.measure.speed(p, line[i - 1]);
|
65 | }
|
66 | return p;
|
67 | });
|
68 | return speed.length > 0 ? speed : null;
|
69 | };
|
70 | exports.gpx = { line, properties, location };
|