113 lines
3.7 KiB
TypeScript
113 lines
3.7 KiB
TypeScript
/** GIS 편집 FID·속성·선택 변환 보조. 기존 값과 처리 순서를 유지한다. */
|
|
import GisApp from "@common/business_components/ui/map/lib/gis.core";
|
|
import type { GisEditSessionSnapshot } from "@/app/(map-layout)/map/components/gis-edit/gis-edit-types";
|
|
import { GIS_EDIT_PIPE_SNAP_BBOX_BUFFER_RATIO } from "../model/map-constants";
|
|
|
|
export const expandGisEditPipeSnapExtent = (extent: number[]) => {
|
|
const [minX = 0, minY = 0, maxX = 0, maxY = 0] = extent;
|
|
const width = Math.max(0, maxX - minX);
|
|
const height = Math.max(0, maxY - minY);
|
|
const bufferX = width * GIS_EDIT_PIPE_SNAP_BBOX_BUFFER_RATIO;
|
|
const bufferY = height * GIS_EDIT_PIPE_SNAP_BBOX_BUFFER_RATIO;
|
|
return [minX - bufferX, minY - bufferY, maxX + bufferX, maxY + bufferY];
|
|
};
|
|
|
|
export const normalizeGisEditFid = (value: unknown) => {
|
|
const raw = String(value ?? "").trim();
|
|
if (!raw) return "";
|
|
const withoutNamespace = raw.includes(":")
|
|
? (raw.split(":").pop() ?? raw)
|
|
: raw;
|
|
return withoutNamespace.startsWith("tb_ms_swage_ppl.")
|
|
? withoutNamespace.slice("tb_ms_swage_ppl.".length)
|
|
: withoutNamespace;
|
|
};
|
|
|
|
export const getGisEditFeatureFid = (data: any) =>
|
|
normalizeGisEditFid(
|
|
data?.get?.("fid") ??
|
|
data?.values_?.fid ??
|
|
data?.fid ??
|
|
data?.getId?.() ??
|
|
data?.id_ ??
|
|
"",
|
|
);
|
|
|
|
export const isGisEditPreviewFeatureData = (data: any) =>
|
|
Boolean(String(data?.get?.("changeId") ?? data?.changeId ?? "").trim());
|
|
|
|
export const highlightGisEditSelectedFeature = (featureData: any) => {
|
|
if (
|
|
!featureData ||
|
|
typeof featureData.getGeometry !== "function" ||
|
|
typeof featureData.setStyle !== "function"
|
|
) {
|
|
return;
|
|
}
|
|
|
|
const select = GisApp.Module.select as any;
|
|
select?.selectFeature?.(featureData, true);
|
|
};
|
|
|
|
export const isVisibleGisEditSessionChange = (
|
|
change: GisEditSessionSnapshot["changes"][number],
|
|
) => !change.attributeOnly || Boolean(change.basicInfoSavedAt);
|
|
|
|
export const getLatestNumericEditSn = (histories: any[]) =>
|
|
histories.reduce<number | null>((latest, history) => {
|
|
const editSn = String(history?.editSn ?? "").trim();
|
|
if (!/^\d+$/.test(editSn)) return latest;
|
|
const value = Number(editSn);
|
|
return latest === null || value > latest ? value : latest;
|
|
}, null);
|
|
|
|
export const getGisEditAttributeText = (
|
|
attributes: Record<string, unknown> | null | undefined,
|
|
keys: string[],
|
|
) => {
|
|
for (const key of keys) {
|
|
const value = String(attributes?.[key] ?? "").trim();
|
|
if (value) return value;
|
|
}
|
|
return "";
|
|
};
|
|
|
|
export const buildGisEditHiddenPipeFilter = (fids: string[]) => {
|
|
const normalizedFids = Array.from(
|
|
new Set(
|
|
fids
|
|
.map((fid) => normalizeGisEditFid(fid))
|
|
.filter((fid) => /^\d+$/.test(fid)),
|
|
),
|
|
);
|
|
if (normalizedFids.length === 0) return null;
|
|
return `fid NOT IN (${normalizedFids.join(",")})`;
|
|
};
|
|
|
|
export const findInvalidPipeRequiredChange = (
|
|
changes: Array<{
|
|
changeId: string;
|
|
editType: string;
|
|
clientTempId?: string;
|
|
attributes?: Record<string, unknown> | null;
|
|
}>,
|
|
) =>
|
|
changes.find((change) => {
|
|
const attributes = change.attributes ?? {};
|
|
const hasAttributePayload = Object.keys(attributes).length > 0;
|
|
if (change.editType !== "ADD" && !hasAttributePayload) return false;
|
|
|
|
const mngInstCd = getGisEditAttributeText(attributes, ["mngInstCd"]);
|
|
const fcltMngNo = getGisEditAttributeText(attributes, ["fcltMngNo"]);
|
|
const instMngNo = getGisEditAttributeText(attributes, ["instMngNo"]);
|
|
const usgCd = getGisEditAttributeText(attributes, ["usgCd"]);
|
|
return (
|
|
!mngInstCd ||
|
|
!fcltMngNo ||
|
|
/^NEW-/i.test(fcltMngNo) ||
|
|
!instMngNo ||
|
|
/^NEW-/i.test(instMngNo) ||
|
|
!usgCd
|
|
);
|
|
});
|