Nav
The Nav instance provides methods for generating turn-by-turn directions between two or more points on a Unit Map®. An instance is created via the UnitMap.nav() method.
map.on("ready", function () {
// Create a Nav instance via `map.nav()`, which can only be called once the map has loaded.
var nav = map.nav();
});
Directions are generated by the Unit Map® SDK and require a network request. The result is delivered asynchronously to the provided callback.
Nav.directions(waypoints, [options], [callback])
Request turn-by-turn directions that visit the given waypoints in order. The resulting Trip is rendered onto the map and passed to the callback.
var waypoints = [
{
point: [348.6403180261453, 569.3762174646059],
floor_id: "1010",
properties: { name: "Unit 111" }
},
{
point: [963.0352594306071, 836.9749146699905],
floor_id: "1010",
properties: { name: "Pool" }
}
];
map.nav().directions(waypoints, function (error, trip) {
if (error) {
console.error(error);
return;
}
console.log("Trip time (seconds):", trip.time());
});Arguments
| Argument | Required | Type | Default Value | Description |
|---|---|---|---|---|
| waypoints | Yes | Array | undefined | An ordered array of at least two waypoint objects to route through. See the Waypoint section below. |
| options | No | Object | undefined | An object literal of routing options. See the Options section below. May be omitted, in which case a callback may be passed as the second argument. |
| callback | No | Function | undefined | A function invoked with (error, trip) once the directions have been generated. On success, trip is a Trip instance. |
Waypoint
Each waypoint is an object literal describing a point in map space on a specific floor. Waypoints can be user generated or derived from the Location resource in the Unit Map REST API.
| Property | Required | Type | Default Value | Description |
|---|---|---|---|---|
| point | Yes | Array | undefined | An [x, y] coordinate pair in map space.Example: [348.64, 569.37]. |
| floor_id | Yes | String | undefined | The id of the Floor the point is located on. |
| properties | No | Object | undefined | An object of user-defined data to associate with the waypoint. Returned on the corresponding Location and Maneuver. |
Options
| Option | Type | Default Value | Description |
|---|---|---|---|
| mode | String | pedestrian | The travel mode used to generate the route. |
| pedestrian.mode | String | default | The pedestrian routing preference. Supported values are default, wheelchair, stairs, and elevators. |
| conditionalWaypoints.waypoints | Array | undefined | An array of optional waypoint objects (same shape as waypoints) that the routing engine may include only if they fall along the generated trip — for example access-controlled doors. |
| exclude.waypoints | Array | undefined | An array of waypoint objects (same shape as waypoints) the route should avoid. |
| exclude.areas | Array | undefined | An array of area objects to avoid. Each area requires a points array of [x, y] coordinate pairs describing a polygon. |
var options = {
pedestrian: { mode: "wheelchair" },
conditionalWaypoints: {
waypoints: [
{
point: [833.62, 884.13],
floor_id: "1010",
properties: { name: "West Pool Gate", action: "Enter access code" }
}
]
},
exclude: {
areas: [
{
name: "Building 3",
points: [
[916.28, 911.2],
[1083.1, 913.57],
[1085.47, 1196.33],
[909.18, 1202.25]
]
}
]
}
};
map.nav().directions(waypoints, options, function (error, trip) {
// ...
});Returns
A new Trip instance is passed to the callback. The directions are also rendered onto the map automatically.
Nav.clearDirections()
Removes the currently displayed directions from the map. Calling this when no directions are displayed is a no-op. This method is chainable.
map.nav().clearDirections();Events
The following events are dispatched during navigation. Bind to them with UnitMap.on.
| Name | Description |
|---|---|
tripleg:change | Sent when the visible TripLeg changes. The event object includes the active trip. |
location:dragstart | Sent when a draggable Location begins being dragged. |
location:dragmove | Sent continuously while a draggable Location is being dragged. |
location:dragend | Sent when a draggable Location is released. The event object includes the location and the new point. |
Updated 17 days ago

