Util

The ALKMaps utility functions class

Summary
UtilThe ALKMaps utility functions class
Functions
getParameterStringCreate a query string from the given object.
sendRequestSends a request.
buildDirectionReportBuilds the DOM table for the directions report.
buildMileageReportBuilds the DOM table for the Mileage report.
buildDetailReportBuilds the DOM table for the detail report.
buildStateReportBuilds the DOM table for the State report.
buildGeoTunnelReportBuilds the DOM table for the geotunnel report.
buildLeastCostReportBuilds the DOM table for the least cost report.
buildTableCellGets the user given API key from either the script query string or the ALKMaps property.
buildTableOrRowBuilds an DOM table or row.
strContainsChecks if one string is a sub-string of the other.
parseQueryParses the given query string into an object of name/value pairs.
getScriptSrcGets the source path from the HTML script tag of the given file.
getAPIKeyGets the user given API key from either the script query string or the ALKMaps property.
getYearGets the current year.
getImageLocationGets the file path for the given image file name.
showLoading
hideLoading

Functions

getParameterString

util.getParameterString = function (params)

Create a query string from the given object.

Parameters

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"
});

Returns

{String} The query string.  “?City=Princeton&State=NJ&Zip=08540”

sendRequest

util.sendRequest = function(params)

Sends a request.

Parameters

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&region=NA",
    success: function(response){
        console.log(response);
    }
});

buildDirectionReport

util.buildDirectionReport = function(rptLegs)

Builds the DOM table for the directions report.

Parameters

rptLegs{Array<Array<Object>>} Array containing the individual arrays of directions for each leg of the trip.
L.ALKMaps.Util.buildDirectionReport(rptLegs);

Returns

{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>

buildMileageReport

util.buildMileageReport = function (rptLines,
distUnits)

Builds the DOM table for the Mileage report.

Parameters

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");

Returns

{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>

buildDetailReport

util.buildDetailReport = function (rptLegs,
distUnits)

Builds the DOM table for the detail report.

Parameters

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");

Returns

{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>

buildStateReport

util.buildStateReport = function(mileageRptLines,
stateRptLines,
distUnits)

Builds the DOM table for the State report.

Parameters

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");

Returns

{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>

buildGeoTunnelReport

util.buildGeoTunnelReport = function(gtPoints)

Builds the DOM table for the geotunnel report.

Parameters

gtPoints{Array<Object>} Array containing the points of the geotunnel.
L.ALKMaps.Util.buildGeoTunnelReport(gtPoints);

Returns

{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>

buildLeastCostReport

util.buildLeastCostReport = function(leastCostLines,
distUnits)

Builds the DOM table for the least cost report.

Parameters

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");

Returns

{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>

buildTableCell

util.buildTableCell = function (tag,
content,
colspan,
cssClass)

Gets the user given API key from either the script query string or the ALKMaps property.

Parameters

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");

Returns

{DOM} <th class=”alkTypeCol”>Type</th>

buildTableOrRow

util.buildTableOrRow = function (tag,
trs,
cssClass,
id)

Builds an DOM table or row.

Parameters

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"
));

Returns

{DOM} <tr class=”alkHeaderRow”> <th class=”alkLonLatCol”>Longitude, Latitude</th> </tr>

strContains

util.strContains = function(str,
sub)

Checks if one string is a sub-string of the other.

Parameters

str{String} String being checked to see if it contains the substring.
sub{String] The sub-string.
var hasSubString = L.ALKMaps.Util.strContains("racecar", "car");

Returns

{Boolean} True

parseQuery

util.parseQuery = function(query)

Parses the given query string into an object of name/value pairs.

Parameters

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);

Returns

{Object} Parameter name/value pairs.  {color: “blue”, shape: “circle”}

getScriptSrc

util.getScriptSrc = function(fileName)

Gets the source path from the HTML script tag of the given file.

Parameters

filename{String} Name of the script file.
var source = L.ALKMaps.Util.getScriptSrc("myScript.js");

Returns

{String} The script source path.

getAPIKey

Gets the user given API key from either the script query string or the ALKMaps property.

Parameters

filename{String} Name of the ALKMaps Leaflet plugin script.
var key = L.ALKMaps.Util.getAPIKey();

Returns

{String} The API key.

getYear

util.getYear = function()

Gets the current year.

var year = L.ALKMaps.Util.getYear();

Returns

{Integer} The current 4 digit year.  2014

getImageLocation

util.getImageLocation = function (image)

Gets the file path for the given image file name.

Parameters

filename{String} Name of the image file.
var imgPath = L.ALKMaps.Util.getImageLocation("SomeALKMapsPic.png");

Returns

{String} The path of the image file.

showLoading

util.showLoading = function(map)

hideLoading

util.hideLoading = function(map)
util.getParameterString = function (params)
Create a query string from the given object.
util.sendRequest = function(params)
Sends a request.
util.buildDirectionReport = function(rptLegs)
Builds the DOM table for the directions report.
util.buildMileageReport = function (rptLines,
distUnits)
Builds the DOM table for the Mileage report.
util.buildDetailReport = function (rptLegs,
distUnits)
Builds the DOM table for the detail report.
util.buildStateReport = function(mileageRptLines,
stateRptLines,
distUnits)
Builds the DOM table for the State report.
util.buildGeoTunnelReport = function(gtPoints)
Builds the DOM table for the geotunnel report.
util.buildLeastCostReport = function(leastCostLines,
distUnits)
Builds the DOM table for the least cost report.
util.buildTableCell = function (tag,
content,
colspan,
cssClass)
Gets the user given API key from either the script query string or the ALKMaps property.
util.buildTableOrRow = function (tag,
trs,
cssClass,
id)
Builds an DOM table or row.
util.strContains = function(str,
sub)
Checks if one string is a sub-string of the other.
util.parseQuery = function(query)
Parses the given query string into an object of name/value pairs.
util.getScriptSrc = function(fileName)
Gets the source path from the HTML script tag of the given file.
util.getYear = function()
Gets the current year.
util.getImageLocation = function (image)
Gets the file path for the given image file name.
util.showLoading = function(map)
util.hideLoading = function(map)
Close