Skip to content

Commit

Permalink
simplified getLetterDesignator
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed May 6, 2019
1 parent c30067f commit 80d0548
Showing 1 changed file with 15 additions and 65 deletions.
80 changes: 15 additions & 65 deletions mgrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,72 +297,22 @@ function UTMtoLL(utm) {
* for.
* @return {char} The letter designator.
*/
function getLetterDesignator(lat) {
//This is here as an error flag to show that the Latitude is
//outside MGRS limits
let LetterDesignator = 'Z';

if ((84 >= lat) && (lat >= 72)) {
LetterDesignator = 'X';
}
else if ((72 > lat) && (lat >= 64)) {
LetterDesignator = 'W';
}
else if ((64 > lat) && (lat >= 56)) {
LetterDesignator = 'V';
}
else if ((56 > lat) && (lat >= 48)) {
LetterDesignator = 'U';
}
else if ((48 > lat) && (lat >= 40)) {
LetterDesignator = 'T';
}
else if ((40 > lat) && (lat >= 32)) {
LetterDesignator = 'S';
}
else if ((32 > lat) && (lat >= 24)) {
LetterDesignator = 'R';
}
else if ((24 > lat) && (lat >= 16)) {
LetterDesignator = 'Q';
}
else if ((16 > lat) && (lat >= 8)) {
LetterDesignator = 'P';
}
else if ((8 > lat) && (lat >= 0)) {
LetterDesignator = 'N';
}
else if ((0 > lat) && (lat >= -8)) {
LetterDesignator = 'M';
}
else if ((-8 > lat) && (lat >= -16)) {
LetterDesignator = 'L';
}
else if ((-16 > lat) && (lat >= -24)) {
LetterDesignator = 'K';
}
else if ((-24 > lat) && (lat >= -32)) {
LetterDesignator = 'J';
}
else if ((-32 > lat) && (lat >= -40)) {
LetterDesignator = 'H';
}
else if ((-40 > lat) && (lat >= -48)) {
LetterDesignator = 'G';
}
else if ((-48 > lat) && (lat >= -56)) {
LetterDesignator = 'F';
}
else if ((-56 > lat) && (lat >= -64)) {
LetterDesignator = 'E';
}
else if ((-64 > lat) && (lat >= -72)) {
LetterDesignator = 'D';
}
else if ((-72 > lat) && (lat >= -80)) {
LetterDesignator = 'C';
function getLetterDesignator(latitude) {
if (latitude <= 84 && latitude >= 72) {
// the X band is 12 degrees high
return 'X';
} else if (latitude < 72 || latitude >= -80) {
// Latitude bands are lettered C through X, excluding I and O
const bandLetters = 'CDEFGHJKLMNPQRSTUVWX';
const bandHeight = 8;
const minLatitude = -80;
const index = Math.floor((latitude - minLatitude) / bandHeight);
return bandLetters[index];
} else if (latitude > 84 || latitude < -80) {
//This is here as an error flag to show that the Latitude is
//outside MGRS limits
return 'Z';
}
return LetterDesignator;
}

/**
Expand Down

0 comments on commit 80d0548

Please sign in to comment.