Files
tlt-bus-map/client/index.html

57 lines
1.7 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bus Location Finder</title>
<style>
#map {
height: 1000px;
width: 100%;
}
</style>
</head>
<body>
<h2>Bus Location Finder</h2>
<form id="search-form">
<label for="bus-id">Enter Bus ID (TAK):</label>
<input type="text" id="bus-id" name="bus-id">
<button type="submit">Search</button>
</form>
<div id="map"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.css" />
<script src="/socket.io/socket.io.js"></script>
<script>
const socket = io();
// Stuff for the map
var map = L.map('map').setView([59.4370, 24.7536], 12);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
// Function to handle form submission
document.getElementById('search-form').addEventListener('submit', function(event) {
//event.preventDefault(); // Prevent the form from submitting normally
var tak = document.getElementById('bus-id').value.trim();
socket.emit('takSearch', tak);
});
socket.on('takSearch', function(data) {
// Process the received data and update the map accordingly
// For example:
data.forEach(function(item) {
var marker = L.marker([item.latitude, item.longitude]).addTo(map);
marker.bindPopup(`Transport Type: ${item.transportType}<br>Line Number: ${item.lineNumber}<br>TAK: ${item.tak}`);
});
});
</script>
</body>
</html>