• Stars
    star
    203
  • Rank 192,890 (Top 4 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created about 6 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ“Œ The JavaScript API to consume openrouteservice(s) painlessly!

The JavaScript API to consume openrouteservice(s) painlessly!

Build and test codecov

This library lets you consume the openrouteservice API in JavaScript applications. It allows you to painlessly consume the following services:

  • Directions (routing)
  • Geocoding | Reverse Geocoding | Structured Geocoding (powered by Pelias)
  • Isochrones (accessibility)
  • Time-distance matrix
  • POIs (points of interest)
  • Elevation (linestring or point)
  • Optimization

See the examples in the examples folder

Note: In order to use this client, you have to register for a token at openrouteservice. To understand the features of openrouteservice, please don't forget to read the docs. For visualization purposes on the map please use openrouteservice maps.

Documentation

This library uses the ORS API for request validation. To understand the input of each API specifically, please check API Playground that provides an interactive documentation.

Installation and Usage

Requirements

  • git
  • nodeJS
  • if not included in nodeJS: npm

Install the library with npm:

npm install openrouteservice-js --save

Use es module import

import Openrouteservice from 'openrouteservice-js'
let orsDirections = new Openrouteservice.Directions({ api_key: "XYZ"});
// ...

Use requirejs

const Openrouteservice = require("openrouteservice-js");
let orsDirections = new Openrouteservice.Directions({ api_key: "XYZ"});
// ...

Use the distribution file directly in html

<script type="module" src="../openrouteservice-js/dist/ors-js-client.js"></script>
<script>
  let orsDirections = new Openrouteservice.Directions({ api_key: "XYZ"});
  // ...
</script>

Pair with local openrouteservice instance

// Note: The API key is currently still passed as a parameter but not needed by the local instance
import Openrouteservice from 'openrouteservice-js'
let orsDirections = new Openrouteservice.Directions(
  { host: "http://localhost:8082/ors" }
);
// ...

Integrate the APIs in your application

Isochrones Example

// Add your api_key here
const Isochrones = new Openrouteservice.Isochrones({ api_key: "XYZ"})
try {
  let response = await Isochrones.calculate({
    locations: [[8.690958, 49.404662], [8.687868, 49.390139]],
    profile: 'driving-car',
    range: [600],
    units: 'km',
    range_type: 'distance',
    attributes: ['area'],
    smoothing: 0.9,
    avoidables: ['highways'],
    avoid_polygons: {
      type: 'Polygon',
      coordinates: [
        [
          [8.683533668518066, 49.41987949639816],
          [8.680272102355957, 49.41812070066643],
          [8.683919906616211, 49.4132348262363],
          [8.689756393432617, 49.41806486484901],
          [8.683533668518066, 49.41987949639816]
        ]
      ]
    },
    area_units: 'km'
  })
  // Add your own result handling here
  console.log("response: ", response)
    
} catch (err) {
  console.log("An error occurred: " + err.status)
  console.error(await err.response.json())
}

Directions HGV example (browser)

Note: Nested parameters from the options object are easier accessible like restrictions, avoidables and avoid_polygons (cf. API docs)

<script>
  window.onload = async function() {
    // Add your api_key here
    let orsDirections = new Openrouteservice.Directions({ api_key: "XYZ"});

    try {
      let response = await orsDirections.calculate({
        coordinates: [[8.690958, 49.404662], [8.687868, 49.390139]],
        profile: 'driving-hgv',
        restrictions: {
          height: 10,
          weight: 5
        },
        extra_info: ['waytype', 'steepness'],
        avoidables: ['highways', 'tollways', 'ferries', 'fords'],
        avoid_polygons: {
          type: 'Polygon',
          coordinates: [
            [
              [8.683533668518066, 49.41987949639816],
              [8.680272102355957, 49.41812070066643],
              [8.683919906616211, 49.4132348262363],
              [8.689756393432617, 49.41806486484901],
              [8.683533668518066, 49.41987949639816]
            ]
          ]
        },
        format: 'json'
      })
      // Add your own result handling here
      console.log("response: ", response)

    } catch (err) {
      console.log("An error occurred: " + err.status)
      console.error(await err.response.json())
    }
  };
</script>

Geocode examples

// Add your api_key here
const Geocode = new Openrouteservice.Geocode({ api_key: "XYZ"})

try {
  let response = await Geocode.geocode({
    text: "Heidelberg",
    boundary_circle: { lat_lng: [49.412388, 8.681247], radius: 50 },
    boundary_bbox: [[49.260929, 8.40063], [49.504102, 8.941707]],
    boundary_country: ["DE"]
  })
  // Add your own result handling here
  console.log("response: ", response)

} catch (err) {
  console.log("An error occurred: " + err.status)
  console.error(await err.response.json())
}

try {
  let response_reverse = await Geocode.reverseGeocode({
  point: { lat_lng: [49.412388, 8.681247], radius: 50 },
  boundary_country: ["DE"]
})
  // Add your own result handling here
  console.log("response: ", response_reverse)

} catch (err) {
  console.log("An error occurred: " + err.status)
  console.error(await err.response.json())
}


try {
  let response_structured = await Geocode.structuredGeocode({
  locality: "Heidelberg"
})
  // Add your own result handling here
  console.log("response: ", response_structured)

} catch (err) {
  console.log("An error occurred: " + err.status)
  console.error(await err.response.json())
}

Matrix example

// Add your api_key here
const Matrix = new Openrouteservice.Matrix({ api_key: "XYZ"})

try {
  let response = Matrix.calculate({
  locations: [[8.690958, 49.404662], [8.687868, 49.390139], [8.687868, 49.390133]],
  profile: "driving-car",
  sources: ['all'],
  destinations: ['all']
})
  // Add your own result handling here
  console.log("response: ", response)

} catch (err) {
  console.log("An error occurred: " + err.status)
  console.error(await err.response.json())
}

Elevation example

// Add your api_key here
const Elevation = new Openrouteservice.Elevation({api_key: "XYZ"})

try {
  let response = Elevation.lineElevation({
  format_in: 'geojson',
  format_out: 'geojson',
  geometry: {
    coordinates: [[13.349762, 38.11295], [12.638397, 37.645772]],
    type: 'LineString'
  }
})
  // Add your own result handling here
  console.log("response: ", response)

} catch (err) {
  console.log("An error occurred: " + err.status)
  console.error(await err.response.json())
}

Optimization example

Or consume Optimization API to solve vehicle routing problems

// Add your api_key here
let Optimization = new openrouteservice.Optimization({api_key: "XYZ"});

try {
  let response = Optimization.optimize({
  jobs: [
    {
      id: 1,
      service: 300,
      amount: [1],
      location: [2.03655, 48.61128],
      skills: [1]
    },
    {
      id: 2,
      service: 300,
      amount: [1],
      location: [2.03655, 48.61128],
      skills: [2]
    },
  ],
  vehicles: [
    {
      id: 1,
      profile: 'driving-car',
      start: [2.35044, 48.71764],
      end: [2.35044, 48.71764],
      capacity: [3],
      skills: [1, 2],
    }
  ],
})
  // Add your own result handling here
  console.log("response: ", response)

} catch (err) {
  console.log("An error occurred: " + err.status)
  console.error(await err.response.json())
}

Development Setup

Clone the openrouteservice-js repository from GitHub into a development environment of your choice.

git clone https://github.com/GIScience/openrouteservice-js.git
cd openrouteservice-js

# Install the dependencies
npm install

# Make your openrouteservice API key available for tests, examples and dev_app
sh setup.sh <your-api-key>

Start the dev_app for debugging when working with source files:

# runs the app at http://localhost:5173
vite

Now you can either use the devtools of your browser to set breakpoints (e.g. in OrsGeocode) or create a JavaScript Debug configuration to debug with WebStorm: debug_config

Run the config in debug mode to open the Chrome browser and reload the page after changes for them to take effect immediately.

Running Tests

To run specific unit test files in src/__tests__ on demand during development, run

npm run test:e2e

Choose one of your installed browsers in the cypress UI you want to test in and select the test file you want to run.

Component tests for the web app can be run by switching to component testing.

To run tests without ui use the npm scripts ending with :ci e.g. for unit, component and e2e tests:

npm run test:ci

Commits and versioning

  • This app uses the commitizen plugin to generate standardized commit types/messages. After applying any change in a feature branch, use git add . and then npm run commit (instead of git commit ...)
  • The plugin standard-version is used to generate changelog entries, version tag and to bump the app version in package.json.

Deployment flow:

  • Apply the changes in a feature branch and test it locally
  • Once the feature is ready, merge it to develop, deploy it to the testing environment
  • Checkout in main, merge from develop and use npm run release to generate a release. This will generate a new release commit as well as a git tag and an entry in CHANGELOG.md.

For more details about commitizen and standard-version see this article

More Repositories

1

openrouteservice

🌍 The open source route planner api with plenty of features.
Java
1,442
star
2

openrouteservice-py

🐍 The Python API to consume openrouteservice(s) painlessly!
Python
389
star
3

openrouteservice-app

πŸš™ The open source route planner app with plenty of features.
JavaScript
224
star
4

openpoiservice

πŸ“ Openpoiservice is a flask application which hosts a highly customizable points of interest database derived from OpenStreetMap data.
Python
171
star
5

GIScene.js

3D WebGIS framework. Based on Three.js. Easy to learn and customize. For examples and API see:
JavaScript
116
star
6

oshdb

OpenStreetMap History Data Analysis Framework
Java
110
star
7

ors-map-client

Openrouteservice API web SPA client using VueJS, Vuetify and Vue2Leaflet
JavaScript
108
star
8

Leaflet.Heightgraph

Leaflet plugin to visualize height information and road attributes.
JavaScript
100
star
9

orstools-qgis-plugin

Plugin for QGIS with a set of tools to use openrouteservice APIΒ΄s, based on openstreetmap
Python
96
star
10

openrouteservice-r

🌐 query openrouteservice API from R
R
93
star
11

helios

HELIOS - the Heidelberg LiDAR Operations Simulator - is a software package for interactive real-time simulation and visualisation of terrestrial, mobile and airborne laser scan surveys written in Java.
Java
85
star
12

openrouteservice-examples

πŸ“š (Mostly) real-world examples and inspirations to use the full breadth of ORS services and clients
Jupyter Notebook
84
star
13

openrouteservice-docs

πŸ“ This repository stores the swagger specifications of the openrouteservice API. Browse to swagger for a detailed overview.
63
star
14

openelevationservice

πŸŒ„ A GeoJSON based service to query SRTM elevation for points/lines.
Python
63
star
15

openrouteservice-app-legacy

OpenRouteService is an online route planning application that is based on open source software, open data and open standards.
JavaScript
55
star
16

ohsome2label

Historical OpenStreetMap Objects to Machine Learning Training Samples
Python
48
star
17

ohsome-api

API for analysing OpenStreetMap history data
Java
44
star
18

OSM-realtime-update

πŸ•‘ OpenStreetMap Data Extracts - updated on the fly!
JavaScript
41
star
19

ohsome-quality-api

Data quality estimations for OpenStreetMap
Python
34
star
20

sketch-map-tool

Create re-digitizable paper maps for offline data collection in the field.
Python
32
star
21

openfuelservice

πŸš—β˜οΈπŸ’Έ The opensource vehicle fuel consumption, emission and cost calculator api
Python
17
star
22

ohsome-py

Python bindings for the ohsome API
Jupyter Notebook
17
star
23

vostok

VOSTOK, the Voxel Octree Solar Toolkit, is a C++ command-line tool to compute a detailed model of incoming solar radiation distribution on a patch of land, including structures like buildings and vegetation, represented by a 3D point cloud data set.
C++
15
star
24

osmatrix-client

OSMatrix is a web-based application to visualize characteristics of OpenStreetMap, which are usually not displayed in cartographic representations of the data.
Python
14
star
25

ohsome-r

This ohsome R package grants access to the power of the ohsome API from R.
R
11
star
26

measures-rest

A REST server to provide measures for geospatial datasets
Java
10
star
27

ohsome-examples

A curated list of examples of using the https://github.com/giscience/ohsome-api
Jupyter Notebook
9
star
28

osmgpxmapmatcher

Java
9
star
29

osm-vis-data

Data for OSMvis
8
star
30

osmgpxinclinecalculator

Tools for incline computation with OSM GPX files
Java
7
star
31

gis-training-resource-center

Io
7
star
32

ohsome-dashboard

Web Client for easy access to OSM History and Quality Analyses
JavaScript
7
star
33

ohsome-qgis-plugin

ohsome Qgis plugin
Python
6
star
34

global-urban-building-completeness-analysis

Code related to the paper entitled "Investigating completeness and inequalities in OpenStreetMap: spatio-temporal analysis of global urban building data"
Jupyter Notebook
6
star
35

socialmedia2traffic-api

SocialMedia2Traffic API
Python
6
star
36

osmatrix

JavaScript
5
star
37

ol-print-layout-control

An extension of openlayers Control. It Helps the user to define a map area that fits to the desired output page format and orientation.
TypeScript
5
star
38

ohsome-now-stats-frontend

This is the frontend application for the ohsomeNow stats.
TypeScript
5
star
39

ohsome-now-stats

The goal of this project is to quantify the changes that are happening to the OpenStreetMap (OSM) database every minute.
Jupyter Notebook
5
star
40

ohsome-now-stats-service

This is the REST service for the ohsomeNow stats.
Kotlin
4
star
41

Safer-Route

R
4
star
42

osm-bikeability

Bikeability index based on OpenStreetMap features for european urban areas
Python
4
star
43

Long-term-validation-of-inner-urban-mobility-metrics-derived-from-Twitter

Long-term validation of inner-urban mobility metrics derived from Twitter
Jupyter Notebook
4
star
44

osmalert

OSM Alert: ohsome Alert variant for ISEP 2023
Java
3
star
45

osm-transform

Custom data filtering and enrichment for OpenStreetMap PBF files for a better openrouteservice graph building
C++
3
star
46

openrouteservice-java

β˜• The Java API to consume openrouteservice(s) painlessly!
3
star
47

ohsome-quality-api-examples

Jupyter Notebook with examples on how to use the OQT API with Python.
Jupyter Notebook
3
star
48

osmgpxpreprocessor

Pre-processing tools for incline computation with OSM GPX files
Java
3
star
49

green-15min-city

HeiGIT's OSS4SDG hackathon submission
HTML
3
star
50

mapswipe-analytics-client

JavaScript
2
star
51

POI-data-matching

Jupyter Notebook
2
star
52

mapswipe-tutorial

JavaScript
2
star
53

ohsome-api-dockerized

Dockerized Version of the ohsome-api
Dockerfile
2
star
54

healthcare-access-idai

Material on an analysis of healthcare access in Mozambique with the impact of cyclone Idai
R
2
star
55

osmgpxfilter

Java
2
star
56

heigit-disaster-portal

Python
2
star
57

OSM_Events

Supplementary Data and Visualizations for the Paper β€œAn Analysis of the Spatial and Temporal Distribution of Large-Scale Data Production Events in OpenStreetMap”
Python
2
star
58

mapswipe-live

JavaScript
1
star
59

giscience2023

Webpage for the Workshop given at the GIScience Conference 2023
SCSS
1
star
60

nairobi-uber-access

HTML
1
star
61

measures-rest-oshdb-docker

Scripts for starting measures for geospatial datasets in docker container, using the OSHDB
Shell
1
star
62

openpoiservice-docker

openpoiservice-docker
Shell
1
star
63

wegovnow

Embeddable Geo-Spatial Data Repository - WeGovNow Data Quality Management System
C
1
star
64

mapswipe-processing

Python
1
star
65

OSMlanduse-BFM

Jupyter Notebook
1
star
66

pybossa-mapswipe-2

HTML
1
star
67

vue2-leaflet-height-graph

Vue2Leaflet plugin to wrap Leaflet.Heightgraph control for Vue applications
JavaScript
1
star
68

mapswipe-analytics-backend

backend workers to generate and enrich mapswipe data and statistics
Python
1
star
69

shop-completeness

HTML
1
star
70

badges

Collection of badges for indicating the state of a project
Shell
1
star
71

osmatrix-processing

No longer maintained: Processing of osmatrix in postgreSQL
Java
1
star
72

hot-tm-critical-numbers

A GIScience Heidelberg project for for the HOT Tasking Manager.
Python
1
star
73

openrouteservice-schema

Repository for schemas used in the ORS
1
star
74

osm-measure-repository

A repository of OpenStreetMap (OSM) measures
Java
1
star
75

measures-rest-sparql

A SPARQL endpoint for the Measures REST OSHDB App framework.
Python
1
star
76

ai-assisted-osm-mapping-stats

Find out the global scale and evolution of AI-assisted mapping in OpenStreetMap
Jupyter Notebook
1
star
77

Jakarta_Thesis_Klipper

Flood Impact Assessment on Road Network and Healthcare Access
Python
1
star
78

ohsome-js-utils

This library contains JavaScript functions to help clients to use the Ohsome-Api for analyzing historical OpenStreetMap data.
TypeScript
1
star
79

ors-config-migration

Tool for migrating ors-config.json files to ors-config.yml
Python
1
star
80

ors-netascore-workshop-agile-24

Workshop at AGILE 2024
CSS
1
star
81

openrouteservice-workshop-r

Repo to run an openrouteserice workshop via R on binder
HTML
1
star