Fix delimiter breaking Geohash detection
parent
8b77ad7748
commit
1a88a0164c
|
@ -45,6 +45,7 @@ export function convertCoordinates (inLat, inLong, inFormat, outFormat, precisio
|
||||||
convLong = convertSingleCoordinate(inLong, inFormat, "Decimal Degrees", 15).split("°");
|
convLong = convertSingleCoordinate(inLong, inFormat, "Decimal Degrees", 15).split("°");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert Geohash and MGRS here, as they need both the lat and long values
|
||||||
if (outFormat === "Geohash") {
|
if (outFormat === "Geohash") {
|
||||||
convLat = geohash.encode(parseFloat(convLat), parseFloat(convLong), precision);
|
convLat = geohash.encode(parseFloat(convLat), parseFloat(convLong), precision);
|
||||||
} else if (outFormat === "Military Grid Reference System") {
|
} else if (outFormat === "Military Grid Reference System") {
|
||||||
|
@ -244,12 +245,14 @@ export function findFormat (input, delim) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test MGRS and Geohash
|
// Test MGRS and Geohash
|
||||||
if (input.split(" ").length === 1) {
|
if (input.split(" ").length <= 1) {
|
||||||
|
const filteredInput = input.replace(/[^A-Za-z0-9]/, "").toUpperCase();
|
||||||
const mgrsPattern = new RegExp(/^[0-9]{2}[C-HJ-NP-X]{2}[A-Z]+/);
|
const mgrsPattern = new RegExp(/^[0-9]{2}[C-HJ-NP-X]{2}[A-Z]+/);
|
||||||
const geohashPattern = new RegExp(/^[0123456789bcdefghjkmnpqrstuvwxyz]+$/);
|
const geohashPattern = new RegExp(/^[0123456789BCDEFGHJKMNPQRSTUVWXYZ]+$/);
|
||||||
if (mgrsPattern.test(input.toUpperCase())) {
|
log.error(filteredInput);
|
||||||
|
if (mgrsPattern.test(filteredInput)) {
|
||||||
return "Military Grid Reference System";
|
return "Military Grid Reference System";
|
||||||
} else if (geohashPattern.test(input.toLowerCase())) {
|
} else if (geohashPattern.test(filteredInput)) {
|
||||||
return "Geohash";
|
return "Geohash";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -292,6 +295,8 @@ export function findDelim (input) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Loop through the standard delimiters, and try to find them in the input
|
||||||
for (let i = 0; i < delims.length; i++) {
|
for (let i = 0; i < delims.length; i++) {
|
||||||
const delim = delims[i];
|
const delim = delims[i];
|
||||||
if (input.includes(delim)) {
|
if (input.includes(delim)) {
|
||||||
|
|
Loading…
Reference in New Issue