Skip to content

Commit

Permalink
Improved parsing of lat/lon parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
pathmapper committed Apr 8, 2024
1 parent 00ee2ea commit fe74481
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,28 @@ if ('URLSearchParams' in window) {
"op4": config.map_4.overlay_opacity || 0.5
}
}
const lonParam = parseFloat(searchParams.get("lon"));
const latParam = parseFloat(searchParams.get("lat"));
function parseQueryParam(param) {
if (param === null || param === undefined) {
return undefined;
}

let normalizedParam = param;
if (param.includes(',')) {
normalizedParam = param.replace(',', '.');
}

const parsed = parseFloat(normalizedParam);
if (isNaN(parsed)) {
return undefined;
}

return parsed;
}

const lonParam = parseQueryParam(searchParams.get("lon"));
const latParam = parseQueryParam(searchParams.get("lat"));

if (!isNaN(lonParam) && !isNaN(latParam)) {
if (lonParam !== undefined && latParam !== undefined) {
config.center = [lonParam, latParam];
}
}
Expand Down

0 comments on commit fe74481

Please sign in to comment.