修改代码

This commit is contained in:
zyy 2019-07-23 18:33:30 +08:00
parent b938022cbf
commit d26085b8a5
3 changed files with 217 additions and 188 deletions

View File

@ -1,36 +1,118 @@
// import Group from 'zrender/src/container/Group';
// import BezierCurve from 'zrender/src/graphic/shape/BezierCurve';
// import Line from 'zrender/src/graphic/shape/Line';
import Group from 'zrender/src/container/Group';
import BezierCurve from 'zrender/src/graphic/shape/BezierCurve';
import Line from 'zrender/src/graphic/shape/Line';
import JTriangle from '../../utils/JTriangle';
import Path from 'zrender/src/graphic/Path';
// import Path from 'zrender/src/graphic/Path';
// 创建区段限速限集合
export const ELimitLines = Path.extend({
type: 'ELimitLines',
shape: {
points: null
},
buildPath: function (ctx, model) {
// export const ELimitLines = Path.extend({
// type: 'ELimitLines',
// shape: {
// points: null
// },
// buildPath: function (ctx, model) {
// /** 创建区段*/
// if (model && model.points.length > 1) {
// if (model.isCurve) {
// ctx.beginPath();
// 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;
// ctx.moveTo(shape[`x1`], shape[`y1`]);
// if (model.points.length <= 3) {
// ctx.quadraticCurveTo(shape[`cpx1`], shape[`cpy1`], shape[`x2`], shape[`y2`]);
// } else {
// ctx.bezierCurveTo(shape[`cpx1`], shape[`cpy1`], shape[`cpx2`], shape[`cpy2`], shape[`x2`], shape[`y2`]);
// }
// } else {
// const swPadding = model.style.Switch.switchLen; // 定位和反位时区段距离岔芯的距离
// var switchWidth = model.style.Section.line.width + model.style.Section.line.beyondWidth; // 道岔宽度
// const beg = Object.assign({}, model.points[0]);
// const end = Object.assign({}, model.points[model.points.length - 1]);
// if (model.isSwitchSection && beg.y !== end.y) {
// const swch = model.switch;
// if (swch) {
// const traingle = new JTriangle(swch.intersection, swch.skew);
// if ((swch.intersection.x === beg.x) && (swch.intersection.y === beg.y)) {
// beg.x = beg.x + traingle.drictx * (swPadding + switchWidth) * traingle.getCotRate();
// beg.y = beg.y + traingle.dricty * (swPadding + switchWidth);
// }
// if ((swch.intersection.x === end.x) && (swch.intersection.y === end.y)) {
// end.x = end.x + traingle.drictx * (swPadding + switchWidth) * traingle.getCotRate();
// end.y = end.y + traingle.dricty * (swPadding + switchWidth);
// }
// }
// }
// if (model.points.length == 2) {
// ctx.moveTo(beg.x, beg.y);
// ctx.lineTo(end.x, end.y);
// ctx.closePath();
// } else {
// ctx.moveTo(beg.x, beg.y);
// ctx.lineTo(model.points[1].x, model.points[1].y);
// ctx.closePath();
// for (let i = 1; i < (model.points.length - 2); i++) {
// ctx.moveTo(model.points[i].x, model.points[i].y);
// ctx.lineTo(model.points[i + 1].x, model.points[i + 1].y);
// ctx.closePath();
// }
// ctx.moveTo(model.points[model.points.length - 2].x, model.points[model.points.length - 2].y);
// ctx.lineTo(end.x, end.y);
// ctx.closePath();
// }
// }
// }
// }
// });
export default class ELimitLines 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) {
ctx.beginPath();
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;
ctx.moveTo(shape[`x1`], shape[`y1`]);
if (model.points.length <= 3) {
ctx.quadraticCurveTo(shape[`cpx1`], shape[`cpy1`], shape[`x2`], shape[`y2`]);
} else {
ctx.bezierCurveTo(shape[`cpx1`], shape[`cpy1`], shape[`cpx2`], shape[`cpy2`], shape[`x2`], shape[`y2`]);
}
this.add(new BezierCurve({
isLine: true,
zlevel: this.zlevel,
progressive: model.progressive,
z: this.z,
culling: true,
shape: shape,
position: model.position,
style: {
lineWidth: model.style.Section.speedLimit.width,
stroke: model.style.Section.speedLimit.lineColor,
fillOpacity: 0
}
}));
} else {
const swPadding = model.style.Switch.switchLen; // 定位和反位时区段距离岔芯的距离
var switchWidth = model.style.Section.line.width + model.style.Section.line.beyondWidth; // 道岔宽度
@ -53,146 +135,81 @@ export const ELimitLines = Path.extend({
}
if (model.points.length == 2) {
ctx.moveTo(beg.x, beg.y);
ctx.lineTo(end.x, end.y);
ctx.closePath();
this.add(new Line({
isLine: true,
zlevel: this.zlevel,
progressive: model.progressive,
z: this.z,
position: model.position,
shape: {
x1: beg.x,
y1: beg.y,
x2: end.x,
y2: end.y
},
style: {
lineWidth: model.style.Section.speedLimit.width,
stroke: model.style.Section.speedLimit.lineColor
}
}));
} else {
ctx.moveTo(beg.x, beg.y);
ctx.lineTo(model.points[1].x, model.points[1].y);
ctx.closePath();
this.add(new Line({
isLine: true,
zlevel: this.zlevel,
progressive: model.progressive,
z: this.z,
position: model.position,
shape: {
x1: beg.x,
y1: beg.y,
x2: model.points[1].x,
y2: model.points[1].y
},
style: {
lineWidth: model.style.Section.speedLimit.width,
stroke: model.style.Section.speedLimit.lineColor
}
}));
for (let i = 1; i < (model.points.length - 2); i++) {
ctx.moveTo(model.points[i].x, model.points[i].y);
ctx.lineTo(model.points[i + 1].x, model.points[i + 1].y);
ctx.closePath();
this.add(new Line({
isLine: true,
zlevel: this.zlevel,
z: this.z,
progressive: model.progressive,
position: model.position,
shape: {
x1: model.points[i].x,
y1: model.points[i].y,
x2: model.points[i + 1].x,
y2: model.points[i + 1].y
},
style: {
lineWidth: model.style.Section.speedLimit.width,
stroke: model.style.Section.speedLimit.lineColor
}
}));
}
ctx.moveTo(model.points[model.points.length - 2].x, model.points[model.points.length - 2].y);
ctx.lineTo(end.x, end.y);
ctx.closePath();
this.add(new Line({
isLine: true,
zlevel: this.zlevel,
z: this.z,
position: model.position,
progressive: model.progressive,
shape: {
x1: model.points[model.points.length - 2].x,
y1: model.points[model.points.length - 2].y,
x2: end.x,
y2: end.y
},
style: {
lineWidth: model.style.Section.speedLimit.width,
stroke: model.style.Section.speedLimit.lineColor
}
}));
}
}
}
}
});
// export default class ELimitLines 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,
// progressive: model.progressive,
// z: this.z,
// culling: true,
// shape: shape,
// position: model.position,
// style: {
// lineWidth: model.style.Section.speedLimit.width,
// stroke: model.style.Section.speedLimit.lineColor,
// fillOpacity: 0
// }
// }));
// } else {
// const beg = Object.assign({}, model.points[0]);
// const end = Object.assign({}, model.points[model.points.length - 1]);
// if (model.points.length == 2) {
// this.add(new Line({
// isLine: true,
// zlevel: this.zlevel,
// progressive: model.progressive,
// z: this.z,
// position: model.position,
// shape: {
// x1: beg.x,
// y1: beg.y,
// x2: end.x,
// y2: end.y
// },
// style: {
// lineWidth: model.style.Section.speedLimit.width,
// stroke: model.style.Section.speedLimit.lineColor
// }
// }));
// } else {
// this.add(new Line({
// isLine: true,
// zlevel: this.zlevel,
// progressive: model.progressive,
// z: this.z,
// position: model.position,
// shape: {
// x1: beg.x,
// y1: beg.y,
// x2: model.points[1].x,
// y2: model.points[1].y
// },
// style: {
// lineWidth: model.style.Section.speedLimit.width,
// stroke: model.style.Section.speedLimit.lineColor
// }
// }));
// for (let i = 1; i < (model.points.length - 2); i++) {
// this.add(new Line({
// isLine: true,
// zlevel: this.zlevel,
// z: this.z,
// progressive: model.progressive,
// position: model.position,
// shape: {
// x1: model.points[i].x,
// y1: model.points[i].y,
// x2: model.points[i + 1].x,
// y2: model.points[i + 1].y
// },
// style: {
// lineWidth: model.style.Section.speedLimit.width,
// stroke: model.style.Section.speedLimit.lineColor
// }
// }));
// }
// this.add(new Line({
// isLine: true,
// zlevel: this.zlevel,
// z: this.z,
// position: model.position,
// progressive: model.progressive,
// shape: {
// x1: model.points[model.points.length - 2].x,
// y1: model.points[model.points.length - 2].y,
// x2: end.x,
// y2: end.y
// },
// style: {
// lineWidth: model.style.Section.speedLimit.width,
// stroke: model.style.Section.speedLimit.lineColor
// }
// }));
// }
// }
// }
// }
// }
}

