summaryrefslogtreecommitdiff
path: root/OsmAndBuilder/models/OsmAndPoint.ts
blob: a051205fa2b8e468ed8fa8eb11c8111c8080a21a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { BaseBuilder } from 'gpx-builder';
const { Point, PointOptions } = BaseBuilder.MODELS;

export interface OsmAndPointOptions extends PointOptions {
  atemp?: number;
  bearing?: number;
  cad?: number;
  course?: number;
  depth?: number;
  hr?: number;
  speed?: number;
  wtemp?: number;
}

export class OsmAndPoint extends Point {
  /**
   * Extended garmin point.
   *
   * @see https://www8.garmin.com/xmlschemas/TrackPointExtensionv2.xsd
   */

  public constructor(
    lat: number,
    lon: number,
    options: OsmAndPointOptions = {},
  ) {
    super(lat, lon, options);
    const { background, color, icon } = options;

    const ext = 'osmand';
    const data = {
      ...(typeof background === 'string' ? { [`${ext}:background`]: background } : {}),
      ...(typeof color === 'string' ? { [`${ext}:color`]: color } : {}),
      ...(typeof icon === 'string' ? { [`${ext}:icon`]: icon } : {}),
    };

    this.extensions = {
      ...this.extensions,
      ...(Object.keys(data).length > 0 ? data : {}),
    };
  }
}