init
Some checks failed
Build and Release / release (push) Failing after 16s

This commit is contained in:
2026-04-20 09:29:40 +07:00
commit ea1e12a5bc
20 changed files with 4335 additions and 0 deletions

45
utils/bbox.js Normal file
View File

@@ -0,0 +1,45 @@
function getBBox(geometry) {
let minLng = Infinity, minLat = Infinity;
let maxLng = -Infinity, maxLat = -Infinity;
function process(coords) {
if (typeof coords[0] === "number") {
const [lng, lat] = coords;
minLng = Math.min(minLng, lng);
minLat = Math.min(minLat, lat);
maxLng = Math.max(maxLng, lng);
maxLat = Math.max(maxLat, lat);
} else {
coords.forEach(process);
}
}
// 🔥 handle theo type cho rõ ràng
switch (geometry.type) {
case "Point":
process(geometry.coordinates);
break;
case "MultiPoint":
case "LineString":
process(geometry.coordinates);
break;
case "MultiLineString":
case "Polygon":
process(geometry.coordinates);
break;
case "MultiPolygon":
process(geometry.coordinates);
break;
default:
throw new Error("Unsupported geometry type: " + geometry.type);
}
return { minLng, minLat, maxLng, maxLat };
}
module.exports = { getBBox };