AnalysisSystemForRadionucli.../src/utils/map.js

14 lines
602 B
JavaScript
Raw Normal View History

2023-06-16 18:58:31 +08:00
/**
* 将十进制度格式的经度转换为度分秒
* @param {*} decimal
* @param {*} isLongitude 是不是经度
* @returns
*/
export function decimalToDms(decimal, isLongitude = true) {
2023-06-25 15:55:33 +08:00
const absoluteValue = Math.abs(decimal)
const degree = Math.floor(absoluteValue)
const minute = Math.floor((absoluteValue - degree) * 60);
const second = Math.round(((absoluteValue - degree) * 60 - minute) * 60)
2023-06-16 18:58:31 +08:00
const tail = isLongitude ? (decimal > 0 ? 'E' : decimal < 0 ? 'W' : '') : (decimal > 0 ? 'N' : decimal < 0 ? 'S' : '')
2023-06-25 15:55:33 +08:00
return `${degree}°${minute}'${second}"${tail}`
2023-06-16 18:58:31 +08:00
}