Azure Maps: How can I add multiple avoids in the CalculateRouteDirectionsOptions property of calculateRouteDirections?

asked 2021-04-21T13:48:30.15+00:00
Matt Cass 1 Reputation point

Despite the "avoid" property of the route options being an array, as per the link below:

https://learn.microsoft.com/en-us/rest/api/maps/route/getroutedirections#avoid

When attempting to pass these through the RouteURL.calculateRouteDirections() as an array it causes a TypeError: r.toLowerCase is not a function in atlas-service.min.js

https://learn.microsoft.com/en-us/javascript/api/azure-maps-rest/atlas.service.routeurl?view=azure-maps-typescript-latest#calculateroutedirections-aborter--geojson-position----calculateroutedirectionsoptions-

Here is the object model we're passing:

// Route options to be passed through  
var routeOptions = {                             
        avoid: ['motorways', 'tollRoads'],  
        departAt: '',  
        arriveAt: '',   
        routeType: 'fastest',  
        travelMode: 'car',  
        vehicleCommercial: true,  
        vehicleEngineType: 'combustion',  
        vehicleWidth: 0,  
        vehicleHeight: 0,  
        vehicleLength: 0,  
        vehicleWeight: 1600  
    };  

Interestingly, this does work if the avoid property is set to a string, but this only allows us to pass one avoid through to the routing.

Am I missing something? Is it possible to specify multiple avoids through the calculateRouteDirection() function?

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
337 questions
No comments
{count} votes

1 answer

Sort by: Most helpful
  1. answered 2021-04-21T15:00:10.727+00:00
    rbrundritt 6,921 Reputation points Microsoft Employee

    Currently the JavaScript module only supports passing in one avoid parameter at a time since JSON objects only allow unique keys (the service expects each avoid option to be added a separate parameter). A workaround for this is to pass the parameters into another string option already formatted. For example:

    arriveAt: '&avoid=ferries&avoid=motorways&avoid=tollRoads'