This is the documentation of version 1.0.0-rc.1. Go to the latest version, 1.0.0-rc.5.
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. The values are:

    • fast optimises for 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 finds a good compromise between small travel time and short travel distance.
    • efficient finds a good compromise between small travel time and low fuel or energy consumption.
    • thrilling includes interesting or challenging roads and uses as few motorways as possible. Routes planned with routeType=thrilling are limited to 900km.
    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.