import Polyline from 'zrender/src/graphic/shape/Polyline'; import Group from 'zrender/src/container/Group'; import Polygon from 'zrender/src/graphic/shape/Polygon'; class ESigPost extends Group { constructor(model) { super(); this.model = model; this.create(); } create() { const model = this.model; const style = this.model.style; // 基座 let verPoints = [[model.x, model.y + style.Signal.post.standardHeight * 1.2], [model.x, model.y - style.Signal.post.standardHeight * 1.2]]; if (style.Signal.post.standardVerticalShape && style.Signal.post.standardVerticalShape === '8') { verPoints = [ [model.x - model.drict * 2, model.y + style.Signal.post.standardHeight * 1.2], [model.x - model.drict * 2, model.y - style.Signal.post.standardHeight * 1.2], [model.x, model.y - style.Signal.post.standardHeight * 1.2], [model.x, model.y - style.Signal.post.standardRailWidth / 2], [model.x + model.drict * 2, model.y - style.Signal.post.standardRailWidth / 2], [model.x + model.drict * 2, model.y + style.Signal.post.standardRailWidth / 2], [model.x, model.y + style.Signal.post.standardRailWidth / 2], [model.x, model.y + style.Signal.post.standardHeight * 1.2] ]; this.ver = new Polygon({ _subType: 'SignalLamp', _val: '3', zlevel: model.zlevel, z: model.z + 1, shape: { points: verPoints }, style: { lineWidth: style.Signal.post.standardVerticalWidth, stroke: style.Signal.post.standardColor, fill: style.Signal.post.standardColor } }); } else { this.ver = new Polyline({ _subType: 'SignalLamp', _val: '3', zlevel: model.zlevel, z: model.z + 1, shape: { points: verPoints }, style: { lineWidth: style.Signal.post.standardVerticalWidth, stroke: style.Signal.post.standardColor, fill: style.Signal.post.standardColor } }); } // 横杆 this.hor = new Polyline({ zlevel: model.zlevel, z: model.z, _val: '3', shape: { points: [ [model.x, model.y], [model.x + model.drict * style.Signal.post.standardLength * 1.2, model.y] ] }, style: { lineWidth: style.Signal.post.standardRailWidth, stroke: style.Signal.post.standardColor } }); this.add(this.ver); this.add(this.hor); } setVerColor(color) { if (color) { this.ver && this.ver.setStyle({ stroke: color }); this.ver && this.ver.setStyle({ fill: color }); } } setHorColor(color) { if (color) { this.hor && this.hor.setStyle({ stroke: color }); } } setColor(color) { if (color) { this.ver && this.ver.setStyle({ stroke: color }); this.ver && this.ver.setStyle({ fill: color }); this.hor && this.hor.setStyle({ stroke: color }); } } /* 灯柱变换为三角形并闪烁*/ setTerminalOptional() { this.triangle = new Polygon({ zlevel: this.model.zlevel, _val: '3', z: this.model.z, shape: { points: [ [this.model.x, this.model.y + this.model.style.Signal.post.standardHeight * 1.2], [this.model.x, this.model.y - this.model.style.Signal.post.standardHeight * 1.2], [this.model.x + this.model.drict * this.model.style.Signal.post.standardLength * 1.2, this.model.y] ] }, style: { fill: this.model.style.Signal.post.terminalOptional } }); this.add(this.triangle); this.triangle.animateStyle(true) .when(0, { fill: this.model.style.backgroundColor }) .when(1000, { fill: this.model.style.Signal.post.terminalOptional }) .when(2000, { fill: this.model.style.backgroundColor }) .start(); this.ver.hide(); this.hor.hide(); } /* 关闭闪烁三角形并还原灯柱 */ removeTerminalOptional() { this.triangle && this.triangle.stopAnimation(false); this.triangle && this.remove(this.triangle); this.ver.show(); this.hor.show(); } getLampPosition(type) { const model = this.model; const style = this.model.style; if (style.Signal.post.standardShow) { type = '01'; } const length = style.Signal.post.standardShow ? style.Signal.post.standardLength : 0; if (type === '01') { return { x: model.x + model.drict * style.Signal.lamp.radiusR * 3 / 2 + model.drict * length, y: model.y }; } else { return { x: this.hor.shape.points[1][0] + model.drict * style.Signal.lamp.radiusR + model.drict * length, y: this.hor.shape.points[1][1] }; } } } export default ESigPost;