2019-11-29 12:51:58 +08:00
|
|
|
import Polyline from 'zrender/src/graphic/shape/Polyline';
|
|
|
|
import Group from 'zrender/src/container/Group';
|
2020-04-08 18:38:08 +08:00
|
|
|
import Polygon from 'zrender/src/graphic/shape/Polygon';
|
2019-11-29 12:51:58 +08:00
|
|
|
|
|
|
|
class ESigPost extends Group {
|
2019-12-03 13:36:02 +08:00
|
|
|
constructor(model) {
|
|
|
|
super();
|
|
|
|
this.model = model;
|
|
|
|
this.create();
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2019-12-03 13:36:02 +08:00
|
|
|
create() {
|
|
|
|
const model = this.model;
|
|
|
|
const style = this.model.style;
|
2020-12-18 13:10:55 +08:00
|
|
|
// 基座
|
|
|
|
let verPoints = [[model.x, model.y + style.Signal.post.standardHeight * 1.2], [model.x, model.y - style.Signal.post.standardHeight * 1.2]];
|
|
|
|
if (style.Signal.post.standardVerticalShape && style.Signal.post.standardVerticalShape === '8') {
|
|
|
|
verPoints = [
|
|
|
|
[model.x - model.drict * 2, model.y + style.Signal.post.standardHeight * 1.2],
|
|
|
|
[model.x - model.drict * 2, model.y - style.Signal.post.standardHeight * 1.2],
|
|
|
|
[model.x, model.y - style.Signal.post.standardHeight * 1.2],
|
|
|
|
[model.x, model.y - style.Signal.post.standardRailWidth / 2],
|
|
|
|
[model.x + model.drict * 2, model.y - style.Signal.post.standardRailWidth / 2],
|
|
|
|
[model.x + model.drict * 2, model.y + style.Signal.post.standardRailWidth / 2],
|
|
|
|
[model.x, model.y + style.Signal.post.standardRailWidth / 2],
|
|
|
|
[model.x, model.y + style.Signal.post.standardHeight * 1.2]
|
|
|
|
];
|
|
|
|
this.ver = new Polygon({
|
|
|
|
_subType: 'SignalLamp',
|
|
|
|
_val: '3',
|
|
|
|
zlevel: model.zlevel,
|
|
|
|
z: model.z,
|
|
|
|
shape: {
|
|
|
|
points: verPoints
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
lineWidth: style.Signal.post.standardVerticalWidth,
|
|
|
|
stroke: style.Signal.post.standardColor,
|
|
|
|
fill: style.Signal.post.standardColor
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.ver = new Polyline({
|
|
|
|
_subType: 'SignalLamp',
|
|
|
|
_val: '3',
|
|
|
|
zlevel: model.zlevel,
|
|
|
|
z: model.z,
|
|
|
|
shape: {
|
|
|
|
points: verPoints
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
lineWidth: style.Signal.post.standardVerticalWidth,
|
|
|
|
stroke: style.Signal.post.standardColor,
|
|
|
|
fill: style.Signal.post.standardColor
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-03-19 18:39:20 +08:00
|
|
|
// 横杆
|
2019-12-03 13:36:02 +08:00
|
|
|
this.hor = new Polyline({
|
|
|
|
zlevel: model.zlevel,
|
|
|
|
z: model.z,
|
2020-05-25 14:06:16 +08:00
|
|
|
_val: '3',
|
2019-12-03 13:36:02 +08:00
|
|
|
shape: {
|
|
|
|
points: [
|
|
|
|
[model.x, model.y],
|
2020-02-03 17:17:56 +08:00
|
|
|
[model.x + model.drict * style.Signal.post.standardLength * 1.2, model.y]
|
2019-12-03 13:36:02 +08:00
|
|
|
]
|
|
|
|
},
|
|
|
|
style: {
|
2020-12-18 13:10:55 +08:00
|
|
|
lineWidth: style.Signal.post.standardRailWidth,
|
2019-12-03 13:36:02 +08:00
|
|
|
stroke: style.Signal.post.standardColor
|
|
|
|
}
|
|
|
|
});
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2019-12-03 13:36:02 +08:00
|
|
|
this.add(this.ver);
|
|
|
|
this.add(this.hor);
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2020-03-19 18:39:20 +08:00
|
|
|
setColor(color) {
|
|
|
|
if (color) {
|
|
|
|
this.ver && this.ver.setStyle({ stroke: color });
|
|
|
|
this.hor && this.hor.setStyle({ stroke: color });
|
|
|
|
}
|
|
|
|
}
|
2020-04-08 18:38:08 +08:00
|
|
|
/* 灯柱变换为三角形并闪烁*/
|
2020-04-08 16:21:08 +08:00
|
|
|
setTerminalOptional() {
|
2020-04-08 18:38:08 +08:00
|
|
|
this.triangle = new Polygon({
|
|
|
|
zlevel: this.model.zlevel,
|
2020-04-30 13:19:33 +08:00
|
|
|
_val: '3',
|
2020-04-08 18:38:08 +08:00
|
|
|
z: this.model.z,
|
|
|
|
shape: {
|
|
|
|
points: [
|
|
|
|
[this.model.x, this.model.y + this.model.style.Signal.post.standardHeight * 1.2],
|
|
|
|
[this.model.x, this.model.y - this.model.style.Signal.post.standardHeight * 1.2],
|
|
|
|
[this.model.x + this.model.drict * this.model.style.Signal.post.standardLength * 1.2, this.model.y]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
fill: this.model.style.Signal.post.terminalOptional
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.add(this.triangle);
|
|
|
|
this.triangle.animateStyle(true)
|
|
|
|
.when(0, { fill: this.model.style.backgroundColor })
|
|
|
|
.when(1000, { fill: this.model.style.Signal.post.terminalOptional })
|
|
|
|
.when(2000, { fill: this.model.style.backgroundColor })
|
|
|
|
.start();
|
|
|
|
this.ver.hide();
|
|
|
|
this.hor.hide();
|
|
|
|
}
|
|
|
|
/* 关闭闪烁三角形并还原灯柱 */
|
|
|
|
removeTerminalOptional() {
|
2020-04-29 11:36:16 +08:00
|
|
|
this.triangle && this.triangle.stopAnimation(false);
|
2020-04-08 18:38:08 +08:00
|
|
|
this.triangle && this.remove(this.triangle);
|
|
|
|
this.ver.show();
|
|
|
|
this.hor.show();
|
2020-04-08 16:21:08 +08:00
|
|
|
}
|
2019-12-03 13:36:02 +08:00
|
|
|
getLampPosition(type) {
|
|
|
|
const model = this.model;
|
|
|
|
const style = this.model.style;
|
2020-02-03 17:17:56 +08:00
|
|
|
if (style.Signal.post.standardShow) {
|
2020-03-02 16:16:17 +08:00
|
|
|
type = '01';
|
2020-02-03 17:17:56 +08:00
|
|
|
}
|
2020-12-18 13:10:55 +08:00
|
|
|
const length = style.Signal.post.standardShow ? style.Signal.post.standardLength : 0;
|
2019-12-03 13:36:02 +08:00
|
|
|
if (type === '01') {
|
|
|
|
return {
|
2020-02-03 17:17:56 +08:00
|
|
|
x: model.x + model.drict * style.Signal.lamp.radiusR * 3 / 2 + model.drict * length,
|
2019-12-03 13:36:02 +08:00
|
|
|
y: model.y
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return {
|
2020-02-03 17:17:56 +08:00
|
|
|
x: this.hor.shape.points[1][0] + model.drict * style.Signal.lamp.radiusR + model.drict * length,
|
2019-12-03 13:36:02 +08:00
|
|
|
y: this.hor.shape.points[1][1]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default ESigPost;
|