TripLegSelection

A collection of zero or more TripLeg instances, returned by the legs() method on a Trip. It provides a chainable API for navigating between the legs of a trip.

map.nav().directions(waypoints, function (error, trip) {
  var legs = trip.legs();

  // Display the first leg:
  legs.first().show();
});

TripLegSelection.length

The number of TripLeg instances in the collection.

TripLegSelection.first()

Get the first TripLeg in the collection.

Returns

A new TripLegSelection instance.

TripLegSelection.last()

Get the last TripLeg in the collection.

Returns

A new TripLegSelection instance.

TripLegSelection.next()

Get the TripLeg following the currently displayed leg. If the current leg is the last leg, the last leg is returned.

trip.legs().next().show();

Returns

A new TripLegSelection instance.

TripLegSelection.previous()

Get the TripLeg preceding the currently displayed leg. If the current leg is the first leg, the first leg is returned.

trip.legs().previous().show();

Returns

A new TripLegSelection instance.

TripLegSelection.at(index)

Get the TripLeg at the given index.

Arguments

ArgumentRequiredTypeDefault ValueDescription
indexYesIntegerundefinedThe index of the desired leg.

Returns

A new TripLegSelection instance.

TripLegSelection.show()

Display the first TripLeg in the collection, making it the active leg of the Trip. This method is chainable.

Returns

The object chain.

TripLegSelection.each(iterator)

Iterate over each TripLeg in the collection. This method is chainable.

Arguments

ArgumentRequiredTypeDefault ValueDescription
iteratorYesFunctionundefinedA function invoked with each TripLeg in the collection.

Returns

The object chain.

TripLegSelection.map(iterator)

Map over each TripLeg in the collection, returning an array of the iterator results.

Arguments

ArgumentRequiredTypeDefault ValueDescription
iteratorYesFunctionundefinedA function invoked with each TripLeg in the collection.

Returns

An Array of the iterator return values.