rt-sim-training-client/src/jmapNew/shape/Train/TrainHead.js
joylink_fanyuhong 720125cfa5 列车调整
2020-02-13 13:12:22 +08:00

62 lines
1.8 KiB
JavaScript

import Group from 'zrender/src/container/Group';
import Rect from 'zrender/src/graphic/shape/Rect';
import Polygon from 'zrender/src/graphic/shape/Polygon';
/** 车头*/
export default class TrainHead extends Group {
constructor(model) {
super();
this.model = model;
this.create();
}
create() {
const model = this.model;
const style = this.model.style;
const baseMargin = (model.drect === -1 ? 1 : 0);
this.line = new Rect({
zlevel: model.zlevel,
z: model.z,
shape: {
x: model.point.x - baseMargin * (style.Train.trainHead.trainConntWidth),
y: model.point.y,
width: style.Train.trainHead.trainConntWidth * model.scale,
height: style.Train.trainHead.trainHeadRectHeight
},
style: {
lineWidth: 0.1,
stroke: style.trainSidelineColor,
fill: style.Train.trainHead.trainHeadFillColor
}
});
this.arrow = new Polygon({
zlevel: model.zlevel,
z: model.z,
shape: {
points: [
[model.point.x + model.drect * (style.Train.trainHead.trainHeadTriangleFirst.x), model.point.y + style.Train.trainHead.trainHeadTriangleFirst.y],
[model.point.x + model.drect * (style.Train.trainHead.trainHeadTriangleSecond.x), model.point.y + style.Train.trainHead.trainHeadTriangleSecond.y],
[model.point.x + model.drect * (style.Train.trainHead.trainHeadTriangleThird.x), model.point.y + style.Train.trainHead.trainHeadTriangleThird.y]
]
},
style: {
lineWidth: 0.1,
stroke: style.trainSidelineColor,
fill: style.Train.trainHead.trainHeadFillColor
}
});
this.add(this.line);
this.add(this.arrow);
}
setColor(color) {
this.line && this.line.setStyle('fill', color);
this.arrow && this.arrow.setStyle('fill', color);
}
setLineShow(isShow, sss) {
isShow ? this.line.show() : this.line.hide();
}
setArrowShow(isShow) {
isShow ? this.arrow.show() : this.arrow.hide();
}
}