diff --git a/src/graphics/slope/Slope.ts b/src/graphics/slope/Slope.ts index 624106e..fd63a2f 100644 --- a/src/graphics/slope/Slope.ts +++ b/src/graphics/slope/Slope.ts @@ -30,19 +30,17 @@ export class Slope extends JlGraphic { lineGraphic: Graphics; slopeNumber: VectorText; slopeLong: VectorText; + changePoints: IPointData[] = []; constructor() { super(Slope.Type); this.lineGraphic = new Graphics(); this.slopeNumber = new VectorText(); - this.slopeNumber.name = 'slopeNumber'; this.slopeLong = new VectorText(); - this.slopeLong.name = 'slopeLong'; const vectorTexts = [this.slopeNumber, this.slopeLong]; vectorTexts.forEach((vectorText) => { vectorText.setVectorFontSize(14); vectorText.anchor.set(0.5); vectorText.style.fill = '0xffffff'; - vectorText.transformSave = true; }); this.transformSave = true; this.addChild(this.lineGraphic); @@ -69,29 +67,21 @@ export class Slope extends JlGraphic { this.datas.points.forEach((p, i) => { if (i !== 0) { this.lineGraphic.lineTo(p.x, p.y + distanceY); + this.changePoints.push({ x: p.x, y: p.y + distanceY }); } else { this.lineGraphic.moveTo(p.x, p.y - distanceY); + this.changePoints.push({ x: p.x, y: p.y - distanceY }); } }); //坡度值 this.slopeNumber.text = Math.abs( parseFloat(this.datas.slopeNumber / 1000 + '') ); - const slopeNumberPosition = this.datas.childTransforms?.find( - (t) => t.name === this.slopeNumber.name - )?.transform.position; - if (slopeNumberPosition) { - this.slopeNumber.position.set( - slopeNumberPosition.x, - slopeNumberPosition.y - ); - } else { - const centerPos = calculateLineMidpoint( - this.datas.points[0], - this.datas.points[this.datas.points.length - 1] - ); - this.slopeNumber.position.set(centerPos.x, centerPos.y - 15); - } + const centerPos = calculateLineMidpoint( + this.datas.points[0], + this.datas.points[this.datas.points.length - 1] + ); + this.slopeNumber.position.set(centerPos.x, centerPos.y - 15); //坡度长度 const slopeKiloMarkerL = this.queryStore.queryById( this.datas.refDeviceId[0] @@ -102,18 +92,7 @@ export class Slope extends JlGraphic { this.slopeLong.text = slopeKiloMarkerR.datas.kilometerSystem[0]?.kilometer - slopeKiloMarkerL.datas.kilometerSystem[0]?.kilometer; - const slopeLongPosition = this.datas.childTransforms?.find( - (t) => t.name === this.slopeLong.name - )?.transform.position; - if (slopeLongPosition) { - this.slopeLong.position.set(slopeLongPosition.x, slopeLongPosition.y); - } else { - const centerPos = calculateLineMidpoint( - this.datas.points[0], - this.datas.points[this.datas.points.length - 1] - ); - this.slopeLong.position.set(centerPos.x, centerPos.y + 15); - } + this.slopeLong.position.set(centerPos.x, centerPos.y + 15); } loadRelations() { if (this.datas.refDeviceId.length) { diff --git a/src/graphics/slope/SlopeAssistant.ts b/src/graphics/slope/SlopeAssistant.ts index a2199aa..519ceed 100644 --- a/src/graphics/slope/SlopeAssistant.ts +++ b/src/graphics/slope/SlopeAssistant.ts @@ -110,14 +110,11 @@ class SlopeGraphicHitArea implements IHitArea { this.slope = slope; } contains(x: number, y: number): boolean { - for (let i = 1; i < this.slope.datas.points.length; i++) { - const p1 = this.slope.datas.points[i - 1]; - const p2 = this.slope.datas.points[i]; - if (linePoint(p1, p2, { x, y }, SlopeConsts.lineWidth)) { - return true; - } - } - return false; + let contains = false; + const p1 = this.slope.changePoints[0]; + const p2 = this.slope.changePoints[1]; + contains = contains || linePoint(p1, p2, { x, y }, SlopeConsts.lineWidth); + return contains; } }