diff --git a/apps/wr/app/(map-layout)/map/mainMap/page.tsx b/apps/wr/app/(map-layout)/map/mainMap/page.tsx index 1922a8a3f..6240c1fe8 100644 --- a/apps/wr/app/(map-layout)/map/mainMap/page.tsx +++ b/apps/wr/app/(map-layout)/map/mainMap/page.tsx @@ -6,7 +6,14 @@ import { mapService } from "../../service"; import GisApp from "@common/business_components/ui/map/lib/gis.core"; import { SearchBar } from "@common/business_components/ui/map/searchBar/searchBar"; import { useWrStore } from "@/app/store"; -import { getFeatureCd } from "@/components/lib/func/mapUtil"; +import { + featurePopUpOpen, + getClickFeatureId, + getFeatureCd, + getSelectedLayers, + getWrFeaturePk, + getWrLayerNm, +} from "@/components/lib/func/mapUtil"; import toast, { Toaster } from "react-hot-toast"; const Map = () => { @@ -24,7 +31,7 @@ const Map = () => { const fetchData = async () => { try { - const response = await mapService.getLyrStngs('WR_NETWORK'); + const response = await mapService.getLyrStngs("WR_NETWORK"); setTreeData(response); // API 응답 저장 } catch (error) { console.error("데이터 불러오기 실패:", error); @@ -71,11 +78,11 @@ const Map = () => { }; // SearchModal, GisContent 등에서 호출 - const onFeatureFocus = () => { - console.log("onFeatureFocus"); + const onFeatureFocus = (data: any) => { + console.log('data',data) }; - const onFeatureSelect = (data: any) => { + const onFeatureSelect = (data: any ,popUpClick?:boolean) => { const map = gisMaps.current; if (!map) { @@ -93,27 +100,19 @@ const Map = () => { // 2. data가 OpenLayers Feature 인스턴스인지 확인 let foundFeature: any = null; let featureId = data.fid; - const layerName = data.layerNm; - if (layerName === "하수재이용시설") { + + if(popUpClick){ + const layerName = getWrLayerNm(data); + const featurePk = getWrFeaturePk(layerName ?? ""); // 재이용시설 - featureId = `${layerName}.${data.searchPk}`; - } else if ( - //빗물이용시설, 중수도시설 - layerName === "빗물이용시설" || - layerName == "중수도시설" - ) { - featureId = `${layerName}.${data.bdstInfoSn}`; - } else if (layerName === "하수처리시설") { - //하수처리시설 - featureId = `${layerName}.${data.bscFctCd}`; - } else if (layerName === "온배수시설") { - //온배수시설 - featureId = `${layerName}.${data.bdstRuseFcltSn}`; - } else if (layerName == "수요처") { - //수요처 - featureId = `${layerName}.${data.dmdInfoId.replaceAll("-", "")}`; - } else { - featureId = `${layerName}.${data.fid || data.id || data.ftrIdn}`; + if (featurePk) { + featureId = `${layerName}.${data[featurePk]}`; + } else { + console.warn("해당 피처는 선택된 레이어에서 찾을수 없습니다."); + } + }else{ + featureId=getClickFeatureId(data) + } map .getLayers() @@ -143,6 +142,10 @@ const Map = () => { select.selectFeature(foundFeature, true); } else { console.warn("OpenLayers Feature를 찾을 수 없습니다:"); + console.log("foundFeature :", foundFeature ); + console.warn("featureId : ", featureId); + console.warn("data : ", data); + console.warn(": 끝"); } const currentId = data?.fid || data?.id || data?.ftrIdn; const lastId = featureData?.fid || featureData?.id || featureData?.ftrIdn; @@ -150,10 +153,16 @@ const Map = () => { setFeatureData(data); setIsOpen(true); setIsSearchModalOpen(false); + + if (popUpClick ){ + const layerName = getWrLayerNm(data); + const isColumn = getFeatureCd(foundFeature.getProperties(), String(layerName)); + if(layerName&&isColumn) + featurePopUpOpen(layerName,isColumn,popupDetailRef) + } }; useEffect(() => { - if (isFeatured) { onFeatureSelect(isFeatured); } @@ -163,41 +172,13 @@ const Map = () => { const bc = new BroadcastChannel("mapDetailPopUp"); bc.onmessage = (event) => { if (event.data.type === "SELECT_FEATURE") { - onFeatureSelect(event.data.feature); + onFeatureSelect(event.data.feature,true); closePopup(); } }; }, []); - const getSelectedLayers = (isFeature: any) => { - const map = gisMaps.current; - if (!map) { - console.warn("지도가 초기화되지 않았습니다."); - return; - } - let result = null; - const layers = map - ? map - .getLayers() - .getArray() - .filter((l: any) => l.getVisible()) - : []; // gisMap이 null인지 확인 후 레이어 가져오기 - let featureLayer: { get: (key: string) => any } = { get: () => null }; - layers.forEach((layer: any) => { - const source = layer.getSource(); - if ( - source && - source.hasFeature && - isFeature && - typeof isFeature.getId === "function" && - source.hasFeature(isFeature) - ) { - featureLayer = layer; // 피처가 속한 레이어 찾기) - } - }); - result = featureLayer.get("lyrNm"); - return result; - }; + const renderDetailView = useCallback( (props: any) => { @@ -208,44 +189,38 @@ const Map = () => { } const isFeature = props?.featureData; - - if( typeof isFeature.getProperties === "function" ){ - + if (typeof isFeature.getProperties === "function") { if ( - Object.keys(isFeature?.getProperties()).length === 0 && - isFeature.constructor === Object + !( + Object.keys(isFeature?.getProperties()).length === 0 && + isFeature.constructor === Object + ) ) { - const url = `/mapDetailPopUp?layerNm=${encodeURIComponent(props.seletectedLayerNm)}`; - const width = window.screen.availWidth; - const height = window.screen.availHeight; - const left = 0; - const top = 0; - const popupOptions = `width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=no`; - popupRef.current = window.open(url, "지도 레이어 팝업", popupOptions); - } else { - const layerNm = getSelectedLayers(isFeature); - const safeProps = isFeature.getProperties(); - const featureCd = getFeatureCd(safeProps, String(layerNm)); - const url = `/mapFeaturePopup?layerNm=${encodeURIComponent(String(layerNm))}&featureCd=${encodeURIComponent(featureCd)} `; - const width = - String(layerNm) === "하수재이용시설" - ? Math.floor(window.innerWidth * 0.8) - : Math.floor(window.innerWidth * 0.4); // 화면 폭의 40% - const height = - String(layerNm) === "하수재이용시설" - ? Math.floor(window.innerHeight - 150) - : Math.floor(window.innerHeight - 450); // 150px 여백 확보; // calc(100% - 70px) - const left = (window.screen.availWidth - width) / 2; - const top = (window.screen.availHeight - height) / 2; - const popupOptions = `width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes`; - popupDetailRef.current = window.open( - url, - "지도 시설 상세정보 팝업", - popupOptions - ); + const layerNm = getSelectedLayers(isFeature,gisMaps); + const safeProps = isFeature.getProperties(); + const featureCd = getFeatureCd(safeProps, String(layerNm)); + // const url = `/mapFeaturePopup?layerNm=${encodeURIComponent(String(layerNm))}&featureCd=${encodeURIComponent(featureCd)} `; + // const width = + // String(layerNm) === "하수재이용시설" + // ? Math.floor(window.innerWidth * 0.8) + // : Math.floor(window.innerWidth * 0.4); // 화면 폭의 40% + // const height = + // String(layerNm) === "하수재이용시설" + // ? Math.floor(window.innerHeight - 150) + // : Math.floor(window.innerHeight - 450); // 150px 여백 확보; // calc(100% - 70px) + // const left = (window.screen.availWidth - width) / 2; + // const top = (window.screen.availHeight - height) / 2; + // const popupOptions = `width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes`; + // popupDetailRef.current = window.open( + // url, + // "지도 시설 상세정보 팝업", + // popupOptions + // ); + if(layerNm) + featurePopUpOpen(layerNm,featureCd,popupDetailRef) } - }else{ - console.log(' data확인 필요') + } else { + console.log(" data확인 필요"); } }, [checkedLayers, checkedLayersData, featureData] // 필요 시 의존성 넣기 @@ -259,9 +234,10 @@ const Map = () => { } }; - const onOpenPopup = (data:any) => { - if(data){ - + const onOpenPopup = (data: any) => { + if (data) { + setIsOpen(true); + setFeatureData(null); const url = `/mapDetailPopUp?layerNm=${encodeURIComponent(data)}`; const width = window.screen.availWidth; const height = window.screen.availHeight; @@ -269,12 +245,10 @@ const Map = () => { const top = 0; const popupOptions = `width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=no`; popupRef.current = window.open(url, "지도 레이어 팝업", popupOptions); - }else{ - toast.error('시설 및 수요처가 선택되지 않았습니다.') + } else { + toast.error("시설 및 수요처가 선택되지 않았습니다."); } - - - } + }; return (