rt-sim-training-client/src/jmap/shape/Section/ESeparator.js

93 lines
2.9 KiB
JavaScript
Raw Normal View History

2019-07-16 16:03:56 +08:00
import Group from 'zrender/src/container/Group';
import Polyline from 'zrender/src/graphic/shape/Polyline';
import Circle from 'zrender/src/graphic/shape/Circle';
/** 分隔符*/
export default class ESeparator extends Group {
constructor(model) {
super();
this.model = model;
this.zlevel = model.zlevel;
2019-07-16 16:19:01 +08:00
this.style = model.style;
2019-07-16 16:03:56 +08:00
this.z = 6;
2019-07-24 11:12:15 +08:00
this.setType();
2019-07-16 16:03:56 +08:00
}
2019-07-24 11:12:15 +08:00
createModel(points, lineWidth = null, stroke = null) {
const model = this.model;
2019-07-17 15:54:01 +08:00
this.partition = new Polyline({
zlevel: this.zlevel,
2019-07-22 17:20:01 +08:00
progressive: model.progressive,
2019-07-17 15:54:01 +08:00
z: this.z,
shape: {
2019-07-24 11:12:15 +08:00
points: points
2019-07-17 15:54:01 +08:00
},
style: {
2019-07-24 11:12:15 +08:00
lineWidth: lineWidth || this.style.Section.separator.width,
stroke: stroke || this.style.Section.separator.color
2019-07-17 15:54:01 +08:00
}
});
2019-07-24 11:12:15 +08:00
this.add(this.partition);
}
2019-07-16 16:03:56 +08:00
2019-07-24 11:12:15 +08:00
// 创建 侵限分隔符
createCircle() {
const model = this.model;
2019-07-17 15:54:01 +08:00
this.circle = new Circle({
zlevel: this.zlevel,
2019-07-22 13:39:33 +08:00
z: this.z,
2019-07-22 17:20:01 +08:00
progressive: model.progressive,
2019-07-17 15:54:01 +08:00
shape: {
cx: model.point.x,
cy: model.point.y,
2019-07-23 13:40:55 +08:00
r: this.style.Section.line.width
2019-07-17 15:54:01 +08:00
},
style: {
2019-07-23 13:40:55 +08:00
stroke: this.style.Section.line.invadeColor,
2019-07-17 15:54:01 +08:00
GBaseLineWidth: 0.5,
fill: this.style.transparentColor
}
});
2019-07-24 11:12:15 +08:00
this.add(this.circle);
2019-07-16 16:03:56 +08:00
}
2019-07-17 15:54:01 +08:00
setType() {
const type = this.model.sepType;
2019-07-16 16:03:56 +08:00
const model = this.model;
2019-07-16 16:19:01 +08:00
if (model && this.style && model.traingle) {
2019-07-24 11:12:15 +08:00
if (type === '01') { // 普通分割
const points = [
2019-07-23 13:40:55 +08:00
[model.point.x, model.point.y - (this.style.Section.line.width)],
[model.point.x, model.point.y + (this.style.Section.line.width)]
2019-07-24 11:12:15 +08:00
];
this.createModel(points);
} else if (type === '02') { // 单侧分割符
const points = [
2019-07-23 13:40:55 +08:00
[model.point.x + model.drict * (this.style.Section.line.width), model.point.y - (this.style.Section.line.width * 1.5)],
[model.point.x, model.point.y - (this.style.Section.line.width * 1.5)],
[model.point.x, model.point.y + (this.style.Section.line.width * 1.5)]
2019-07-24 11:12:15 +08:00
];
this.createModel(points);
} else if (type === '03') { // 尽头分隔符
const points = [
2019-07-23 13:40:55 +08:00
[model.point.x + model.drict * (this.style.Section.line.width) * 1.2, model.point.y - (this.style.Section.line.width * 1.2)],
[model.point.x, model.point.y - (this.style.Section.line.width * 1.2)],
[model.point.x, model.point.y + (this.style.Section.line.width * 1.2)],
[model.point.x + model.drict * (this.style.Section.line.width) * 1.2, model.point.y + (this.style.Section.line.width * 1.2)]
2019-07-24 11:12:15 +08:00
];
const lineWidth = this.style.Section.separator.endWidth;
const stroke = this.style.Section.separator.endColor;
this.createModel(points, lineWidth, stroke);
} else if (type === '04') { // 侵限分隔符
this.createCircle();
2019-07-16 16:03:56 +08:00
}
}
if (model.traingle) {
this.origin = [model.point.x, model.point.y];
this.rotation = Math.PI * 2 - Math.atan2(model.traingle.absy, model.traingle.absx) * model.traingle.drictx * model.traingle.dricty;
this.dirty(); // 可以无需调用
}
}
}