chore: init backend and ignore local artifacts
This commit is contained in:
45
utils/bbox.js
Normal file
45
utils/bbox.js
Normal 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 };
|
||||
Reference in New Issue
Block a user