src/misc/filters.js
function DMSCoordinatesFilter() {
  const degreesToStringHDMS = function(degrees, hemispheres, fractionDigits) {
    const normalizedDegrees = modulo(degrees + 180, 360) - 180;
    const dms = Math.abs(3600 * normalizedDegrees);
    const d = Math.floor(dms / 3600);
    const m = Math.floor((dms / 60) % 60);
    const s = (dms % 60);
    return `${d}\u00b0 ${
      padNumber(m, 2)}\u2032 ${
      padNumber(s, 2, fractionDigits)}\u2033 ${
      hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0)}`;
  };

  /**
   * @param {import("ol/coordinate.js").Coordinate} coordinates Array of two numbers.
   * @param {(number|string)=} opt_fractionDigits Optional number of digit.
   *     Default to 0.
   * @param {string=} opt_template Optional template. Default to
   *     '{x} {y}'. Where "{x}" will be replaced by the easting
   *     coordinate, {y} by the northing one. Note: Use a html entity to use the
   *     semicolon symbol into a template.
   * @return {string} DMS formatted coordinates.
   */
  const filterFn = function(coordinates, opt_fractionDigits, opt_template) {
    const fractionDigits = parseInt(/** @type {string} */(opt_fractionDigits), 10) | 0;

    const template = opt_template ? opt_template : '{x} {y}';

    const xdms = degreesToStringHDMS(coordinates[0], 'EW', fractionDigits);
    const ydms = degreesToStringHDMS(coordinates[1], 'NS', fractionDigits);

    return template.replace('{x}', xdms).replace('{y}', ydms);
  };

  return filterFn;
}
function DMSCoordinatesFilter() {
  const degreesToStringHDMS = function(degrees, hemispheres, fractionDigits) {
    const normalizedDegrees = modulo(degrees + 180, 360) - 180;
    const dms = Math.abs(3600 * normalizedDegrees);
    const d = Math.floor(dms / 3600);
    const m = Math.floor((dms / 60) % 60);
    const s = (dms % 60);
    return `${d}\u00b0 ${
      padNumber(m, 2)}\u2032 ${
      padNumber(s, 2, fractionDigits)}\u2033 ${
      hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0)}`;
  };

  /**
   * @param {import("ol/coordinate.js").Coordinate} coordinates Array of two numbers.
   * @param {(number|string)=} opt_fractionDigits Optional number of digit.
   *     Default to 0.
   * @param {string=} opt_template Optional template. Default to
   *     '{x} {y}'. Where "{x}" will be replaced by the easting
   *     coordinate, {y} by the northing one. Note: Use a html entity to use the
   *     semicolon symbol into a template.
   * @return {string} DMS formatted coordinates.
   */
  const filterFn = function(coordinates, opt_fractionDigits, opt_template) {
    const fractionDigits = parseInt(/** @type {string} */(opt_fractionDigits), 10) | 0;

    const template = opt_template ? opt_template : '{x} {y}';

    const xdms = degreesToStringHDMS(coordinates[0], 'EW', fractionDigits);
    const ydms = degreesToStringHDMS(coordinates[1], 'NS', fractionDigits);

    return template.replace('{x}', xdms).replace('{y}', ydms);
  };

  return filterFn;
}
function DMSCoordinatesFilter ( ) { const degreesToStringHDMS = function ( degrees , hemispheres , fractionDigits ) { const normalizedDegrees = modulo ( degrees + 180 , 360 ) - 180 ; const dms = Math . abs ( 3600 * normalizedDegrees ) ; const d = Math . floor ( dms / 3600 ) ; const m = Math . floor ( ( dms / 60 ) % 60 ) ; const s = ( dms % 60 ) ; return ` ${ d } \u00b0 ${ padNumber ( m , 2 ) } \u2032 ${ padNumber ( s , 2 , fractionDigits ) } \u2033 ${ hemispheres . charAt ( normalizedDegrees < 0 ? 1 : 0 ) } ` ; } ; /**
   * @param {import("ol/coordinate.js").Coordinate} coordinates Array of two numbers.
   * @param {(number|string)=} opt_fractionDigits Optional number of digit.
   *     Default to 0.
   * @param {string=} opt_template Optional template. Default to
   *     '{x} {y}'. Where "{x}" will be replaced by the easting
   *     coordinate, {y} by the northing one. Note: Use a html entity to use the
   *     semicolon symbol into a template.
   * @return {string} DMS formatted coordinates.
   */ const filterFn = function ( coordinates , opt_fractionDigits , opt_template ) { const fractionDigits = parseInt ( /** @type {string} */ ( opt_fractionDigits ) , 10 ) | 0 ; const template = opt_template ? opt_template : '{x} {y}' ; const xdms = degreesToStringHDMS ( coordinates [ 0 ] , 'EW' , fractionDigits ) ; const ydms = degreesToStringHDMS ( coordinates [ 1 ] , 'NS' , fractionDigits ) ; return template . replace ( '{x}' , xdms ) . replace ( '{y}' , ydms ) ; } ; return filterFn ; }
Format coordinates as DMS coordinates.

Example without parameters:

<p>{{[7.1234, 46.9876] | ngeoDMSCoordinates}}</p>
<!-- will Become  7° 07' 24'' E 46° 59' 15'' N-->

Example with defined fractionDigits and a template.

<p>{{[7.1234, 46.9876] | ngeoDMSCoordinates:2:'[{y}; {x]'}}</p>
<!-- will Become [46° 59' 15.36'' N; 7° 07' 24.24'' E] -->

@return {dmsCoordinates} A function to format numbers into a DMS coordinates string.
@ngInject
@ngdoc filter
@ngname ngeoDMSCoordinates
Format coordinates as DMS coordinates .