GIScience / openrouteservice-js

:pushpin: The JavaScript API to consume openrouteservice(s) painlessly!
https://openrouteservice.org
Apache License 2.0
191 stars 35 forks source link

Add Optimization Service support #45

Closed damian66 closed 1 year ago

damian66 commented 2 years ago

Added support for Optimization Service, requested in #38. I tried to match the code style with other files. I also decided to keep it as simple as possible - feel free to suggest changes. Service arguments are saved in the class instance to match the behavior of the rest of the repository.

Usage

Example of how the optimization service could be consumed. It was included in the README.md file as well.

var openrouteservice = require("openrouteservice-js");

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

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],
    }
  ],
})
.then(function(response) {
  // Add your own result handling here
  console.log('response', JSON.stringify(response));
})
.catch(function(err) {
  var str = 'An error occurred: ' + err;
  console.log(str)
});
TheGreatRefrigerator commented 2 years ago

Hi @damian66,

thanks a lot for the contribution!

I'll see if i can find some time within the next weeks to review, can't promise anything though. Until then, if people want to use this please use damian's fork.

sonarcloud[bot] commented 2 years ago

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
19.3% 19.3% Duplication

TheGreatRefrigerator commented 1 year ago

superseded by https://github.com/GIScience/openrouteservice-js/pull/56