View File

@ -1,7 +1,7 @@
import Group from 'zrender/src/container/Group';
import ETextName from '../element/ETextName'; // 名称文字 (共有)
import ERelease from './ERelease'; // 线段 (共有)
import { ELimitLines } from './ELimitLines'; // 区段限速 (私有)
import ELimitLines from './ELimitLines'; // 区段限速 (私有)
import ELines from './ELines'; // 创建多线条 曲线 (私有)
import ESeparator from './ESeparator'; // 分隔符 (私有)
import { EAxle } from './EAxle'; // 创建计轴 (私有)
@ -81,44 +81,56 @@ export default class Section extends Group {
// 创建限速线
this.speedLimitLeft = new ELimitLines({
zlevel: this.zlevel,
z: model.isCurve ? this.z - 1 : this.z,
z: this.z,
progressive: 5,
position: [x, -y],
isLine: true,
culling: model.isCurve, // 是否裁剪
shape: {
points: model.points,
isCurve: model.isCurve, // 是否曲线
isSwitchSection: model.isSwitchSection,
relSwitchCode: model.relSwitchCode,
switch: model.switch,
style: style
},
style: {
lineWidth: style.Section.speedLimit.width,
stroke: style.Section.speedLimit.lineColor
}
style: style,
points: model.points,
isCurve: model.isCurve, // 是否曲线
isSwitchSection: model.isSwitchSection,
relSwitchCode: model.relSwitchCodes,
switch: model.switch
// isLine: true,
// culling: model.isCurve, // 是否裁剪
// shape: {
// points: model.points,
// isCurve: model.isCurve, // 是否曲线
// isSwitchSection: model.isSwitchSection,
// relSwitchCode: model.relSwitchCode,
// switch: model.switch,
// style: style
// },
// style: {
// lineWidth: style.Section.speedLimit.width,
// stroke: style.Section.speedLimit.lineColor
// }
});
this.speedLimitRight = new ELimitLines({
style: style,
zlevel: this.zlevel,
z: model.isCurve ? this.z - 1 : this.z,
z: this.z,
progressive: 5,
position: [x, -y],
isLine: true,
culling: model.isCurve, // 是否裁剪
shape: {
points: model.points,
isCurve: model.isCurve, // 是否曲线
isSwitchSection: model.isSwitchSection,
relSwitchCode: model.relSwitchCodes,
switch: model.switch,
style: style
},
style: {
lineWidth: style.Section.speedLimit.width,
stroke: style.Section.speedLimit.lineColor
}
points: model.points,
isCurve: model.isCurve, // 是否曲线
isSwitchSection: model.isSwitchSection,
relSwitchCode: model.relSwitchCodes,
switch: model.switch
// isLine: true,
// culling: model.isCurve, // 是否裁剪
// shape: {
// points: model.points,
// isCurve: model.isCurve, // 是否曲线
// isSwitchSection: model.isSwitchSection,
// relSwitchCode: model.relSwitchCodes,
// switch: model.switch,
// style: style
// },
// style: {
// lineWidth: style.Section.speedLimit.width,
// stroke: style.Section.speedLimit.lineColor
// }
});
this.add(this.section);
@ -428,8 +440,8 @@ export default class Section extends Group {
});
this.release.hide();
// this.speedLimitLeft.hide();
// this.speedLimitRight.hide();
this.speedLimitLeft.hide();
this.speedLimitRight.hide();
}
}

