Home

Awesome

AnyRouting

A full featured(performance focused), modular, light directions plugin for all maps engines(MapLibre GL JS, Mapbox GL JS, Leaflet, OpenLayers etc.).

Demo

Demo App

Installation

npm i --save @any-routing/core @any-routing/maplibre-engine @any-routing/annotation-plugin

Example

import { Map } from 'maplibre-gl';
import { AnyRouting } from '@any-routing/core';
import { HereProvider, HereRoutingData } from '@any-routing/here-data-provider';
import { defaultMapLibreProjectorOptions, MapLibreProjector } from '@any-routing/maplibre-engine';
import { AnnotationPlugin } from '@any-routing/annotation-plugin';

const map = new Map({...});

const dataProvider = new HereProvider({ apiKey: '1234' });
const projector = new MapLibreProjector({
  ...defaultMapLibreProjectorOptions,
  map
});

const routing = new AnyRouting<HereRoutingData>({
  dataProvider,
  waypointsSyncStrategy: 'none',
  plugins: [projector, new AnnotationPlugin({ map })],
});

routing.on('routesFound', console.log);
routing.on('routeSelected', console.log);

map.on('load', () => {
  routing.initialize();
  routing.setWaypoints([
    { position: { lat: 49.9539315, lng: 18.8531001 }, properties: { label: 'A' } },
    { position: { lng: 21.01178, lat: 52.22977 }, properties: { label: 'B' } },
  ]);

  routing.recalculateRoute({ fitViewToData: true });
});

Supported data providers

Supported Map engine

:exclamation: Help grow the library by sharing your providers

Architecture

Architecture

AnyRouting Class

Config

PropertyDefaultDescription
dataProvider(Requred)-The request data provider
projector(Requred)-The map projector
plugins[]AnyRouting Plugins

Instance Properties

PropertyDescription
mapReturn the MapLibre GL or Mapbox GL instance
optionsReturn Config

Instance Methods

MethodDescription
async recalculateRoute(opts)Calculate routes between waypoints
selectRoute(routeId)Select the alternative route
on(event, callback)Subscribe to specific event
off(event, callback)Unsubscribe from specific event

Events

EventDescriptionData
routesFoundFire when routes calculatedProvider data

Contribute

Nx CLI Required

First install all depenencies by

npm i

Build library

npm run libre-routing:build

Run playground app

npm run start