A full featured(performance focused), modular, light directions plugin for all maps engines(MapLibre GL JS, Mapbox GL JS, Leaflet, OpenLayers etc.).
npm i --save @any-routing/core @any-routing/maplibre-engine @any-routing/annotation-plugin
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 });
});
❗ Help grow the library by sharing your providers
Property | Default | Description |
---|---|---|
dataProvider (Requred) |
- | The request data provider |
projector (Requred) |
- | The map projector |
plugins |
[] |
AnyRouting Plugins |
Property | Description |
---|---|
map |
Return the MapLibre GL or Mapbox GL instance |
options |
Return Config |
Method | Description |
---|---|
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 |
Event | Description | Data |
---|---|---|
routesFound |
Fire when routes calculated | Provider data |
Nx CLI Required
First install all depenencies by
npm i
npm run libre-routing:build
npm run start