From fdbfd27e74d2aed99db8d33bca547dcb99588683 Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Fri, 31 May 2024 12:25:34 -0400 Subject: [PATCH] round coord to 7 for 1cm precision --- .../components/AddLayerPanel/createLayerFunctions.js | 12 ++++++------ .../modals/GeoModal/GeoModal.component.jsx | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/editor/components/components/AddLayerPanel/createLayerFunctions.js b/src/editor/components/components/AddLayerPanel/createLayerFunctions.js index e3cc72ad2..7a555f538 100644 --- a/src/editor/components/components/AddLayerPanel/createLayerFunctions.js +++ b/src/editor/components/components/AddLayerPanel/createLayerFunctions.js @@ -34,8 +34,8 @@ function createMapbox() { const coord = AFRAME.scenes[0].getAttribute('metadata')['coord']; if (coord) { - latitude = roundToSix(parseFloat(coord.latitude)); - longitude = roundToSix(parseFloat(coord.longitude)); + latitude = roundCoord(parseFloat(coord.latitude)); + longitude = roundCoord(parseFloat(coord.longitude)); } geoLayer.setAttribute( @@ -82,8 +82,8 @@ function loadScript(url, callback) { document.head.appendChild(script); } -const roundToSix = (num) => { - return Math.round(num * 1e6) / 1e6; +const roundCoord = (num) => { + return Math.round(num * 1e7) / 1e7; }; function create3DTiles() { @@ -100,8 +100,8 @@ function create3DTiles() { const coord = AFRAME.scenes[0].getAttribute('metadata')['coord']; if (coord) { - latitude = roundToSix(parseFloat(coord.latitude)); - longitude = roundToSix(parseFloat(coord.longitude)); + latitude = roundCoord(parseFloat(coord.latitude)); + longitude = roundCoord(parseFloat(coord.longitude)); elevation = parseFloat(coord.elevation) || 0; } diff --git a/src/editor/components/modals/GeoModal/GeoModal.component.jsx b/src/editor/components/modals/GeoModal/GeoModal.component.jsx index 77b074e6b..2ad27dfc4 100644 --- a/src/editor/components/modals/GeoModal/GeoModal.component.jsx +++ b/src/editor/components/modals/GeoModal/GeoModal.component.jsx @@ -16,16 +16,16 @@ const GeoModal = ({ isOpen, onClose }) => { elevation: 0 }); - const roundToSix = (num) => { - return Math.round(num * 1e6) / 1e6; + const roundCoord = (num) => { + return Math.round(num * 1e7) / 1e7; }; useEffect(() => { // get coordinate data in this format: {latitude: ..., longitude: ..., elevation: ...} const coord = AFRAME.scenes[0].getAttribute('metadata')['coord']; if (coord) { - const lat = roundToSix(parseFloat(coord.latitude)); - const lng = roundToSix(parseFloat(coord.longitude)); + const lat = roundCoord(parseFloat(coord.latitude)); + const lng = roundCoord(parseFloat(coord.longitude)); const elevation = parseFloat(coord.elevation) || 0; if (!isNaN(lat) && !isNaN(lng)) { @@ -37,8 +37,8 @@ const GeoModal = ({ isOpen, onClose }) => { const onMapClick = useCallback((event) => { setMarkerPosition((prev) => ({ ...prev, - lat: roundToSix(event.latLng.lat()), - lng: roundToSix(event.latLng.lng()) + lat: roundCoord(event.latLng.lat()), + lng: roundCoord(event.latLng.lng()) })); }, []);