-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtripPlanner.js
89 lines (80 loc) · 3.33 KB
/
tripPlanner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
function planTrip() {
// Get input values
const startLocation = document.getElementById('startLocation').value;
const destination = document.getElementById('destination').value;
const transportMode = document.getElementById('transportMode').value;
const departureTime = document.getElementById('departureTime').value;
// Validate inputs
if (!startLocation || !destination) {
alert('Please fill in both start location and destination');
return;
}
// Show all sections
document.querySelector('.trip-summary').style.display = 'block';
document.querySelector('.route-details').style.display = 'block';
document.querySelector('.weather-info').style.display = 'block';
document.querySelector('.additional-info').style.display = 'block';
// Update trip summary
document.getElementById('summary-start').textContent = startLocation;
document.getElementById('summary-destination').textContent = destination;
document.getElementById('summary-mode').textContent = transportMode.charAt(0).toUpperCase() + transportMode.slice(1);
document.getElementById('summary-departure').textContent = formatDateTime(departureTime);
// Mock data for demonstration
const mockTripData = {
duration: '1 hour 30 minutes',
distance: '45 kilometers',
steps: [
'Head north on Main St',
'Turn right onto Oak Ave',
'Continue onto Highway 101',
'Take exit 25 towards Downtown',
'Arrive at destination'
],
weather: {
temperature: '22°C',
condition: 'Partly Cloudy',
precipitation: '10%'
},
alerts: {
traffic: 'Minor delays on Highway 101',
transit: 'All services running normally'
}
};
// Update duration and distance
document.getElementById('summary-duration').textContent = mockTripData.duration;
document.getElementById('summary-distance').textContent = mockTripData.distance;
// Update route steps
const routeSteps = document.getElementById('route-steps');
routeSteps.innerHTML = '';
mockTripData.steps.forEach(step => {
const li = document.createElement('li');
li.textContent = step;
routeSteps.appendChild(li);
});
// Update weather information
const weatherDetails = document.getElementById('weather-details');
weatherDetails.innerHTML = `
<p><strong>Temperature:</strong> ${mockTripData.weather.temperature}</p>
<p><strong>Condition:</strong> ${mockTripData.weather.condition}</p>
<p><strong>Precipitation Chance:</strong> ${mockTripData.weather.precipitation}</p>
`;
// Update additional information
document.getElementById('traffic-alerts').innerHTML = `
<p><strong>Traffic Alert:</strong> ${mockTripData.alerts.traffic}</p>
`;
document.getElementById('transit-updates').innerHTML = `
<p><strong>Transit Update:</strong> ${mockTripData.alerts.transit}</p>
`;
}
function formatDateTime(dateTimeString) {
if (!dateTimeString) return 'Not specified';
const dateTime = new Date(dateTimeString);
return dateTime.toLocaleString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
}