@mappedin/step-by-step
v6.13.0-beta.0
Published
A navigation extension for [Mappedin JS](https://www.npmjs.com/package/@mappedin/mappedin-js) that generates human-readable, step-by-step navigation instructions from Mappedin directions data.
Readme
@mappedin/step-by-step
A navigation extension for Mappedin JS that generates human-readable, step-by-step navigation instructions from Mappedin directions data.
Usage
Installation
With NPM:
npm install @mappedin/step-by-stepWith Yarn:
yarn add @mappedin/step-by-stepWith pnpm:
pnpm add @mappedin/step-by-stepGetting Started
import { StepByStep } from '@mappedin/step-by-step';
import { MapData, Directions } from '@mappedin/mappedin-js';
const mapData = await getMapData(...);
// ...
const directions: Directions = await mapData.getDirections(start, end);
// Create a StepByStep instance
const stepByStep = new StepByStep(mapData, directions, {
language: 'en-US',
});
// Generate the instructions
await stepByStep.generate();
// Access the formatted instructions
const instructions = stepByStep.instructions;
// Display instructions to the user
instructions.forEach(instruction => {
console.log(instruction.text);
if (instruction.distanceText) {
console.log(` ${instruction.distanceText}`);
}
if (instruction.landmark) {
console.log(` Landmark: ${instruction.landmark.name}`);
}
});Changing Units and Language
// Update to imperial units
await stepByStep.format({ units: 'imperial' });
// Or update both at once
await stepByStep.format({ units: 'metric', language: 'de-DE' });Updating Directions
// Get new directions
const newDirections = await mapData.getDirections(newStart, newEnd);
// Update and regenerate instructions
await stepByStep.setDirections(newDirections);