TomTom Maps for JavaScript
    Preparing search index...

    Function getImportantRoads

    • Lists the important roads a route takes: the motorways and main roads that identify its course, which tell it apart from its alternatives.

      Parameters

      • route: Route

        The route, with its importantRoadStretch sections.

      • options: ImportantRoadsOptions = {}

        Where to look along the route, and how much of a road to require.

      Returns ImportantRoad[]

      The roads in order along the route, each once however many stretches it has.

      • A road is the stretches sharing a first road number, or a street name when they have no number: the routing API may rank the stretches of one motorway apart. Stretches with neither group by their index, as a road with no name to print.
      • It reads the route's importantRoadStretch sections, which calculateRoute returns unless its sectionTypes leaves them out. A route without them has no important roads.
      • A road's sections only hold its stretches within within, whole, so they suit RoutingModule.setSectionFocus on the routes shown.
      • Pass sections.distinct as within for the roads that set a route apart from its alternatives.
      const routes = await calculateRoute({ locations, maxAlternatives: 2 });
      routes.features.forEach((route) => {
      const roads = getImportantRoads(route, { within: route.properties.sections.distinct, minLengthInMeters: 5000 });
      console.log(`via ${roads.map((road) => road.name).filter(Boolean).join(', ')}`);
      });