지도 대상 선택 이동 시 지역·시설 검색조건 초기화

This commit is contained in:
kiminchan
2026-10-02 16:51:47 +09:00
parent 8c614b84a7
commit 6ef4603a7c
25 changed files with 433 additions and 70 deletions
@@ -1,3 +1,4 @@
import { fitMapSelection } from "@/features/map-search/lib/map-navigation";
/**
* 화면명: 하수맨홀 정보
* ➡️ 경로 : 하수관망도 메인 페이지 (시설물 클릭) - 오른쪽 팝업창 (하수맨홀)
@@ -69,7 +70,7 @@ export async function searchUpperPpls(
const geometry = foundFeature?.getGeometry();
if (geometry) {
const extent = geometry.getExtent();
gisMap.getView().fit(extent, {
fitMapSelection(gisMap, extent, {
duration: 300,
padding: [50, 50, 50, 50],
maxZoom: 14,
@@ -3,6 +3,7 @@
* 선택한 하수처리구역의 관로 분석 현황과 보수이력 연계 기능을 제공한다.
*/
"use client";
import { fitMapSelection } from "@/features/map-search/lib/map-navigation";
import React, {
useCallback,
@@ -228,7 +229,7 @@ const SwtrmtPrcsZoneAnalysis = ({
repairLayerRef.current?.changed();
const extent = selectedFeature.getGeometry()?.getExtent();
if (extent) {
gisMap.getView().fit(extent, {
fitMapSelection(gisMap, extent, {
padding: [100, 100, 100, 460],
duration: 350,
maxZoom: 18,
@@ -1,4 +1,5 @@
"use client";
import { beginMapNavigation } from "@/features/map-search/lib/map-navigation";
import { useCallback, useEffect, useRef, useState } from "react";
@@ -217,6 +218,8 @@ export const useFloodPredictionMap = ({
floodLayerType,
onRequestFloodLayer,
}: UseFloodPredictionMapOptions) => {
/** 레이어 준비 대기와 늦은 오버레이 응답도 같은 선택 세대로 제한한다. */
const navigationRef = useRef<ReturnType<typeof beginMapNavigation> | null>(null);
// 자동 레이어 선택이 완료된 뒤 다시 적용할 침수예측 행을 보관한다.
const [pendingSelection, setPendingSelection] =
useState<FloodPredictionSelection | null>(null);
@@ -241,6 +244,7 @@ export const useFloodPredictionMap = ({
/** 선택행의 시군구·분석시각으로 도시침수지도 중앙 오버레이를 표시한다. */
const loadFloodPredictionOverlay = useCallback(
async (selection: FloodPredictionSelection) => {
const navigation = navigationRef.current;
const { sggCd, analysisDateTime, extent } = selection;
const map = mapRef.current;
if (!map || !/^\d{12}$/.test(analysisDateTime)) return;
@@ -250,6 +254,7 @@ export const useFloodPredictionMap = ({
const response = await getRawJson(
`/sewerage-service/api/v1/fldng/predc/prst/gridMap?sggCd=${encodeURIComponent(sggCd)}&analysisDateTime=${encodeURIComponent(analysisDateTime)}`,
);
if (!navigation?.isCurrent()) return;
const payload = response?.data ?? response;
const row =
payload && typeof payload === "object" && !Array.isArray(payload)
@@ -284,6 +289,8 @@ export const useFloodPredictionMap = ({
/** 활성화된 도시침수지도에서 선택 행의 시군구·빈도 피처를 선택하고 지도와 오버레이를 이동한다. */
const applyFloodPredictionSelection = useCallback(
async (selection: FloodPredictionSelection) => {
const navigation = navigationRef.current;
if (!navigation?.isCurrent()) return true;
const map = mapRef.current;
const select = GisApp.Module.select as unknown as
| FloodSelectionModule
@@ -302,10 +309,12 @@ export const useFloodPredictionMap = ({
);
if (floodLayers.length === 0) return false;
await select.resetSelectedFeature?.();
if (!navigation.commit(selection.extent)) return true;
select.resetSelectedFeature?.();
const selectedFeatureIds = new Set<string>();
/** 현재 로드된 동일 시군구·빈도 피처를 중복 없이 선택한다. */
const selectLoadedGroupFeatures = (source: FloodPredictionSource) => {
if (!navigation.isCurrent()) return;
const features = source?.getFeatures?.() ?? [];
features.forEach((feature) => {
const featureSggCd = String(feature.get?.("sgg_cd") ?? "").trim();
@@ -352,6 +361,8 @@ export const useFloodPredictionMap = ({
async (payload: unknown, popupContext: FloodPredictionPopupContext) => {
const selection = parseFloodPredictionSelection(payload);
if (!selection) return;
navigationRef.current = beginMapNavigation(mapRef.current);
setPendingSelection(null);
if (await applyFloodPredictionSelection(selection)) return;
pendingPopupRef.current = popupContext;
@@ -0,0 +1,81 @@
import type Map from "ol/Map";
import type { FitOptions } from "ol/View";
/** 지도 객체별 이동 요청과 검색바 초기화 revision을 보관한다. 다른 지도와 상태를 공유하지 않는다. */
type NavigationState = {
generation: number;
revision: number;
listeners: Set<() => void>;
};
const states = new WeakMap<object, NavigationState>();
/** 부분 지도 인터페이스를 사용하는 기능도 동일한 인스턴스로 요청을 관리한다. */
type NavigationTarget = { getView?: () => unknown };
/** 지도 생명주기와 함께 회수되는 상태를 반환한다. */
function stateFor(map: object): NavigationState {
let state = states.get(map);
if (!state) {
state = { generation: 0, revision: 0, listeners: new Set() };
states.set(map, state);
}
return state;
}
/** 빈/역전/비수치 범위를 이동 성공으로 취급하지 않는다. */
export function isNavigationExtent(extent: unknown): extent is number[] {
return Array.isArray(extent) && extent.length === 4 &&
extent.every(Number.isFinite) && extent[0] <= extent[2] && extent[1] <= extent[3];
}
/** 검색바 조작은 아직 완료되지 않은 목록 이동보다 우선한다. */
export function invalidateMapNavigation(map: object | null | undefined) {
if (map) stateFor(map).generation += 1;
}
/** 검색바는 이미 발생한 초기화도 revision으로 읽어 늦은 마운트에서 유실하지 않는다. */
export function getMapSearchRevision(map: object | null | undefined) {
return map ? stateFor(map).revision : 0;
}
/** 한 지도 검색바의 초기화만 구독한다. */
export function subscribeMapSearch(map: object | null | undefined, listener: () => void) {
if (!map) return () => {};
const state = stateFor(map);
state.listeners.add(listener);
return () => { state.listeners.delete(listener); };
}
/** 조회 시작에 발급하고 도형 확보 뒤 commit한다. 최신 요청만 한 번 검색바를 초기화한다. */
export function beginMapNavigation(map: NavigationTarget | null | undefined) {
const state = map ? stateFor(map) : null;
const generation = state ? ++state.generation : -1;
let committed = false;
const isCurrent = () => Boolean(state && state.generation === generation);
return {
isCurrent,
commit(extent: unknown) {
if (!isCurrent() || !map?.getView?.() || !isNavigationExtent(extent)) return false;
if (!committed && state) {
committed = true;
state.revision += 1;
state.listeners.forEach((listener) => listener());
}
return true;
},
};
}
/** 도형이 이미 준비된 목록 선택은 기존 fit 옵션을 그대로 사용한다. */
export function fitMapSelection(map: Pick<Map, "getView"> | null | undefined, extent: unknown, options: FitOptions & { constrainResolution?: boolean }) {
if (!map?.getView?.()?.fit || !isNavigationExtent(extent)) return false;
const navigation = beginMapNavigation(map);
if (!navigation.commit(extent)) return false;
map.getView().fit(extent, options);
return true;
}
/** 공통 GeoJSON 검색의 비동기 로드 완료 시 호출할 선택적 계약이다. */
export function mapSearchNavigationOptions(map: NavigationTarget | null | undefined) {
const navigation = beginMapNavigation(map);
return { beforeFocus: (extent: unknown) => navigation.commit(extent) };
}