代码调整

This commit is contained in:
joylink_cuiweidong 2020-03-16 10:36:01 +08:00
parent a29b0360d5
commit a7193c5424

View File

@ -16,7 +16,7 @@ export default class Train extends Group {
this.model = model;
this.style = style;
this.z = 40;
this.size = 0;
// this.size = 0;
this.section = null;
this.isShowShape = true;
this.fontSize = style.Train.common.useSelfText ? style.Train.common.nameFontSize || style.Train.common.trainTextFontSize : model.nameFontSize || style.Train.common.nameFontSize || style.Train.common.trainTextFontSize;
@ -117,16 +117,25 @@ export default class Train extends Group {
// 算出折线的长度
this.lineLength = 0;
let oldPoint = null;
this.pointList = [];
oldmodel.points.forEach((point)=>{
if (oldPoint) {
const temp = Math.sqrt(
Math.pow(point.x - oldPoint.x, 2) +
Math.pow(point.y - oldPoint.y, 2),
);
this.pointList.push({length:temp, pointStart:{x:oldPoint.x, y:oldPoint.y}, pointEnd:{x:point.x, y:point.y}});
this.lineLength += temp;
}
oldPoint = point;
});
oldPoint = 0;
this.pointList.forEach(point=>{
point.percentStart = oldPoint / this.lineLength;
oldPoint += point.length;
point.percentEnd = oldPoint / this.lineLength;
});
this.triangle = new ETriangle({
style: this.style,
zlevel: this.zlevel,
@ -153,68 +162,16 @@ export default class Train extends Group {
updateSection() {
const train = this.model;
if (train.physicalCode && train.offsetp && this.triangle) {
const data = train.physicalCode;
const oldmodel = store.getters['map/getDeviceByCode'](data);
// 待处理(多个点的问题)
// debugger;
let points = Object.assign([], oldmodel.points);
if (train.right === 0) {
points = Object.assign([], points.reverse());
}
// const points = oldmodel.points;
if (this.nextPointIndex > points.length - 1) {
const leftPoint = oldmodel.points[0];
const rightPoint = oldmodel.points[oldmodel.points.length - 1];
this.startX = leftPoint.x + (rightPoint.x - leftPoint.x) * train.offsetp;
this.startY = leftPoint.y + (rightPoint.y - leftPoint.y) * train.offsetp;
} else {
// debugger;
// this.lineLength * train.offsetp
// if (this.currentLength > targetDistance) {
// this.currentLength = this.currentLength - targetDistance;
// this.nextPointIndex++;
// targetDistance = Math.sqrt(
// Math.pow(points[this.nextPointIndex - 1].x - points[this.nextPointIndex].x, 2) +
// Math.pow(points[this.nextPointIndex - 1].y - points[this.nextPointIndex].y, 2),
// );
// }
// debugger;
// 目标距离
console.log('2222222222///////////////////////', this.currentAdd);
let targetDistance = Math.sqrt(
Math.pow(points[this.nextPointIndex - 1].x - points[this.nextPointIndex].x, 2) +
Math.pow(points[this.nextPointIndex - 1].y - points[this.nextPointIndex].y, 2),
);
const right = train.right == 1 ? 0 : 1;
let currentDistance = this.lineLength * Math.abs(right - train.offsetp) - this.currentAdd;
console.log('33333333333/////////////////', currentDistance);
// 利用运动距离与目标距离, 判断运动的点是否超过下一个目标点, 超过了就重置下一个点
if (currentDistance >= targetDistance) {
this.nextPointIndex++;
this.currentAdd += targetDistance;
if (this.nextPointIndex <= points.length - 1) {
currentDistance = this.lineLength * Math.abs(right - train.offsetp) - this.currentAdd;
console.log('44444444444///////////////', this.currentAdd);
console.log('///////////////////////////////////', currentDistance);
targetDistance = Math.sqrt(
Math.pow(points[this.nextPointIndex - 1].x - points[this.nextPointIndex].x, 2) +
Math.pow(points[this.nextPointIndex - 1].y - points[this.nextPointIndex].y, 2),
);
} else {
return;
}
this.pointList.forEach(point=>{
if (train.offsetp > point.percentStart && train.offsetp <= point.percentEnd) {
this.startX = point.pointStart.x + (point.pointEnd.x - point.pointStart.x) * (train.offsetp - point.percentStart);
this.startY = point.pointStart.y + (point.pointEnd.y - point.pointStart.y) * (train.offsetp - point.percentStart);
}
const rate = (this.lineLength * Math.abs(right - train.offsetp) - this.currentAdd) / targetDistance;
this.startX = points[this.nextPointIndex - 1].x + (points[this.nextPointIndex].x - points[this.nextPointIndex - 1].x) * rate;
this.startY = points[this.nextPointIndex - 1].y + (points[this.nextPointIndex].y - points[this.nextPointIndex - 1].y) * rate;
// console.log(this.nextPointIndex, '------', this.startX, '------', this.startY, '////////', currentDistance, '11111', targetDistance, 'ssssss', this.currentAdd);
}
});
const point = {x:this.startX, y:this.startY};
this.triangle.point = point;
this.triangle.updateTriangle(point, train.right);
this.triangle.dirty();
this.dirty();
}
}