summaryrefslogtreecommitdiff
path: root/OsmAndBuilder
diff options
context:
space:
mode:
authorCamil Staps2026-02-02 18:38:26 +0100
committerCamil Staps2026-02-02 18:38:26 +0100
commit4029b88e2c79eaed519c829e373ac916f426f311 (patch)
tree617fd189c60a5e80b61b417c1c77c154ae1bd149 /OsmAndBuilder
Initial commitHEADmain
Diffstat (limited to 'OsmAndBuilder')
-rw-r--r--OsmAndBuilder/OsmAndBuilder.ts24
-rw-r--r--OsmAndBuilder/index.ts2
-rw-r--r--OsmAndBuilder/models/OsmAndPoint.ts42
3 files changed, 68 insertions, 0 deletions
diff --git a/OsmAndBuilder/OsmAndBuilder.ts b/OsmAndBuilder/OsmAndBuilder.ts
new file mode 100644
index 0000000..9c0930a
--- /dev/null
+++ b/OsmAndBuilder/OsmAndBuilder.ts
@@ -0,0 +1,24 @@
+import { BaseBuilder } from 'gpx-builder';
+import { OsmAndPoint } from './models/OsmAndPoint.ts';
+
+export class OsmAndBuilder extends BaseBuilder {
+ public static MODELS = {
+ ...BaseBuilder.MODELS,
+ Point: OsmAndPoint,
+ };
+
+ /**
+ * OsmAnd builder includes extensions for waypoint customization:
+ * https://osmand.net/docs/technical/osmand-file-formats/osmand-gpx/#waypoints-customization
+ */
+ public constructor() {
+ super();
+ this.data = {
+ ...this.data,
+ attributes: {
+ ...this.data.attributes,
+ 'xmlns:osmand': 'https://osmand.net/docs/technical/osmand-file-formats/osmand-gpx',
+ },
+ };
+ }
+}
diff --git a/OsmAndBuilder/index.ts b/OsmAndBuilder/index.ts
new file mode 100644
index 0000000..8ff9833
--- /dev/null
+++ b/OsmAndBuilder/index.ts
@@ -0,0 +1,2 @@
+import { OsmAndBuilder } from './OsmAndBuilder.ts';
+export { OsmAndBuilder };
diff --git a/OsmAndBuilder/models/OsmAndPoint.ts b/OsmAndBuilder/models/OsmAndPoint.ts
new file mode 100644
index 0000000..a051205
--- /dev/null
+++ b/OsmAndBuilder/models/OsmAndPoint.ts
@@ -0,0 +1,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 : {}),
+ };
+ }
+}