|
|
|
|
|
Routing the track

EMAPI.Router - The class responsible for routing and visualize it on the map.

addWaypoint function adds a new waypoint to the list of wayPoints (array of objects). The data passed to the third parameter substitution function (callback)) included:

var router = new EMAPI.Router(); //create a new instance of the EMAPI.Router class

router.addWaypoint(lonLat, pointType, callback);

where:
lonLat{Array(EMAPI.LonLat)} object representing geogrphical coordinates point of the route.
pointType{Integer} Type of the waypoint:
0 = starting point,
1 = via point,
2 = final point.
Via point is always added just before the final one.
callback{Function} The data's geographic function of desired point.

router.addWaypoint(new EMAPI.LonLat(19.405975341022, 51.85613979201), 0, null);  //adding a starting point
router.addWaypoint(new EMAPI.LonLat(19.952545165219, 52.117469879906), 1, null); //adding via point
router.addWaypoint(new EMAPI.LonLat(20.673522948394, 52.418336289777), 2, null); //adding final point


calculateRoute function calculates the route between points placed in the list wayPoints after the selected vehicle, driver and routing parameters.. The data passed to the last parameter substitution function included:

router.calculateRoute(vehicle, driver, roadType, routeOptions, callback);

where:
vehicle{EMAPI.Router.VehicleParams} EMAPI.Router.DriverParams representing the settings for the vehicle to be used to designate the route.
driver{EMAPI.Router.DriverParams} EMAPI.Router.DriverParams representing the settings for the vehicle to be used to designate the route.
roadType{Integer} Typ Type of route calculation:
0 = the shortest,
1 = the fastest,
2 = the cheapest.
routeOptions{Object} An object that contains routing options in the form of logical fields:
useDifficulties = true forces the use of traffic congestion,
useFerry = true turn on the use of ferries,
useGroundRoad = true turn off the use of unpaved roads.
callback{Function} The service function of results the route.


An example of using:

var router = new EMAPI.Router(  //create a new instance of the EMAPI.Router class
  {
    map: mapa, // map on which routes are to be visualized
    reportPointsHandlerPointsName: 'punkty_id' //DIV element, which sets the list of waypoints
  }
);

router.removeWaypoints(); //delete waypoints from an array of objects

router.addWaypoint(new EMAPI.LonLat(19.405975341022, 51.85613979201), 0, null);  //adding a starting point
router.addWaypoint(new EMAPI.LonLat(19.952545165219, 52.117469879906), 1, null); //adding the via point
router.addWaypoint(new EMAPI.LonLat(20.673522948394, 52.418336289777), 2, null); //adding the final point

router.calculateRoute(
  router.vehicles.items[0], //using the default vehicle
  router.drivers.items[0], //using the default driver
  0, //calculate the shortest route
  {useGroundRoad:true, useFerry:true, useTollRoad:true, useVignetteRoads:true, useDifficulties:true}, //route will be calculated using unpaved roads, ferries, obstructions, toll roads
  function(pos) //funkcja obsługi rezultatów wyznaczonej trasy
    {
    alert("The route has been calculated"); //displays window with information about the correct calculation of the route
    }
);

The list of added waypoints.:


--> Kliknij aby obliczyć trasę <--