in website/src/components/explorer/index.tsx [132:211]
function doSplitUserInput(userInput: string, userResolution: number) {
if (userInput) {
// Acceptable inputs, in order of test preference:
// GeoJSON
// WKT
// Valid hexadecimal cell ID
// Valid hexadecimal cell ID, prefixed by 0x
// Valid decimal cell ID
// lat,lng coordinate pairs
const resultPolygon = tryParsePolygonInput(userInput, userResolution);
if (resultPolygon) {
return resultPolygon;
}
let showCellId = false;
let showResolutionInput = null;
const unwrapAnyArray = fullyUnwrap(userInput);
const split = unwrapAnyArray.split(/\s/).filter((str) => str !== "");
const result = [];
for (let i = 0; i < split.length; i++) {
const currentInput = fullyTrim(split[i]);
const nextInput = fullyTrim(split[i + 1]);
const cellIdFromDecimal = maybeDecimalCell(currentInput);
const cellIdFromPrefixedHex = maybePrefixedHexCell(currentInput);
if (isValidCell(currentInput)) {
result.push(currentInput);
} else if (
cellIdFromPrefixedHex !== null &&
isValidCell(cellIdFromPrefixedHex)
) {
result.push(cellIdFromPrefixedHex);
showCellId = true;
} else if (cellIdFromDecimal) {
result.push(cellIdFromDecimal);
// Show what the cell ID would look like normally
showCellId = true;
} else if (
i < split.length - 1 &&
Number.isFinite(Number.parseFloat(currentInput)) &&
Number.isFinite(Number.parseFloat(nextInput))
) {
const lat = Number.parseFloat(currentInput);
const lng = Number.parseFloat(nextInput);
if (userResolution === -1) {
// Note this order is important for picking to work correctly
for (let res = 0; res < 16; res++) {
result.push(latLngToCell(lat, lng, res));
}
// We don't need to set showCellId, because we are showing multiple cell IDs
// anyways, so they will be clickable.
} else {
result.push(latLngToCell(lat, lng, userResolution));
showCellId = true;
}
showResolutionInput = -1;
// consumed, skip next coordinate
i++;
}
}
return {
splitUserInput: result,
showResolutionInput,
showCellId,
inputGeoJson: null,
};
}
return {
splitUserInput: [],
showCellId: false,
showResolutionInput: null,
inputGeoJson: null,
};
}