Skip to main content

Reports

Contents

The maps toolkit allows you to retrieve reporting information for your routes.

Retrieving Reports

There are two ways to retrieve reports for your routes. The first is to retrieve some or all of your reports when you add the route to the maps. The second is to call the ALKMaps.Map class, getReports method to retrieve report information for routes not displayed on the map.

addRoute

Reporting information can easily be retrieved as part of the callback parameters when a route is added to a routing layer.

To get report data back when you add a route to a routing layer, simply add a reportOptions object containing the type and format properties and the requested reports will be returned in a report object. This object will contain a property for each type report requested.

routingLayer.addRoute({
  ...
  functionOptions:{
    routeId: "MyRoute",
    async: true,
    callback: function(params){
      var reportList = params.report;

      document.getElementById("reportDiv").innerHTML = reportList.Directions;
      //document.getElementById("reportDiv").innerHTML = reportList.Detail;
      //document.getElementById("reportDiv").innerHTML = reportList.Mileage;
      //document.getElementById("reportDiv").innerHTML = reportList.States;
    }
  },
  ...
  reportOptions: {
    type: "Mileage,State,Directions,Detail",
    format: "html"
  }
});

getReports

To retrieve a report or reports independently from adding a route to the map, you can use the ALKMaps.Map class getReports function.

ALKMaps.Map.getReports is an asynchronous function that takes four parameters. The coords parameter takes a list of longitude and latitude for each stop. The options parameter takes the route options to be used for the report. The reportOptions parameter takes the type and format of the desired report.

//Get Directions and mileage reports.
var stops = [
  new ALKMaps.LonLat(-75.173297,39.942892),
  new ALKMaps.LonLat(-74.438942,39.362469)
];
stops = ALKMaps.LonLat.transformArray(stops, new ALKMaps.Projection("EPSG:4326"), map.getProjectionObject());
var opt = {
  vehicleType:"LightTruck",
  routingType:"Practical",
  routeOptimization: 1,
  highwayOnly: false,
  distanceUnits: "Miles",
  tollCurrency: "US",
  inclTollData:true,
  region: "NA"  //Valid values are NA, EU, OC and SA.
};

var reportOptions = {
  type: "Directions,Mileage", //Comma separated report type values
  format: "json",
  lang: "ENUS", //Valid values are ENUS, ENGB, DE, FR, ES, IT
  dataVersion: "current"  //Valid values are Current, PCM_EU, PCM_OC, PCM_SA, PCM_GT, PCM_AF, PCM_AS, PCM_ME, or PCM18 through the current version
};

map.getReports({
  coords: [[stops[0].lon,stops[0].lat],[stops[1].lon,stops[1].lat]],
  options: opt,
  reportOptions: reportOptions,
  success: function(resp){
    //Display reports
  }

getReports with POST Request

Alternatively, you can use the ALKMaps.Services.postReports to retrieve a report or reports by sending a POST request.

When there are too many parameters, it’s recommended to use POST request as IE Trident and Edge have request length limitations on HTTP GET method.

For a full documentation of the request body, please visit API documentation page under Services section.

ALKMaps.Services.postReports({
  request: request,
  dataVersion: "Current",
  success: function(resp) {},
  failure: function(resp) {}
});

DerivedRouteReports POST Request

The ALKMaps.Services.postDerivedRouteReports operation will return either mileage or detail report for the reduced trip based upon a series of latitude/longitudes pings.

For a full documentation of request body, please visit API documentation page under Services section.

ALKMaps.Services.postDerivedRouteReports({
  request: request,
  dataset: "Current",
  success: function(resp) {},
  failure: function(resp) {}
});

Report Formats

The ALK Maps toolkit provides reports in two primary formats, HTML and JSON.

HTML

The ALK Maps toolkit comes with access to basic HTML versions of the available reports. These are meant to provide simple HTML representations that provide basic styling hooks. Simple styling, as well as column management, can be done with these versions. For more advanced styling or markup requirements, you should consider rendering your own HTML based on JSON reports.

All available columns of data are shown in the default HTML styling. Each column is assigned a unique CSS class that can be used for column specific styling. If you wish to hide one or more columns, simply set the display attribute to a value of none for each class you wish to hide.

For example, if you would like to hide the “Leg Miles” and “Leg Hours” columns from the Details report, you can simply add the following CSS definitions.

.alkDetailReportTable .alkLegDistanceCol,
.alkDetailReportTable .alkLegHoursCol {
  display: none;
}

JSON

The JSON format matches the same structure as the existing PC*Miler Web Services.

Report Types

The four most commonly used reports are described below.

Directions Report

The Directions Report provides turn-by-turn directions for the associated route.

Details Report

The Details Report provides a comprehensive report of each leg of the route.

Mileage Report

The Mileage Report provides the mileage, time, and cost for each stop on the route.

State Report

The State Report provides detailed mileage information for each state travelled through on the route.

WeatherAlerts Report

A list of weather alert objects whose affected areas intersect the resulting route path.

Last updated June 7, 2024.
Contents