# Conflicts:
#	src/jmap/shape/Switch/index.js
This commit is contained in:
zyy 2019-07-22 13:41:12 +08:00
commit 274a48c33b
15 changed files with 209 additions and 263 deletions

View File

@ -90,17 +90,17 @@ class ESigButton extends Group {
this.add(this.sigNormalButtom); this.add(this.sigNormalButtom);
this.add(this.sigReentryButton); this.add(this.sigReentryButton);
this.setVisible(model.show); this.hide();
} }
setVisible(show) { hide() {
if (show) { this.sigNormalButtom.hide();
this.sigNormalButtom.show(); this.sigReentryButton.hide();
this.sigReentryButton.show(); }
} else {
this.sigNormalButtom.hide(); show() {
this.sigReentryButton.hide(); this.sigNormalButtom.show();
} this.sigReentryButton.show();
} }
} }

View File

@ -5,26 +5,25 @@ class ESigDelay extends Group {
constructor(model) { constructor(model) {
super(); super();
this.model = model; this.model = model;
this.zlevel = model.zlevel;
this.z = model.z;
this._create(); this._create();
} }
_create() { _create() {
const model = this.model;
this.name = new Text({ this.name = new Text({
_subType: this.model._subType, _subType: model._subType,
zlevel: this.zlevel, zlevel: model.zlevel,
z: this.z, z: model.z,
silent: this.model.silent || false, silent: model.silent || false,
style: { style: {
x: this.model.x, x: model.x,
y: this.model.y, y: model.y,
text: this.model.text, text: model.text,
textFont: this.model.textFont, textFont: model.textFont,
textFill: this.model.textFill, textFill: model.textFill,
textAlign: this.model.textAlign, textAlign: model.textAlign,
textPosition: this.model.textPosition || 'inside', textPosition: model.textPosition || 'inside',
textVerticalAlign: this.model.textVerticalAlign || null textVerticalAlign: model.textVerticalAlign || null
} }
}); });
this.add(this.name); this.add(this.name);

View File

@ -5,26 +5,25 @@ class ESigName extends Group {
constructor(model) { constructor(model) {
super(); super();
this.model = model; this.model = model;
this.zlevel = model.zlevel;
this.z = model.z;
this._create(); this._create();
} }
_create() { _create() {
const model = this.model;
this.name = new Text({ this.name = new Text({
_subType: this.model._subType, _subType: model._subType,
zlevel: this.zlevel, zlevel: model.zlevel,
z: this.z, z: model.z,
silent: this.model.silent || false, silent: model.silent || false,
style: { style: {
x: this.model.x, x: model.x,
y: this.model.y, y: model.y,
text: this.model.text, text: model.text,
textFont: this.model.textFont, textFont: model.textFont,
textFill: this.model.textFill, textFill: model.textFill,
textAlign: this.model.textAlign, textAlign: model.textAlign,
textPosition: this.model.textPosition || 'inside', textPosition: model.textPosition || 'inside',
textVerticalAlign: this.model.textVerticalAlign || null textVerticalAlign: model.textVerticalAlign || null
} }
}); });
this.add(this.name); this.add(this.name);
@ -38,10 +37,12 @@ class ESigName extends Group {
this.name.setStyle('textFill', color); this.name.setStyle('textFill', color);
} }
// 隐藏
hide() { hide() {
this.name.hide(); this.name.hide();
} }
// 显示
show() { show() {
this.name.show(); this.name.show();
} }

View File

@ -51,6 +51,16 @@ class ESigPass extends Group {
.when(4000, { fill: fill, stroke: style.style.Signal.sidelineColor }) .when(4000, { fill: fill, stroke: style.style.Signal.sidelineColor })
.start(); .start();
} }
// 隐藏
hide() {
this.arrows.hide();
}
// 显示
show() {
this.arrows.show();
}
} }
export default ESigPass; export default ESigPass;

View File

@ -26,6 +26,16 @@ class ESigDrict extends Group {
}); });
this.add(this.sigDrict); this.add(this.sigDrict);
} }
// 隐藏
hide() {
this.sigDrict.hide();
}
// 显示
show() {
this.sigDrict.show();
}
} }
export default ESigDrict; export default ESigDrict;

View File

