Routing

Routing is done using Trimble MAPS data for commercial vehicles. This data includes bridge heights and clearances, load limits, weight limits and allowances, one-way road designations, left-hand and dangerous turn restrictions, urban road classifications, as well as hazmat, truck-restricted, truck-designated and truck-prohibited roads.

Route

The first step in adding routes to your map is to create a new Route object providing a RouteOptions object as a constructor paramteter.

const myRoute = new TrimbleMaps.Route({
  //Put your RouteOptions attributes here
});

Route Options

The RouteOptions object requires a routeId and an array of stops. There are a number of optional parameters that can also be provided in order to change the route path or the way it is displayed.

const myRoute = new TrimbleMaps.Route({
  routeId: "myRoute",
  stops: [
    new TrimbleMaps.LngLat(-74.566234, 40.49944),
    new TrimbleMaps.LngLat(-74.629749, 40.261187)
  ]
});

Adding the Route to a Map

A route can be added to a map by calling the addTo method on the route object.

myRoute.addTo(myMap);

Events

A route will raise a series of events during the loading and rendering of the route. The primary events are the routeloading and route. The routeloading event is raised when the calls are started and the route event is raised when the route is completely loaded and rendered. These events can be useful for adding loading indicators to you application.

const myRoute = new TrimbleMaps.Route({
  routeId: "myRoute",
  stops: [
    new TrimbleMaps.LngLat(-74.566234, 40.49944),
    new TrimbleMaps.LngLat(-74.629749, 40.26118)
  ]
});

myRoute.on("routeloading", function () {
  console.log("loading route");
});

myRoute.on("route", function () {
  console.log("route complete");
});

Reports

The requested reports for a route can be retrieved by listening to the report event on the route object. The report event will return an object containing all the reports specified in the reportType property in the route options. This event will be raised each time the route is updated. There is also a corresponding reportloading event that is raised when a report call is started.

const myRoute = new TrimbleMaps.Route({
  routeId: "myRoute",
  stops: [
    new TrimbleMaps.LngLat(-74.566234, 40.49944),
    new TrimbleMaps.LngLat(-74.629749, 40.26118)
  ],
  reportType: [
    TrimbleMaps.Common.ReportType.MILEAGE,
    TrimbleMaps.Common.ReportType.DETAIL
  ]
});

myRoute.on("report", function (reports) {
  console.log(reports);
});