37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { API_ENDPOINTS } from "@/api/config";
|
|
import { requestJson } from "@/api/http";
|
|
import { FeatureCollection } from "@/lib/useEditorState";
|
|
|
|
export type GeometriesBBoxQuery = {
|
|
minLng: number;
|
|
minLat: number;
|
|
maxLng: number;
|
|
maxLat: number;
|
|
time?: number;
|
|
entity_id?: string;
|
|
};
|
|
|
|
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);
|
|
}
|