Class: Dms

dms~Dms()

Functions for parsing and representing degrees / minutes / seconds.

Constructor

new Dms()

Source:

Members

(static) separator

Separator character to be used to separate degrees, minutes, seconds, and cardinal directions. Default separator is U+202F ‘narrow no-break space’. To change this (e.g. to empty string or full space), set Dms.separator prior to invoking formatting.
Source:
Example
import LatLon, { Dms } from '/js/geodesy/latlon-spherical.js';
  const p = new LatLon(51.2, 0.33).toString('dms');  // 51° 12′ 00″ N, 000° 19′ 48″ E
  Dms.separator = '';                                // no separator
  const pʹ = new LatLon(51.2, 0.33).toString('dms'); // 51°12′00″N, 000°19′48″E

Methods

(static) compassPoint(bearing, precisionopt) → {string}

Returns compass point (to given precision) for supplied bearing.
Parameters:
Name Type Attributes Default Description
bearing number Bearing in degrees from north.
precision number <optional>
3 Precision (1:cardinal / 2:intercardinal / 3:secondary-intercardinal).
Source:
Returns:
Compass point for supplied bearing.
Type
string
Example
const point = Dms.compassPoint(24);    // point = 'NNE'
  const point = Dms.compassPoint(24, 1); // point = 'N'

(static) fromLocale(str) → {string}

Converts DMS string from locale thousands/decimal separators to JavaScript comma/dot separators for subsequent parsing. Both thousands and decimal separators must be followed by a numeric character, to facilitate parsing of single lat/long string (in which whitespace must be left after the comma separator).
Parameters:
Name Type Description
str string Degrees/minutes/seconds formatted with locale separators.
Source:
Returns:
Degrees/minutes/seconds formatted with standard Javascript separators.
Type
string
Example
const lat = Dms.fromLocale('51°28′40,12″N');                          // '51°28′40.12″N' in France
  const p = new LatLon(Dms.fromLocale('51°28′40,37″N, 000°00′05,29″W'); // '51.4779°N, 000.0015°W' in France

(static) parse(dms) → {number}

Parses string representing degrees/minutes/seconds into numeric degrees. This is very flexible on formats, allowing signed decimal degrees, or deg-min-sec optionally suffixed by compass direction (NSEW); a variety of separators are accepted. Examples -3.62, '3 37 12W', '3°37′12″W'. Thousands/decimal separators must be comma/dot; use Dms.fromLocale to convert locale-specific thousands/decimal separators.
Parameters:
Name Type Description
dms string | number Degrees or deg/min/sec in variety of formats.
Source:
Returns:
Degrees as decimal number.
Type
number
Example
const lat = Dms.parse('51° 28′ 40.37″ N');
  const lon = Dms.parse('000° 00′ 05.29″ W');
  const p1 = new LatLon(lat, lon); // 51.4779°N, 000.0015°W

(static) toBrng(deg, formatopt, dpopt) → {string}

Converts numeric degrees to deg/min/sec as a bearing (0°..360°).
Parameters:
Name Type Attributes Default Description
deg number Degrees to be formatted as specified.
format string <optional>
d Return value as 'd', 'dm', 'dms' for deg, deg+min, deg+min+sec.
dp number <optional>
4|2|0 Number of decimal places to use – default 4 for d, 2 for dm, 0 for dms.
Source:
Returns:
Degrees formatted as deg/min/secs according to specified format.
Type
string
Example
const lon = Dms.toBrng(-3.62, 'dms'); // 356°22′48″

(static) toLat(deg, formatopt, dpopt) → {string}

Converts numeric degrees to deg/min/sec latitude (2-digit degrees, suffixed with N/S).
Parameters:
Name Type Attributes Default Description
deg number Degrees to be formatted as specified.
format string <optional>
d Return value as 'd', 'dm', 'dms' for deg, deg+min, deg+min+sec.
dp number <optional>
4|2|0 Number of decimal places to use – default 4 for d, 2 for dm, 0 for dms.
Source:
Returns:
Degrees formatted as deg/min/secs according to specified format.
Type
string
Example
const lat = Dms.toLat(-3.62, 'dms'); // 3°37′12″S

(static) toLocale(str) → {string}

Converts DMS string from JavaScript comma/dot thousands/decimal separators to locale separators. Can also be used to format standard numbers such as distances.
Parameters:
Name Type Description
str string Degrees/minutes/seconds formatted with standard Javascript separators.
Source:
Returns:
Degrees/minutes/seconds formatted with locale separators.
Type
string
Example
const Dms.toLocale('123,456.789');                   // '123.456,789' in France
  const Dms.toLocale('51°28′40.12″N, 000°00′05.31″W'); // '51°28′40,12″N, 000°00′05,31″W' in France

(static) toLon(deg, formatopt, dpopt) → {string}

Convert numeric degrees to deg/min/sec longitude (3-digit degrees, suffixed with E/W).
Parameters:
Name Type Attributes Default Description
deg number Degrees to be formatted as specified.
format string <optional>
d Return value as 'd', 'dm', 'dms' for deg, deg+min, deg+min+sec.
dp number <optional>
4|2|0 Number of decimal places to use – default 4 for d, 2 for dm, 0 for dms.
Source:
Returns:
Degrees formatted as deg/min/secs according to specified format.
Type
string
Example
const lon = Dms.toLon(-3.62, 'dms'); // 3°37′12″W