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; lineGraphic: Graphics;
slopeNumber: VectorText; slopeNumber: VectorText;
slopeLong: VectorText; slopeLong: VectorText;
changePoints: IPointData[] = [];
constructor() { constructor() {
super(Slope.Type); super(Slope.Type);
this.lineGraphic = new Graphics(); this.lineGraphic = new Graphics();
this.slopeNumber = new VectorText(); this.slopeNumber = new VectorText();
this.slopeNumber.name = 'slopeNumber';
this.slopeLong = new VectorText(); this.slopeLong = new VectorText();
this.slopeLong.name = 'slopeLong';
const vectorTexts = [this.slopeNumber, this.slopeLong]; const vectorTexts = [this.slopeNumber, this.slopeLong];
vectorTexts.forEach((vectorText) => { vectorTexts.forEach((vectorText) => {
vectorText.setVectorFontSize(14); vectorText.setVectorFontSize(14);
vectorText.anchor.set(0.5); vectorText.anchor.set(0.5);
vectorText.style.fill = '0xffffff'; vectorText.style.fill = '0xffffff';
vectorText.transformSave = true;
}); });
this.transformSave = true; this.transformSave = true;
this.addChild(this.lineGraphic); this.addChild(this.lineGraphic);
@ -69,29 +67,21 @@ export class Slope extends JlGraphic {
this.datas.points.forEach((p, i) => { this.datas.points.forEach((p, i) => {
if (i !== 0) { if (i !== 0) {
this.lineGraphic.lineTo(p.x, p.y + distanceY); this.lineGraphic.lineTo(p.x, p.y + distanceY);
this.changePoints.push({ x: p.x, y: p.y + distanceY });
} else { } else {
this.lineGraphic.moveTo(p.x, p.y - distanceY); this.lineGraphic.moveTo(p.x, p.y - distanceY);
this.changePoints.push({ x: p.x, y: p.y - distanceY });
} }
}); });
//坡度值 //坡度值
this.slopeNumber.text = Math.abs( this.slopeNumber.text = Math.abs(
parseFloat(this.datas.slopeNumber / 1000 + '') 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( const centerPos = calculateLineMidpoint(
this.datas.points[0], this.datas.points[0],
this.datas.points[this.datas.points.length - 1] this.datas.points[this.datas.points.length - 1]
); );
this.slopeNumber.position.set(centerPos.x, centerPos.y - 15); this.slopeNumber.position.set(centerPos.x, centerPos.y - 15);
}
//坡度长度 //坡度长度
const slopeKiloMarkerL = this.queryStore.queryById( const slopeKiloMarkerL = this.queryStore.queryById(
this.datas.refDeviceId[0] this.datas.refDeviceId[0]
@ -102,19 +92,8 @@ export class Slope extends JlGraphic {
this.slopeLong.text = this.slopeLong.text =
slopeKiloMarkerR.datas.kilometerSystem[0]?.kilometer - slopeKiloMarkerR.datas.kilometerSystem[0]?.kilometer -
slopeKiloMarkerL.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() { loadRelations() {
if (this.datas.refDeviceId.length) { if (this.datas.refDeviceId.length) {
this.datas.refDeviceId.forEach((id) => { this.datas.refDeviceId.forEach((id) => {

View File

@ -110,14 +110,11 @@ class SlopeGraphicHitArea implements IHitArea {
this.slope = slope; this.slope = slope;
} }
contains(x: number, y: number): boolean { contains(x: number, y: number): boolean {
for (let i = 1; i < this.slope.datas.points.length; i++) { let contains = false;
const p1 = this.slope.datas.points[i - 1]; const p1 = this.slope.changePoints[0];
const p2 = this.slope.datas.points[i]; const p2 = this.slope.changePoints[1];
if (linePoint(p1, p2, { x, y }, SlopeConsts.lineWidth)) { contains = contains || linePoint(p1, p2, { x, y }, SlopeConsts.lineWidth);
return true; return contains;
}
}
return false;
} }
} }