UNPKG

@geoapify/route-planner-sdk

Version:

TypeScript SDK for the Geoapify Route Planner API. Supports route optimization, delivery planning, and timeline visualization in browser and Node.js

43 lines (42 loc) 1.6 kB
export class RouteResultEditorBase { constructor(result) { this.unassignedReq = "unassigned"; this.assignAgentReqStart = "assign-agent-"; this.result = result; } checkIfArrayIsUnique(myArray) { return myArray.length === new Set(myArray).size; } getAgentByIndex(agentIndex) { return this.result.getRawData().properties.params.agents[agentIndex]; } getJobByIndex(jobIndex) { return this.result.getRawData().properties.params.jobs[jobIndex]; } getShipmentByIndex(shipmentIndex) { return this.result.getRawData().properties.params.shipments[shipmentIndex]; } validateAgent(agentIndex) { let agentFound = this.getAgentByIndex(agentIndex); if (!agentFound) { throw new Error(`Agent with index ${agentIndex} not found`); } } updateResult(newResult) { this.result.getRawData().features = newResult.getRawData().features; this.result.getRawData().properties.issues = newResult.getRawData().properties.issues; } addAgentCapabilities(agents) { for (let agentIndex = 0; agentIndex < agents.length; agentIndex++) { const agent = agents[agentIndex]; const capabilityName = `assign-agent-${agentIndex}`; if (!agent.capabilities) { agent.capabilities = []; } // Only add the capability if it's not already present if (!agent.capabilities.includes(capabilityName)) { agent.capabilities.push(capabilityName); } } } }