Source: map/utils/convertDecimalDegreeToDegreeMinutes.js

import { roundNumber } from "../../utils/utils.js";

/**
 * converts decimal degrees (50.222°) into degree decimal minutes (40° 26.767′ N) 
 * or degree minutes and seconds (40° 26′ 46″ N)
 * 
 * @param {string} degree 
 * @param {boolean} isLat 
 * @returns {object} degree minutes seconds
 * @memberof vef.map
 */
export function convertDecimalDegreeToDegreeMinutes(degree, isLat) {
    let orientation = 'N';
    if (!isLat) {
        orientation = 'E';
    }

    if (degree < 0) {
        if (!isLat) {
            orientation = 'W'
        } else {
            orientation = 'S';
        }
    }

    let min = Math.abs(60 * (degree - parseInt(degree)));
    let sec = (3600 * Math.abs(degree - parseInt(degree))) - (60 * parseInt(min));

    return {
        degree: (parseInt(degree) > 0) ? parseInt(degree) : parseInt(degree) * -1,
        decimalMinutes: roundNumber(min, 4),
        minutes: parseInt(min),
        seconds: roundNumber(min, 0),
        orientation: orientation
    };
}