Class: DmsFormatter2
A utility class for creating degree-minute-second formatters for angle values.
Each DMS formatter is a function which generates output strings from input angle values. The formatting behavior of a formatter is defined by its format template.
Format templates are strings which contain zero or more fragments enclosed by curly braces ({}
); For a given
format template, an output string is generated from an input duration by replacing each fragment in the template
with a string generated from the input. The parts of the template string that are not contained in any fragment are
passed to the output unchanged. Each fragment defines how its replacement string is generated. There are two types
of fragments:
- Sign fragment. In EBNF notation, these take the form
['+', ['[', x, ']']], ('-' , ['[', y, ']'])
, wherex
andy
are arbitrary strings. Each sign fragment is replaced with a string representing the sign of the input. The negative sign string is defined byy
. Ify
is not defined, the negative sign string defaults to'-'
(dash). The positive sign string is defined byx
. If the positive sign token does not appear in the fragment definition, the positive sign string defaults to''
(the empty string), otherwise it defaults to'+'
. - Numeric fragment. In EBNF notation, these take the form
{x}, ['?'], ['.', [{x}], ['(', {x}, ')']]
, wherex = 'D' | 'M' | 'S' | 'd' | 'm' | 's'
. Each numeric fragment is replaced with the numeric value of the duration in degrees, minutes, or seconds, depending on which character is used forx
. With uppercase letters, the entire portion of the input value is used. With lowercase letters, only the portion of the input value that does not divide evenly into the next smallest unit is used (for hours, which is the largest unit, there is no difference between using'H'
and'h'
).- The number of
x
characters to the left of the decimal point (including all characters if no decimal point is present) in the definition controls the number of leading zeroes with which the output will be padded. - If the optional
'?'
character is present, the output will drop all digits to the left of the decimal point if all such digits are equal to 0. - The total number of
x
characters to the right of the decimal point in the definition controls the decimal precision of the output. Trailing zeroes to the right of the decimal point will be added to the output to a number of decimal places equal to the number of non-parentheticalx
characters to the right of the decimal point in the definition. If there are nox
characters to the right of the decimal point in the definition, then the output will have infinite decimal precision with no extraneous trailing zeroes. - Rounding behavior is always round down.
- The number of
Example
const formatter = DmsFormatter2.create('{d}°{mm}\'{ss}"', UnitType.DEGREE);
formatter(10); // 10°00'00"
formatter(10.51); // 10°30'36"
Example
const formatter = DmsFormatter2.create('{d}°{mm}\'{ss.s(s)}"', UnitType.DEGREE);
formatter(10); // 10°00'00.0"
formatter(10.09169); // 10°05'30.08"
Example
const formatter = DmsFormatter2.create('{d}°{mm.mm}\'', UnitType.DEGREE);
formatter(10.09169); // 10°05.50'
Example
const formatter = DmsFormatter2.create('{-}{d}°{mm}\'', UnitType.DEGREE);
formatter(10); // 10°00'
formatter(-10); // -10°00'
const formatterWithPositiveSign = DmsFormatter2.create('{+-}{d}°{mm}\'', UnitType.DEGREE);
formatterWithPositiveSign(10); // +10°00'
const formatterWithRealMinusSign = DmsFormatter2.create('{-[–]}{d}°{mm}\'', UnitType.DEGREE);
formatterWithRealMinusSign(10); // –10°00'
Constructors
constructor
• new DmsFormatter2(): DmsFormatter2
Returns
Properties
DEFAULT_OPTIONS
▪ Static
Readonly
DEFAULT_OPTIONS: Readonly
<DmsFormatter2Options
>
The default options for degree-minute-second formatters.
Defined in
src/sdk/graphics/text/DmsFormatter2.ts:89
Methods
create
▸ create(format
, unit
, precision
, nanString?
): (angle
: number
) => string
Creates a function which formats angles, expressed as numeric values, to strings. The formatting behavior of
the function is defined by a specified format template. For more information on format templates and their syntax,
please refer to the DmsFormatter2 class documentation. All formatter options except nanString
, if
specified, will use their default values.
Parameters
Name | Type | Description |
---|---|---|
format | string | A template defining how the function formats angles. |
unit | Unit <Angle > | The unit type in which the input angle values are expressed. |
precision | number | The precision of the formatter, in the unit type defined by the unit argument. Input values will be rounded to the nearest multiple of this quantity. Precision values less than or equal to zero will be taken to mean infinite precision (i.e. no rounding will take place). |
nanString? | string | The string to output when the input angle is NaN . Defaults to 'NaN' . |
Returns
fn
A function which formats angles, expressed as numeric values, to strings.
▸ (angle
): string
Parameters
Name | Type |
---|---|
angle | number |
Returns
string
Defined in
src/sdk/graphics/text/DmsFormatter2.ts:107
▸ create(format
, unit
, precision
, options?
): (angle
: number
) => string
Creates a function which formats angles, expressed as numeric values, to strings. The formatting behavior of the function is defined by a specified format template. For more information on format templates and their syntax, please refer to the DmsFormatter2 class documentation.
Parameters
Name | Type | Description |
---|---|---|
format | string | A template defining how the function formats angles. |
unit | Unit <Angle > | The unit type in which the input angle values are expressed. |
precision | number | The precision of the formatter, in the unit type defined by the unit argument. Input values will be rounded to the nearest multiple of this quantity. Precision values less than or equal to zero will be taken to mean infinite precision (i.e. no rounding will take place). |
options? | Readonly <Partial <DmsFormatter2Options >> | Options to configure the formatter. Options not explicitly defined will be set to the following default values: nanString = 'NaN' cache = false |
Returns
fn
A function which formats angles, expressed as numeric values, to strings.
▸ (angle
): string
Parameters
Name | Type |
---|---|
angle | number |
Returns
string
Defined in
src/sdk/graphics/text/DmsFormatter2.ts:128
createForNumberUnit
▸ createForNumberUnit(format
, precision
, nanString?
): (angle
: NumberUnitInterface
<Angle
, Unit
<Angle
>>) => string
Creates a function which formats angles, expressed as NumberUnitInterface objects, to strings. The
formatting behavior of the function is defined by a specified format template. For more information on format
templates and their syntax, please refer to the DmsFormatter2 class documentation. All formatter options
except nanString
, if specified, will use their default values.
Parameters
Name | Type | Description |
---|---|---|
format | string | A template defining how the function formats angles. |
precision | NumberUnitInterface <Angle , Unit <Angle >> | The precision of the formatter. Input values will be rounded to the nearest multiple of this quantity. Precision values less than or equal to zero will be taken to mean infinite precision (i.e. no rounding will take place). |
nanString? | string | The string to output when the input angle is NaN . Defaults to 'NaN' . |
Returns
fn
A function which formats angles, expressed as NumberUnitInterface objects, to strings.
▸ (angle
): string
Parameters
Name | Type |
---|---|
angle | NumberUnitInterface <Angle , Unit <Angle >> |
Returns
string
Defined in
src/sdk/graphics/text/DmsFormatter2.ts:196
▸ createForNumberUnit(format
, precision
, options?
): (angle
: NumberUnitInterface
<Angle
, Unit
<Angle
>>) => string
Creates a function which formats angles, expressed as NumberUnitInterface objects, to strings. The formatting behavior of the function is defined by a specified format template. For more information on format templates and their syntax, please refer to the DmsFormatter2 class documentation.
Parameters
Name | Type | Description |
---|---|---|
format | string | A template defining how the function formats angles. |
precision | NumberUnitInterface <Angle , Unit <Angle >> | The precision of the formatter. Input values will be rounded to the nearest multiple of this quantity. Precision values less than or equal to zero will be taken to mean infinite precision (i.e. no rounding will take place). |
options? | Readonly <Partial <DmsFormatter2Options >> | Options to configure the formatter. Options not explicitly defined will be set to the following default values: nanString = 'NaN' cache = false |
Returns
fn
A function which formats angles, expressed as NumberUnitInterface objects, to strings.
▸ (angle
): string
Parameters
Name | Type |
---|---|
angle | NumberUnitInterface <Angle , Unit <Angle >> |
Returns
string
Defined in
src/sdk/graphics/text/DmsFormatter2.ts:215