1
0
mirror of https://github.com/KubaPro010/fm-dx-webserver.git synced 2026-02-26 22:13:53 +01:00

hotfix for US state boxes

This commit is contained in:
Marek Farkaš
2024-09-18 14:59:24 +02:00
committed by GitHub
parent 201d7bf261
commit 835cfa8352

View File

@@ -21,15 +21,22 @@ async function loadUsStatesGeoJson() {
// Function to get bounding box of a state
function getStateBoundingBox(coordinates) {
let minLat = Infinity, maxLat = -Infinity, minLon = Infinity, maxLon = -Infinity;
// Check if it's a MultiPolygon or a Polygon
for (const polygon of coordinates) {
for (const coord of polygon[0]) { // First level in case of MultiPolygon
const [lon, lat] = coord;
if (lat < minLat) minLat = lat;
if (lat > maxLat) maxLat = lat;
if (lon < minLon) minLon = lon;
if (lon > maxLon) maxLon = lon;
// If it's a Polygon, it won't have an extra level of arrays
const linearRings = Array.isArray(polygon[0][0]) ? polygon : [polygon];
for (const ring of linearRings) {
for (const [lon, lat] of ring) {
if (lat < minLat) minLat = lat;
if (lat > maxLat) maxLat = lat;
if (lon < minLon) minLon = lon;
if (lon > maxLon) maxLon = lon;
}
}
}
return { minLat, maxLat, minLon, maxLon };
}