31 lines
971 B
TypeScript
31 lines
971 B
TypeScript
import { API_ENDPOINTS } from "@/api/config";
|
|
import { requestJson } from "@/api/http";
|
|
import type { GeometriesBBoxQuery } from "@/types/api";
|
|
import type { FeatureCollection } from "@/types/geo";
|
|
|
|
export type { GeometriesBBoxQuery } from "@/types/api";
|
|
|
|
function buildBBoxQueryString(params: GeometriesBBoxQuery): string {
|
|
const query = new URLSearchParams({
|
|
minLng: String(params.minLng),
|
|
minLat: String(params.minLat),
|
|
maxLng: String(params.maxLng),
|
|
maxLat: String(params.maxLat),
|
|
});
|
|
|
|
if (params.time !== undefined) {
|
|
query.set("time", String(params.time));
|
|
}
|
|
|
|
if (params.entity_id) {
|
|
query.set("entity_id", params.entity_id);
|
|
}
|
|
|
|
return query.toString();
|
|
}
|
|
|
|
export async function fetchGeometriesByBBox(params: GeometriesBBoxQuery): Promise<FeatureCollection> {
|
|
const url = `${API_ENDPOINTS.geometries}?${buildBBoxQueryString(params)}`;
|
|
return requestJson<FeatureCollection>(url);
|
|
}
|