Source: map/utils/formatLatLng.js

  1. import { roundNumber } from "../../utils/utils.js";
  2. import { convertDecimalDegreeToDegreeMinutes } from "./convertDecimalDegreeToDegreeMinutes.js";
  3. /**
  4. * Format lat/lng to a readable string with decimal degrees
  5. *
  6. * @param {number} lat
  7. * @param {number} lng
  8. * @returns {string} formatted lat/lng
  9. * @memberof vef.map.utils
  10. */
  11. export function formatLatLng(lat, lng, mode) {
  12. if (mode == "degreeminutes") {
  13. const latDms = convertDecimalDegreeToDegreeMinutes(lat, true);
  14. const readableLat = `${latDms.degree}° ${latDms.minutes}' ${latDms.seconds}" ${latDms.orientation}`;
  15. const longDms = convertDecimalDegreeToDegreeMinutes(lng, false);
  16. const readableLong = `${longDms.degree}° ${longDms.minutes}' ${longDms.seconds}" ${longDms.orientation}`;
  17. return readableLat + ", " + readableLong;
  18. } else {
  19. lat = roundNumber(Math.abs(lat), 2, true) + ((lat < 0) ? "° S" : "° N");
  20. lng = roundNumber(Math.abs(lng), 2, true) + ((lng < 0) ? "° W" : "° E");
  21. return `${lat}, ${lng}`;
  22. }
  23. }