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

103 lines
3.0 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;
this._create(model);
}
_create(model) {
2019-07-16 16:19:01 +08:00
if (model && this.style) {
2019-07-16 16:03:56 +08:00
this.partition = new Polyline({
zlevel: this.zlevel,
z: this.z,
shape: {
points: [
[model.point.x, model.point.y],
[model.point.x, model.point.y]
]
},
style: {
2019-07-16 16:19:01 +08:00
lineWidth: this.style.Section.sectionSeparatorWidth,
stroke: this.style.Section.sectionSeparatorColor
2019-07-16 16:03:56 +08:00
}
});
this.circle = new Circle({
zlevel: this.zlevel,
z: this.z + 9,
shape: {
cx: model.point.x,
cy: model.point.y,
2019-07-16 16:19:01 +08:00
r: this.style.Section.sectionWidth
2019-07-16 16:03:56 +08:00
},
style: {
2019-07-16 16:19:01 +08:00
stroke: this.style.Section.sectionInvadeColor,
2019-07-16 16:03:56 +08:00
GBaseLineWidth: 0.5,
2019-07-16 16:19:01 +08:00
fill: this.style.transparentColor
2019-07-16 16:03:56 +08:00
}
});
this.add(this.partition);
this.setType(model.sepType, model.borderBorderShow);
}
}
setType(type, show) {
const model = this.model;
2019-07-16 16:19:01 +08:00
if (model && this.style && model.traingle) {
2019-07-16 16:03:56 +08:00
this.remove(this.circle);
if (type === '00') {
this.partition.setShape('points', [
[model.point.x, model.point.y],
[model.point.x, model.point.y]
]);
} else if (type === '01') {
this.partition.setShape('points', [
2019-07-16 16:19:01 +08:00
[model.point.x, model.point.y - (this.style.Section.sectionWidth)],
[model.point.x, model.point.y + (this.style.Section.sectionWidth)]
2019-07-16 16:03:56 +08:00
]);
this.add(this.partition);
} else if (type === '02') {
this.partition.setShape('points', [
2019-07-16 16:19:01 +08:00
[model.point.x + model.drict * (this.style.Section.sectionWidth), model.point.y - (this.style.Section.sectionWidth * 1.5)],
[model.point.x, model.point.y - (this.style.Section.sectionWidth * 1.5)],
[model.point.x, model.point.y + (this.style.Section.sectionWidth * 1.5)]
2019-07-16 16:03:56 +08:00
]);
this.add(this.partition);
} else if (type === '03') {
this.partition.setShape('points', [
2019-07-16 16:19:01 +08:00
[model.point.x + model.drict * (this.style.Section.sectionWidth) * 1.2, model.point.y - (this.style.Section.sectionWidth * 1.2)],
[model.point.x, model.point.y - (this.style.Section.sectionWidth * 1.2)],
[model.point.x, model.point.y + (this.style.Section.sectionWidth * 1.2)],
[model.point.x + model.drict * (this.style.Section.sectionWidth) * 1.2, model.point.y + (this.style.Section.sectionWidth * 1.2)]
2019-07-16 16:03:56 +08:00
]);
this.add(this.partition);
} else if (type === '04') {
this.add(this.circle);
}
}
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(); // 可以无需调用
}
if (this.partition) {
if (type === '03' && !show) {
this.partition.hide();
} else {
this.partition.show();
}
}
}
}