The ALKMaps utility functions class
Util | The ALKMaps utility functions class |
Functions | |
getParameterString | Create a query string from the given object. |
sendRequest | Sends a request. |
buildDirectionReport | Builds the DOM table for the directions report. |
buildMileageReport | Builds the DOM table for the Mileage report. |
buildDetailReport | Builds the DOM table for the detail report. |
buildStateReport | Builds the DOM table for the State report. |
buildGeoTunnelReport | Builds the DOM table for the geotunnel report. |
buildLeastCostReport | Builds the DOM table for the least cost report. |
buildTableCell | Gets the user given API key from either the script query string or the ALKMaps property. |
buildTableOrRow | Builds an DOM table or row. |
strContains | Checks if one string is a sub-string of the other. |
parseQuery | Parses the given query string into an object of name/value pairs. |
getScriptSrc | Gets the source path from the HTML script tag of the given file. |
getAPIKey | Gets the user given API key from either the script query string or the ALKMaps property. |
getYear | Gets the current year. |
getImageLocation | Gets the file path for the given image file name. |
showLoading | |
hideLoading |
util.getParameterString = function ( params )
Create a query string from the given object.
params | {Object} Object containing the name/value pairs of the parameters in the query string. |
L.ALKMaps.Util.getParameterString({ City: "Princeton", State: "NJ", Zip: "08540" });
{String} The query string. “?City=Princeton&State=NJ&Zip=08540”
util.sendRequest = function( params )
Sends a request.
url | {String} request url. |
success | {Function} Function handles success asynchronous service response. |
failure | {Function} Function handles failure asynchronous service response. |
L.ALKMaps.Util.sendRequest({ url: "http://pcmiler.alk.com/APIs/REST/v1.0/service.svc/locations?AUTHTOKEN=YourAPIKey&city=Seattle&state=WA&postcode=98104&list=1®ion=NA", success: function(response){ console.log(response); } });
util.buildDirectionReport = function( rptLegs )
Builds the DOM table for the directions report.
rptLegs | {Array<Array<Object>>} Array containing the individual arrays of directions for each leg of the trip. |
L.ALKMaps.Util.buildDirectionReport(rptLegs);
{DOM} <ol class=”alkDirectionsReport”> <li class=”alkHeaderRow”><span class=”alkDirectionCol”>Driving Directions</span> <span class=”alkOdometerCol”>Odometer</span> <span class=”alkTimeCol”>Time</span> <span class=”alkDelayCol”>Delay</span> </li> ... </ol>
util.buildMileageReport = function ( rptLines, distUnits )
Builds the DOM table for the Mileage report.
rptLines | {Array<Object>} Array containing the individual lines of the report. |
distUnits | {String} The unit of measurement in which distances will be displayed. |
L.ALKMaps.Util.buildMileageReport(rptLines,"Miles");
{DOM} <table class=”alkReportTable alkMileageReportTable”> <tr class=”alkReportHeaderRow”> <th class=”alkPostalCodeCol”>Postal Code</th> <th class=”alkAddressCol”>Address</th> <th class=”alkCityCol”>City</th> <th class=”alkStateCol”>State</th> <th class=”alkCountyCol”>County</th> <th class=”alkLonLatCol”>Lon, Lat</th> <th class=”alkLegDistanceCol”>Miles</th> <th class=”alkTotalDistanceCol”>Total</th> <th class=”alkTotalCostCol”>Cost</th> <th class=”alkTotalHoursCol”>Hours</th> <th class=”alkTotalTollsCol”>Tolls($)</th> <th class=”alkETACol”>ETA/ETD</th> </tr> ... </table>
util.buildDetailReport = function ( rptLegs, distUnits )
Builds the DOM table for the detail report.
rptLegs | {Array<Array<Object>>} Array containing the individual arrays of directions for each leg of the trip. |
distUnits | {String} The unit of measurement in which distances will be displayed. |
L.ALKMaps.Util.buildDetailReport(rptLegs,"Miles");
{DOM} <table class=”alkReportTable alkDetailReportTable”> <tr class=”alkReportHeaderRow”> <th class=”alkStateCol”>State</th> <th class=”alkRouteCol”>Route</th> <th class=”alkDistanceCol”>Miles</th> <th class=”alkHoursCol”>Hours</th> <th class=”alkInterchangeCol”>Interchange</th> <th class=”alkLegDistanceCol”>Leg Miles</th> <th class=”alkLegHoursCol”>Leg Hours</th> <th class=”alkTotalDistanceCol”>Total Miles</th> <th class=”alkTotalHoursCol”>Total Hours</th> <th class=”alkLegTollsCol”>Leg Tolls($)</th> <th class=”alkTollPlazaCol”>Toll Plaza Abbr.</th> </tr> ... </table>
util.buildStateReport = function( mileageRptLines, stateRptLines, distUnits )
Builds the DOM table for the State report.
mileageRptLines | {Array<Object>} Array containing the individual lines of the mileage report. |
stateRptLines | {Array<Object>} Array containing the individual lines of the state report. |
distUnits | {String} The unit of measurement in which distances will be displayed. |
L.ALKMaps.Util.buildStateReport(mileageRptLines, stateRptLines, "Miles");
{DOM} <table class=”alkReportTable alkStateReportTable”> <tr class=”alkHeaderRow”> <th class=”alkStateCol”>State/Country</th> <th class=”alkTotalDistanceCol”>Total</th> <th class=”alkTollDistanceCol”>Toll</th> <th class=”alkFreeDistanceCol”>Free</th> <th class=”alkFerryDistanceCol”>Ferry</th> <th class=”alkLoadedDistanceCol”>Loaded</th> <th class=”alkEmptyDistanceCol”>Empty</th> <th class=”alkTotalTollsCol”>Toll($)</th> </tr> ... </table>
util.buildGeoTunnelReport = function( gtPoints )
Builds the DOM table for the geotunnel report.
gtPoints | {Array<Object>} Array containing the points of the geotunnel. |
L.ALKMaps.Util.buildGeoTunnelReport(gtPoints);
{DOM} <table class=”alkReportTable alkGeoTunnelReportTable”> <tr class=”alkHeaderRow”> <th class=”alkLonLatCol”>Longitude, Latitude</th> </tr> <tr> <td class=”alkLonLatCol”>-75.339368, 40.11442</td> </tr>... </table>
util.buildLeastCostReport = function( leastCostLines, distUnits )
Builds the DOM table for the least cost report.
leastCostLines | {Array<Object>} Array containing the individual lines of the least cost report. |
distUnits | {String} The unit of measurement in which distances will be displayed. |
L.ALKMaps.Util.buildLeastCostReport(leastCostLines, "Miles");
{DOM} <table class=”alkReportTable alkLeastCostReportTable”> <tr id=”alkLeastCostReportHeader”> <th class=”alkTypeCol”>Type</th> <th class=”alkTotalDistanceCol”>Miles</th> <th class=”alkTotalCostCol”>Cost</th> <th class=”alkTotalHoursCol”>Hours</th> <th class=”alkTotalTollsCol”>Tolls($)</th> <th class=”alkFuelCol”>Fuel</th> <th class=”alkLaborCol”>Labor</th> <th class=”alkOtherCol”>Other</th> <th class=”alkEstghgCol”>EST. GHG</th> </tr> <tr id=”Practical Tolls Allowed”>...</tr> <tr id=”Shortest Tolls Allowed”>...</tr> <tr id=”Fastest Tolls Allowed”>...</tr> <tr id=”Practical Avoid Tolls”>...</tr> <tr id=”Shortest Avoid Tolls”>...</tr> <tr id=”Fastest Avoid Tolls”>...</tr> </table>
util.buildTableCell = function ( tag, content, colspan, cssClass )
Gets the user given API key from either the script query string or the ALKMaps property.
tag | {String} DOM tag type. |
content | {String} Content to be displayed inside table cell. |
colspan | {Integer} Number of columns the cell should span. |
cssClass | {String} Name of the css class that will be used to style the cell. |
L.ALKMaps.Util.buildTableCell("th", "Type", 1, "alkTypeCol");
{DOM} <th class=”alkTypeCol”>Type</th>
util.buildTableOrRow = function ( tag, trs, cssClass, id )
Builds an DOM table or row.
tag | {String} DOM tag type. |
trs | {Array<DOM>} Array of DOM table rows. |
cssClass | {String} Name of the css class that will be used to style the table/row. |
id | {String} id of the table element. |
L.ALKMaps.Util.buildTableOrRow( "tr", new Array( L.ALKMaps.Util.buildTableCell("th", "Longitude, Latitude", null, "alkLonLatCol") ), "alkHeaderRow" ));
{DOM} <tr class=”alkHeaderRow”> <th class=”alkLonLatCol”>Longitude, Latitude</th> </tr>
util.parseQuery = function( query )
Parses the given query string into an object of name/value pairs.
query | {String} A query string containing 0 or more parameters. |
var query = "http://SomeSite.com/HomePage?color=blue&shape=circle" var key = L.ALKMaps.Util.parseQuery(query);
{Object} Parameter name/value pairs. {color: “blue”, shape: “circle”}
Create a query string from the given object.
util.getParameterString = function ( params )
Sends a request.
util.sendRequest = function( params )
Builds the DOM table for the directions report.
util.buildDirectionReport = function( rptLegs )
Builds the DOM table for the Mileage report.
util.buildMileageReport = function ( rptLines, distUnits )
Builds the DOM table for the detail report.
util.buildDetailReport = function ( rptLegs, distUnits )
Builds the DOM table for the State report.
util.buildStateReport = function( mileageRptLines, stateRptLines, distUnits )
Builds the DOM table for the geotunnel report.
util.buildGeoTunnelReport = function( gtPoints )
Builds the DOM table for the least cost report.
util.buildLeastCostReport = function( leastCostLines, distUnits )
Gets the user given API key from either the script query string or the ALKMaps property.
util.buildTableCell = function ( tag, content, colspan, cssClass )
Builds an DOM table or row.
util.buildTableOrRow = function ( tag, trs, cssClass, id )
Checks if one string is a sub-string of the other.
util.strContains = function( str, sub )
Parses the given query string into an object of name/value pairs.
util.parseQuery = function( query )
Gets the source path from the HTML script tag of the given file.
util.getScriptSrc = function( fileName )
Gets the current year.
util.getYear = function()
Gets the file path for the given image file name.
util.getImageLocation = function ( image )
util.showLoading = function( map )
util.hideLoading = function( map )