TomTom Maps for JavaScript
    Preparing search index...

    Type Alias CostModel

    The cost model criteria for route optimisation.

    They define the routing preferences and constraints that influence path selection. They combine route type, traffic, and avoidance criteria to decide what makes a route "better" for 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[];
        avoidAreas?: HasBBox[];
        routeType?: RouteType;
        traffic?: TrafficInput;
    }
    Index
    avoid?: Avoidable[]

    What the route calculation tries to avoid when determining the route.

    None
    
    avoidAreas?: HasBBox[]

    Rectangular areas for the routing engine to bypass, each expressed as a HasBBox.

    You can pass up to 10 rectangles, for example to avoid construction zones, restricted areas, or known congestion points.

    Constraints per rectangle:

    • Maximum size: ~160×160 km
    • Cannot cross the 180th meridian
    • Latitude must be between −80° and +80°
    // Avoid an area using a BBox array [west, south, east, north]
    avoidAreas: [
    [2.265938, 48.81851, 2.41115, 48.90309]
    ]
    routeType?: RouteType

    The type of optimisation that route calculation uses, as RouteType describes.

    fast
    
    traffic?: TrafficInput

    How route computation considers traffic.

    The 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 the response includes live traffic. With historical traffic in the cost model, the response can still include live traffic.