diff --git a/apps/wr/app/(popUp-layout)/mapDrgtPopUp/searchBar.tsx b/apps/wr/app/(popUp-layout)/mapDrgtPopUp/searchBar.tsx index 21a98d696..b1a049236 100644 --- a/apps/wr/app/(popUp-layout)/mapDrgtPopUp/searchBar.tsx +++ b/apps/wr/app/(popUp-layout)/mapDrgtPopUp/searchBar.tsx @@ -46,7 +46,7 @@ export function SearchBar({ gisMaps, ctpvCode, sggCode }: CtpvSggPrcsFcltSelectB async function fetchCtpvData() { try { const ctpvData = await fetch(`/geoserver/hasudo/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=hasudo%3Atb_ms_ctpv&outputFormat=application%2Fjson&cql_filter=mctpv_cd=%27${ctpvCd.trim()}%27&srsName=EPSG:5179`) - .then(res => res.json()); + .then(res => res.json()); console.log('시도 데이터', ctpvData.features[0]); const format = new GeoJSON(); @@ -110,10 +110,48 @@ export function SearchBar({ gisMaps, ctpvCode, sggCode }: CtpvSggPrcsFcltSelectB const url = `/geoserver/hasudo/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=hasudo:tb_ms_ctpv&outputFormat=application/json&propertyName=mctpv_korn_nm,mctpv_cd`; const res = await fetch(url).then(res => res.json()); - const list = res.features.map((f: any) => ({ - text: f.properties.mctpv_korn_nm, - val: f.properties.mctpv_cd, - })); + const list = res.features + .map((f: any) => ({ + text: f.properties.mctpv_korn_nm, + val: f.properties.mctpv_cd, + })) + .sort((a, b) => { + // 커스텀 순서 정의 + const customOrder = [ + "서울특별시", + "부산광역시", + "대구광역시", + "인천광역시", + "광주광역시", + "대전광역시", + "울산광역시", + "세종특별자치시", + "경기도", + "강원특별자치도", // 경기도 다음에 배치 + "충청북도", + "충청남도", + "전북특별자치도", // 충청남도 다음에 배치 + "전라남도", + "경상북도", + "경상남도", + "제주특별자치도" + ]; + + const indexA = customOrder.indexOf(a.text); + const indexB = customOrder.indexOf(b.text); + + // 둘 다 커스텀 순서에 있으면 해당 순서로 + if (indexA !== -1 && indexB !== -1) { + return indexA - indexB; + } + + // 하나만 커스텀 순서에 있으면 그것을 앞으로 + if (indexA !== -1) return -1; + if (indexB !== -1) return 1; + + // 둘 다 커스텀 순서에 없으면 기본 알파벳 순서 + return a.text.localeCompare(b.text, 'ko'); + }); console.log('시도 데이터', list); setCtpv(list); @@ -126,7 +164,7 @@ export function SearchBar({ gisMaps, ctpvCode, sggCode }: CtpvSggPrcsFcltSelectB const list = res.features.map((f: any) => ({ text: f.properties.sgg_korn_nm, val: f.properties.sgg_cd, - })); + })).sort((a, b) => a.text.localeCompare(b.text, 'ko')); console.log('시군구 데이터', list); setSgg(list);