desc: 修改section代码

This commit is contained in:
zyy 2019-07-24 11:12:15 +08:00
parent 627a7d86c8
commit e06411df1c
2 changed files with 86 additions and 111 deletions

View File

@ -10,23 +10,29 @@ export default class ESeparator extends Group {
this.zlevel = model.zlevel;
this.style = model.style;
this.z = 6;
this._create(model);
this.setType();
}
_create(model) {
createModel(points, lineWidth = null, stroke = null) {
const model = this.model;
this.partition = new Polyline({
zlevel: this.zlevel,
progressive: model.progressive,
z: this.z,
shape: {
points: []
points: points
},
style: {
lineWidth: this.style.Section.separator.width,
stroke: this.style.Section.separator.color
lineWidth: lineWidth || this.style.Section.separator.width,
stroke: stroke || this.style.Section.separator.color
}
});
this.add(this.partition);
}
// 创建 侵限分隔符
createCircle() {
const model = this.model;
this.circle = new Circle({
zlevel: this.zlevel,
z: this.z,
@ -42,45 +48,38 @@ export default class ESeparator extends Group {
fill: this.style.transparentColor
}
});
this.add(this.partition);
this.setType();
this.add(this.circle);
}
setType() {
const type = this.model.sepType;
const model = this.model;
if (model && this.style && model.traingle) {
this.remove(this.circle);
if (type === '00') {
this.partition.setShape('points', [
[model.point.x, model.point.y],
[model.point.x, model.point.y]
]);
} else if (type === '01') {
this.partition.setShape('points', [
if (type === '01') { // 普通分割
const points = [
[model.point.x, model.point.y - (this.style.Section.line.width)],
[model.point.x, model.point.y + (this.style.Section.line.width)]
]);
this.add(this.partition);
} else if (type === '02') {
this.partition.setShape('points', [
];
this.createModel(points);
} else if (type === '02') { // 单侧分割符
const points = [
[model.point.x + model.drict * (this.style.Section.line.width), model.point.y - (this.style.Section.line.width * 1.5)],
[model.point.x, model.point.y - (this.style.Section.line.width * 1.5)],
[model.point.x, model.point.y + (this.style.Section.line.width * 1.5)]
]);
this.add(this.partition);
} else if (type === '03') {
this.partition.setShape('points', [
];
this.createModel(points);
} else if (type === '03') { // 尽头分隔符
const points = [
[model.point.x + model.drict * (this.style.Section.line.width) * 1.2, model.point.y - (this.style.Section.line.width * 1.2)],
[model.point.x, model.point.y - (this.style.Section.line.width * 1.2)],
[model.point.x, model.point.y + (this.style.Section.line.width * 1.2)],
[model.point.x + model.drict * (this.style.Section.line.width) * 1.2, model.point.y + (this.style.Section.line.width * 1.2)]
]);
this.add(this.partition);
this.partition.setStyle({'lineWidth': this.style.Section.separator.endWidth, 'stroke': this.style.Section.separator.endColor });
} else if (type === '04') {
this.add(this.circle);
];
const lineWidth = this.style.Section.separator.endWidth;
const stroke = this.style.Section.separator.endColor;
this.createModel(points, lineWidth, stroke);
} else if (type === '04') { // 侵限分隔符
this.createCircle();
}
}

View File

@ -56,7 +56,13 @@ export default class Section extends Group {
style: style
});
// 创建延时释放
this.add(this.section);
}
// 创建延时释放 (需要在创建)
creatRelease(stroke, lineWidth) {
const model = this.model;
const style = this.style;
const traingle = new JTriangle(model.points[0], model.points[model.points.length - 1]);
this.release = new ERelease({
@ -69,16 +75,23 @@ export default class Section extends Group {
x2: model.points[0].x + traingle.getCos(traingle.absz / 3 * 2),
y2: model.points[0].y + traingle.getSin(traingle.absz / 3 * 2)
},
lineWidth: style.Section.line.width,
stroke: style.Section.line.spareColor
lineWidth: lineWidth || style.Section.line.width,
stroke: stroke || style.Section.line.spareColor
});
this.add(this.release);
}
// 创建限速线 (需要在创建)
creatSpeedLimit() {
const model = this.model;
const style = this.style;
const traingle = new JTriangle(model.points[0], model.points[model.points.length - 1]);
let x = traingle.drictx * (style.Section.speedLimit.Distance) * traingle.getSinRate();
let y = traingle.dricty * (style.Section.speedLimit.Distance) * traingle.getCosRate();
if (x == Infinity) { x = 0; }
if (y == Infinity) { y = 0; }
// 创建限速线
this.speedLimitLeft = new ELimitLines({
zlevel: this.zlevel,
z: this.z,
@ -90,20 +103,6 @@ export default class Section extends Group {
relSwitchCode: model.relSwitchCode,
isCurve: model.isCurve, // 是否曲线
points: model.points
// isLine: true,
// culling: model.isCurve, // 是否裁剪
// shape: {
// points: model.points,
// isCurve: model.isCurve, // 是否曲线
// isSwitchSection: model.isSwitchSection,
// relSwitchCode: model.relSwitchCode,
// switch: model.switch,
// style: style
// },
// style: {
// lineWidth: style.Section.speedLimit.width,
// stroke: style.Section.speedLimit.lineColor
// }
});
this.speedLimitRight = new ELimitLines({
@ -117,29 +116,13 @@ export default class Section extends Group {
relSwitchCode: model.relSwitchCode,
isCurve: model.isCurve, // 是否曲线
points: model.points
// isLine: true,
// culling: model.isCurve, // 是否裁剪
// shape: {
// points: model.points,
// isCurve: model.isCurve, // 是否曲线
// isSwitchSection: model.isSwitchSection,
// relSwitchCode: model.relSwitchCodes,
// switch: model.switch,
// style: style
// },
// style: {
// lineWidth: style.Section.speedLimit.width,
// stroke: style.Section.speedLimit.lineColor
// }
});
this.add(this.section);
this.add(this.release);
this.add(this.speedLimitLeft);
this.add(this.speedLimitRight);
}
/** 创建区段名称*/
// 创建区段名称
createSectionText() {
const model = this.model;
const style = this.style;
@ -287,7 +270,7 @@ export default class Section extends Group {
}
}
/** 创建计轴*/
// 创建计轴 (需要在创建)
createAxles() {
const model = this.model;
const style = this.style;
@ -378,7 +361,7 @@ export default class Section extends Group {
}
}
/** 创建分隔符*/
// 创建分隔符 (内层需要在创建)
createSeparator() {
const model = this.model;
const style = this.style;
@ -439,9 +422,13 @@ export default class Section extends Group {
lineWidth: this.style.Section.line.width
});
this.release.hide();
// this.speedLimitLeft.hide();
// this.speedLimitRight.hide();
if (this.release) {
this.remove(this.release);
}
if (this.speedLimitLeft && this.speedLimitRight) {
this.remove(this.speedLimitLeft);
this.remove(this.speedLimitRight);
}
}
}
@ -548,66 +535,55 @@ export default class Section extends Group {
/** 延时释放 10*/
timeRelease() {
if (this.release) {
this.section.setStyle({
stroke: this.style.Section.line.routeLockColor,
lineWidth: this.style.Section.line.width + this.style.Section.line.beyondWidth
});
this.release.show();
this.release.setStyle('lineWidth', this.style.Section.line.width + this.style.Section.line.beyondWidth);
this.release.setStyle('stroke', this.style.Section.line.routeLockColor);
this.release.animateStyle(true)
.when(1000, { stroke: this.style.Section.line.routeLockColor })
.when(2000, { stroke: this.style.Section.line.timeReleaseColor })
.start();
}
const lineWidth = this.style.Section.line.width + this.style.Section.line.beyondWidth;
const stroke = this.style.Section.line.routeLockColor;
this.creatRelease(stroke, lineWidth);
this.section.setStyle({
stroke: this.style.Section.line.routeLockColor,
lineWidth: this.style.Section.line.width + this.style.Section.line.beyondWidth
});
this.release.animateStyle(true)
.when(1000, { stroke: this.style.Section.line.routeLockColor })
.when(2000, { stroke: this.style.Section.line.timeReleaseColor })
.start();
}
/** 保护区段延时解锁 11*/
protectiveTimeRelease() {
if (this.release) {
this.section.setStyle({
stroke: this.style.Section.line.protectiveLockColor,
lineWidth: this.style.Section.line.width + this.style.Section.line.beyondWidth
});
this.release.show();
this.release.setStyle('lineWidth', this.style.Section.line.width + this.style.Section.line.beyondWidth);
this.release.setStyle('stroke', this.style.Section.line.protectiveLockColor);
this.release.animateStyle(true)
.when(1000, { stroke: this.style.Section.line.protectiveLockColor })
.when(2000, { stroke: this.style.Section.line.protectiveTimeReleaseColor })
.start();
}
const lineWidth = this.style.Section.line.width + this.style.Section.line.beyondWidth;
const stroke = this.style.Section.line.protectiveLockColor;
this.creatRelease(stroke, lineWidth);
this.section.setStyle({
stroke: this.style.Section.line.protectiveLockColor,
lineWidth: this.style.Section.line.width + this.style.Section.line.beyondWidth
});
this.release.animateStyle(true)
.when(1000, { stroke: this.style.Section.line.protectiveLockColor })
.when(2000, { stroke: this.style.Section.line.protectiveTimeReleaseColor })
.start();
}
/** 区段切除*/
sectionCutOff() {
if (this.release) {
const lineWidth = this.style.Section.line.width + (this.model.status != '01' ? this.style.Section.line.beyondWidth : 0);
this.section.animateStyle(true, [
{ time: 0, styles: { lineWidth: lineWidth } },
{ time: 1000, styles: { stroke: this.style.backgroundColor } },
{ time: 2000, styles: { lineWidth: lineWidth } }
]);
}
const lineWidth = this.style.Section.line.width + (this.model.status != '01' ? this.style.Section.line.beyondWidth : 0);
this.section.animateStyle(true, [
{ time: 0, styles: { lineWidth: lineWidth } },
{ time: 1000, styles: { stroke: this.style.backgroundColor } },
{ time: 2000, styles: { lineWidth: lineWidth } }
]);
}
/** 设置限速*/
setSpeedUpperLimit() {
if (this.section) {
this.speedLimitLeft.show();
this.speedLimitRight.show();
this.creatSpeedLimit();
}
}
/** 计轴预复位 12*/
axleReset() {
if (this.release) {
this.release.show();
this.release.setStyle({
stroke: this.style.Section.axle.resetColor
});
}
const stroke = this.style.Section.axle.resetColor;
this.creatRelease(stroke, null);
}
/** 计轴失效 13*/