/** 관로조사 지도 데이터 조회 API와 응답 변환 함수를 제공한다. */ import { getRawJson } from "@/shared/api/sewerage-api"; import type { ExmnMapFilters, ExmnMapJobType } from "./exmn-map-types"; type ExmnLayerScope = { sggCd?: string; ctpvNm?: string; sggNm?: string; exmnBizId?: string; trtdstId?: string; }; /** 구버전 응답이 하류맨홀을 포함해도 업로드 관로조사의 상류맨홀 피처만 지도에 전달한다. */ export const retainUpstreamManholeFeatures = (response: any) => { const featureCollection = response?.data?.type === "FeatureCollection" ? response.data : response?.type === "FeatureCollection" ? response : null; if (!featureCollection || !Array.isArray(featureCollection.features)) return response; const features = featureCollection.features.filter( (feature: any) => String(feature?.properties?.manholePosition ?? "").toUpperCase() === "UPSTREAM", ); const upstreamCollection = { ...featureCollection, features, totalFeatures: features.length, numberReturned: features.length, }; return response?.data === featureCollection ? { ...response, data: upstreamCollection } : upstreamCollection; }; /** 사업차수·구조등급·운영등급 AND 조건으로 조사결과 GeoJSON을 조회한다. */ export const getExmnMapLayer = async ( jobType: ExmnMapJobType, filters: ExmnMapFilters, scope: ExmnLayerScope = {}, signal?: AbortSignal, ) => { const query = new URLSearchParams({ jobType }); if (scope.sggCd?.trim()) query.set("sggCd", scope.sggCd.trim()); if (scope.ctpvNm?.trim()) query.set("ctpvNm", scope.ctpvNm.trim()); if (scope.sggNm?.trim()) query.set("sggNm", scope.sggNm.trim()); if (scope.exmnBizId?.trim()) query.set("exmnBizId", scope.exmnBizId.trim()); if (scope.trtdstId?.trim()) query.set("trtdstId", scope.trtdstId.trim()); if (filters.bizCycl) query.set("bizCycl", filters.bizCycl); if (filters.structuralGrade) query.set("structuralGrade", filters.structuralGrade); if (filters.operationalGrade) query.set("operationalGrade", filters.operationalGrade); const response = await getRawJson(`/sewerage-service/api/v1/exmnMap/layers?${query.toString()}`, { signal }); return jobType === "MNHL" ? retainUpstreamManholeFeatures(response) : response; };