graphhopper-ts-client
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

TypeScript client for the GraphHopper Directions API

Please refer to the original repository for information on the API and examples.

The bundled version can be referenced in the browser and provides a GHOptimization property in the window object.

Usage

Browser

This method doesn't add value with respect to the official source.

Include the vendor~optimization bundle and the optimization bundle in your html, for instance:

<script type="text/javascript" src="https://raw.githubusercontent.com/massimosiani/graphhopper-ts-client/master/dist/vendors~gh-optimization-client.chunk.js"></script>
<script type="text/javascript" src="https://raw.githubusercontent.com/massimosiani/graphhopper-ts-client/master/dist/gh-optimization-client.bundle.js"></script>

Then you are ready to instantiate the object and call the API:

const args = { key: 'your_key', profile: 'car' };
const ghOptimization = new GHOptimization.GraphHopperOptimization(args);
ghOptimization.addPoint({ lng: -0.103512, lat: 51.503634 });
ghOptimization.addPoint({ lng: -0.074673, lat: 51.519339 });
ghOptimization.addPoint({ lng: -0.103168, lat: 51.52681 });
ghOptimization.addVehicle({
    vehicle_id: `_vehicle_0`,
    start_address: {
        location_id: '_start_location',
        lon: -0.103512,
        lat: 51.503634
    }
});
ghOptimization.doVRPRequest();

NPM

To take full advantage of the TypeScript features, install the lib with npm:

npm install graphhopper-ts-client --save

And use it in your code:

import { GraphHopperOptimization } from 'graphhopper-ts-client';

const key = "[Sign-up for free and get your own key: https://www.graphhopper.com/products/]";
const profile = "car";

const ghOptimization = new GHOptimization.GraphHopperOptimization(args);
ghOptimization.addPoint({ lng: -0.103512, lat: 51.503634 });
ghOptimization.addPoint({ lng: -0.074673, lat: 51.519339 });
ghOptimization.addPoint({ lng: -0.103168, lat: 51.52681 });
ghOptimization.addVehicle({
    vehicle_id: `_vehicle_0`,
    start_address: {
        location_id: '_start_location',
        lon: -0.103512,
        lat: 51.503634
    }
});
ghOptimization.doVRPRequest();

Example

An example can be found in the test/index.html file.

Dependencies (1)

Dev Dependencies (15)

Package Sidebar

Install

npm i graphhopper-ts-client

Weekly Downloads

1

Version

0.1.1

License

ISC

Unpacked Size

120 kB

Total Files

24

Last publish

Collaborators

  • massimosiani