This is the documentation of version 1.0.0-rc.4. Go to the latest version, 1.0.0-rc.5.
TomTom Maps for JavaScript
    Preparing search index...

    Function compareRoutes

    • Compares a route with a reference route: what it takes on that the reference doesn't, such as a toll or a ferry, and what it stays clear of, such as a jam or a closed road.

      Parameters

      • route: Route

        The route to explain.

      • reference: Route

        The route to explain it against, such as the selected alternative or the route typical traffic would take.

      • options: CompareRoutesOptions = {}

        The section types to weigh.

      Returns RouteComparison

      The stretches each route drives alone, and getSectionsWithin on each side.

      • It compares the two routes alone, with getDistinctSections, rather than reading their sections.distinct, which were found against every route of their response.
      • Routes of separate calculateRoute calls compare where they carry the same coordinates along a road they share. Where they don't, that road counts as distinct on both sides.
      • A route calculated with costModel: { traffic: 'historical' } still carries the live traffic sections along it. Compare the live route with it to tell which jams and closures it avoids.
      • distinct empty on both sides means the two routes drive the same roads.
      const [live, usual] = await Promise.all([
      calculateRoute({ locations }),
      calculateRoute({ locations, costModel: { traffic: 'historical' } }),
      ]);
      const { avoids } = compareRoutes(live.features[0], usual.features[0], { types: ['traffic'] });
      avoids.traffic?.sections.forEach((incident) => console.log(`avoids ${incident.categories.join(', ')}`));