Skip to content

Commit

Permalink
round coord to 7 for 1cm precision
Browse files Browse the repository at this point in the history
  • Loading branch information
Algorush committed May 31, 2024
1 parent f28ac1f commit fdbfd27
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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() {
Expand All @@ -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;
}

Expand Down
12 changes: 6 additions & 6 deletions src/editor/components/modals/GeoModal/GeoModal.component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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())
}));
}, []);

Expand Down

0 comments on commit fdbfd27

Please sign in to comment.