Okay, I understand. I apologize that the previous example wasn't up to your standards. Let's try again, focusing on a more visually appealing and slightly more interactive experience. This version will still use hardcoded data, but it will include:
- Improved styling with a more modern look and feel.
- Tooltips on the map markers showing shipment details.
- Clickable table rows that highlight the corresponding marker on the map.
- A function to center the map around a shipment when its table row is clicked.
Here's the updated HTML/CSS/JavaScript code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pumpkin Shipment Tracker</title>
<!-- Leaflet CSS -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" integrity="sha512-xodZBNTC5n17Xt2atTPvknnqHuS+hQqEE5ZZyv3q9s6aK/9yK1VjQk3uJuKkEjvHAjnLcHs0QZXIJMCGpH2Q==" crossorigin=""/>
<!-- Font Awesome CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" integrity="sha512-9usAa10IRO0HhonpyAIVpjrylPvoDwiPUiKdWk5t3PyolY1cOd4DSE0Ga+ri4AuTroPR5aQvXU9xC6qOPnzFeg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 0;
background-color: #f8f9fa; /* Light gray background */
color: #343a40; /* Dark gray text */
}
.container {
width: 90%;
max-width: 1200px;
margin: 30px auto;
background-color: #fff;
padding: 30px;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
color: #e67e22; /* Pumpkin Orange */
margin-bottom: 25px;
}
#map {
height: 400px;
width: 100%;
margin-bottom: 25px;
border-radius: 10px;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}
table {
width: 100%;
border-collapse: collapse;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}
th, td {
padding: 15px;
text-align: left;
border-bottom: 1px solid #dee2e6; /* Light gray border */
}
th {
background-color: #e67e22; /* Pumpkin Orange */
color: #fff;
font-weight: 500;
text-transform: uppercase;
letter-spacing: 0.05em;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #ddd;
cursor: pointer; /* Make the cursor indicate clickability */
}
/* Mobile Styles */
@media (max-width: 768px) {
.container {
width: 95%;
padding: 20px;
}
table {
font-size: 0.9em;
}
th, td {
padding: 12px;
}
}
/* Active Table Row Style */
.active-row {
background-color: #c9d9f0 !important; /* Softer Blue for active row */
}
/* Custom Map Marker Style */
.pumpkin-marker {
background: #e67e22; /* Pumpkin Orange */
border: 3px solid #fff;
border-radius: 50%;
width: 20px;
height: 20px;
display: block;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<h1>Pumpkin Shipment Tracker</h1>
<div id="map"></div>
<table>
<thead>
<tr>
<th>Shipment ID</th>
<th>Origin</th>
<th>Destination</th>
<th>Status</th>
<th>Location (Lat/Lon)</th>
</tr>
</thead>
<tbody id="shipment-table-body">
<tr data-shipment-id="SHIP-001" data-lat="40.7128" data-lng="-74.0060">
<td>SHIP-001</td>
<td>USA</td>
<td>Canada</td>
<td>In Transit</td>
<td>40.7128, -74.0060</td>
</tr>
<tr data-shipment-id="SHIP-002" data-lat="52.5200" data-lng="13.4050">
<td>SHIP-002</td>
<td>Mexico</td>
<td>Germany</td>
<td>Delivered</td>
<td>52.5200, 13.4050</td>
</tr>
<tr data-shipment-id="SHIP-003" data-lat="37.7749" data-lng="-122.4194">
<td>SHIP-003</td>
<td>Spain</td>
<td>Japan</td>
<td>Delayed</td>
<td>37.7749, -122.4194</td>
</tr>
</tbody>
</table>
</div>
<!-- Leaflet JavaScript -->
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js" integrity="sha512-XQoYMMe3QxpFgCQRRfZJkNR/c8R5bykbU+n9UhjL2opDyPZV9njqaaKEEvrHgU0gC0mRZxUwnTgW4LuvKS7KMQ==" crossorigin=""></script>
<script>
// Initialize Map
const map = L.map('map').setView([0, 0], 2);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
// Shipment Data (Hardcoded)
const shipments = [
{ id: 'SHIP-001', origin: 'USA', destination: 'Canada', status: 'In Transit', lat: 40.7128, lng: -74.0060 }, // New York
{ id: 'SHIP-002', origin: 'Mexico', destination: 'Germany', status: 'Delivered', lat: 52.5200, lng: 13.4050 }, // Berlin
{ id: 'SHIP-003', origin: 'Spain', destination: 'Japan', status: 'Delayed', lat: 37.7749, lng: -122.4194 } // San Francisco
];
// Create Custom Markers
const pumpkinIcon = L.divIcon({
className: 'pumpkin-marker',
iconSize: [20, 20],
iconAnchor: [10, 10],
popupAnchor: [0, -10]
});
const markers = {}; // Store markers for later access
// Add Markers to the Map and Store in Markers object
shipments.forEach(shipment => {
const marker = L.marker([shipment.lat, shipment.lng], { icon: pumpkinIcon })
.bindTooltip(
`<b>Shipment ID:</b> ${shipment.id}<br>` +
`<b>Origin:</b> ${shipment.origin}<br>` +
`<b>Destination:</b> ${shipment.destination}<br>` +
`<b>Status:</b> ${shipment.status}`
).addTo(map);
markers[shipment.id] = marker; // Store marker reference
});
// Calculate Centroid and Set Map View
function setMapView(shipments) {
if (shipments.length > 0) {
let sumLat = 0;
let sumLng = 0;
shipments.forEach(shipment => {
sumLat += shipment.lat;
sumLng += shipment.lng;
});
const avgLat = sumLat / shipments.length;
const avgLng = sumLng / shipments.length;
map.setView([avgLat, avgLng], 4);
}
}
setMapView(shipments);
// Handle Table Row Clicks
const tableBody = document.getElementById('shipment-table-body');
tableBody.addEventListener('click', function(event) {
const target = event.target.closest('tr');
if (!target) return; // Exit if not clicking on a row
const shipmentId = target.dataset.shipmentId;
const lat = parseFloat(target.dataset.lat);
const lng = parseFloat(target.dataset.lng);
// Center map on the shipment
map.setView([lat, lng], 10); // Adjust zoom level as needed
// Remove active class from other rows
document.querySelectorAll('.active-row').forEach(row => row.classList.remove('active-row'));
// Add active class to the clicked row
target.classList.add('active-row');
//Open Popup
markers[shipmentId].openPopup();
});
</script>
</body>
</html>