Replace IGCZ enum with typedef

This commit is contained in:
Maximilian Krög
2022-07-16 23:20:28 +02:00
parent d20690394c
commit 4d2156ff3a

View File

@@ -9,14 +9,9 @@ import {get as getProjection} from '../proj.js';
import {transformGeometryWithOptions} from './Feature.js';
/**
* @typedef {'barometric' | 'gps' | 'none'} IGCZ
* IGC altitude/z. One of 'barometric', 'gps', 'none'.
* @enum {string}
*/
const IGCZ = {
BAROMETRIC: 'barometric',
GPS: 'gps',
NONE: 'none',
};
/**
* @const
@@ -47,7 +42,7 @@ const NEWLINE_RE = /\r\n|\r|\n/;
/**
* @typedef {Object} Options
* @property {IGCZ|string} [altitudeMode='none'] Altitude mode. Possible
* @property {IGCZ} [altitudeMode='none'] Altitude mode. Possible
* values are `'barometric'`, `'gps'`, and `'none'`.
*/
@@ -79,9 +74,7 @@ class IGC extends TextFeature {
* @private
* @type {IGCZ}
*/
this.altitudeMode_ = options.altitudeMode
? options.altitudeMode
: IGCZ.NONE;
this.altitudeMode_ = options.altitudeMode ? options.altitudeMode : 'none';
}
/**
@@ -119,11 +112,11 @@ class IGC extends TextFeature {
x = -x;
}
flatCoordinates.push(x, y);
if (altitudeMode != IGCZ.NONE) {
if (altitudeMode != 'none') {
let z;
if (altitudeMode == IGCZ.GPS) {
if (altitudeMode == 'gps') {
z = parseInt(m[11], 10);
} else if (altitudeMode == IGCZ.BAROMETRIC) {
} else if (altitudeMode == 'barometric') {
z = parseInt(m[12], 10);
} else {
z = 0;
@@ -156,7 +149,7 @@ class IGC extends TextFeature {
return null;
}
const layout =
altitudeMode == IGCZ.NONE ? GeometryLayout.XYM : GeometryLayout.XYZM;
altitudeMode == 'none' ? GeometryLayout.XYM : GeometryLayout.XYZM;
const lineString = new LineString(flatCoordinates, layout);
const feature = new Feature(
transformGeometryWithOptions(lineString, false, opt_options)