From 12383a675cf3a773879241f7afd35da3c5b9cfbe Mon Sep 17 00:00:00 2001 From: sundowndev Date: Mon, 3 Sep 2018 15:36:57 +0200 Subject: [PATCH] Position class --- src/Position.js | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/Position.js diff --git a/src/Position.js b/src/Position.js new file mode 100644 index 0000000..ba3f7f9 --- /dev/null +++ b/src/Position.js @@ -0,0 +1,65 @@ +"use strict"; + +/** + * Position class + * @constructor + */ +export default function Position() { + this.latitude = 0; + this.longitude = 0; + + /** + * Transform Latitude to DDM + * @param lat + * @returns {{decimal: number, minutes: number, direction: string}} + */ + this.LatToDDM = (lat) => { + let sDirection = (lat > 0) ? 'N' : 'S'; + + let iDecimal = Math.abs(parseInt(lat)); + let iMinutes = Math.abs(parseInt((lat - parseInt(lat)) * 60)); + + /* + return { + decimal: iDecimal, + minutes: iMinutes, + direction: sDirection + }; + */ + return { + decimal: iDecimal, + minutes: iMinutes, + direction: sDirection + }; + }; + + /** + * Check position + * @param geo + * @param circle + * @returns {boolean} + */ + this.CheckPos = (geo, circle) => { + const DDM = this.LatToDDM(geo.lat); + + switch (circle) { + case 'eq': + return (DDM.decimal === 0); + + case 'cancer': + return (DDM.decimal === 23 && DDM.minutes === 26 && DDM.direction === 'N'); + + case 'cap': + return (DDM.decimal === 23 && DDM.minutes === 26 && DDM.direction === 'S'); + + case 'artic': + return (DDM.decimal === 66 && DDM.minutes === 33 && DDM.direction === 'N'); + + case 'antartic': + return (DDM.decimal === 66 && DDM.minutes === 33 && DDM.direction === 'S'); + + default: + return false; + } + }; +} \ No newline at end of file