-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
221 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{} | ||
{"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "LineString", "coordinates": [[-95.08141793795379, 29.564580908696907], [-95.0814563954045, 29.56467675123534], [-95.0814797733473, 29.56480640650252], [-95.08157335667411, 29.564815758720055], [-95.08157234926806, 29.56492419510491], [-95.08157315565839, 29.564959141875754]]}, "properties": {"name": "Rover Path"}}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"type": "FeatureCollection", "features": []} | ||
{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"Name": "hey"}, "geometry": {"coordinates": [-95.08133613847313, 29.56504641409886], "type": "Point"}, "id": 102}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
#navPage { | ||
flex-direction: column; | ||
} | ||
|
||
#conti { | ||
display: flex; | ||
flex-direction: row; | ||
height: 90vh | ||
} | ||
|
||
#navMap { | ||
width: 70%; | ||
} | ||
|
||
#navControls { | ||
width: 30%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,118 @@ | ||
import React from "react"; | ||
import React, { useState, useEffect, useRef } from "react"; | ||
import "../../pages-style/page.css"; | ||
import "../../pages-style/nav.css"; | ||
import Map from "../../components/Map"; | ||
|
||
function nav() { | ||
function Nav() { | ||
const [points, setPoints] = useState([]); | ||
const [startId, setStartId] = useState(''); | ||
const [endId, setEndId] = useState(''); | ||
const intervalRef = useRef(null); | ||
|
||
useEffect(() => { | ||
fetch('http://localhost:8000/get_geojson') | ||
.then(response => response.json()) | ||
.then(data => { | ||
const validPoints = data.features.filter(point => | ||
point.geometry.type === 'Point' && point.properties.Name | ||
); | ||
setPoints(validPoints); | ||
}) | ||
.catch(error => console.error('Error fetching points:', error)); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (startId && endId) { | ||
calculateShortestPath(startId, endId); | ||
intervalRef.current = setInterval(() => { | ||
calculateShortestPath(startId, endId); | ||
}, 3000); | ||
|
||
return () => clearInterval(intervalRef.current); | ||
} | ||
}, [startId, endId]); | ||
|
||
const calculateShortestPath = (startId, endId) => { | ||
const data = { | ||
start_id: startId, | ||
end_id: endId | ||
}; | ||
|
||
fetch('http://localhost:8000/get_shortest_path', { | ||
method: 'POST', | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify(data) | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
const distance = data.distance; | ||
if (distance < 10) { | ||
clearInterval(intervalRef.current); | ||
} | ||
console.log('Distance:', distance); | ||
}) | ||
.catch((error) => { | ||
console.error('Error:', error); | ||
}); | ||
}; | ||
|
||
const handleFormSubmit = (e) => { | ||
e.preventDefault(); | ||
if (startId && endId) { | ||
clearInterval(intervalRef.current); | ||
calculateShortestPath(startId, endId); | ||
} | ||
}; | ||
|
||
return ( | ||
<div id="navPage" className="pagecontainer"> | ||
<h1>Navigation</h1> | ||
<div className="map-container"> | ||
<Map /> | ||
<div id="navPage" className="pagecontainer"> | ||
<h1>Navigation</h1> | ||
<div id="conti"> | ||
<div className="map-container" id="navMap"> | ||
<Map zoom={19} /> | ||
</div> | ||
<div id="navControls"> | ||
<form onSubmit={handleFormSubmit}> | ||
<div> | ||
<h3>Select Start Point</h3> | ||
<select | ||
value={startId} | ||
onChange={(e) => setStartId(parseInt(e.target.value, 10))} | ||
required | ||
> | ||
<option value="" disabled>Select start point</option> | ||
{points.map(point => ( | ||
<option key={point.id} value={point.id}> | ||
{point.properties.Name} | ||
</option> | ||
))} | ||
</select> | ||
</div> | ||
<div> | ||
<h3>Select End Point</h3> | ||
<select | ||
value={endId} | ||
onChange={(e) => setEndId(parseInt(e.target.value, 10))} | ||
required | ||
> | ||
<option value="" disabled>Select end point</option> | ||
{points.map(point => ( | ||
<option key={point.id} value={point.id}> | ||
{point.properties.Name} | ||
</option> | ||
))} | ||
</select> | ||
</div> | ||
<button type="submit">Submit</button> | ||
</form> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
); | ||
} | ||
|
||
export default nav; | ||
export default Nav; |
Oops, something went wrong.