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

103 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-07-16 16:03:56 +08:00
import Group from 'zrender/src/container/Group';
import Line from 'zrender/src/graphic/shape/Line';
import BezierCurve from 'zrender/src/graphic/shape/BezierCurve';
/** 创建区段线集合*/
export default class ELines extends Group {
constructor(model) {
super();
this.model = model;
this.zlevel = model.zlevel;
this.z = model.z;
this._create(model);
}
_create(model) {
/** 创建区段*/
if (model && model.points.length > 1) {
if (model.isCurve) {
const shape = {};
for (let i = 1; i < (model.points.length - 1); i++) {
shape[`cpx${i}`] = model.points[i].x;
shape[`cpy${i}`] = model.points[i].y;
}
shape[`x1`] = model.points[0].x;
shape[`y1`] = model.points[0].y;
shape[`x2`] = model.points[model.points.length - 1].x;
shape[`y2`] = model.points[model.points.length - 1].y;
this.add(new BezierCurve({
isLine: true,
zlevel: this.zlevel,
2019-07-22 17:20:01 +08:00
progressive: model.progressive,
2019-07-22 13:39:33 +08:00
z: this.z + 1,
2019-07-16 16:03:56 +08:00
culling: true,
shape: shape,
style: {
2019-07-23 13:40:55 +08:00
lineWidth: model.style.Section.line.width,
stroke: model.style.Section.line.spareColor,
2019-07-16 16:03:56 +08:00
fillOpacity: 0
}
}));
} else {
for (let i = 0; i < (model.points.length - 1); i++) {
this.add(new Line({
isLine: true,
zlevel: this.zlevel,
2019-07-22 17:20:01 +08:00
progressive: model.progressive,
2019-07-16 16:03:56 +08:00
z: this.z,
shape: {
x1: model.points[i].x,
y1: model.points[i].y,
x2: model.points[i + 1].x,
y2: model.points[i + 1].y
},
style: {
2019-07-23 13:40:55 +08:00
lineWidth: model.style.Section.line.width,
stroke: model.style.Section.line.spareColor
2019-07-16 16:03:56 +08:00
}
}));
}
}
}
}
setStyle(styles) {
this.eachChild((child) => {
if (child.setStyle && child.isLine) {
child.setStyle(styles);
}
});
}
animateStyle(loop, animates) {
if (animates && animates.length) {
this.eachChild((child) => {
if (child.animateStyle && child.isLine) {
let an = child.animateStyle(loop);
animates.forEach(elem => {
an = an.when(elem.time, elem.styles);
});
an.start();
}
});
}
}
stopAnimation(flag) {
this.eachChild((child) => {
if (child.stopAnimation && child.isLine) {
child.stopAnimation(flag);
}
});
}
setBorderVisible(isVisible) {
this.lineBorder && this.lineBorder.hide();
if (isVisible) {
this.lineBorder && this.lineBorder.show();
}
}
}