UNPKG

@geoapify/route-planner-sdk

Version:

A TypeScript SDK for the Geoapify Route Planner API that simplifies route optimization requests, and helps visualize and edit resulting routes.

86 lines (85 loc) 3.89 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { RoutePlannerResult } from "./models/entities/route-planner-result"; import { RouteResultJobEditor } from "./tools/route-editor/route-result-job-editor"; import { RouteResultShipmentEditor } from "./tools/route-editor/route-result-shipment-editor"; import { Utils } from "./tools/utils"; export class RoutePlannerResultEditor { constructor(result) { this.result = new RoutePlannerResult(Utils.cloneObject(result.getOptions()), Utils.cloneObject(result.getRaw())); } /** * Assigns a job to an agent. Removes the job if it's currently assigned to another agent * @param agentId - The ID of the agent. * @param jobIds - The IDs of the jobs. * @returns {boolean} - Returns true if the job was successfully assigned. */ assignJobs(agentId, jobIds) { return __awaiter(this, void 0, void 0, function* () { return new RouteResultJobEditor(this.result).assignJobs(agentId, jobIds); }); } /** * Assigns a shipment to an agent. Removes the shipment if it's currently assigned to another agent * @param shipmentIds - The IDs of the shipments. * @param agentId - The ID of the agent. * @returns {boolean} - Returns true if the shipment was successfully assigned. */ assignShipments(agentId, shipmentIds) { return __awaiter(this, void 0, void 0, function* () { return new RouteResultShipmentEditor(this.result).assignShipments(agentId, shipmentIds); }); } /** * Removes a job from the plan. * @param jobIds - The IDs of the jobs to remove. * @returns {boolean} - Returns true if the job was successfully removed. */ removeJobs(jobIds) { return __awaiter(this, void 0, void 0, function* () { return new RouteResultJobEditor(this.result).removeJobs(jobIds); }); } /** * Removes a shipment from the plan. * @param shipmentIds - The IDs of the shipments to remove. * @returns {boolean} - Returns true if the shipment was successfully removed. */ removeShipments(shipmentIds) { return __awaiter(this, void 0, void 0, function* () { return new RouteResultShipmentEditor(this.result).removeShipments(shipmentIds); }); } /** * Adds new jobs to an agent's schedule. * @param jobs - An array of job objects to be added. * @param agentId - The ID of the agent. * @returns {boolean} - Returns true if jobs were successfully added. */ addNewJobs(agentId, jobs) { return new RouteResultJobEditor(this.result).addNewJobs(agentId, jobs); } /** * Adds new shipments to an agent's schedule. * @param shipments - An array of shipment objects to be added. * @param agentId - The ID of the agent. * @returns {boolean} - Returns true if shipments were successfully added. */ addNewShipments(agentId, shipments) { return new RouteResultShipmentEditor(this.result).addNewShipments(agentId, shipments); } /** * Returns the modified result. * @returns {RoutePlannerResult} - The modified result object. */ getModifiedResult() { return this.result; } }