Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"ol": ">=9"
},
"devDependencies": {
"@asyncapi/cli": "^3.2.0",
"@asyncapi/generator": "^2.7.1",
"@asyncapi/modelina": "^5.3.7",
"@babel/preset-env": "^7.28.0",
"@babel/preset-typescript": "^7.27.1",
"@commitlint/cli": "19.8.1",
Expand All @@ -34,6 +37,7 @@
"@types/lodash.debounce": "4.0.9",
"@types/lodash.throttle": "4.1.9",
"@types/mapbox-gl": "3.4.1",
"@types/node": "^24.3.0",
"@types/offscreencanvas": "2019.7.3",
"@types/topojson": "3.2.6",
"@types/uuid": "10.0.0",
Expand Down Expand Up @@ -113,6 +117,7 @@
"tsc": "tsc",
"types:backend": " yarn types:stops && yarn types:routing && yarn types:moco",
"types:moco": "openapi-typescript https://moco.dev.geops.io/api/v1/swagger/?format=openapi --output src/types/moco.d.ts",
"types:realtime": "asyncapi generate models typescript https://backend.developer.geops.io/tralis-docs/asyncapi.json --output src/types/realtime-asyncapi-types --tsModelType=interface --tsRawPropertyNames --tsEnumType=enum && eslint --fix src/types/realtime-asyncapi-types/*.ts",
"types:routing": "openapi-typescript https://developer.geops.io/swagger/routing.json --output src/types/routing.d.ts",
"types:stops": "openapi-typescript https://developer.geops.io/swagger/stops.json --output src/types/stops.d.ts",
"up": "yarn upgrade-interactive --latest"
Expand Down
2 changes: 1 addition & 1 deletion src/common/styles/realtimeDefaultStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
getRadius = () => {
return 0;
},
getText = (text?: string) => {
getText = (text?: null | string) => {
return text;
},
getTextColor = () => {
Expand Down Expand Up @@ -249,12 +249,12 @@
} = trajectory.properties;
let { color, name, text_color: textColor } = line || {};

name = getText(name);

Check failure on line 252 in src/common/styles/realtimeDefaultStyle.ts

View workflow job for this annotation

GitHub Actions / build

Argument of type 'string | null | undefined' is not assignable to parameter of type 'string | undefined'.

const cancelled = state === 'JOURNEY_CANCELLED';

if (!type) {
type = 'rail';

Check failure on line 257 in src/common/styles/realtimeDefaultStyle.ts

View workflow job for this annotation

GitHub Actions / build

Type '"rail"' is not assignable to type '"MultiLineString"'.
}

if (!name) {
Expand Down Expand Up @@ -291,7 +291,7 @@
if (useDelayStyle) {
key += `${operatorProvidesRealtime}${delay}${cancelled}`;
} else {
color = color || getBgColor(type, line);

Check failure on line 294 in src/common/styles/realtimeDefaultStyle.ts

View workflow job for this annotation

GitHub Actions / build

Argument of type 'Line | null | undefined' is not assignable to parameter of type 'RealtimeLine | undefined'.
key += `${color}`;

if (isDisplayStrokeAndDelay) {
Expand All @@ -304,7 +304,7 @@
if (useDelayStyle) {
textColor = '#000000';
} else {
textColor = textColor || getTextColor(type, line);

Check failure on line 307 in src/common/styles/realtimeDefaultStyle.ts

View workflow job for this annotation

GitHub Actions / build

Argument of type 'Line | null | undefined' is not assignable to parameter of type 'RealtimeLine | undefined'.
}

key += `${name}${textColor}`;
Expand All @@ -327,7 +327,7 @@
delayBg = getDelayBgCanvas(
origin,
radiusDelay,
getDelayColor(delay, cancelled),

Check failure on line 330 in src/common/styles/realtimeDefaultStyle.ts

View workflow job for this annotation

GitHub Actions / build

Argument of type 'number | undefined' is not assignable to parameter of type 'number | null'.
);
}

Expand All @@ -344,14 +344,14 @@
cancelled ? 19 : 14,
Math.min(cancelled ? 19 : 17, radius * 1.2),
) * pixelRatio;
const text = getDelayText(delay, cancelled);

Check failure on line 347 in src/common/styles/realtimeDefaultStyle.ts

View workflow job for this annotation

GitHub Actions / build

Argument of type 'number | null | undefined' is not assignable to parameter of type 'number | null'.

if (text) {
delayText = getDelayTextCanvas(
text,
fontSize,
getDelayFont(fontSize, text),
getDelayColor(delay, cancelled, true),

Check failure on line 354 in src/common/styles/realtimeDefaultStyle.ts

View workflow job for this annotation

GitHub Actions / build

Argument of type 'number | null | undefined' is not assignable to parameter of type 'number | null'.
delayOutlineColor,
pixelRatio,
);
Expand All @@ -369,7 +369,7 @@
// Get the color of the vehicle
let circleFillColor = color || '#fff';
if (useDelayStyle) {
circleFillColor = getDelayColor(delay, cancelled);

Check failure on line 372 in src/common/styles/realtimeDefaultStyle.ts

View workflow job for this annotation

GitHub Actions / build

Argument of type 'number | null | undefined' is not assignable to parameter of type 'number | null'.
}

const circle = getCircleCanvas(
Expand Down
20 changes: 15 additions & 5 deletions src/common/utils/getVehiclePosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { RealtimeTrajectory } from '../../types';

export interface VehiclePosition {
coord?: Coordinate;
rotation?: number;
rotation?: null | number;
}

/**
Expand All @@ -23,7 +23,10 @@ export interface VehiclePosition {
const getVehiclePosition = (
now: number,
trajectory: {
properties: { olGeometry?: SimpleGeometry };
properties: {
coordinate?: Coordinate;
olGeometry?: SimpleGeometry;
};
} & RealtimeTrajectory,
noInterpolate: boolean,
): VehiclePosition => {
Expand Down Expand Up @@ -64,11 +67,11 @@ const getVehiclePosition = (
// So we make the choice here to display the last (or the first) position
// of an trajectory event instead of removing them, if the current date is
// outside the time intervals we display the vehicle at the last (or first) position known.
if (now < firstInterval[0]) {
if (firstInterval?.[0] && now < firstInterval[0]) {
// Display first position known.
[, , rotation] = firstInterval;
coord = geometry.getFirstCoordinate();
} else if (now > lastInterval[0]) {
} else if (lastInterval?.[0] && now > lastInterval[0]) {
// Display last position known.
[, , rotation] = lastInterval;
coord = geometry.getLastCoordinate();
Expand All @@ -79,7 +82,14 @@ const getVehiclePosition = (
const [start, startFrac] = intervals[j];
const [end, endFrac] = intervals[j + 1];

if (start <= now && now <= end) {
if (
start &&
end &&
startFrac &&
endFrac &&
start <= now &&
now <= end
) {
// interpolate position inside the time interval.
const timeFrac = Math.min((now - start) / (end - start), 1);
const geomFrac = timeFrac * (endFrac - startFrac) + startFrac;
Expand Down
11 changes: 11 additions & 0 deletions src/types/realtime-asyncapi-types/AnonymousSchema_139.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type AnonymousSchema_139 =
| 'bus'
| 'cablecar'
| 'coach'
| 'ferry'
| 'funicular'
| 'gondola'
| 'rail'
| 'subway'
| 'tram';
export default AnonymousSchema_139;
11 changes: 11 additions & 0 deletions src/types/realtime-asyncapi-types/AnonymousSchema_226.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type AnonymousSchema_226 =
| 'bus'
| 'cablecar'
| 'coach'
| 'ferry'
| 'funicular'
| 'gondola'
| 'rail'
| 'subway'
| 'tram';
export default AnonymousSchema_226;
8 changes: 8 additions & 0 deletions src/types/realtime-asyncapi-types/AnonymousSchema_236.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type AnonymousSchema_236 =
| 'BOARDING'
| 'JOURNEY_CANCELLED'
| 'LEAVING'
| 'PENDING'
| 'STOP_CANCELLED'
| 'TIME_BASED';
export default AnonymousSchema_236;
8 changes: 8 additions & 0 deletions src/types/realtime-asyncapi-types/AnonymousSchema_243.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type AnonymousSchema_243 =
| 'BOARDING'
| 'JOURNEY_CANCELLED'
| 'LEAVING'
| 'PENDING'
| 'STOP_CANCELLED'
| 'TIME_BASED';
export default AnonymousSchema_243;
2 changes: 2 additions & 0 deletions src/types/realtime-asyncapi-types/AnonymousSchema_65.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type AnonymousSchema_65 = 'BOARDING' | 'DRIVING' | 'JOURNEY_CANCELLED';
export default AnonymousSchema_65;
12 changes: 12 additions & 0 deletions src/types/realtime-asyncapi-types/BufferMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type ClientReference from './ClientReference';
import type DeletedVehicleMessage from './DeletedVehicleMessage';
import type PartialTrajectoryMessage from './PartialTrajectoryMessage';
import type Source from './Source';
interface BufferMessage {
additionalProperties?: Map<string, any>;
client_reference: ClientReference;
content: (DeletedVehicleMessage | null | PartialTrajectoryMessage)[];
source: Source.BUFFER;
timestamp: number;
}
export default BufferMessage;
2 changes: 2 additions & 0 deletions src/types/realtime-asyncapi-types/ClientReference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type ClientReference = '';
export default ClientReference;
2 changes: 2 additions & 0 deletions src/types/realtime-asyncapi-types/Content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type Content = 'PONG';
export default Content;
10 changes: 10 additions & 0 deletions src/types/realtime-asyncapi-types/DeletedVehicleMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type ClientReference from './ClientReference';
import type Source from './Source';
interface DeletedVehicleMessage {
additionalProperties?: Map<string, any>;
client_reference: ClientReference;
content: string;
source: Source.DELETED_VEHICLES;
timestamp: number;
}
export default DeletedVehicleMessage;
15 changes: 15 additions & 0 deletions src/types/realtime-asyncapi-types/FullTrajectory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type FullTrajectoryProperties from './FullTrajectoryProperties';
import type GeometryCollectionGeometry from './GeometryCollectionGeometry';
import type LineStringGeometry from './LineStringGeometry';
import type MultiLineStringGeometry from './MultiLineStringGeometry';
import type ReservedType from './ReservedType';
interface FullTrajectory {
additionalProperties?: Map<string, any>;
geometry:
| GeometryCollectionGeometry
| LineStringGeometry
| MultiLineStringGeometry;
properties: FullTrajectoryProperties;
type: ReservedType.FEATURE;
}
export default FullTrajectory;
10 changes: 10 additions & 0 deletions src/types/realtime-asyncapi-types/FullTrajectoryCollection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type FullTrajectory from './FullTrajectory';
import type FullTrajectoryCollectionProperties from './FullTrajectoryCollectionProperties';
import type ReservedType from './ReservedType';
interface FullTrajectoryCollection {
additionalProperties?: Map<string, any>;
features: FullTrajectory[];
properties: FullTrajectoryCollectionProperties;
type: ReservedType.FEATURE_COLLECTION;
}
export default FullTrajectoryCollection;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
interface FullTrajectoryCollectionProperties {
additionalProperties?: Map<string, any>;
gen_level?: null | number;
gen_range: number[];
graph?: null | string;
license?: null | string;
licenseNote?: null | string;
licenseUrl?: null | string;
operator?: null | string;
operatorUrl?: null | string;
publisher?: null | string;
publisherUrl?: null | string;
tenant?: string;
train_id: string;
}
export default FullTrajectoryCollectionProperties;
9 changes: 9 additions & 0 deletions src/types/realtime-asyncapi-types/FullTrajectoryMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type FullTrajectoryCollection from './FullTrajectoryCollection';
interface FullTrajectoryMessage {
additionalProperties?: Map<string, any>;
client_reference: string;
content: FullTrajectoryCollection | null;
source: string;
timestamp: number;
}
export default FullTrajectoryMessage;
15 changes: 15 additions & 0 deletions src/types/realtime-asyncapi-types/FullTrajectoryProperties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type AnonymousSchema_139 from './AnonymousSchema_139';
interface FullTrajectoryProperties {
additionalProperties?: Map<string, any>;
event_timestamp?: null | number;
gen_level?: null | number;
gen_range: null | number[];
graph?: null | string;
journey_id: number;
line_id: number;
line_name?: null | string;
stroke?: null | string;
train_id: string;
type?: AnonymousSchema_139 | null;
}
export default FullTrajectoryProperties;
14 changes: 14 additions & 0 deletions src/types/realtime-asyncapi-types/GeometryCollectionGeometry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type LineStringGeometry from './LineStringGeometry';
import type MultiLineStringGeometry from './MultiLineStringGeometry';
import type MultiPointGeometry from './MultiPointGeometry';
import type ReservedType from './ReservedType';
interface GeometryCollectionGeometry {
additionalProperties?: Map<string, any>;
geometries: (
| LineStringGeometry
| MultiLineStringGeometry
| MultiPointGeometry
)[];
type: ReservedType.GEOMETRY_COLLECTION;
}
export default GeometryCollectionGeometry;
6 changes: 6 additions & 0 deletions src/types/realtime-asyncapi-types/JourneyExtraData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface JourneyExtraData {
additionalProperties?: Map<string, any>;
event_location_name?: null | string;
event_timestamp?: null | string;
}
export default JourneyExtraData;
10 changes: 10 additions & 0 deletions src/types/realtime-asyncapi-types/Line.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
interface Line {
additionalProperties?: Map<string, any>;
color: null | string;
id: number;
name: null | string;
stroke: null | string;
tags: string[];
text_color: null | string;
}
export default Line;
7 changes: 7 additions & 0 deletions src/types/realtime-asyncapi-types/LineStringGeometry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type ReservedType from './ReservedType';
interface LineStringGeometry {
additionalProperties?: Map<string, any>;
coordinates: number[][];
type: ReservedType.LINE_STRING;
}
export default LineStringGeometry;
6 changes: 6 additions & 0 deletions src/types/realtime-asyncapi-types/LogContent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface LogContent {
additionalProperties?: Map<string, any>;
info: null | string;
warning: null | string;
}
export default LogContent;
11 changes: 11 additions & 0 deletions src/types/realtime-asyncapi-types/LogMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type ClientReference from './ClientReference';
import type LogContent from './LogContent';
import type Source from './Source';
interface LogMessage {
additionalProperties?: Map<string, any>;
client_reference: ClientReference;
content: LogContent;
source: Source.WEBSOCKET;
timestamp: number;
}
export default LogMessage;
7 changes: 7 additions & 0 deletions src/types/realtime-asyncapi-types/MultiLineStringGeometry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type ReservedType from './ReservedType';
interface MultiLineStringGeometry {
additionalProperties?: Map<string, any>;
coordinates: number[][][];
type: ReservedType.MULTI_LINE_STRING;
}
export default MultiLineStringGeometry;
7 changes: 7 additions & 0 deletions src/types/realtime-asyncapi-types/MultiPointGeometry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type ReservedType from './ReservedType';
interface MultiPointGeometry {
additionalProperties?: Map<string, any>;
coordinates: number[][];
type: ReservedType.MULTI_POINT;
}
export default MultiPointGeometry;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type OperatorProvidesRealtimeJourney = 'maybe' | 'no' | 'unknown' | 'yes';
export default OperatorProvidesRealtimeJourney;
9 changes: 9 additions & 0 deletions src/types/realtime-asyncapi-types/PartialTrajectoryMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type TrackerTrajectory from './TrackerTrajectory';
interface PartialTrajectoryMessage {
additionalProperties?: Map<string, any>;
client_reference: string;
content: null | TrackerTrajectory;
source: string;
timestamp: number;
}
export default PartialTrajectoryMessage;
11 changes: 11 additions & 0 deletions src/types/realtime-asyncapi-types/PongMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type ClientReference from './ClientReference';
import type Content from './Content';
import type Source from './Source';
interface PongMessage {
additionalProperties?: Map<string, any>;
client_reference: ClientReference;
content: Content.PONG;
source: Source.WEBSOCKET;
timestamp: number;
}
export default PongMessage;
2 changes: 2 additions & 0 deletions src/types/realtime-asyncapi-types/ReservedStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type ReservedStatus = 'open';
export default ReservedStatus;
2 changes: 2 additions & 0 deletions src/types/realtime-asyncapi-types/ReservedType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type ReservedType = 'MultiLineString';
export default ReservedType;
10 changes: 10 additions & 0 deletions src/types/realtime-asyncapi-types/SerializedCancellationChange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type AnonymousSchema_243 from './AnonymousSchema_243';
interface SerializedCancellationChange {
additionalProperties?: Map<string, any>;
new_to?: null | string;
no_stop_between?: (null | string)[];
no_stop_till?: null | string;
old_to?: null | string;
state?: AnonymousSchema_243 | null;
}
export default SerializedCancellationChange;
5 changes: 5 additions & 0 deletions src/types/realtime-asyncapi-types/Situation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface Situation {
additionalProperties?: Map<string, any>;
description: null | string;
}
export default Situation;
18 changes: 18 additions & 0 deletions src/types/realtime-asyncapi-types/Slash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type BufferMessage from './BufferMessage';
import type DeletedVehicleMessage from './DeletedVehicleMessage';
import type FullTrajectoryMessage from './FullTrajectoryMessage';
import type LogMessage from './LogMessage';
import type PartialTrajectoryMessage from './PartialTrajectoryMessage';
import type PongMessage from './PongMessage';
import type StatusMessage from './StatusMessage';
import type StopSequenceMessage from './StopSequenceMessage';
type Slash =
| BufferMessage
| DeletedVehicleMessage
| FullTrajectoryMessage
| LogMessage
| PartialTrajectoryMessage
| PongMessage
| StatusMessage
| StopSequenceMessage;
export default Slash;
2 changes: 2 additions & 0 deletions src/types/realtime-asyncapi-types/Source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type Source = 'websocket';
export default Source;
6 changes: 6 additions & 0 deletions src/types/realtime-asyncapi-types/StatusContent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type ReservedStatus from './ReservedStatus';
interface StatusContent {
additionalProperties?: Map<string, any>;
status: ReservedStatus.RESERVED_OPEN;
}
export default StatusContent;
11 changes: 11 additions & 0 deletions src/types/realtime-asyncapi-types/StatusMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type ClientReference from './ClientReference';
import type Source from './Source';
import type StatusContent from './StatusContent';
interface StatusMessage {
additionalProperties?: Map<string, any>;
client_reference: ClientReference;
content: StatusContent;
source: Source.WEBSOCKET;
timestamp: number;
}
export default StatusMessage;
Loading
Loading