@@ -262,29 +262,55 @@ function getSortValues (getterFn, a, b) {
262262 return { aVal, bVal }
263263}
264264
265- /**
266- * Gets a comparator value for a given route's type (OTP mode).
267- */
265+ // Lookup for the sort values associated with various OTP modes.
266+ // Note: JSDoc format not used to avoid bug in documentationjs.
267+ // https://github.com/documentationjs/documentation/issues/372
268+ const modeComparatorValue = {
269+ SUBWAY : 1 ,
270+ TRAM : 2 ,
271+ RAIL : 3 ,
272+ GONDOLA : 4 ,
273+ FERRY : 5 ,
274+ CABLE_CAR : 6 ,
275+ FUNICULAR : 7 ,
276+ BUS : 8
277+ }
278+
279+ // Lookup that maps route types to the OTP mode sort values.
280+ // Note: JSDoc format not used to avoid bug in documentationjs.
281+ // https://github.com/documentationjs/documentation/issues/372
282+ const routeTypeComparatorValue = {
283+ 0 : modeComparatorValue . TRAM , // - Tram, Streetcar, Light rail.
284+ 1 : modeComparatorValue . SUBWAY , // - Subway, Metro.
285+ 2 : modeComparatorValue . RAIL , // - Rail. Used for intercity or long-distance travel.
286+ 3 : modeComparatorValue . BUS , // - Bus.
287+ 4 : modeComparatorValue . FERRY , // - Ferry.
288+ 5 : modeComparatorValue . CABLE_CAR , // - Cable tram.
289+ 6 : modeComparatorValue . GONDOLA , // - Gondola, etc.
290+ 7 : modeComparatorValue . FUNICULAR , // - Funicular.
291+ // TODO: 11 and 12 are not a part of OTP as of 2019-02-14, but for now just
292+ // associate them with bus/rail.
293+ 11 : modeComparatorValue . BUS , // - Trolleybus.
294+ 12 : modeComparatorValue . RAIL // - Monorail.
295+ }
296+
297+ // Gets a comparator value for a given route's type (OTP mode).
298+ // Note: JSDoc format not used to avoid bug in documentationjs.
299+ // ttps://github.com/documentationjs/documentation/issues/372
268300function getRouteTypeComparatorValue ( route ) {
269- switch ( route . mode ) {
270- case 'SUBWAY' :
271- return 1
272- case 'TRAM' :
273- return 2
274- case 'RAIL' :
275- return 3
276- case 'GONDOLA' :
277- return 4
278- case 'FERRY' :
279- return 5
280- case 'CABLE_CAR' :
281- return 6
282- case 'FUNICULAR' :
283- return 7
284- case 'BUS' :
285- return 8
286- default :
287- return 9999
301+ // For some strange reason, the short route response in OTP returns the
302+ // string-based modes, but the long route response returns the
303+ // integer route type. This attempts to account for both of those cases.
304+ if ( ! route ) throw new Error ( 'Route is undefined.' , route )
305+ if ( typeof modeComparatorValue [ route . mode ] !== 'undefined' ) {
306+ return modeComparatorValue [ route . mode ]
307+ } else if ( typeof routeTypeComparatorValue [ route . type ] !== 'undefined' ) {
308+ return routeTypeComparatorValue [ route . type ]
309+ } else {
310+ // Default the comparator value to a large number (placing the route at the
311+ // end of the list).
312+ console . warn ( 'no mode/route type found for route' , route )
313+ return 9999
288314 }
289315}
290316
0 commit comments