Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MGRS parsing issue #104

Closed
avenmia opened this issue May 24, 2022 · 1 comment
Closed

MGRS parsing issue #104

avenmia opened this issue May 24, 2022 · 1 comment

Comments

@avenmia
Copy link

avenmia commented May 24, 2022

Wikipedia gives the following examples for MGRS values:

https://en.wikipedia.org/wiki/Military_Grid_Reference_System

4Q .....................GZD only, precision level 6° × 8° (in most cases)
4QFJ ...................GZD and 100 km Grid Square ID, precision level 100 km
4QFJ 1 6 ...............precision level 10 km
4QFJ 12 67 .............precision level 1 km
4QFJ 123 678 ...........precision level 100 m
4QFJ 1234 6789 .........precision level 10 m
4QFJ 12345 67890 .......precision level 1 m

But parsing fails because the parse function in mgrs.js checks if the first two values are of type number.

geodesy/mgrs.js

Lines 149 to 158 in 8f4ef33

static parse(mgrsGridRef) {
if (!mgrsGridRef) throw new Error(`invalid MGRS grid reference ‘${mgrsGridRef}’`);
// check for military-style grid reference with no separators
if (!mgrsGridRef.trim().match(/\s/)) {
if (!Number(mgrsGridRef.slice(0, 2))) throw new Error(`invalid MGRS grid reference ‘${mgrsGridRef}’`);
let en = mgrsGridRef.trim().slice(5); // get easting/northing following zone/band/100ksq
en = en.slice(0, en.length/2)+' '+en.slice(-en.length/2); // separate easting/northing
mgrsGridRef = mgrsGridRef.slice(0, 3)+' '+mgrsGridRef.slice(3, 5)+' '+en; // insert spaces
}

@chrisveness
Copy link
Owner

Thank you for raising this issue.

I have corrected the MGRS parsing to accept single-digit zones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants