A GraphHopper API client written in TypeScript
npm install graphhopper-ts-clientPlease 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.
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:
``
Then you are ready to instantiate the object and call the API:
`_vehicle_0
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: ,`
start_address: {
location_id: '_start_location',
lon: -0.103512,
lat: 51.503634
}
});
ghOptimization.doVRPRequest();
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();
An example can be found in the test/index.html file.