diff --git a/src/graphics/pathLine/PathLine.ts b/src/graphics/pathLine/PathLine.ts index bd5a110..fc42ead 100644 --- a/src/graphics/pathLine/PathLine.ts +++ b/src/graphics/pathLine/PathLine.ts @@ -2,6 +2,12 @@ import { JlGraphic, GraphicData, JlGraphicTemplate } from 'src/jl-graphic'; import { Graphics, IPointData } from 'pixi.js'; import { RunLine } from '../runLine/RunLine'; import { getDrawApp } from 'src/drawApp'; +// calculateDistanceFromPointToLine +import { + calculateDistanceFromPointToLine, + calculateFootPointFromPointToLine, + distance, +} from 'src/jl-graphic'; export interface KilometerPoint { get point(): IPointData; @@ -85,7 +91,25 @@ export class PathLine extends JlGraphic { }); } generatePathLineKilometerPoints(stas: string[]) { - // this.datas.points.forEach() + const kilometerPoints: KilometerPoint[] = []; + stas.forEach((stasId) => { + const sta = this.queryStore.queryById(stasId); + this.datas.points.some((p, index) => { + if (index) { + const prep = this.datas.points[index - 1]; + const fp = calculateFootPointFromPointToLine(prep, p, sta.position); + const length = distance(prep.x, prep.y, p.x, p.y); + if ( + distance(fp.x, fp.y, prep.x, prep.y) <= length && + distance(fp.x, fp.y, p.x, p.y) <= length + ) { + kilometerPoints.push({ point: fp, kilometer: 0 }); + return true; + } + } + }); + }); + this.datas.kilometerPoints = kilometerPoints; } }