rt-sim-training-client/src/jmapNew/shape/StationStand/detain/EDetainRect.js

102 lines
3.0 KiB
JavaScript
Raw Normal View History

2020-08-19 18:27:36 +08:00
import Group from 'zrender/src/container/Group';
import Rect from 'zrender/src/graphic/shape/Rect';
class EDetainCircle extends Group {
constructor(model) {
super();
this.model = model;
this.create();
}
create() {
2020-09-09 13:55:42 +08:00
const model = this.model.modelData;
2020-08-19 18:27:36 +08:00
const style = this.model.style;
2020-09-09 13:55:42 +08:00
const standX = model.position.x - model.width / 2;
const standY = model.position.y - model.height / 2;
let y1;
let y2;
2020-08-19 18:27:36 +08:00
if (model.right && model.inside) {
y1 = standY + model.height / 2;
y2 = standY;
2020-08-19 18:27:36 +08:00
} else if (model.right && !model.inside) {
y1 = standY;
y2 = standY + model.height / 2;
2020-08-19 18:27:36 +08:00
} else if (!model.right && model.inside) {
y1 = standY;
y2 = standY + model.height / 2;
2020-08-19 18:27:36 +08:00
} else if (!model.right && !model.inside) {
y1 = standY + model.height / 2;
y2 = standY;
2020-08-19 18:27:36 +08:00
}
this.detainRectTop = new Rect({
2020-09-09 13:55:42 +08:00
zlevel: this.model.zlevel,
z: this.model.z + 1,
2020-08-19 18:27:36 +08:00
shape: {
2020-09-09 13:55:42 +08:00
x: standX,
y: y1,
2020-08-19 18:27:36 +08:00
width: model.width,
height: model.height / 2
},
style: {
2020-09-09 13:55:42 +08:00
lineWidth: style.StationStand.detainRect.lineWidth || 0,
stroke: style.StationStand.detainRect.spareStrokeColor,
2020-08-19 18:27:36 +08:00
fill: '#000'
}
});
this.detainRectBottom = new Rect({
zlevel: this.model.zlevel,
z: this.model.z + 1,
shape: {
x: standX,
y: y2,
width: model.width,
height: model.height / 2
},
style: {
lineWidth: style.StationStand.detainRect.lineWidth || 0,
stroke: style.StationStand.detainRect.spareStrokeColor,
fill: '#000'
}
});
this.add(this.detainRectTop);
this.add(this.detainRectBottom);
this.detainRectTop.hide();
this.detainRectBottom.hide();
2020-08-19 18:27:36 +08:00
}
setColor(color1, color2) {
this.detainRectTop.setStyle('fill', color1);
this.detainRectBottom.setStyle('fill', color2);
2020-08-19 18:27:36 +08:00
}
setShow() {
this.detainRectTop.show();
this.detainRectBottom.show();
2020-08-19 18:27:36 +08:00
}
setHide() {
this.detainRectTop.hide();
this.detainRectBottom.hide();
2020-08-19 18:27:36 +08:00
}
2020-09-09 13:55:42 +08:00
recover() {
this.setHide();
}
2020-09-15 17:08:28 +08:00
setState(model) {
2020-09-09 13:55:42 +08:00
const style = this.model.style;
2020-09-15 18:28:32 +08:00
/** 设置扣车*/
2020-09-15 17:08:28 +08:00
if (model.stationHoldTrain && model.centerHoldTrain) {
this.setShow();
this.setColor(...style.StationStand.detainRect.centerTrainColor);
2020-09-15 17:08:28 +08:00
} else if (model.stationHoldTrain) {
this.setShow();
this.setColor(...style.StationStand.detainRect.localTrainColor);
2020-09-15 17:08:28 +08:00
} else if (model.centerHoldTrain) {
this.setShow();
this.setColor(...style.StationStand.detainRect.centerTrainColor);
2020-09-09 13:55:42 +08:00
}
}
2020-08-19 18:27:36 +08:00
}
export default EDetainCircle;