@@ -11,12 +11,12 @@ export class Route extends Record
1111
1212 if ( ! ( 'name' in data ) )
1313 throw new FeedError ( `Missing required field "name" in route with id "${ this . id } "` ) ;
14+ if ( ! ( 'headsign' in data ) )
15+ throw new FeedError ( `Missing required field "headsign" in route with id "${ this . id } "` ) ;
1416 if ( ! ( 'agency' in data ) )
1517 throw new FeedError ( `Missing required field "agency" in route with id "${ this . id } "` ) ;
1618 if ( ! ( 'modality' in data ) )
1719 throw new FeedError ( `Missing required field "modality" in route with id "${ this . id } "` ) ;
18- if ( ! ( 'headsign' in data ) )
19- throw new FeedError ( `Missing required field "modality" in route with id "${ this . id } "` ) ;
2020 if ( ! ( 'stops' in data ) )
2121 throw new FeedError ( `Missing required field "stops" in route with id "${ this . id } "` ) ;
2222
@@ -32,8 +32,8 @@ export class Route extends Record
3232 this . stops = data . stops ;
3333 this . visible = data . visible ?? true ;
3434
35- this . stopAtNode = undefined ;
36- this . initialTime = data . initialTime ?? 0 ;
35+ this . _stopAtNode = data . _stopAtNode ?? undefined ;
36+ this . _initialTime = data . _initialTime ?? 0 ;
3737 }
3838
3939 // Finalize loading the route
@@ -42,22 +42,16 @@ export class Route extends Record
4242 this . stops = this . stops . map ( s => s . _copy ( ) ) ;
4343
4444 // Calculate cumulative time for the stops of the route
45- let lastHeadsignSequence = null ;
45+ let lastHeadsignStopSequence = null ;
4646 for ( let [ index , stop ] of this . stops . entries ( ) ) {
47- // Set the flags of the first and last stops
48- stop . first = index === 0 ;
49- stop . last = index === this . stops . length - 1 ;
50-
51- // Set the time of the first stop
52- stop . time = index > 0 ? stop . time : 0 ;
47+ // Set the duration and cumulative time of the stop
48+ stop . duration = index > 0 ? stop . duration : 0 ;
49+ stop . _cumulativeTime = ( index > 0 ? this . stops [ index - 1 ] . _cumulativeTime : this . _initialTime ) + stop . duration ;
5350
54- // Calculate cumulative time for the stop
55- stop . cumulativeTime = ( index > 0 ? this . stops [ index - 1 ] . cumulativeTime : this . initialTime ) + stop . time ;
56-
57- // Set the actual headsign sequence of the stop
51+ // Set the headsign stop sequence of the stop
5852 if ( stop . headsign !== null )
59- lastHeadsignSequence = stop . sequence ;
60- stop . _actualHeadsignSequence = lastHeadsignSequence ;
53+ lastHeadsignStopSequence = stop . sequence ;
54+ stop . _headsignStopSequence = lastHeadsignStopSequence ;
6155 }
6256 }
6357
@@ -66,7 +60,7 @@ export class Route extends Record
6660 return {
6761 id : this . id ,
6862 name : this . _feed . applyTranslation ( this , 'name' , options ?. language ) ,
69- headsign : this . _feed . applyTranslation ( this , [ 'stops' , this . stopAtNode ?. _actualHeadsignSequence , 'headsign' ] , options ?. language )
63+ headsign : this . _feed . applyTranslation ( this , [ 'stops' , this . _stopAtNode ?. _actualHeadsignSequence , 'headsign' ] , options ?. language )
7064 ?? this . _feed . applyTranslation ( this , 'headsign' , options ?. language ) ,
7165 abbr : this . _feed . applyTranslation ( this , 'abbr' , options ?. language ) ,
7266 description : this . _feed . applyTranslation ( this , 'description' , options ?. language ) ,
@@ -76,8 +70,9 @@ export class Route extends Record
7670 modality : this . modality . toJSON ( options ) ,
7771 icon : this . icon ,
7872 stops : this . stops . map ( stop => stop . toJSON ( options ) ) ,
79- stopAtNode : this . stopAtNode ?. toJSON ( options ) ,
8073 visible : this . visible ,
74+
75+ stopAtNode : this . _stopAtNode ?. toJSON ( options ) ,
8176 } ;
8277 }
8378
@@ -122,31 +117,26 @@ export class Route extends Record
122117 }
123118
124119 // Slice the route to begin at the specified sequence
125- _sliceBeginningAtSequence ( seqence ) {
120+ _sliceBeginningAtSequence ( seqence , modifiedProps = { } ) {
126121 let index = this . getStopIndexWithSequence ( seqence ) ;
127- return index > - 1 ? this . _copy ( { stops : this . stops . slice ( index ) } ) : this . _copy ( ) ;
122+ return index > - 1 ? this . _copy ( { ... modifiedProps , stops : this . stops . slice ( index ) } ) : this . _copy ( modifiedProps ) ;
128123 }
129124
130125 // Slice the route to end at the specified sequence
131- _sliceEndingAtSequence ( seqence ) {
126+ _sliceEndingAtSequence ( seqence , modifiedProps = { } ) {
132127 let index = this . getStopIndexWithSequence ( seqence ) ;
133- return index > - 1 ? this . _copy ( { stops : this . stops . slice ( 0 , index + 1 ) } ) : this . _copy ( ) ;
128+ return index > - 1 ? this . _copy ( { ... modifiedProps , stops : this . stops . slice ( 0 , index + 1 ) } ) : this . _copy ( modifiedProps ) ;
134129 }
135130
136131 // Slice the route to begin at the specified node
137- _sliceBeginningAtNode ( node ) {
132+ _sliceBeginningAtNode ( node , modifiedProps = { } ) {
138133 let index = this . getStopIndexAtNode ( node ) ;
139- return index > - 1 ? this . _copy ( { stops : this . stops . slice ( index ) } ) : this . _copy ( ) ;
134+ return index > - 1 ? this . _copy ( { ... modifiedProps , stops : this . stops . slice ( index ) } ) : this . _copy ( modifiedProps ) ;
140135 }
141136
142137 // Slice the route to end at the specified node
143- _sliceEndingAtNode ( node ) {
138+ _sliceEndingAtNode ( node , modifiedProps = { } ) {
144139 let index = this . getStopIndexAtNode ( node ) ;
145- return index > - 1 ? this . _copy ( { stops : this . stops . slice ( 0 , index + 1 ) } ) : this . _copy ( ) ;
146- }
147-
148- // Apply an initial time to the route
149- _withInitialTime ( initialTime ) {
150- return this . _copy ( { initialTime} ) ;
140+ return index > - 1 ? this . _copy ( { ...modifiedProps , stops : this . stops . slice ( 0 , index + 1 ) } ) : this . _copy ( modifiedProps ) ;
151141 }
152142}
0 commit comments