import type { IActivityHandler } from "@vertigis/workflow"; import { lineString, lineSliceAlong, length } from "@turf/turf"; /** An interface that defines the inputs of the activity. */ interface SliceLineInputs { /** * @displayName Path * @description an array of path coordinates. * @required */ path: []; /** * @displayName start * @description start distance to slice * @required */ start: number; /** * @displayName end * @description end distance to slice * @required */ end: number; } /** An interface that defines the outputs of the activity. */ interface SliceLineOutputs { /** * @description The result of the activity. */ result: object; } function sliceLine(path: [], start: number, stop: number) { const line = lineString(path); const linelength = length(line, { units: "meters" }); if (stop > linelength) { stop = linelength; } const sliced = lineSliceAlong(line, start, stop, { units: "meters" }); return sliced; } /** * @displayName Slice Line * @category Geocortex * @description Slice Line based on start and end distance - Ver 1.01 */ export default class SliceLineActivity implements IActivityHandler { /** Perform the execution logic of the activity. */ execute(inputs: SliceLineInputs): SliceLineOutputs { const result = sliceLine(inputs.path, inputs.start, inputs.end); return { result: result, }; } }