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

ArgumentRequiredTypeDefault ValueDescription
waypointsYesArrayundefinedAn ordered array of at least two waypoint objects to route through. See the Waypoint section below.
optionsNoObjectundefinedAn 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.
callbackNoFunctionundefinedA 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.

PropertyRequiredTypeDefault ValueDescription
pointYesArrayundefinedAn [x, y] coordinate pair in map space.
Example: [348.64, 569.37].
floor_idYesStringundefinedThe id of the Floor the point is located on.
propertiesNoObjectundefinedAn object of user-defined data to associate with the waypoint. Returned on the corresponding Location and Maneuver.

Options

OptionTypeDefault ValueDescription
modeStringpedestrianThe travel mode used to generate the route.
pedestrian.modeStringdefaultThe pedestrian routing preference. Supported values are default, wheelchair, stairs, and elevators.
conditionalWaypoints.waypointsArrayundefinedAn 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.waypointsArrayundefinedAn array of waypoint objects (same shape as waypoints) the route should avoid.
exclude.areasArrayundefinedAn 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.

Events

The following events are dispatched during navigation. Bind to them with UnitMap.on.

NameDescription
tripleg:changeSent when the visible TripLeg changes. The event object includes the active trip.
location:dragstartSent when a draggable Location begins being dragged.
location:dragmoveSent continuously while a draggable Location is being dragged.
location:dragendSent when a draggable Location is released. The event object includes the location and the new point.