Browse Source

laanc 상세맵 작업중

pull/2/head
junh_eee(이준희) 11 months ago
parent
commit
e0ad66c5e6
  1. 76
      src/components/map/mapbox/draw/LaancDrawControl.js
  2. 16
      src/views/laanc/FlightArea.js

76
src/components/map/mapbox/draw/LaancDrawControl.js

@ -12,6 +12,7 @@ export const LaancDrawControl = props => {
const drawObj = props.drawObj; const drawObj = props.drawObj;
const mapObject = props.mapObject; const mapObject = props.mapObject;
const [drawObjId, setDrawObjId] = useState();
const [bufferId, setBufferId] = useState(); const [bufferId, setBufferId] = useState();
const [geojson, setGeoJson] = useState(); const [geojson, setGeoJson] = useState();
@ -27,7 +28,7 @@ export const LaancDrawControl = props => {
useEffect(() => { useEffect(() => {
if (mapObject) { if (mapObject) {
mapObject.on('draw.create', handlerCreateObj); mapObject.on('draw.create', handlerSetId);
mapObject.on('draw.update', handlerFormatAreaInfo); mapObject.on('draw.update', handlerFormatAreaInfo);
mapObject.on('click', handlerOnClick); mapObject.on('click', handlerOnClick);
@ -68,11 +69,12 @@ export const LaancDrawControl = props => {
}; };
// 도형 첫 생성하면 properties.id에 현재 drawType 넣어줌 // 도형 첫 생성하면 properties.id에 현재 drawType 넣어줌
const handlerCreateObj = e => { const handlerSetId = e => {
const id = e.features[0].id; const id = e.features[0].id;
const mode = handlerReturnMode(drawObj.getMode()); const mode = handlerReturnMode(drawObj.getMode());
if (mode) { if (mode) {
drawObj.setFeatureProperty(id, 'id', mode); drawObj.setFeatureProperty(id, 'id', mode);
setDrawObjId(id);
handlerFormatAreaInfo(e); handlerFormatAreaInfo(e);
} }
}; };
@ -137,8 +139,6 @@ export const LaancDrawControl = props => {
const handlerPastDraw = () => { const handlerPastDraw = () => {
if (props.areaCoordList) { if (props.areaCoordList) {
console.log(props.areaCoordList[0], '>>>>areaCoordList---');
const areas = props.areaCoordList[0]; const areas = props.areaCoordList[0];
const paths = []; const paths = [];
areas.coordList.forEach(coord => paths.push([coord.lon, coord.lat])); areas.coordList.forEach(coord => paths.push([coord.lon, coord.lat]));
@ -147,8 +147,24 @@ export const LaancDrawControl = props => {
console.log('pastDraw'); console.log('pastDraw');
const drawGeoJson = drawObj.getAll(); const drawGeoJson = drawObj.getAll();
if (areas.areaType === 'CIRCLE') { if (areas.areaType === 'CIRCLE') {
console.log(paths, '>>>');
// handlerCreateDrawObj(
// drawObjId,
// setDrawObjId,
// 'Polygon',
// [paths],
// 'CIRCLE'
// );
} else { } else {
if (areas.areaType === 'LINE') { if (areas.areaType === 'LINE') {
handlerCreateDrawObj(
drawObjId,
setDrawObjId,
'LineString',
paths,
'LINE'
);
// 버퍼 생성 // 버퍼 생성
if (areas.bufferCoordList) { if (areas.bufferCoordList) {
const bufferPaths = []; const bufferPaths = [];
@ -157,17 +173,22 @@ export const LaancDrawControl = props => {
bufferPaths.push([bfCoord.lon, bfCoord.lat]) bufferPaths.push([bfCoord.lon, bfCoord.lat])
); );
const buffer = drawObj.get(bufferId); handlerCreateDrawObj(
if (buffer) drawObj.delete(bufferId); bufferId,
setBufferId,
const newBuffer = { 'LineString',
type: 'LineString', bufferPaths,
coordinates: bufferPaths 'BUFFER'
}; );
const newBufferId = drawObj.add(newBuffer);
setBufferId(newBufferId);
} }
} else if (areas.areaType === 'POLYGON') { } else if (areas.areaType === 'POLYGON') {
handlerCreateDrawObj(
drawObjId,
setDrawObjId,
'Polygon',
[paths],
'POLYGON'
);
} }
} }
// 현재 그려진 도형 저장 // 현재 그려진 도형 저장
@ -180,6 +201,26 @@ export const LaancDrawControl = props => {
} }
}; };
// 기존에 그려진 도형 지우고 새 도형 생성
const handlerCreateDrawObj = (id, setter, type, coord, propertyId) => {
const obj = drawObj.get(id);
if (obj) drawObj.delete(id);
const newObj = {
type: type,
coordinates: coord
};
const newObjId = drawObj.add(newObj);
drawObj.setFeatureProperty(newObjId[0], 'id', propertyId);
setter(newObjId[0]);
if (propertyId !== 'BUFFER') {
drawObj.changeMode('direct_select', {
featureId: newObjId[0]
});
}
};
const handlerRemoveMarker = () => { const handlerRemoveMarker = () => {
const ele = document.getElementsByClassName('mapboxgl-popup'); const ele = document.getElementsByClassName('mapboxgl-popup');
const eleArr = Array.from(ele); const eleArr = Array.from(ele);
@ -198,6 +239,9 @@ export const LaancDrawControl = props => {
}; };
const handlerCreateAllMarker = coords => { const handlerCreateAllMarker = coords => {
const areas = props.areaCoordList[0];
if (areas.areaType !== 'CIRCLE') {
for (let i = 0; i < coords.length; i++) { for (let i = 0; i < coords.length; i++) {
if (i === 0) { if (i === 0) {
handlerCreateOneMarker([0, -10], coords[i], 'Start'); handlerCreateOneMarker([0, -10], coords[i], 'Start');
@ -207,11 +251,15 @@ export const LaancDrawControl = props => {
handlerCreateOneMarker([0, 0], lngLat, text); handlerCreateOneMarker([0, 0], lngLat, text);
} }
} }
} else {
handlerCreateOneMarker([0, -10], coords[0], areas.bufferZone);
}
}; };
const drawInit = () => { const drawInit = () => {
drawObj.deleteAll(); drawObj.deleteAll();
handlerRemoveMarker(); handlerRemoveMarker();
setDrawObjId();
props.handlerInitCoordinates(); props.handlerInitCoordinates();
@ -229,7 +277,7 @@ export const LaancDrawControl = props => {
} else if (mode === 'POLYGON') { } else if (mode === 'POLYGON') {
drawObj.changeMode('draw_polygon'); drawObj.changeMode('draw_polygon');
} else if (mode === 'CIRCLE') { } else if (mode === 'CIRCLE') {
drawObj.changeMode('draw_circle'); drawObj.changeMode('draw_circle', { initialRadiusInKm: 100 / 1000 });
} }
}; };

16
src/views/laanc/FlightArea.js

@ -560,6 +560,22 @@ export default function FlightArea({
> >
초기화 초기화
</Button> </Button>
<Button
color='primary'
onClick={() => {
const drawObjCnt = drawObj
.getAll()
.features.filter(
obj => obj.properties.id !== 'BUFFER'
).length;
if (drawObjCnt > 2) {
alert('구역은 2개까지만 설정 가능합니다.');
}
}}
>
추가
</Button>
{wheather[0]?.coordList[0].lat != 0 ? ( {wheather[0]?.coordList[0].lat != 0 ? (
<Button color='primary' onClick={handlerWeather}> <Button color='primary' onClick={handlerWeather}>
날씨 정보 날씨 정보

Loading…
Cancel
Save