This commit is contained in:
fan 2023-08-08 15:54:39 +08:00
commit 8abb01a1c1
2 changed files with 14 additions and 38 deletions

View File

@ -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) {

View File

@ -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;
}
}