You've already forked fm-dx-webserver
mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-02-27 06:23:53 +01:00
hotfix for US state boxes
This commit is contained in:
@@ -21,15 +21,22 @@ async function loadUsStatesGeoJson() {
|
|||||||
// Function to get bounding box of a state
|
// Function to get bounding box of a state
|
||||||
function getStateBoundingBox(coordinates) {
|
function getStateBoundingBox(coordinates) {
|
||||||
let minLat = Infinity, maxLat = -Infinity, minLon = Infinity, maxLon = -Infinity;
|
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 polygon of coordinates) {
|
||||||
for (const coord of polygon[0]) { // First level in case of MultiPolygon
|
// If it's a Polygon, it won't have an extra level of arrays
|
||||||
const [lon, lat] = coord;
|
const linearRings = Array.isArray(polygon[0][0]) ? polygon : [polygon];
|
||||||
if (lat < minLat) minLat = lat;
|
|
||||||
if (lat > maxLat) maxLat = lat;
|
for (const ring of linearRings) {
|
||||||
if (lon < minLon) minLon = lon;
|
for (const [lon, lat] of ring) {
|
||||||
if (lon > maxLon) maxLon = lon;
|
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 };
|
return { minLat, maxLat, minLon, maxLon };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user