@ -17,12 +17,13 @@ class Signal extends Group {
super(); super();
this._code = _code; this._code = _code;
this._type = _type; this._type = _type;
this.zlevel = zlevel;
this.model = model; this.model = model;
this.state = state; this.state = state;
this.style = style; this.style = style;
this.count = parseInt(model.lampPositionType); this.count = parseInt(model.lampPositionType);
this.lamps = new Array(this.count); this.lamps = new Array(this.count);
this.zlevel = zlevel;
this.z = 1;
this.create(); this.create();
this.setState(state); this.setState(state);
} }
@ -36,7 +37,7 @@ class Signal extends Group {
// 信号机高柱矮柱 // 信号机高柱矮柱
this.sigPost = new ESigPost({ this.sigPost = new ESigPost({
zlevel: this.zlevel, zlevel: this.zlevel,
z: 1, z: this.z,
style: style, style: style,
drict: drict, drict: drict,
type: model.lampPostType, type: model.lampPostType,
@ -50,7 +51,7 @@ class Signal extends Group {
for (let i = 0; i < this.count; i++) { for (let i = 0; i < this.count; i++) {
const lamp = new ESigLmap({ const lamp = new ESigLmap({
zlevel: this.zlevel, zlevel: this.zlevel,
z: 1, z: this.z,
style: style, style: style,
index: i + 1, index: i + 1,
drict: drict, drict: drict,
@ -66,25 +67,9 @@ class Signal extends Group {
// 信号机名称 // 信号机名称
const sigNameX = model.position.x + model.namePosition.x; const sigNameX = model.position.x + model.namePosition.x;
const sigNameY = model.position.y + posit * (style.Signal.signalDistance + style.Section.sectionWidth + style.Signal.signalR * 2 + model.namePosition.y); const sigNameY = model.position.y + posit * (style.Signal.signalDistance + style.Section.sectionWidth + style.Signal.signalR * 2 + model.namePosition.y);
// this.sigName = new Text({
// zlevel: this.zlevel,
// z: 1,
// silent: model.silent || false,
// style: {
// x: sigNameX,
// y: sigNameY,
// text: model.name,
// textFont: `bold ${style.Signal.signalTextFontSize} px ${style.textFontFormat}`,
// textFill: style.Signal.sigTextGreen,
// textAlign: 'middle',
// textPosition: this.model.textPosition || 'inside',
// textVerticalAlign: posit == 1 ? 'top' : 'bottom'
// }
// });
this.sigName = new ESigName({ this.sigName = new ESigName({
zlevel: this.zlevel, zlevel: this.zlevel,
z: 1, z: this.z,
style: style, style: style,
x: sigNameX, x: sigNameX,
y: sigNameY, y: sigNameY,
@ -101,7 +86,7 @@ class Signal extends Group {
const sigRouteY = endPoint.y + (style.Signal.signalSigRouteOffset.y); const sigRouteY = endPoint.y + (style.Signal.signalSigRouteOffset.y);
this.sigRoute = new ESigRoute({ this.sigRoute = new ESigRoute({
zlevel: this.zlevel, zlevel: this.zlevel,
z: 1, z: this.z,
style: style, style: style,
x: sigRouteX, x: sigRouteX,
y: sigRouteY, y: sigRouteY,
@ -114,7 +99,7 @@ class Signal extends Group {
const sigPassY = endPoint.y + (style.Signal.signalSigPassOffset.y); const sigPassY = endPoint.y + (style.Signal.signalSigPassOffset.y);
this.sigPass = new ESigPass({ this.sigPass = new ESigPass({
zlevel: this.zlevel, zlevel: this.zlevel,
z: 1, z: this.z,
style: style, style: style,
count: this.count, count: this.count,
drict: drict, drict: drict,
@ -132,7 +117,7 @@ class Signal extends Group {
const sigDelayY = endPoint.y - (style.Signal.signalSigDelayOffset.y) * posit; const sigDelayY = endPoint.y - (style.Signal.signalSigDelayOffset.y) * posit;
this.sigDelay = new ESigDelay({ this.sigDelay = new ESigDelay({
zlevel: this.zlevel, zlevel: this.zlevel,
z: 1, z: this.z,
style: style, style: style,
x: sigDelayX, x: sigDelayX,
y: sigDelayY, y: sigDelayY,
@ -146,7 +131,7 @@ class Signal extends Group {
// 信号灯按钮 // 信号灯按钮
this.sigButton = new ESigButton({ this.sigButton = new ESigButton({
zlevel: this.zlevel, zlevel: this.zlevel,
z: 1, z: this.z,
style: style, style: style,
posit: posit, posit: posit,
show: model.buttonShow, show: model.buttonShow,
@ -213,8 +198,7 @@ class Signal extends Group {
// 封锁 // 封锁
block() { block() {
this.lamps[0] && this.lamps[0].setColor(this.style.Signal.signalLampRedColor); this.lamps[0] && this.lamps[0].setColor(this.style.Signal.signalLampRedColor);
// this.sigName.setColor(this.style.Signal.sectionBlockTextColor); this.sigName.setColor(this.style.Signal.sectionBlockTextColor);
this.sigName.setStyle({'textFill': this.style.Signal.sectionBlockTextColor});
} }
// 功能封锁 // 功能封锁
@ -290,8 +274,7 @@ class Signal extends Group {
recover() { recover() {
this.sigDelay.hide(); this.sigDelay.hide();
this.sigPass.animationRecover(); this.sigPass.animationRecover();
// this.sigName.setColor(this.style.Signal.signalTextGreen); this.sigName.setColor(this.style.Signal.signalTextGreen);
this.sigName.setStyle({'textFill': this.style.Signal.signalTextGreen});
} }
setState(state) { setState(state) {

View File

@ -34,8 +34,12 @@ class EDetain extends Group {
this.detain.setStyle('textFill', color); this.detain.setStyle('textFill', color);
} }
setVisible(show) { hide() {
show ? this.detain.show(): this.detain.hide(); this.detain.hide();
}
show() {
this.detain.show();
} }
} }

View File

@ -40,8 +40,12 @@ class EJump extends Group {
this.jump.setStyle('textFill', color); this.jump.setStyle('textFill', color);
} }
setVisible(show) { hide() {
show ? this.jump.show(): this.jump.hide(); this.jump.hide();
}
show() {
this.jump.show();
} }
} }

View File

@ -40,8 +40,12 @@ class ELevel extends Group {
this.level.setStyle('textFill', color); this.level.setStyle('textFill', color);
} }
setVisible(show) { hide() {
show ? this.level.show(): this.level.hide(); this.level.hide();
}
show() {
this.level.show();
} }
} }

View File

@ -31,8 +31,12 @@ class EReentry extends Group {
this.reentry.setStyle('textFill', color); this.reentry.setStyle('textFill', color);
} }
setVisible(show) { hide() {
show ? this.reentry.show(): this.reentry.hide(); this.reentry.hide();
}
show() {
this.reentry.show();
} }
} }

View File

@ -31,8 +31,12 @@ class ESafeEmergent extends Group {
this.add(this.emergent); this.add(this.emergent);
} }
setVisible(show) { hide() {
show ? this.emergent.show(): this.emergent.hide(); this.emergent.hide();
}
show() {
this.emergent.show();
} }
} }

View File

@ -40,8 +40,12 @@ class ETime extends Group {
this.time.setStyle('textFill', color); this.time.setStyle('textFill', color);
} }
setVisible(show) { hide() {
show ? this.time.show(): this.time.hide(); this.time.hide();
}
show() {
this.time.show();
} }
} }

View File

@ -13,10 +13,11 @@ class StationStand extends Group {
super(); super();
this._code = _code; this._code = _code;
this._type = _type; this._type = _type;
this.zlevel = zlevel;
this.model = model; this.model = model;
this.state = state; this.state = state;
this.style = style; this.style = style;
this.zlevel = zlevel;
this.z = 1;
this.doors = new Group(); this.doors = new Group();
this._create(); this._create();
this.setVisible(model.visible); this.setVisible(model.visible);
@ -30,7 +31,7 @@ class StationStand extends Group {
/** 屏蔽门*/ /** 屏蔽门*/
this.safeDoor = new ESafeDoor({ this.safeDoor = new ESafeDoor({
zlevel: this.zlevel, zlevel: this.zlevel,
z: 1, z: this.z,
style: style, style: style,
x: model.position.x, x: model.position.x,
y: model.position.y, y: model.position.y,
@ -45,7 +46,7 @@ class StationStand extends Group {
const standY = model.position.y + drict * (style.StationStand.standDistance + standH); const standY = model.position.y + drict * (style.StationStand.standDistance + standH);
this.safeStand = new ESafeStand({ this.safeStand = new ESafeStand({
zlevel: this.zlevel, zlevel: this.zlevel,
z: 1, z: this.z,
style: style, style: style,
x: standX, x: standX,
y: standY, y: standY,
@ -59,7 +60,7 @@ class StationStand extends Group {
const emergentY = model.position.y + drict * (style.StationStand.standEmergentOffset.y + emergentH); const emergentY = model.position.y + drict * (style.StationStand.standEmergentOffset.y + emergentH);
this.emergent = new ESafeEmergent({ this.emergent = new ESafeEmergent({
zlevel: this.zlevel, zlevel: this.zlevel,
z: 10, z: this.z + 1,
style: style, style: style,
x: emergentX, x: emergentX,
y: emergentY, y: emergentY,
@ -74,7 +75,7 @@ class StationStand extends Group {
const reentryY = model.position.y + (style.StationStand.standReentryDirection || drict) * (style.StationStand.standReentryOffset.y) + drict * reentryH; const reentryY = model.position.y + (style.StationStand.standReentryDirection || drict) * (style.StationStand.standReentryOffset.y) + drict * reentryH;
this.reentry = new EReentry({ this.reentry = new EReentry({
zlevel: this.zlevel, zlevel: this.zlevel,
z: 1, z: this.z + 1,
style: style, style: style,
drict: drict, drict: drict,
x: reentryX, x: reentryX,
@ -90,7 +91,7 @@ class StationStand extends Group {
const detainY = model.position.y + (style.StationStand.standDetainDirection || drict) * (style.StationStand.standDetainOffset.y) + drict * detainH; const detainY = model.position.y + (style.StationStand.standDetainDirection || drict) * (style.StationStand.standDetainOffset.y) + drict * detainH;
this.detain = new EDetain({ this.detain = new EDetain({
zlevel: this.zlevel, zlevel: this.zlevel,
z: 1, z: this.z,
style: style, style: style,
x: detainX, x: detainX,
y: detainY, y: detainY,
@ -105,11 +106,11 @@ class StationStand extends Group {
const timeY = model.position.y + (style.StationStand.standTimeDirection || drict) * (style.StationStand.standTimeOffset.y) + drict * timeH; const timeY = model.position.y + (style.StationStand.standTimeDirection || drict) * (style.StationStand.standTimeOffset.y) + drict * timeH;
this.time = new ETime({ this.time = new ETime({
zlevel: this.zlevel, zlevel: this.zlevel,
z: 2, z: this.z + 1,
style: style, style: style,
x: timeX, x: timeX,
y: timeY, y: timeY,
name: model.parkingTime || '30' name: model.parkingTime
}); });
/** 运行等级*/ /** 运行等级*/
@ -119,11 +120,11 @@ class StationStand extends Group {
const levelY = model.position.y + (style.StationStand.standLevelDirection || drict) * (style.StationStand.standLevelOffset.y) + drict * levelH; const levelY = model.position.y + (style.StationStand.standLevelDirection || drict) * (style.StationStand.standLevelOffset.y) + drict * levelH;
this.level = new ELevel({ this.level = new ELevel({
zlevel: this.zlevel, zlevel: this.zlevel,
z: 2, z: this.z + 1,
style: style, style: style,
x: levelX, x: levelX,
y: levelY, y: levelY,
name: model.intervalRunTime || '5' name: model.intervalRunTime
}); });
this.add(this.safeDoor); this.add(this.safeDoor);
@ -145,11 +146,11 @@ class StationStand extends Group {
/** 恢复初始状态*/ /** 恢复初始状态*/
recover() { recover() {
this.time.setVisible(false); this.time.hide();
this.level.setVisible(false); this.level.hide();
this.detain.setVisible(false); this.detain.hide();
this.reentry.setVisible(false); this.reentry.hide();
this.emergent.setVisible(false); this.emergent.hide();
if (this.model.visible) { this.safeDoor.hasDoor(true); } if (this.model.visible) { this.safeDoor.hasDoor(true); }
this.safeDoor.setColor(this.style.StationStand.standDoorDefaultColor); this.safeDoor.setColor(this.style.StationStand.standDoorDefaultColor);
} }
@ -172,7 +173,7 @@ class StationStand extends Group {
/** 站台紧急关闭*/ /** 站台紧急关闭*/
emergentClose() { emergentClose() {
this.safeStand.setColor(this.style.StationStand.standSpareColor); this.safeStand.setColor(this.style.StationStand.standSpareColor);
this.emergent.setVisible(true); this.emergent.show();
} }
/** 未设置跳停*/ /** 未设置跳停*/
@ -186,35 +187,35 @@ class StationStand extends Group {
/** 未设置扣车*/ /** 未设置扣车*/
unDetainTrain() { unDetainTrain() {
this.detain.setVisible(false); this.detain.hide();
} }
/** 车站扣车*/ /** 车站扣车*/
standDetainTrain() { standDetainTrain() {
this.detain.setVisible(true); this.detain.show();
this.detain.setColor(this.style.StationStand.standDetainTrainTextColor); this.detain.setColor(this.style.StationStand.standDetainTrainTextColor);
} }
/** 中心扣车*/ /** 中心扣车*/
centerDetainTrain() { centerDetainTrain() {
this.detain.setVisible(true); this.detain.show();
this.detain.setColor(this.style.StationStand.standCenterDetainTrainColor); this.detain.setColor(this.style.StationStand.standCenterDetainTrainColor);
} }
/** 中心+车站扣车*/ /** 中心+车站扣车*/
standAndCenterDetainTrain() { standAndCenterDetainTrain() {
this.detain.setVisible(true); this.detain.show();
} }
/** 人工设置停战时间*/ /** 人工设置停战时间*/
setManuallyArmisticeTime(val) { setManuallyArmisticeTime(val) {
this.time.setVisible(true); this.time.show();
this.time.setName(val); this.time.setName(val);
} }
/** 人工设置运行等级*/ /** 人工设置运行等级*/
setManuallyOperationLevel(val) { setManuallyOperationLevel(val) {
this.level.setVisible(true); this.level.show();
this.level.setName(val); this.level.setName(val);
} }
@ -245,17 +246,17 @@ class StationStand extends Group {
/** 无折返(默认)*/ /** 无折返(默认)*/
noReentry() { noReentry() {
this.reentry.setVisible(false); this.reentry.hide();
} }
/** 无人折返*/ /** 无人折返*/
noHumanReentry() { noHumanReentry() {
this.reentry.setVisible(true); this.reentry.show();
this.reentry.setColor(this.style.StationStand.standNoHumanReentryColor); this.reentry.setColor(this.style.StationStand.standNoHumanReentryColor);
} }
/** 自动换端*/ /** 自动换端*/
autoChangeEnds() { autoChangeEnds() {
this.reentry.setVisible(true); this.reentry.show();
this.reentry.setColor(this.style.StationStand.standAutoChangeEndsColor); this.reentry.setColor(this.style.StationStand.standAutoChangeEndsColor);
} }

View File

@ -1,12 +1,12 @@
/* /*
* 道岔 * 道岔
*/ */
import Text from 'zrender/src/graphic/Text';
import Rect from 'zrender/src/graphic/shape/Rect';
import Line from 'zrender/src/graphic/shape/Line'; import Line from 'zrender/src/graphic/shape/Line';
import Group from 'zrender/src/container/Group'; import Group from 'zrender/src/container/Group';
import Polygon from 'zrender/src/graphic/shape/Polygon'; import Polygon from 'zrender/src/graphic/shape/Polygon';
import JTriangle from '../../utils/JTriangle'; import JTriangle from '../../utils/JTriangle';
import ESwName from './ESwName.js';
import ESwCore from './ESwCore.js';
export default class Switch extends Group { export default class Switch extends Group {
constructor({ _code, _type, zlevel, model, state }, style, jmap) { constructor({ _code, _type, zlevel, model, state }, style, jmap) {
@ -26,65 +26,35 @@ export default class Switch extends Group {
} }
_create() { _create() {
const model = this.model;
this.triangle = new JTriangle(model.intersection, model.skew);
this.createSwitch();
this.createNameText();
}
/** 道岔实体,不显示,响应鼠标事件*/
createSwitch() {
const model = this.model; const model = this.model;
const style = this.style; const style = this.style;
var halfWidth = style.Section.sectionWidth / 2; this.triangle = new JTriangle(model.intersection, model.skew);
var switchWidth = style.Section.sectionWidth + style.Section.sectionBeyondWidth*2 + 0.8;
var swPadding = style.Switch.switchLen;
var directx = this.triangle.drictx;
var directy = this.triangle.dricty;
var direct = -this.triangle.drictx * this.triangle.dricty;
var coverLength = switchWidth * 1.5;
var line = new Line({ let halfWidth = style.Section.sectionWidth / 2;
const switchWidth = style.Section.sectionWidth + style.Section.sectionBeyondWidth*2 + 0.8;
const swPadding = style.Switch.switchLen;
const directx = this.triangle.drictx;
const directy = this.triangle.dricty;
const direct = -this.triangle.drictx * this.triangle.dricty;
const coverLength = switchWidth * 1.5;
this.swCore = new ESwCore({
zlevel: this.zlevel, zlevel: this.zlevel,
z: this.z, z: this.z,
silent: true, style: style,
shape: { intersectionX: model.intersection.x,
x1: model.intersection.x - coverLength, intersectionY: model.intersection.y,
y1: model.intersection.y, coverLength: coverLength,
x2: model.intersection.x + coverLength, lineWidth: switchWidth,
y2: model.intersection.y triangle: this.triangle
},
style: {
lineWidth: switchWidth,
stroke: style.backgroundColor
}
}); });
var skewLine = new Line({
zlevel: this.zlevel,
z: this.z,
silent: true,
shape: {
x1: model.intersection.x,
y1: model.intersection.y,
x2: model.intersection.x + directx * this.triangle.getCotRate() * coverLength,
y2: model.intersection.y + directy * coverLength
},
style: {
lineWidth: switchWidth,
stroke: style.backgroundColor
}
});
this.switchView = new Group({name: `${this._code}_SwitchView`});
this.switchView.add(line);
this.switchView.add(skewLine);
halfWidth += 0.3; halfWidth += 0.3;
var point1 = [model.intersection.x - directx * halfWidth, model.intersection.y + directy * halfWidth]; const point1 = [model.intersection.x - directx * halfWidth, model.intersection.y + directy * halfWidth];
var point2 = [point1[0] + directx * switchWidth / this.triangle.getSinRate(), point1[1]]; const point2 = [point1[0] + directx * switchWidth / this.triangle.getSinRate(), point1[1]];
var point3 = [point2[0] + directx * this.triangle.getCotRate() * swPadding, point2[1] + directy * swPadding]; const point3 = [point2[0] + directx * this.triangle.getCotRate() * swPadding, point2[1] + directy * swPadding];
var point4 = [point3[0] + direct * this.triangle.getSin(switchWidth), point3[1] - direct * this.triangle.getCos(switchWidth)]; const point4 = [point3[0] + direct * this.triangle.getSin(switchWidth), point3[1] - direct * this.triangle.getCos(switchWidth)];
this.locShelter = new Polygon({ this.locShelter = new Polygon({
zlevel: this.zlevel, zlevel: this.zlevel,
z: this.z, z: this.z,
@ -97,18 +67,18 @@ export default class Switch extends Group {
fill: style.backgroundColor fill: style.backgroundColor
}, },
cursor: 'pointer', cursor: 'pointer',
onmouseover: () => { this.arrowText.show(); }, onmouseover: () => { this.name.getArrowText().show(); },
onmouseout: () => { this.arrowText.hide(); } onmouseout: () => { this.name.getArrowText().hide(); }
}); });
var lpx = Math.abs(this.triangle.getCos(1)); const lpx = Math.abs(this.triangle.getCos(1));
this.locShelter.position = [directx * lpx, -directy * 0.2]; this.locShelter.position = [directx * lpx, -directy * 0.2];
this.locShelter.show(); this.locShelter.show();
var slen = switchWidth / this.triangle.getSinRate(); const slen = switchWidth / this.triangle.getSinRate();
var rpoint1 = [model.intersection.x + directx * halfWidth, model.intersection.y - directy * halfWidth]; const rpoint1 = [model.intersection.x + directx * halfWidth, model.intersection.y - directy * halfWidth];
var rpoint2 = [rpoint1[0] + directx * (swPadding + switchWidth * this.triangle.getCotRate()), rpoint1[1]]; const rpoint2 = [rpoint1[0] + directx * (swPadding + switchWidth * this.triangle.getCotRate()), rpoint1[1]];
var rpoint3 = [rpoint2[0], rpoint2[1] + directy * switchWidth]; const rpoint3 = [rpoint2[0], rpoint2[1] + directy * switchWidth];
var rpoint4 = [rpoint1[0] + this.triangle.getCos(slen), rpoint1[1] + this.triangle.getSin(slen)]; const rpoint4 = [rpoint1[0] + this.triangle.getCos(slen), rpoint1[1] + this.triangle.getSin(slen)];
this.relocShelter = new Polygon({ this.relocShelter = new Polygon({
zlevel: this.zlevel, zlevel: this.zlevel,
z: this.z, z: this.z,
@ -121,23 +91,23 @@ export default class Switch extends Group {
fill: style.backgroundColor fill: style.backgroundColor
}, },
cursor: 'pointer', cursor: 'pointer',
onmouseover: () => { this.arrowText.show(); }, onmouseover: () => { this.name.getArrowText().show(); },
onmouseout: () => { this.arrowText.hide(); } onmouseout: () => { this.name.getArrowText().hide(); }
}); });
var rpx = Math.abs(this.triangle.getCos(halfWidth)) + 0.2; const rpx = Math.abs(this.triangle.getCos(halfWidth)) + 0.2;
this.relocShelter.position = [-directx * rpx, -directy * 0.2]; this.relocShelter.position = [-directx * rpx, -directy * 0.2];
this.relocShelter.hide(); this.relocShelter.hide();
var sinX = style.Section.sectionWidth / this.triangle.getSinRate(); const sinX = style.Section.sectionWidth / this.triangle.getSinRate();
var switchWidth1 = style.Section.sectionWidth / 2; const switchWidth1 = style.Section.sectionWidth / 2;
var width1 = switchWidth1 * this.triangle.getSinRate(); const width1 = switchWidth1 * this.triangle.getSinRate();
var height1 = switchWidth1 * this.triangle.getCosRate(); const height1 = switchWidth1 * this.triangle.getCosRate();
var width2 = (height1 + switchWidth1) / this.triangle.getTanRate(); const width2 = (height1 + switchWidth1) / this.triangle.getTanRate();
var width3 = sinX - width2 - width1; const width3 = sinX - width2 - width1;
var switchPoint1 = [model.intersection.x + directx * width3, model.intersection.y - directy * switchWidth1]; const switchPoint1 = [model.intersection.x + directx * width3, model.intersection.y - directy * switchWidth1];
var switchPoint2 = [switchPoint1[0] - directx * (width2 + width1) - directx * width3, switchPoint1[1]]; const switchPoint2 = [switchPoint1[0] - directx * (width2 + width1) - directx * width3, switchPoint1[1]];
var switchPoint3 = [model.intersection.x - directx * width3, model.intersection.y + directy * switchWidth1]; const switchPoint3 = [model.intersection.x - directx * width3, model.intersection.y + directy * switchWidth1];
var switchPoint4 = [switchPoint1[0] + directx * (width2 + width1) - directx * width3, switchPoint3[1]]; const switchPoint4 = [switchPoint1[0] + directx * (width2 + width1) - directx * width3, switchPoint3[1]];
this.reserveSection = new Polygon({ this.reserveSection = new Polygon({
zlevel: this.zlevel, zlevel: this.zlevel,
shape: { shape: {
@ -149,8 +119,8 @@ export default class Switch extends Group {
fill: style.Section.sectionSpareColor fill: style.Section.sectionSpareColor
}, },
cursor: 'pointer', cursor: 'pointer',
onmouseover: () => { this.arrowText.show(); }, onmouseover: () => { this.name.getArrowText().show(); },
onmouseout: () => { this.arrowText.hide(); } onmouseout: () => { this.name.getArrowText().hide(); }
}); });
this.reserveSection.hide(); this.reserveSection.hide();
@ -169,89 +139,41 @@ export default class Switch extends Group {
} }
}); });
this.add(this.switchView); const arrowTextX = model.intersection.x + 10;
const arrowTextY = model.intersection.y + 15;
const nameTextX = model.namePosition.x + model.intersection.x + this.triangle.drictx * (style.Section.sectionWidth * 3 + style.Switch.switchNameDistance) * this.triangle.getCotRate();
const nameTextY = model.namePosition.y + model.intersection.y + this.triangle.dricty * (style.Switch.switchNameDistance);
this.name = new ESwName({
zlevel: this.zlevel,
z: this.z,
style: style,
arrowTextX: arrowTextX,
arrowTextY: arrowTextY,
nameTextX: nameTextX,
nameTextY: nameTextY,
sectionName: model.sectionName,
name: model.name,
nameShow: model.nameShow,
triangle: this.triangle
});
this.add(this.swCore);
this.add(this.locShelter); this.add(this.locShelter);
this.add(this.relocShelter); this.add(this.relocShelter);
this.add(this.reserveSection); this.add(this.reserveSection);
this.add(this.releaseBackground); this.add(this.releaseBackground);
} this.add(this.name);
/** 道岔名称,显示,响应鼠标事件*/
createNameText() {
const model = this.model;
const style = this.style;
this.arrowText = new Text({
zlevel: this.zlevel,
z: this.z,
position: [0, 0],
style: {
x: model.intersection.x + 10,
y: model.intersection.y + 15,
text: `道岔区段名称: ${model.sectionName}`,
textFill: '#000',
textAlign: 'letf',
textFont: 10 + 'px consolas',
textPadding: 3,
textBackgroundColor: style.Switch.tipBackgroundColor
}
});
this.arrowText.hide();
this.add(this.arrowText);
this.nameText = new Text({
zlevel: this.zlevel,
z: this.z + 6,
style: {
x: model.namePosition.x + model.intersection.x + this.triangle.drictx * (style.Section.sectionWidth * 3 + style.Switch.switchNameDistance) * this.triangle.getCotRate(),
y: model.namePosition.y + model.intersection.y + this.triangle.dricty * (style.Switch.switchNameDistance),
text: model.name,
textAlign: this.triangle.drictx === 1 ? 'left' : 'right',
textVerticalAlign: this.triangle.dricty === 1 ? 'top' : 'bottom',
textFont: style.textFontSize + 'px ' + style.textFontFormat,
textFill: style.Switch.switchTextLossColor
}
});
this.add(this.nameText);
model.nameShow ? this.nameText.show() : this.nameText.hide();
const rect = this.nameText.getBoundingRect();
let textWidth = rect.width * 0.8;
if (this.triangle.drictx !== 1) {
rect.x += rect.width;
textWidth = -textWidth;
}
this.textRect = new Rect({
zlevel: this.zlevel,
z: this.z + 5,
silent: true,
shape: {
x: rect.x,
y: rect.y,
width: textWidth,
height: rect.height
},
style: {
lineWidth: 0,
lineDash: [3, 3],
stroke: style.Switch.switchTextBorderColor,
fill: style.Switch.transparentColor
}
});
this.add(this.textRect);
} }
/** 名称动画*/ /** 名称动画*/
nameTextAnimation() { nameTextAnimation() {
this.nameText.animateStyle(true) this.name.getNameText().animateStyle(true)
.when(0, { textFill: this.style.backgroundColor }) .when(0, { textFill: this.style.backgroundColor })
.when(1000, { textFill: this.style.Switch.switchTextLossColor }) .when(1000, { textFill: this.style.Switch.switchTextLossColor })
.when(2000, { textFill: this.style.backgroundColor }) .when(2000, { textFill: this.style.backgroundColor })
.start(); .start();
this.textRect.animateStyle(true) this.name.getTextRect().animateStyle(true)
.when(0, { textFill: this.style.backgroundColor }) .when(0, { textFill: this.style.backgroundColor })
.when(1000, { textFill: this.style.Switch.switchTextBorderColor }) .when(1000, { textFill: this.style.Switch.switchTextBorderColor })
.when(2000, { textFill: this.style.backgroundColor }) .when(2000, { textFill: this.style.backgroundColor })
@ -261,37 +183,33 @@ export default class Switch extends Group {
/** 设置岔芯是否隐藏*/ /** 设置岔芯是否隐藏*/
setSwitchCoreInvisible(invisible) { setSwitchCoreInvisible(invisible) {
if (invisible) { if (invisible) {
this.switchView.hide(); this.swCore.hide();
} else { } else {
this.switchView.show(); this.swCore.show();
} }
} }
/** 设置岔芯颜色*/ /** 设置岔芯颜色*/
setSwitchCoreColor(color) { setSwitchCoreColor(color) {
this.switchView.eachChild(child => { this.swCore.setColor(color);
child.setStyle({ stroke: color });
});
} }
/** 设置道岔文字颜色*/ /** 设置道岔文字颜色*/
setTextColor(color) { setTextColor(color) {
this.nameText.setStyle('textFill', color); this.name.getNameText().setStyle('textFill', color);
} }
/** 设置道岔文字边框颜色 */ /** 设置道岔文字边框颜色 */
setHasTextBorder(width) { setHasTextBorder(width) {
this.textRect.setStyle('lineWidth', width); this.name.getTextRect().setStyle('lineWidth', width);
} }
/** 恢复状态*/ /** 恢复状态*/
recover() { recover() {
this.setSwitchCoreColor(this.style.backgroundColor); this.setSwitchCoreColor(this.style.backgroundColor);
this.nameText.stopAnimation(false); this.name.getNameText().stopAnimation(false);
this.reserveSection.stopAnimation(false); this.reserveSection.stopAnimation(false);
this.switchView.eachChild((child) => { this.swCore.stopAnimation(false);
child.stopAnimation(false);
});
this.relocShelter.hide(); this.relocShelter.hide();
this.releaseBackground.hide(); this.releaseBackground.hide();
@ -341,8 +259,8 @@ export default class Switch extends Group {
/** 挤叉*/ /** 挤叉*/
setForkAction() { setForkAction() {
this.setLossAction(true); this.setLossAction(true);
this.switchView.eachChild((child) => { this.swCore.animateStyle(item => {
child.animateStyle(true) item.animateStyle(true)
.when(0, { stroke: this.style.backgroundColor }) .when(0, { stroke: this.style.backgroundColor })
.when(1000, { stroke: 'red' }) .when(1000, { stroke: 'red' })
.when(2000, { stroke: this.style.backgroundColor }) .when(2000, { stroke: this.style.backgroundColor })
@ -467,8 +385,8 @@ export default class Switch extends Group {
} }
getShapeTipPoint() { getShapeTipPoint() {
var rect = null; let rect = null;
rect = this.nameText.getBoundingRect(); rect = this.name.getNameText().getBoundingRect();
if (rect) { if (rect) {
return { return {
x: rect.x + rect.width / 2, x: rect.x + rect.width / 2,

View File

@ -42,7 +42,7 @@ export default {
stateLoaded() { console.log('stateLoaded'); }, stateLoaded() { console.log('stateLoaded'); },
viewUpdate() { console.log('viewUpdate'); }, viewUpdate() { console.log('viewUpdate'); },
stateUpdate() { console.log('stateUpdate'); }, stateUpdate() { console.log('stateUpdate'); },
optionsUpdate() { console.log('optionsUpdate'); } // optionsUpdate() { console.log('optionsUpdate'); }
} }
}); });