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

104 lines
3.2 KiB
JavaScript
Raw Normal View History

2020-03-19 16:17:34 +08:00
import Group from 'zrender/src/container/Group';
import EControl from '../element/EControl';
import EMouse from './EMouse';
import {isShowThePrdType} from '../../utils/handlePath';
export default class AtsControl extends Group {
constructor(model, style) {
super();
this.z = 20;
this._code = model.code;
this._type = model._type;
this.zlevel = model.zlevel;
this.model = model;
this.style = style;
this.deviceStyle = style[model._type];
this.isShowShape = true;
if (isShowThePrdType(model.prdType, this.deviceStyle.displayCondition) || model.previewOrMapDraw) {
this.create();
this.createMouseEvent();
this.setState(model);
}
if (model.previewOrMapDraw) {
this.setShowMode();
}
}
create() {
const model = this.model;
this.control = new EControl({
zlevel: this.zlevel,
z: this.z,
arc: {
shape: {
cx: model.position.x,
cy: model.position.y,
r: this.deviceStyle.lamp.radiusR
},
subType: 'Control',
lineWidth: 0,
fill: this.deviceStyle.lamp.controlColor
},
text: {
position: [0, 0],
x: model.position.x,
y: model.position.y + this.deviceStyle.lamp.radiusR + this.deviceStyle.text.distance,
fontWeight: this.deviceStyle.text.fontWeight,
fontSize: this.deviceStyle.text.fontSize,
fontFamily: this.style.fontFamily,
text: model.name,
textFill: '#fff',
textAlign: 'middle',
textVerticalAlign: 'top'
},
style: this.style
});
this.add(this.control);
}
// 设置状态
setState(model) {
if (!this.isShowShape) return;
}
createMouseEvent() {
if (this.deviceStyle.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;
}
setShowMode() {
const showMode = this.model.showMode;
const showConditions = this.deviceStyle.displayCondition;
if (showConditions === '01' || showMode === showConditions) {
this.control && this.control.show();
} else {
this.control && this.control.hide();
}
}
setShowStation(stationCode) {
if (!stationCode || this.model.stationCode === stationCode) {
this.control && this.control.show();
this.isShowShape = true;
this.setState(this.model);
} else {
this.control && this.control.hide();
this.isShowShape = false;
}
}
}