feat: adjust popup and message

This commit is contained in:
dancingCycle 2022-09-19 21:34:00 +02:00
parent dfcc6b4a50
commit cf57c21428
4 changed files with 56 additions and 61 deletions

View File

@ -13,7 +13,7 @@ export default function Map({messages}) {
<>
{/*TODO remove debugging*/}
<h1>Map</h1>
<MapContainer center={position} zoom={7} scrollWheelZoom={false}>
<MapContainer center={position} zoom={6} scrollWheelZoom={false}>
<TileLayer
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"

View File

@ -17,9 +17,16 @@ const MarkerMsg = ({ index,message }) => {
icon={iconBfly}
>
<Popup>
route id: {message.routeId}
ts creation: {message.tsMsgCreation}
ts reception; {message.tsMsgReception}
id: {message.id} <br/>
vehicle id: {message.vehicleId} <br/>
route id: {message.routeId} <br/>
ts creation vehicle: {message.tsMsgCreationVehicle} <br/>
ts creation ITCS: {message.tsMsgCreationItcs} <br/>
ts reception client; {message.tsMsgReception} <br/>
trip id: {message.tripId} <br/>
route id: {message.routeId} <br/>
lat: {message.lat} <br/>
lon: {message.lon} <br/>
</Popup>
</Marker>
</>

View File

@ -15,73 +15,61 @@ export default function parseMessages(buffer){
let incrementality;
/*This timestamp identifies the moment when the content of this feed has been created (in server time). In POSIX time (i.e., number of seconds since January 1st 1970 00:00:00 UTC). To avoid time skew between systems producing and consuming realtime information it is strongly advised to derive timestamp from a time server. It is completely acceptable to use Stratum 3 or even lower strata servers since time differences up to a couple of seconds are tolerable.*/
let timestamp = null;
let timestampFeed = null;
if (feed.header) {
//console.log('getVehPos() header available');
gtfs_realtime_version=feed.header.gtfs_realtime_version;
incrementality=feed.header.incrementality;
timestamp=feed.header.timestamp;
if(gtfs_realtime_version && incrementality, timestamp){
//console.log(`getVehPos() gtfs_realtime_version: ${gtfs_realtime_version}, incrementaltiy: ${incrementality}, timestamp: ${timestamp} available`);
}
timestampFeed=feed.header.timestamp;
}else{
console.error('getVehPos() header NOT available');
}
feed.entity.forEach(entity => {
/*Data about the realtime position of a vehicle.*/
const vehiclePos = entity.vehicle;
if (vehiclePos) {
//console.log('getVehPos() vehiclePos available');
const { trip, position, vehicle } = vehiclePos;
if (trip && position && vehicle) {
const {trip_id, route_id, direction_id, start_time, start_date, schedule_relationship}=trip;
if(trip_id){
//console.log(`getVehPos() trip_id:${trip_id} available`);
}else{
console.log(`getVehPos() trip_id NOT available`);
}
if(route_id){
//console.log(`getVehPos() route_id:${route_id} available`);
}else{
console.log(`getVehPos() route_id NOT available`);
}
if(direction_id){
//console.log(`getVehPos() direction_id:${direction_id} available`);
}else{
console.log(`getVehPos() direction_id NOT available`);
}
const {latitude, longitude, bearing, odometer, speed}=position;
if(latitude){
//console.log(`getVehPos() latitude:${latitude} available`);
}
if(longitude){
//console.log(`getVehPos() longitude:${longitude} available`);
}
//remove tailing dot
//match a dot when it is followed by a whitespace or the end of the string
/*TODO Is this precaution required?*/
let latFormed = latitude.toString().replace(/\.+$/, "");
//console.log(`getVehPos() latFormed:${latFormed}`);
latFormed=charIntoString(latFormed,latFormed.length - 7,'.');
//console.log(`getVehPos() latFormed:${latFormed}`);
let lonFormed = longitude.toString().replace(/\.+$/, "");
lonFormed=charIntoString(lonFormed,lonFormed.length - 7,'.');
//console.log(`getVehPos() lonFormed:${lonFormed}`);
const now= new Date();
const message={
headerGtfsRealtimeVersion: gtfs_realtime_version === undefined ? -1 : parseInt(gtfs_realtime_version,10) || -2,
headerIncrementality: incrementality === undefined ? -1 : parseInt(incrementality,10) || -2,
/*ts msg creation at server in s*/
tsMsgCreation: timestamp === undefined ? -1 : parseInt(timestamp,10) || -2,
/*ts msg reception at client in ms and convert to s*/
tsMsgReception: Math.floor(now.getTime() / 1000),
routeId: route_id === undefined ? -1 : parseInt(route_id,10) || -2,
lat: latFormed === undefined ? -360 : latFormed,
lon: lonFormed === undefined ? -720 : lonFormed,
};
messages.push(message);
} else {
console.error('getVehPos() trip, position & vehicle NOT unavailable ');
}
/*The Trip that this vehicle is serving.*/
const trip=vehiclePos.trip;
/*Additional information on the vehicle that is serving this trip.*/
const vehicle=vehiclePos.vehicle;
/*Current position of this vehicle.*/
const position=vehiclePos.position;
/*Moment at which the vehicle's position was measured. In POSIX time (i.e., number of seconds since January 1st 1970 00:00:00 UTC).*/
const vehPosTimestamp=vehiclePos.timestamp;
//remove tailing dot
//match a dot when it is followed by a whitespace or the end of the string
/*TODO Is this precaution required?*/
let latFormed = position.latitude === undefined ? -360 : position.latitude.toString().replace(/\.+$/, "");
//console.log(`getVehPos() latFormed:${latFormed}`);
latFormed=charIntoString(latFormed,latFormed.length - 7,'.');
//console.log(`getVehPos() latFormed:${latFormed}`);
let lonFormed = position.longitude === undefined ? -720 : position.longitude.toString().replace(/\.+$/, "");
lonFormed=charIntoString(lonFormed,lonFormed.length - 7,'.');
//console.log(`getVehPos() lonFormed:${lonFormed}`);
const now= new Date();
const message={
headerGtfsRealtimeVersion: gtfs_realtime_version === undefined ? -1 : parseInt(gtfs_realtime_version,10) || -2,
/*ts msg creation at vehicle in s*/
tsMsgCreationVehicle: vehPosTimestamp === undefined ? -1 : parseInt(vehPosTimestamp,10) || -2,
/*ts msg creation at ITCS in s*/
tsMsgCreationItcs: timestampFeed === undefined ? -1 : parseInt(timestampFeed,10) || -2,
/*ts msg reception at client in ms and convert to s*/
tsMsgReception: Math.floor(now.getTime() / 1000),
/*Feed-unique identifier for this entity. The ids are used only to provide incrementality support.*/
//TODO Shall id be matched with IVU tenant?
id: entity.id === undefined ? -1 : parseInt(entity.id,10) || -2,
/*Internal system identification of the vehicle.*/
//TODO Shall id be matched with IVU vehicle id?
vehicleId: vehicle.id === undefined ? '' : vehicle.id,
/*The trip_id from the GTFS feed that this selector refers to.*/
tripId: trip.trip_id === undefined ? -1 : parseInt(trip.trip_id,10) || -2,
/*The route_id from the GTFS that this selector refers to.*/
routeId: trip.route_id === undefined ? -1 : parseInt(trip.route_id,10) || -2,
lat: latFormed,
lon: lonFormed,
};
messages.push(message);
} else {
console.error('getVehPos() vehiclePos NOT available');
}

2
package-lock.json generated
View File

@ -27,7 +27,7 @@
"css-loader": "6.7.1",
"html-webpack-plugin": "5.5.0",
"style-loader": "3.3.1",
"svg-url-loader": "^8.0.0",
"svg-url-loader": "8.0.0",
"webpack": "5.74.0",
"webpack-cli": "4.10.0",
"webpack-dev-server": "4.11.0",