Skip to content

Commit

Permalink
fix coordinate formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
panaaj committed Sep 7, 2024
1 parent 16ae380 commit 5ef8db7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 39 deletions.
67 changes: 34 additions & 33 deletions src/app/lib/pipes/coords.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ export class CoordsPipe implements PipeTransform {
public transform(value: number, type: string, isLat?: boolean): string {
const h = isLat ? (value < 0 ? 'S' : 'N') : value < 0 ? 'W' : 'E';
switch (type) {
case 'HDMS':
return this.toHDMS(value, h);
case 'DHMS':
return this.toDHMS(value, h);
case 'HDd':
return this.toHDd(value, h);
case 'SHDd':
return this.toHDdSigned(value, h);
case 'DMdH':
return this.toDMdH(value, h);
case 'HDd':
return this.toHDd(value, h);
case 'HDMS':
return this.toHDMS(value, h);
case 'DHMS':
return this.toDHMS(value, h);
default:
return this.toXY(value);
}
Expand All @@ -28,50 +28,51 @@ export class CoordsPipe implements PipeTransform {
return value.toFixed(precision);
}

// returns H D°M'S"sss
private toHDMS(value: number, hemisphere: string): string {
return `${hemisphere} ${decimalToSexagesimal(value)}`;
}

// returns DHM'S"sss
private toDHMS(value: number, hemisphere: string): string {
let c = decimalToSexagesimal(value);
c =
c.slice(0, c.indexOf(' ') - 1) + hemisphere + c.slice(c.indexOf(' ') + 1);
return c;
// returns H +/-D.ddddd°
private toHDdSigned(
value: number,
hemisphere: string,
precision = 5
): string {
const h = ['S', 'W'].includes(hemisphere)
? `${hemisphere} -`
: `${hemisphere} +`;
let ddec: string = value.toFixed(precision);
ddec = ddec.substring(ddec.indexOf('.'));
return `${h}${Math.floor(Math.abs(value))}${ddec}${this.symDegree}`;
}

// returns DDD° MM.ddd' H (e.g 020° 44.56' E)
private toDMdH(value: number, hemisphere: string, precision = 5): string {
const D = Math.floor(value) ?? 0;
const D = Math.floor(Math.abs(value)) ?? 0;
const d = D === 0 ? Math.abs(value) : Math.abs(value % D);
const mdec = (d * 60).toFixed(precision);
return `${('000' + D.toString()).slice(-3)}${
const pad = ['N', 'S'].includes(hemisphere) ? '00' : '000';
const s = `${(pad + D.toString()).slice(0 - pad.length)}${
this.symDegree
} ${mdec}' ${hemisphere}`;
return s;
}

// returns H D.ddddd°
private toHDd(value: number, hemisphere: string, precision = 5): string {
let ddec: string = value.toFixed(precision);
ddec = ddec.substring(ddec.indexOf('.'));
return `${hemisphere} ${Math.abs(Math.floor(value))}${ddec}${
return `${hemisphere} ${Math.floor(Math.abs(value))}${ddec}${
this.symDegree
}`;
}

// returns H +/-D.ddddd°
private toHDdSigned(
value: number,
hemisphere: string,
precision = 5
): string {
const h =
hemisphere === 'S' || hemisphere === 'W'
? `${hemisphere} -`
: `${hemisphere} +`;
let ddec: string = value.toFixed(precision);
ddec = ddec.substring(ddec.indexOf('.'));
return `${h}${Math.floor(value)}${ddec}${this.symDegree}`;
// returns H D°M'S"sss
private toHDMS(value: number, hemisphere: string): string {
return `${hemisphere} ${decimalToSexagesimal(value)}`;
}

// returns DHM'S"sss
private toDHMS(value: number, hemisphere: string): string {
let c = decimalToSexagesimal(value);
c =
c.slice(0, c.indexOf(' ') - 1) + hemisphere + c.slice(c.indexOf(' ') + 1);
return c;
}
}
12 changes: 6 additions & 6 deletions src/app/modules/settings/settings.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ export class SettingsFacade {
[true, 'Wind Apparent']
]),
coords: [
['XY', '-28.12345'],
['SHDd', `S-28.12345${this.symDegree}`],
['DMdH', `028${this.symDegree} 15.345' S`],
['HDd', `S 28.12345${this.symDegree}`],
['HDMS', `S 28${this.symDegree}15'46"123`],
['DHMS', `28S15'46"123`]
['XY', '-128.12345'],
['SHDd', `W-128.12345${this.symDegree}`],
['DMdH', `128${this.symDegree} 15.34567' W`],
['HDd', `W 128.12345${this.symDegree}`],
['HDMS', `W 128${this.symDegree}15'46"123`],
['DHMS', `128W15'46"123`]
]
};

Expand Down

0 comments on commit 5ef8db7

Please sign in to comment.