Planner.js: A JS library for route planning
🛸️ 🚴 🚉 🚀
$ npm install plannerjs
Include it in the browser:
<script src="https://planner.js.org/js/planner-latest.js"></script>
...
<script>
const { FlexibleTransitPlanner, Units } = PlannerJS;
</script>
Include it in your JavaScript project:
const { FlexibleTransitPlanner, Units } = require('plannerjs');
import { FlexibleTransitPlanner, Units } from 'plannerjs';
Use it in both environments:
const planner = new FlexibleTransitPlanner();
planner.addConnectionSource("https://graph.irail.be/sncb/connections");
planner.addStopSource("https://irail.be/stations/NMBS");
planner.query({
from: "http://irail.be/stations/NMBS/008812005",
to: "http://irail.be/stations/NMBS/008892007",
minimumDepartureTime: new Date(),
walkingSpeed: 3,
minimumWalkingSpeed: 3,
maximumWalkingDistance: 200,
minimumTransferDuration: Units.fromMinutes(1),
maximumTransferDuration: Units.fromMinutes(30),
maximumTravelDuration: Units.fromHours(1.5),
maximumTransfers: 4,
})
.take(3)
.on('data', (path) => {
console.log(JSON.stringify(path, null, 4));
})
.on('end', () => {
console.log('No more paths!')
})
.on('error', (error) => {
console.error(error);
});
Documentation
For further instructions, follow the documentation at https://planner.js.org/
Developing
- Building the docs with typedoc:
npm run doc
- Testing with jest:
npm test
- Build a new browser version with
npm run browser
- Bundle the latest planner for the docs example
npm run doc-bundle
Variables
Const ARRIVAL_DELAY
ARRIVAL_DELAY: "http://semweb.mmlab.be/ns/linkedconnections#arrivalDelay" = "http://semweb.mmlab.be/ns/linkedconnections#arrivalDelay"
Const ARRIVAL_STOP
ARRIVAL_STOP: "http://semweb.mmlab.be/ns/linkedconnections#arrivalStop" = "http://semweb.mmlab.be/ns/linkedconnections#arrivalStop"
Const ARRIVAL_TIME
ARRIVAL_TIME: "http://semweb.mmlab.be/ns/linkedconnections#arrivalTime" = "http://semweb.mmlab.be/ns/linkedconnections#arrivalTime"
Const DCAT
DCAT: "http://www.w3.org/ns/dcat#" = "http://www.w3.org/ns/dcat#"
Const DCT
DCT: "http://purl.org/dc/terms/" = "http://purl.org/dc/terms/"
Const DEPARTURE_DELAY
DEPARTURE_DELAY: "http://semweb.mmlab.be/ns/linkedconnections#departureDelay" = "http://semweb.mmlab.be/ns/linkedconnections#departureDelay"
Const DEPARTURE_STOP
DEPARTURE_STOP: "http://semweb.mmlab.be/ns/linkedconnections#departureStop" = "http://semweb.mmlab.be/ns/linkedconnections#departureStop"
Const DEPARTURE_TIME
DEPARTURE_TIME: "http://semweb.mmlab.be/ns/linkedconnections#departureTime" = "http://semweb.mmlab.be/ns/linkedconnections#departureTime"
Const DISTANCE
DISTANCE: 1 = 1
Const DROP_OFF_TYPE
DROP_OFF_TYPE: "http://vocab.gtfs.org/terms#dropOffType" = "http://vocab.gtfs.org/terms#dropOffType"
Const DURATION
DURATION: 2 = 2
Const GEO
GEO: "http://www.w3.org/2003/01/geo/wgs84_pos" = "http://www.w3.org/2003/01/geo/wgs84_pos"
Const GEOSPARQL
GEOSPARQL: "http://www.opengis.net/ont/geosparql#" = "http://www.opengis.net/ont/geosparql#"
Const GTFS
GTFS: "http://vocab.gtfs.org/terms#" = "http://vocab.gtfs.org/terms#"
Const HEADSIGN
HEADSIGN: "http://vocab.gtfs.org/terms#headsign" = "http://vocab.gtfs.org/terms#headsign"
Const HYDRA
HYDRA: "http://www.w3.org/ns/hydra/core" = "http://www.w3.org/ns/hydra/core"
Const LC
LC: "http://semweb.mmlab.be/ns/linkedconnections#" = "http://semweb.mmlab.be/ns/linkedconnections#"
Const NEXT_CONNECTION
NEXT_CONNECTION: "http://semweb.mmlab.be/ns/linkedconnections#nextConnection" = "http://semweb.mmlab.be/ns/linkedconnections#nextConnection"
Const OSM
OSM: "https://w3id.org/openstreetmap/terms" = "https://w3id.org/openstreetmap/terms"
Const PICKUP_TYPE
PICKUP_TYPE: "http://vocab.gtfs.org/terms#pickupType" = "http://vocab.gtfs.org/terms#pickupType"
Const PLANNER
PLANNER: "https://planner.js.org/terms#" = "https://planner.js.org/terms#"
Const POSITION
POSITION: 0 = 0
Const PROFILE
PROFILE: "https://w3id.org/openplannerteam/profile#" = "https://w3id.org/openplannerteam/profile#"
Const RDF
RDF: "http://www.w3.org/1999/02/22-rdf-syntax-ns" = "http://www.w3.org/1999/02/22-rdf-syntax-ns"
Const RDFS
RDFS: "http://www.w3.org/2000/01/rdf-schema" = "http://www.w3.org/2000/01/rdf-schema"
Const ROUTE
ROUTE: "http://vocab.gtfs.org/terms#route" = "http://vocab.gtfs.org/terms#route"
Const TREE
TREE: "https://w3id.org/tree#" = "https://w3id.org/tree#"
Const TRIP
TRIP: "http://vocab.gtfs.org/terms#trip" = "http://vocab.gtfs.org/terms#trip"
Const XMLS
XMLS: "http://www.w3.org/2001/XMLSchema" = "http://www.w3.org/2001/XMLSchema"
Const container
container: Container = new Container()
Represents distance in m (meters)