Skip to content

Commit

Permalink
add elevation field
Browse files Browse the repository at this point in the history
  • Loading branch information
Algorush committed Jun 3, 2024
1 parent b1aef0d commit c828843
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/editor/components/modals/GeoModal/GeoModal.component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ const GeoModal = ({ isOpen, onClose }) => {

const [markerPosition, setMarkerPosition] = useState({
lat: 37.7637072, // lat: 37.76370724481858, lng: -122.41517686259827
lng: -122.4151768,
elevation: 10
lng: -122.4151768
});

const [elevation, setElevation] = useState(10);
const [autocomplete, setAutocomplete] = useState(null);

const roundCoord = (num) => {
Expand All @@ -42,18 +41,20 @@ const GeoModal = ({ isOpen, onClose }) => {
const elevation = parseFloat(coord.elevation) || 0;

if (!isNaN(lat) && !isNaN(lng)) {
setMarkerPosition({ lat, lng, elevation });
setMarkerPosition({ lat, lng });
}
if (!isNaN(elevation)) {
setElevation(elevation);
}
}
}
}, [isOpen]);

const onMapClick = useCallback((event) => {
setMarkerPosition((prev) => ({
...prev,
setMarkerPosition({
lat: roundCoord(event.latLng.lat()),
lng: roundCoord(event.latLng.lng())
}));
});
}, []);

const handleCoordinateChange = (value) => {
Expand All @@ -64,12 +65,16 @@ const GeoModal = ({ isOpen, onClose }) => {
if (!isNaN(newLat) && !isNaN(newLng)) {
setMarkerPosition({
lat: roundCoord(newLat),
lng: roundCoord(newLng),
height: markerPosition.height
lng: roundCoord(newLng)
});
}
};

const handleElevationChange = (value) => {
const newElevation = parseFloat(value) || 0;
setElevation(newElevation);
};

const onAutocompleteLoad = useCallback((autocompleteInstance) => {
setAutocomplete(autocompleteInstance);
}, []);
Expand All @@ -80,8 +85,7 @@ const GeoModal = ({ isOpen, onClose }) => {
if (place && place.geometry) {
const location = {
lat: place.geometry.location.lat(),
lng: place.geometry.location.lng(),
height: 0
lng: place.geometry.location.lng()
};
setMarkerPosition(location);
}
Expand All @@ -101,7 +105,6 @@ const GeoModal = ({ isOpen, onClose }) => {
const onSaveHandler = () => {
const latitude = markerPosition.lat;
const longitude = markerPosition.lng;
const elevation = markerPosition.elevation;
AFRAME.scenes[0].setAttribute('metadata', 'coord', {
latitude: latitude,
longitude: longitude,
Expand Down Expand Up @@ -172,6 +175,15 @@ const GeoModal = ({ isOpen, onClose }) => {
onChange={handleCoordinateChange}
></Input>
</div>
<div>
<p>Elevation</p>
<Input
leadingIcon={<p className={styles.iconGeo}>Height</p>}
value={elevation}
placeholder="None"
onChange={handleElevationChange}
></Input>
</div>
</div>

<div className={styles.controlButtons}>
Expand Down

0 comments on commit c828843

Please sign in to comment.