TomTom Maps for JavaScript
    Preparing search index...

    Function getSectionsWithin

    • Lists a route's sections within spans of it, type by type, such as the ferries, tolls and traffic on the roads only that route takes.

      Parameters

      • route: Route

        The route, with its sections.

      • options: SectionsWithinOptions = {}

        Where to look along the route, and for which section types.

      Returns SectionsWithin

      The types the route has within the spans, each with its sections there and their length.

      • A section counts when some of its length lies within the spans, so a segment of no length shared with one, which getSectionOverlap still finds, doesn't count. Only its part within the spans adds to lengthInMeters. Its shares entry says how much of it that part is, to prorate a traffic section's delayInSeconds, for example.
      • The sections come back whole, so their ids suit RoutingModule.setSectionFocus on the routes shown.
      • Pass sections.distinct as within for what sets a route apart from its alternatives. compareRoutes weighs it against one other route.
      const routes = await calculateRoute({ locations, maxAlternatives: 2 });
      routes.features.forEach((route) => {
      const own = getSectionsWithin(route, { within: route.properties.sections.distinct, types: ['ferry', 'toll'] });
      if (own.ferry) console.log(`takes a ferry for ${formatDistance(own.ferry.lengthInMeters)}`);
      if (own.toll) console.log(`pays ${own.toll.sections.length} tolls of its own`);
      });