TomTom Maps for JavaScript
    Preparing search index...

    Type Alias CostModel

    Cost model criteria for route optimization.

    Defines routing preferences and constraints that influence path selection. Combines route type, traffic consideration, and avoidance criteria to determine what makes a route "better" in the eyes of the routing engine.

    The cost model affects how the route path is calculated, but does not affect what other data the response includes.

    The cost model balances multiple factors:

    • Time efficiency
    • Distance
    • Fuel/energy consumption
    • User preferences (avoid tolls, ferries, etc.)
    • Traffic conditions
    // Fast route avoiding tolls
    const costModel: CostModel = {
    routeType: 'fast',
    traffic: 'live',
    avoid: ['tollRoads']
    };

    // Eco-friendly route avoiding highways
    const ecoCostModel: CostModel = {
    routeType: 'efficient',
    traffic: 'historical',
    avoid: ['motorways', 'ferries']
    };

    // Scenic route for leisure
    const scenicCostModel: CostModel = {
    routeType: 'thrilling',
    avoid: ['motorways', 'tollRoads']
    };
    type CostModel = {
        avoid?: Avoidable[];
        routeType?: RouteType;
        traffic?: TrafficInput;
    }
    Index

    Properties

    avoid?: Avoidable[]

    Specifies something that the route calculation should try to avoid when determining the route.

    None
    
    routeType?: RouteType

    Specifies the type of optimization used when calculating routes. Possible values are:

    • fast: Route calculation is optimized by travel time, while keeping the routes sensible. For example, the calculation may avoid shortcuts along inconvenient side roads or long detours that only save very little time.
    • short: Route calculation is optimized such that a good compromise between small travel time and short travel distance is achieved.
    • efficient: Route calculation is optimized such that a good compromise between small travel time and low fuel or energy consumption is achieved.
    • thrilling: Route calculation is optimized such that routes include interesting or challenging roads and use as few motorways as possible. There is a limit of 900km on routes planned with routeType=thrilling.
    fast
    
    traffic?: TrafficInput

    Decides how traffic is considered for computing routes.

    Possible values are:

    • live: In addition to historical travel times, routing and estimated travel time consider traffic jams and short- and long-term closures during the travel time window.
    • historical: Routing and estimated travel time consider historical travel times and long term closures. Traffic jams and short-term closures during the travel time window do not influence routing or travel time.
    live
    

    This setting does not affect whether live traffic is included in the response or not.

    • Considering historical traffic in cost model does not mean live traffic is not included in the response.