A-B Wayfinding

The map setup is exactly what we did in the earlier tutorials, where we load the venue data and then render the map with showVenue. We then label all the polygons with Flat labels, to keep the visual stress of the map to a minimum, while still providing the viewer hints on what's around them.

In this example, we take the start and end locations of our navigation by selecting by name from the venue.locations. A typical UI would normally have a click/tap option for selecting locations as well as a search option.

MappedinLocation object has a directionsTo() method, which takes the destination as a parameter. That's how we get back the directions, which we then feed to Journey.draw().

To find out how to start the journey from the user's current location, refer Wayfinding from Blue Dot in the Blue Dot Guide.

const startLocation = venue.locations.find(
(location) => location.name === "ThinkKitchen"
);
const endLocation = venue.locations.find(
(location) => location.name === "American Eagle"
);
const directions = startLocation.directionsTo(endLocation);
mapView.Journey.draw(directions, {
pathOptions: {
color: "green"
}
});

Journey is a helper class to display single and multi-destination wayfinding easily on the map. Functionality of Journey could be replicated by drawing the paths and adding well designed tooltips at connection points.

Multi-Floor Wayfinding

Using Journey helper, no additional work is needed to provide wayfinding between floors. Whenever a user needs to switch a floor, an interactive tooltip with an icon indicating the type of connection (such as elevator or escalator) will be drawn. By clicking or tapping the tooltip, the map view switches the destination floor.

Multi-Destination Wayfinding

With Mappedin SDK, it's possible to draw a path including multiple waypoints. To generate directions, create a DestinationSet from polygons, locations or nodes and request directions from a starting location just like with A-B navigation with startLocation.directionsTo(destinationSet).

const startLocation = venue.locations.find((l) => l.name === "Parking Lot E")!;
const destinations = [
venue.locations.find((l) => l.name === "Apple"),
venue.locations.find((l) => l.name === "Microsoft"),
venue.locations.find((l) => l.name === "ThinkKitchen"),
venue.locations.find((l) => l.name === "Parking Lot E"),
] as MappedinLocation[];
const directions = startLocation.directionsTo(
new MappedinDestinationSet(destinations)
);
mapView.Journey.draw(directions);

Once the user has completed a segment of the journey, the active step can be changed with .setStep(). The following demo will move through the steps when user clicks on the map using the CLICK -event callback.

mapView.on(E_SDK_EVENT.CLICK, (_) => {
mapView.Journey.setStep(++step % destinations.length);
});

The Journey.draw() function takes an TJourneyOptions argument which we can use to style our active and inactive paths. We'll modify pathOptions to be wider than the inactive portions, while adjusting inactivePathOptions to be a light blue color. If desired, the arrows and the pulse on the path can also be styled or removed completely.

mapView.Journey.draw(directions, {
pathOptions: {
nearRadius: 2.5,
farRadius: 2.5,
},
inactivePathOptions: {
nearRadius: 2,
farRadius: 2,
color: "lightblue",
},
});

Wayfinding Without Using Journey

While Journey is a great utility for drawing a single path with all the features, it may sometimes be limiting. For instance, you may only draw one Journey at a time, and subsequent calls to Journey.draw() will overwrite the previous.

For full control over the route, draw the path using the Paths.add() method within the PathsLayer and pass it the directions.path.

const startLocation = venue.locations.find(
(location) => location.name === "ThinkKitchen"
);
const endLocation = venue.locations.find(
(location) => location.name === "American Eagle"
);
const directions = startLocation.directionsTo(endLocation);
mapView.Paths.add(directions.path);

With the release of Mappedin Web SDK v5.8.0 the Paths API has changed. drawPath(), removePath(), and removeAllPaths() has been deprecated and there is a new Paths Layer. If you haven't upgraded, click here to view the legacy guide.

This creates a basic path with no extra features. Using this method, you will need to handle both multi-floor navigation and multi-destination wayfinding manually using Tooltips and by drawing multiple paths.

We can draw a secondary path the same way as the first while providing different start and end locations. To make this new path stand out, style it a different color by changing the color property. The documentation for TPathOptions covers the other options available to you.

The CodeSandbox below demonstrates a single map with multiple destination paths.

Additional Reading

Was this page helpful?