View File

@ -39,7 +39,7 @@ class Signal extends Group {
z: this.z + 1,
shape: {
x: model.position.x,
y: model.position.y + posit * (style.Signal.signalDistance + style.Section.sectionWidth + style.Signal.Lamp.signalR),
y: model.position.y + posit * (style.Signal.signalDistance + style.Section.line.width + style.Signal.Lamp.signalR),
h: style.Signal.Lamp.signalR * 2,
w: style.Signal.Lamp.signalR,
isDwarf: model.lampPositionType == '02',
@ -53,7 +53,7 @@ class Signal extends Group {
const endPoint = {
x: model.position.x + drict * (style.Signal.Lamp.signalR * 2),
y: model.position.y + posit * (style.Signal.signalDistance + style.Section.sectionWidth + style.Signal.Lamp.signalR)
y: model.position.y + posit * (style.Signal.signalDistance + style.Section.line.width + style.Signal.Lamp.signalR)
};
// 信号灯
@ -81,7 +81,7 @@ class Signal extends Group {
// 信号机名称
const sigNameX = model.position.x + model.namePosition.x;
const sigNameY = model.position.y + posit * (style.Signal.signalDistance + style.Section.sectionWidth + style.Signal.Lamp.signalR * 2 + model.namePosition.y);
const sigNameY = model.position.y + posit * (style.Signal.signalDistance + style.Section.line.width + style.Signal.Lamp.signalR * 2 + model.namePosition.y);
this.sigName = new Text({
zlevel: this.zlevel,
z: this.z,