@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
33 lines (32 loc) • 1.83 kB
JavaScript
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());
});
};
export class PreserveOrderBaseHelper {
static getEndPosition(context, agentIndex) {
return __awaiter(this, void 0, void 0, function* () {
const agentFeature = yield context.getOrCreateAgentFeature(agentIndex);
const waypoints = agentFeature.properties.waypoints || [];
if (waypoints.length === 0) {
return 0;
}
const lastWaypointIndex = waypoints.length - 1;
const hasEndAction = (waypoints[lastWaypointIndex].actions || [])
.some((action) => action.type === "end");
return hasEndAction ? lastWaypointIndex : lastWaypointIndex + 1;
});
}
static hasAgentStartLocation(context, agentIndex) {
const agent = context.getRawData().properties.params.agents[agentIndex];
return agent.start_location_index !== undefined || agent.start_location !== undefined;
}
static hasAgentEndLocation(context, agentIndex) {
const agent = context.getRawData().properties.params.agents[agentIndex];
return agent.end_location_index !== undefined || agent.end_location !== undefined;
}
}