This commit is contained in:
joylink_zhaoerwei 2023-08-08 15:22:56 +08:00
parent ddb03f379d
commit 774835ee4b

View File

@ -35,15 +35,12 @@ export class Slope extends JlGraphic {
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);
@ -80,21 +77,11 @@ export class Slope extends JlGraphic {
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( const centerPos = calculateLineMidpoint(
(t) => t.name === this.slopeNumber.name this.datas.points[0],
)?.transform.position; this.datas.points[this.datas.points.length - 1]
if (slopeNumberPosition) { );
this.slopeNumber.position.set( this.slopeNumber.position.set(centerPos.x, centerPos.y - 15);
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 slopeKiloMarkerL = this.queryStore.queryById( const slopeKiloMarkerL = this.queryStore.queryById(
this.datas.refDeviceId[0] this.datas.refDeviceId[0]
@ -105,18 +92,7 @@ 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( this.slopeLong.position.set(centerPos.x, centerPos.y + 15);
(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);
}
} }
loadRelations() { loadRelations() {
if (this.datas.refDeviceId.length) { if (this.datas.refDeviceId.length) {