From fdc15d109e5798384400e7281f25c76a5379c17f Mon Sep 17 00:00:00 2001 From: ival <610568032@qq.com> Date: Mon, 22 Jul 2019 13:40:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jmap/shape/Switch/ESwCore.js | 78 +++++++++++++++++++++++++++ src/jmap/shape/Switch/ESwName.js | 91 ++++++++++++++++++++++++++++++++ 2 files changed, 169 insertions(+) create mode 100644 src/jmap/shape/Switch/ESwCore.js create mode 100644 src/jmap/shape/Switch/ESwName.js diff --git a/src/jmap/shape/Switch/ESwCore.js b/src/jmap/shape/Switch/ESwCore.js new file mode 100644 index 000000000..33a5c595d --- /dev/null +++ b/src/jmap/shape/Switch/ESwCore.js @@ -0,0 +1,78 @@ +import Group from 'zrender/src/container/Group'; +import Line from 'zrender/src/graphic/shape/Line'; + +class ESwCore extends Group { + constructor(model) { + super(); + this.model = model; + this._create(); + } + + _create() { + const model = this.model; + const style = this.model.style; + + this.line = new Line({ + zlevel: model.zlevel, + z: model.z, + silent: true, + shape: { + x1: model.intersectionX - model.coverLength, + y1: model.intersectionY, + x2: model.intersectionX + model.coverLength, + y2: model.intersectionY + }, + style: { + lineWidth: model.switchWidth, + stroke: style.backgroundColor + } + }); + + this.skewLine = new Line({ + zlevel: model.zlevel, + z: model.z, + silent: true, + shape: { + x1: model.intersectionX, + y1: model.intersectionY, + x2: model.intersectionX + model.triangle.drictx * model.triangle.getCotRate() * model.coverLength, + y2: model.intersectiony + model.triangle.dricty * model.coverLength + }, + style: { + lineWidth: model.switchWidth, + stroke: style.backgroundColor + } + }); + + this.add(this.line); + this.add(this.skewLine); + } + + hide() { + this.line.hide(); + this.skewLine.hide(); + } + + show() { + this.line.show(); + this.skewLine.show(); + } + + setColor(color) { + this.line.setStyle('stroke', color); + this.skewLine.setStyle('stroke', color); + } + + stopAnimation(flag) { + this.line.stopAnimation(flag); + this.skewLine.stopAnimation(flag); + } + + animateStyle(cb) { + this.eachChild((child) => { + cb(child); + }); + } +} + +export default ESwCore; diff --git a/src/jmap/shape/Switch/ESwName.js b/src/jmap/shape/Switch/ESwName.js new file mode 100644 index 000000000..8c97e74c5 --- /dev/null +++ b/src/jmap/shape/Switch/ESwName.js @@ -0,0 +1,91 @@ +import Group from 'zrender/src/container/Group'; +import Text from 'zrender/src/graphic/Text'; +import Rect from 'zrender/src/graphic/shape/Rect'; + +class ESwName extends Group { + constructor(model) { + super(); + this.model = model; + this._create(); + } + + _create() { + const model = this.model; + const style = this.model.style; + + this.nameText = new Text({ + zlevel: model.zlevel, + z: model.z + 3, + style: { + x: model.nameTextX, + y: model.nameTextY, + text: model.name, + textAlign: model.triangle.drictx === 1 ? 'left' : 'right', + textVerticalAlign: model.triangle.dricty === 1 ? 'top' : 'bottom', + textFont: style.textFontSize + 'px ' + style.textFontFormat, + textFill: style.Switch.switchTextLossColor + } + }); + + const rect = this.nameText.getBoundingRect(); + let textWidth = rect.width * 0.8; + if (model.triangle.drictx !== 1) { + rect.x += rect.width; + textWidth = -textWidth; + } + + this.textRect = new Rect({ + zlevel: model.zlevel, + z: model.z + 2, + 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.transparentColor + } + }); + + this.arrowText = new Text({ + zlevel: model.zlevel, + z: model.z, + style: { + x: model.arrowTextX, + y: model.arrowTextY, + text: `道岔区段名称: ${model.sectionName}`, + textFill: '#000', + textAlign: 'letf', + textFont: 10 + 'px consolas', + textPadding: 3, + textBackgroundColor: style.tipBackgroundColor + } + }); + + this.add(this.textRect); + this.add(this.nameText); + this.add(this.arrowText); + + this.arrowText.hide(); + model.nameShow ? this.nameText.show() : this.nameText.hide(); + } + + getArrowText() { + return this.arrowText; + } + + getNameText() { + return this.nameText; + } + + getTextRect() { + return this.textRect; + } +} + +export default ESwName;