diff --git a/src/utility/MapUtils.js b/src/utility/MapUtils.js index 7ae40c4f..f9d2e186 100644 --- a/src/utility/MapUtils.js +++ b/src/utility/MapUtils.js @@ -713,16 +713,27 @@ export const handlerDrawEvents = (mapInstance, callback, refObj, drawObj) => { if (startPoint) { mouseCursorRef.current.style.display = 'none'; if (drawMode === 'direct_select') { + const type = drawObj.getAll(); // distanceMarkers.map(i => i.remove()); - - const distance = getDrawDistance(drawObj, drawMode); - totalDistanceRef.current.innerText = `총 거리 : ${distance.toLocaleString()}m`; + if (type.features[0].geometry.type === 'LineString') { + const markerList = getDintancePointPopupList(drawObj); + callback(mapInstance, markerList, drawObj); + const distance = getDrawDistance(drawObj, 'draw_line_string'); + totalDistanceRef.current.innerText = `총 거리 : ${distance.toLocaleString()}m`; + } else { + const distance = getDrawDistance(drawObj, 'draw_polygon'); + const area = getArea(drawObj); + totalDistanceRef.current.innerText = `둘레 : ${distance.toLocaleString()}m`; + totalAreaRef.current.innerText = `면적 : ${area}m²`; + } } } - if (drawMode === 'direct_select') { - const markerList = getDintancePointPopupList(drawObj); - callback(mapInstance, markerList, drawObj); - } + // if (drawMode === 'direct_select') { + // if (drawMode === 'draw_line_string') { + // const markerList = getDintancePointPopupList(drawObj); + // callback(mapInstance, markerList, drawObj); + // } + // } if (drawMode === 'draw_line_string') { if (drawObj.getAll().features[0].geometry.coordinates.length === 1) { mouseCursorRef.current.style.display = 'block'; @@ -765,6 +776,7 @@ export const getDrawDistance = (drawObj, drawMode) => { coordinates: [...feature] } }; + distance = turf.length(obj, { units: 'kilometers' }); distance = distance * 1000; distance = distance