rt-sim-training-client/src/jmapNew/shape/ZcControl/index.js

126 lines
3.6 KiB
JavaScript
Raw Normal View History

2019-11-29 12:51:58 +08:00
/*
* ZC区域控制模式
*/
import Group from 'zrender/src/container/Group';
import EControl from '../element/EControl';
import EMouse from './EMouse';
export default class ZcControl extends Group {
2021-02-05 18:01:16 +08:00
constructor(model, {style}) {
2019-12-17 19:03:38 +08:00
super();
this.z = 20;
this._code = model.code;
this._type = model._type;
this.zlevel = model.zlevel;
this.model = model;
this.style = style;
2020-03-13 13:01:58 +08:00
this.isShowShape = true;
2019-12-17 19:03:38 +08:00
this.create(model);
this.createMouseEvent();
this.setState(model);
2019-11-29 12:51:58 +08:00
2019-12-17 19:03:38 +08:00
}
2019-11-29 12:51:58 +08:00
2019-12-17 19:03:38 +08:00
create(model) {
if (this.style.ZcControl.visible) {
this.control = new EControl({
zlevel: this.zlevel,
z: this.z,
arc: {
shape: {
cx: model.position.x,
cy: model.position.y,
r: this.style.ZcControl.lamp.radiusR
},
subType: 'Control',
2019-12-17 19:03:38 +08:00
lineWidth: 0,
fill: this.style.ZcControl.lamp.controlColor,
mouseover: this.mouseoverArc,
mouseout: this.mouseoutArc
},
text: {
position: [0, 0],
x: model.position.x,
y: model.position.y + this.style.ZcControl.lamp.radiusR + this.style.ZcControl.text.distance,
fontWeight: this.style.ZcControl.text.fontWeight,
fontSize: this.style.ZcControl.text.fontSize,
fontFamily: this.style.fontFamily,
text: model.name,
textFill: '#fff',
textAlign: 'middle',
textVerticalAlign: 'top',
mouseover: this.mouseoverText,
mouseout: this.mouseoutText
},
style: this.style
});
this.add(this.control);
}
2019-11-29 12:51:58 +08:00
2019-12-17 19:03:38 +08:00
}
2019-11-29 12:51:58 +08:00
2021-02-05 18:01:16 +08:00
setAshShow() {
this.control && this.control.setControlColor('#7F7F7F');
}
2019-12-17 19:03:38 +08:00
// 设置状态
setState(model) {
2021-02-05 18:01:16 +08:00
this.recover();
// 只响应前端自定义类型的状态变化
if (model._free) {
this.setAshShow()
} else {
model.fault == 'FAULT' && this.fault();
if (!this.isShowShape) return;
}
2019-12-17 19:03:38 +08:00
}
2020-07-07 10:00:55 +08:00
recover() {
if (this.style.ZcControl.visible) {
this.control.setControlColor(this.style.ZcControl.lamp.controlColor);
}
}
fault() {
if (this.style.ZcControl.visible) {
this.control.setControlColor(this.style.ZcControl.lamp.activeColor);
}
}
2019-12-17 19:03:38 +08:00
createMouseEvent() {
if (this.style.ZcControl.mouseOverStyle) {
this.mouseEvent = new EMouse(this);
this.add(this.mouseEvent);
this.on('mouseout', (e) => { this.mouseEvent.mouseout(e); });
this.on('mouseover', (e) => { this.mouseEvent.mouseover(e); });
}
}
getShapeTipPoint() {
if (this.control) {
var distance = 2;
var rect = this.control.getBoundingRect();
return {
x: rect.x + rect.width / 2,
y: rect.y - distance
};
}
return null;
}
2020-03-11 15:10:08 +08:00
setShowMode() {}
2020-03-13 13:01:58 +08:00
setShowStation(stationCode) {
if (!stationCode || this.model.stationCode === stationCode) {
this.eachChild(item => {
item.show();
});
this.isShowShape = true;
this.setState(this.model);
} else {
this.eachChild(item => {
item.hide();
});
this.isShowShape = false;
}
}
2019-11-29 12:51:58 +08:00
}