2019-11-29 12:51:58 +08:00
|
|
|
import Line from 'zrender/src/graphic/shape/Line';
|
|
|
|
import Arc from 'zrender/src/graphic/shape/Arc';
|
|
|
|
import Group from 'zrender/src/container/Group';
|
|
|
|
|
|
|
|
class ESigLamp extends Group {
|
2019-12-24 14:26:07 +08:00
|
|
|
constructor(model) {
|
|
|
|
super();
|
|
|
|
this.model = model;
|
|
|
|
this.create();
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2019-12-24 14:26:07 +08:00
|
|
|
create() {
|
|
|
|
const model = this.model;
|
|
|
|
const style = this.model.style;
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2019-12-24 14:26:07 +08:00
|
|
|
this.lamp = new Arc({
|
|
|
|
_subType: 'SignalLamp',
|
|
|
|
_val: '3',
|
|
|
|
name: model.index,
|
|
|
|
zlevel: model.zlevel,
|
|
|
|
z: model.z,
|
|
|
|
shape: {
|
|
|
|
cx: model.x,
|
|
|
|
cy: model.y,
|
|
|
|
r: style.Signal.lamp.radiusR
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
lineWidth: style.Signal.lamp.borderWidth,
|
|
|
|
fill: style.backgroundColor,
|
|
|
|
stroke: style.Signal.lamp.borderColor
|
|
|
|
}
|
|
|
|
});
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2019-12-24 14:26:07 +08:00
|
|
|
this.lstop = new Line({
|
|
|
|
_subType: 'SignalLamp',
|
|
|
|
_val: '3',
|
|
|
|
zlevel: model.zlevel,
|
|
|
|
z: model.z,
|
|
|
|
origin: {
|
|
|
|
x: model.originX,
|
|
|
|
y: model.originY
|
|
|
|
},
|
|
|
|
shape: {
|
|
|
|
x1: model.x + (style.Signal.lamp.radiusR + 1) * Math.cos(Math.PI / 4),
|
|
|
|
y1: model.y + (style.Signal.lamp.radiusR + 1) * Math.sin(Math.PI / 4),
|
|
|
|
x2: model.x - (style.Signal.lamp.radiusR + 1) * Math.cos(Math.PI / 4),
|
|
|
|
y2: model.y - (style.Signal.lamp.radiusR + 1) * Math.sin(Math.PI / 4)
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
lineWidth: style.Signal.lamp.stopWidth,
|
|
|
|
stroke: style.backgroundColor
|
|
|
|
}
|
|
|
|
});
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2019-12-24 14:26:07 +08:00
|
|
|
this.rstop = new Line({
|
|
|
|
_subType: 'SignalLamp',
|
|
|
|
_val: '3',
|
|
|
|
zlevel: model.zlevel,
|
|
|
|
z: model.z,
|
|
|
|
origin: {
|
|
|
|
x: model.originX,
|
|
|
|
y: model.originY
|
|
|
|
},
|
|
|
|
shape: {
|
|
|
|
x1: model.x + (style.Signal.lamp.radiusR + 1) * Math.cos(Math.PI / 4),
|
|
|
|
y1: model.y + (style.Signal.lamp.radiusR + 1) * (Math.sin(Math.PI / 4) - Math.sqrt(2)),
|
|
|
|
x2: model.x - (style.Signal.lamp.radiusR + 1) * Math.cos(Math.PI / 4),
|
|
|
|
y2: model.y - (style.Signal.lamp.radiusR + 1) * (Math.sin(Math.PI / 4) - Math.sqrt(2))
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
lineWidth: style.Signal.lamp.stopWidth,
|
|
|
|
stroke: style.backgroundColor
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.add(this.lamp);
|
|
|
|
this.add(this.lstop);
|
|
|
|
this.add(this.rstop);
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2019-12-24 14:26:07 +08:00
|
|
|
setColor(color) {
|
|
|
|
if (this.model.style.Signal.lamp.borderVariable) {
|
|
|
|
this.lamp.setStyle({ fill: color, stroke: color });
|
|
|
|
} else {
|
|
|
|
this.lamp.setStyle({ fill: color });
|
|
|
|
}
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2019-12-24 14:26:07 +08:00
|
|
|
setBorderColor(color) {
|
|
|
|
this.lamp.setStyle({stroke: color});
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2019-12-24 14:26:07 +08:00
|
|
|
setStyle(data) {
|
|
|
|
this.lamp.setStyle(data);
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2019-12-24 14:26:07 +08:00
|
|
|
setStop(has) {
|
|
|
|
if (has) {
|
|
|
|
this.lstop.show();
|
|
|
|
this.rstop.show();
|
|
|
|
} else {
|
|
|
|
this.lstop.hide();
|
|
|
|
this.rstop.hide();
|
|
|
|
}
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
|
2019-12-24 14:26:07 +08:00
|
|
|
getBoundingRect() {
|
|
|
|
return this.lamp.getBoundingRect();
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default ESigLamp;
|