diff --git a/src/components/laanc/map/LaancMap.js b/src/components/laanc/map/LaancMap.js index c041d8af..36a38395 100644 --- a/src/components/laanc/map/LaancMap.js +++ b/src/components/laanc/map/LaancMap.js @@ -12,6 +12,8 @@ import { SimpleSelectMode } from 'mapbox-gl-draw-circle'; import { MAPBOX_TOKEN } from '../../../configs/constants'; +import threebox from 'threebox-plugin'; +// mapUtils import { InitFeature, handlerCreatePoint, @@ -23,33 +25,31 @@ import { layerWayPoint, handlerCreateAirSpace } from '../../../utility/MapUtils'; - +// redux import { clientMapInit } from '@src/redux/features/control/map/mapSlice'; - +import { clientSetIsMapLoading } from '@src/redux/features/laanc/laancSlice'; // geojson import gimpo from '../../map/geojson/gimpoAirportAirArea.json'; - -import threebox from 'threebox-plugin'; - +// components import LaancMapModal from './LaancMapModal'; - const FeatureAirZone = lazy(() => import('../../map/mapbox/feature/FeatureAirZone') ); export default function LaancMap({ page, handleChange, data }) { const dispatch = useDispatch(); + // 공역 타입 const mapState = useSelector(state => state.mapState); - // 비행구역 정보 저장 - const { areaCoordList, isOpenModal } = useSelector(state => state.laancState); + // 비행구역 정보, 비행 구역 설정 모달 오픈 여부, 지도 로딩 여부 + const { areaCoordList, isOpenModal, isMapLoading } = useSelector( + state => state.laancState + ); // 지도 const [mapObject, setMapObject] = useState(); const mapContainer = useRef(null); - // 지도 로드 여부 - const [isMapLoad, setIsMapLoad] = useState(false); // 비행구역 그리기 const [drawObj, setDrawObj] = useState(); @@ -241,7 +241,7 @@ export default function LaancMap({ page, handleChange, data }) { map.addLayer(layerBuffer('preview')); map.addLayer(layerWayPoint('preview')); - setIsMapLoad(true); + dispatch(clientSetIsMapLoading(true)); const preview = map.getSource('preview'); if (preview) setPreviewLayer(preview); @@ -357,7 +357,7 @@ export default function LaancMap({ page, handleChange, data }) { ref={mapContainer} style={{ width: '100%', height: '35vh' }} > - {isMapLoad && mapObject ? ( + {isMapLoading && mapObject ? ( @@ -369,7 +369,6 @@ export default function LaancMap({ page, handleChange, data }) { drawObj={drawObj} mapContainer={mapContainer} weather={weather} - areaCoordList={areaCoordList} /> ) : null} diff --git a/src/components/laanc/map/LaancMapDetail.js b/src/components/laanc/map/LaancMapDetail.js index 29bc629c..349b74bb 100644 --- a/src/components/laanc/map/LaancMapDetail.js +++ b/src/components/laanc/map/LaancMapDetail.js @@ -27,15 +27,13 @@ const FeatureAirZone = lazy(() => ); const LaancMapDraw = lazy(() => import('./LaancMapDraw')); export default function LaancMapDetail({ - mapContainer, drawObj, - handlerSaveCheck, - handlerAddChange, - addData, - handlerInitCoordinates, + mapContainer, setSaveData, + setModal, handlerSaveElev, - setModal + handlerCheckSavable, + handlerInitCoordinates }) { const dispatch = useDispatch(); @@ -402,7 +400,6 @@ export default function LaancMapDetail({ <> state.laancState); + const { drawType, isClickAdd } = useSelector(state => state.laancState); // mapbox 기본 onClick 함수 저장 const originClickRef = useRef(null); @@ -49,9 +55,7 @@ export default function LaancDrawControl(props) { useEffect(() => { if (drawType === 'DONE') { if (number !== 0) { - const obj = drawObj - .getAll() - .features.filter(o => o.properties.id !== 'BUFFER'); + const obj = getDrawFeatures(drawObj); // 구역 생성 후 바로 directMode if (obj.length > 0) { @@ -379,7 +383,7 @@ export default function LaancDrawControl(props) { handlerRemoveError(id); return; } else { - props.handlerSaveCheck(true); + props.handlerCheckSavable(true); } // 비가시권 체크 @@ -423,7 +427,7 @@ export default function LaancDrawControl(props) { handlerRemoveError(id); return; } else { - props.handlerSaveCheck(true); + props.handlerCheckSavable(true); return areaInfo; } }; @@ -483,7 +487,7 @@ export default function LaancDrawControl(props) { if (!isRemain) { dispatch(clientChangeDrawType('RESET')); - props.handlerSaveCheck(false); + props.handlerCheckSavable(false); } else { dispatch(clientChangeDrawType('DONE')); } @@ -507,7 +511,7 @@ export default function LaancDrawControl(props) { props.setViewCoordObj(viewCoordObj); // 계속 20개 미만이라 overAdd false처리 - props.handlerAddChange('overAdd', false); + dispatch(clientIsOverAdd(false)); }; /** @@ -518,15 +522,13 @@ export default function LaancDrawControl(props) { props.handlerCoordinates(areaInfo); setIsDrawDone(true); - const viewCoordObj = drawObj - .getAll() - .features.filter(o => o.properties.id !== 'BUFFER' && o.properties.id); + const viewCoordObj = getDrawFeatures(drawObj); props.setViewCoordObj(viewCoordObj); if (viewCoordObj.length > 19) { - props.handlerAddChange('overAdd', true); + dispatch(clientIsOverAdd(true)); } else { - props.handlerAddChange('isViewAdd', true); + dispatch(clientIsViewAdd(true)); } }; @@ -765,9 +767,7 @@ export default function LaancDrawControl(props) { } } }); - const viewCoordObj = drawObj - .getAll() - .features.filter(o => o.properties.id !== 'BUFFER'); + const viewCoordObj = getDrawFeatures(drawObj); props.setViewCoordObj(viewCoordObj); } } @@ -811,13 +811,14 @@ export default function LaancDrawControl(props) { return; } - if (!props.addData.isAddable) { + // if (!props.addData.isAddable) { + if (!isClickAdd) { // 추가 상태가 아닐 때 drawObj.deleteAll(); handlerRemoveAllMarker(); props.setViewCoordObj([]); - props.handlerSaveCheck(false); + props.handlerCheckSavable(false); props.handlerInitCoordinates(); } @@ -830,14 +831,12 @@ export default function LaancDrawControl(props) { * 초기화 */ const handlerResetMode = () => { - props.handlerAddChange('isAddable', false); - props.handlerAddChange('isViewAdd', false); - props.handlerAddChange('overAdd', false); + dispatch(clientInitAddButton()); drawObj.deleteAll(); handlerRemoveAllMarker(); props.setViewCoordObj([]); - props.handlerSaveCheck(false); + props.handlerCheckSavable(false); drawObj.changeMode('simple_select'); }; diff --git a/src/components/laanc/map/LaancMapModal.js b/src/components/laanc/map/LaancMapModal.js index 9d583d1c..b2e16d1a 100644 --- a/src/components/laanc/map/LaancMapModal.js +++ b/src/components/laanc/map/LaancMapModal.js @@ -13,6 +13,7 @@ import { clientAltitudeData, clientChangeDrawType, clientControlLaancModal, + clientIsClickAdd, clientSaveAreaCoordinateList, clientSaveAreaDetailList } from '@src/redux/features/laanc/laancSlice'; @@ -21,20 +22,24 @@ import { openModal } from '@src/redux/features/comn/message/messageSlice'; const LaancDrawModal = lazy(() => import('./LaancDrawModal')); const LaancMapWeather = lazy(() => import('./LaancMapWeather')); -export default function LaancMapModal({ - drawObj, - mapContainer, - weather, - areaCoordList -}) { +export default function LaancMapModal({ drawObj, mapContainer, weather }) { const dispatch = useDispatch(); - const { drawType, isOpenModal } = useSelector(state => state.laancState); + + // Laanc state + const { + drawType, + isOpenModal, + areaCoordList, + isClickAdd, + isOverAdd, + isViewAdd + } = useSelector(state => state.laancState); // 저장된 비행구역 데이터 const [saveData, setSaveData] = useState(); // 비행구역 저장 가능 여부 - const [isSaveable, setIsSaveable] = useState(false); + const [isSavable, setIsSavable] = useState(false); // 비행구역 고도 const [saveElev, setSaveElev] = useState([]); @@ -53,36 +58,17 @@ export default function LaancMapModal({ * 비행구역 저장 가능 유무 체크 * @param {boolean} save 비행구역 저장 가능 유무 */ - const handlerSaveCheck = save => { - setIsSaveable(save); + const handlerCheckSavable = save => { + setIsSavable(save); }; - // 비행구역 추가 가능 여부 판단 - const [addData, setAddData] = useState({ - isAddable: false, - isViewAdd: false, - overAdd: false - }); - // 비행구역 추가 버튼 클릭 시 const handlerAddClick = () => { - if (!addData.isAddable || !addData.overAdd) { - handlerAddChange('isAddable', true); + if (!isClickAdd || !isOverAdd) { + dispatch(clientIsClickAdd(true)); } }; - /** - * 비행구역 추가 관련 상태 변경 - * @param {string} key addData의 key - * @param {boolean} val addData의 value - */ - const handlerAddChange = (key, val) => { - setAddData(prev => ({ - ...prev, - [key]: val - })); - }; - /** * 비행구역 고도 저장 * @param {number} elev 비행고도 @@ -176,15 +162,13 @@ export default function LaancMapModal({ @@ -193,7 +177,7 @@ export default function LaancMapModal({
- {addData.isViewAdd ? ( + {isViewAdd ? ( ) : null} - {addData.isViewAdd && weather[0]?.coordList[0].lat != 0 ? ( + {isViewAdd && weather[0]?.coordList[0].lat != 0 ? ( @@ -248,7 +232,7 @@ export default function LaancMapModal({