成都一号线 列车精确位置三角代码修改

This commit is contained in:
joylink_cuiweidong 2020-03-10 20:15:47 +08:00
parent 3ef47d146d
commit 27c8b0204e
6 changed files with 209 additions and 191 deletions

View File

@ -1,46 +0,0 @@
import Group from 'zrender/src/container/Group';
import Polygon from 'zrender/src/graphic/shape/Polygon';
/** 创建三角形*/
export default class ETriangle extends Group {
constructor(model) {
super();
this.model = model;
this.zlevel = model.zlevel;
this.z = model.z;
this.create(model);
}
create(model) {
if (model && model.point) {
const right = model.right == 1 ? 1 : -1;
this.angle = new Polygon({
zlevel: model.zlevel,
z: model.z,
shape: {
points:[[model.point.x + 10 * right, model.point.y], [model.point.x + (1 - right) * 10 / 4, model.point.y - 6], [model.point.x + (1 - right) * 10 / 4, model.point.y + 6]]
},
style: {
stroke:'#FFFF00',
lineWidth: 0.5,
fill: '#FFFF00'
}
});
this.add(this.angle);
}
}
// 隐藏
hide() {
this.angle.hide();
}
// 显示
show() {
this.angle.show();
}
// setModel(model) {
// this.shape
// }
}

View File

@ -10,7 +10,6 @@ import { EAxle } from './EAxle'; // 创建计轴 (私有)
import { EBackArrow, EBackArrowTriangle } from './EBackArrow'; // 折返进路箭头
import ELimitName from './ELimitName'; // 成都三号线 限速名称
import JTriangle from '../../utils/JTriangle';
import ETriangle from './ETriangle';
import router from '@/router';
import { drawSectionStyle } from '../../config/defaultStyle';
import store from '@/store';
@ -46,9 +45,9 @@ export default class Section extends Group {
this.creatRelease(); // 创建延时释放
this.createSeparator(); // 创建分隔符
this.createTurnBack(); // 创建成都三号线 折返箭头
if (this.style.Section.trainPosition.display) {
this.createTriangle(); // 创建成都一号线 列车精确位置
}
// if (this.style.Section.trainPosition.display) {
// this.createTriangle(); // 创建成都一号线 列车精确位置
// }
if (model.type === '01' && model.type === '03') {
this.createAxles(); // 创建计轴
}
@ -595,10 +594,10 @@ export default class Section extends Group {
this.remove(this.speedLimitLeft);
this.remove(this.speedLimitRight);
}
if (this.style.Section.trainPosition.display) {
this.triangleL.hide();
this.triangleR.hide();
}
// if (this.style.Section.trainPosition.display) {
// this.triangleL.hide();
// this.triangleR.hide();
// }
}
}
@ -661,112 +660,112 @@ export default class Section extends Group {
// this.triangle.show();
// }
createTriangle() {
const model = this.model;
this.triangleL = new ETriangle({
style: this.style,
zlevel: this.zlevel,
z:10,
right: 0,
point:{x:model.points[model.points.length - 1].x, y:model.points[model.points.length - 1].y}
});
this.triangleR = new ETriangle({
style: this.style,
zlevel: this.zlevel,
z:10,
right: 1,
point:{x:model.points[0].x, y:model.points[0].y}
});
this.add(this.triangleL);
this.add(this.triangleR);
}
// createTriangle() {
// const model = this.model;
// this.triangleL = new ETriangle({
// style: this.style,
// zlevel: this.zlevel,
// z:10,
// right: 0,
// point:{x:model.points[model.points.length - 1].x, y:model.points[model.points.length - 1].y}
// });
// this.triangleR = new ETriangle({
// style: this.style,
// zlevel: this.zlevel,
// z:10,
// right: 1,
// point:{x:model.points[0].x, y:model.points[0].y}
// });
// this.add(this.triangleL);
// this.add(this.triangleR);
// }
// 成都一号线列车的精确位置
updateTriangle() {
const model = this.model;
// debugger;
// if (model.hideOld) {
// // debugger;
// if (model.right == 1) {
// this.triangleR.hide();
// } else {
// this.triangleL.hide();
// }
// }
if (model.right != undefined && model.offsetp != undefined && model.points.length > 1) {
const newX = model.points[0].x + (model.points[1].x - model.points[0].x) * model.offsetp;
const newY = model.points[0].y + (model.points[1].y - model.points[0].y) * model.offsetp;
if (!model.oldX && !model.oldY) {
model.oldX = this.triangleL.model.point.x;
model.oldY = this.triangleL.model.point.y;
}
if (model.right == 1) {
if (model.hideOld) {
// debugger;
this.triangleR.hide();
}
this.triangleL.hide();
this.triangleR.show();
this.triangleR.position = [newX - model.oldX, newY - model.oldY];
// const runner = this.triangleR.animate('position', false).when(100, [newX - model.oldX, newY - model.oldY]);
// runner.done(function() {
// runner.stop();
// data.hide();
// model.oldX = newX;
// model.oldY = newY;
// }).start();
} else {
if (model.hideOld) {
this.triangleL.hide();
}
this.triangleR.hide();
this.triangleL.show();
this.triangleL.position = [newX - model.oldX, newY - model.oldY];
// const runner = this.triangleL.animate('position', false).when(100, [newX - model.oldX, newY - model.oldY]);
// runner.done(function() {
// // debugger;
// runner.stop();
// data.hide();
// model.oldX = newX;
// model.oldY = newY;
// }).start();
// stopAnimation(true)
}
// updateTriangle() {
// const model = this.model;
// // debugger;
// // if (model.hideOld) {
// // // debugger;
// // if (model.right == 1) {
// // this.triangleR.hide();
// // } else {
// // this.triangleL.hide();
// // }
// // }
// if (model.right != undefined && model.offsetp != undefined && model.points.length > 1) {
// const newX = model.points[0].x + (model.points[1].x - model.points[0].x) * model.offsetp;
// const newY = model.points[0].y + (model.points[1].y - model.points[0].y) * model.offsetp;
// if (!model.oldX && !model.oldY) {
// model.oldX = this.triangleL.model.point.x;
// model.oldY = this.triangleL.model.point.y;
// }
// if (model.right == 1) {
// if (model.hideOld) {
// // debugger;
// this.triangleR.hide();
// }
// this.triangleL.hide();
// this.triangleR.show();
// this.triangleR.position = [newX - model.oldX, newY - model.oldY];
// // const runner = this.triangleR.animate('position', false).when(100, [newX - model.oldX, newY - model.oldY]);
// // runner.done(function() {
// // runner.stop();
// // data.hide();
// // model.oldX = newX;
// // model.oldY = newY;
// // }).start();
// } else {
// if (model.hideOld) {
// this.triangleL.hide();
// }
// this.triangleR.hide();
// this.triangleL.show();
// this.triangleL.position = [newX - model.oldX, newY - model.oldY];
// // const runner = this.triangleL.animate('position', false).when(100, [newX - model.oldX, newY - model.oldY]);
// // runner.done(function() {
// // // debugger;
// // runner.stop();
// // data.hide();
// // model.oldX = newX;
// // model.oldY = newY;
// // }).start();
// // stopAnimation(true)
// }
// if (!model.hasTriangle) {
// this.triangle = new ETriangle({
// style: this.style,
// zlevel: this.zlevel,
// z:1000,
// right: model.right,
// point:{x:model.points[0].x + (model.points[1].x - model.points[0].x) * model.offsetp, y:model.points[0].y}
// });
// /** 添加视图*/
// this.add(this.triangle);
// model.hasTriangle = true;
// } else {
// // debugger;
// console.log(2222222);
// const newX = model.points[0].x + (model.points[1].x - model.points[0].x) * model.offsetp;
// const newY = model.points[0].y;
// // debugger;
// if (this.triangle) {
// if (model.offsetp >= 1) {
// this.remove(this.triangle);
// model.hasTriangle = false;
// } else {
// // this.remove(this.triangle);
// // model.hasTriangle = false;
// const runner = this.triangle.animate('position', true).when(100, [newX - this.triangle.model.point.x, newY - this.triangle.model.point.y]);
// runner.start();
// }
// // this.triangle.position = [newX - this.triangle.model.point.x, newY - this.triangle.model.point.y];
// // this.triangle.dirty();
// }
// // if (!model.hasTriangle) {
// // this.triangle = new ETriangle({
// // style: this.style,
// // zlevel: this.zlevel,
// // z:1000,
// // right: model.right,
// // point:{x:model.points[0].x + (model.points[1].x - model.points[0].x) * model.offsetp, y:model.points[0].y}
// // });
// // /** 添加视图*/
// // this.add(this.triangle);
// // model.hasTriangle = true;
// // } else {
// // // debugger;
// // console.log(2222222);
// // const newX = model.points[0].x + (model.points[1].x - model.points[0].x) * model.offsetp;
// // const newY = model.points[0].y;
// // // debugger;
// // if (this.triangle) {
// // if (model.offsetp >= 1) {
// // this.remove(this.triangle);
// // model.hasTriangle = false;
// // } else {
// // // this.remove(this.triangle);
// // // model.hasTriangle = false;
// // const runner = this.triangle.animate('position', true).when(100, [newX - this.triangle.model.point.x, newY - this.triangle.model.point.y]);
// // runner.start();
// // }
// // // this.triangle.position = [newX - this.triangle.model.point.x, newY - this.triangle.model.point.y];
// // // this.triangle.dirty();
// // }
// }
}
}
// // }
// }
// }
/** 封锁 06*/
block() {
@ -927,8 +926,8 @@ export default class Section extends Group {
}
/** 道岔保护区段锁闭 */
model.overlapLock && this.protectiveLock();
/** 成都一号线列车精确位置 */
model.offsetp && this.updateTriangle();
// /** 成都一号线列车精确位置 */
// model.offsetp && this.updateTriangle();
/** 空闲锁闭或者叫进路锁闭 */
model.routeLock && this.routeLock();
/** 轨道封锁 */

View File

@ -0,0 +1,62 @@
import Group from 'zrender/src/container/Group';
import Polygon from 'zrender/src/graphic/shape/Polygon';
/** 创建三角形*/
export default class ETriangle extends Group {
constructor(model) {
super();
this.model = model;
this.zlevel = model.zlevel;
this.z = model.z;
this.create(model);
}
create(model) {
if (model && model.point) {
const right = model.right == 1 ? 1 : -1;
this.angle = new Polygon({
zlevel: model.zlevel,
z: model.z,
shape: {
points:[[model.point.x + 10 * right, model.point.y], [model.point.x, model.point.y - 6], [model.point.x, model.point.y + 6]]
},
style: {
stroke:'#FFFF00',
lineWidth: 0.5,
fill: '#FFFF00'
}
});
this.add(this.angle);
}
}
updateTriangle(model, right) {
const trainRight = right == 1 ? 1 : -1;
// const data = this.angle.shape.points;
// this.angle.shape.points.pop();
// this.angle.shape.points.pop();
// this.angle.shape.points.pop();
// this.angle.shape.points.push([model.x + 10 * trainRight, model.y]);
// this.angle.shape.points.push([model.x, model.y - 6]);
// this.angle.shape.points.push([model.x, model.y + 6]);
const data = [[model.x + 10 * trainRight, model.y], [model.x, model.y - 6], [model.x, model.y + 6]];
// this.angle.shape.points.push([model.x + 10 * trainRight, model.y]);
// this.angle.attr('shape', { points: this.angle.shape.points });
// this.angle.attr({
// shape: {
// points:data
// }
// });
// const object = this.angle;
this.angle.animateTo({
shape: {
points:data
}
}, 10, 0, 'elasticOut', function () {
// done
// object.stopAnimation(true);
});
// this.angle.setS
this.dirty();
}
}

View File

@ -4,6 +4,7 @@ import TrainBody from './TrainBody';
import BoundingRect from 'zrender/src/core/BoundingRect';
import Rect from 'zrender/src/graphic/shape/Rect';
import { deepAssign } from '@/utils/index';
import ETriangle from '../Train/ETriangle';
import store from '@/store';
/** 列车 */
@ -31,7 +32,7 @@ export default class Train extends Group {
});
}
this.create();
this.setState(model);
this.setState(model, this);
}
_computed() {
@ -44,10 +45,10 @@ export default class Train extends Group {
};
if (model.right) {
this.point.x = this.point.x - style.Train.trainHead.trainConntWidth * this.newScale - style.Train.common.trainWidth / 2;
this.point.y = this.point.y - style.Train.common.trainHeight/2;
this.point.y = this.point.y - style.Train.common.trainHeight / 2;
} else {
this.point.x = this.point.x + style.Train.trainHead.trainConntWidth * this.newScale - style.Train.common.trainWidth / 2;
this.point.y = this.point.y + model.trainWindowModel.height - style.Train.common.trainHeight/2;
this.point.y = this.point.y + model.trainWindowModel.height - style.Train.common.trainHeight / 2;
}
} else {
this.point = model.position;
@ -105,6 +106,22 @@ export default class Train extends Group {
scale: this.newScale
});
const data = this.model.physicalCode;
const oldmodel = store.getters['map/getDeviceByCode'](data);
const leftPoint = oldmodel.points[0];
const rightPoint = oldmodel.points[oldmodel.points.length - 1];
const right = this.model.right == 1 ? 1 : 0;
this.startX = leftPoint.x + (1 - right) * (rightPoint.x - leftPoint.x);
this.startY = leftPoint.y + (1 - right) * (rightPoint.y - leftPoint.y);
this.triangle = new ETriangle({
style: this.style,
zlevel: this.zlevel,
z:10,
right: this.model.right,
point:{x:this.startX, y:this.startY}
});
this.add(this.triangle);
this.add(this.trainB);
this.add(this.trainL);
this.add(this.trainR);
@ -123,22 +140,17 @@ export default class Train extends Group {
if (train.physicalCode && train.offsetp) {
const data = train.physicalCode;
const oldmodel = store.getters['map/getDeviceByCode'](data);
oldmodel.offsetp = train.offsetp;
oldmodel.right = train.right;
let models = [];
const model = deepAssign(oldmodel, {_type: 'Section'}); // 修改元素model
models = [model];
store.dispatch('map/updateMapDevices', models).then(()=>{
if (train.oldsection && train.oldsection != train.physicalCode) {
const oldmodels = store.getters['map/getDeviceByCode'](train.oldsection);
const models = deepAssign(oldmodels, {_type: 'Section'}); // 修改元素model
models.hideOld = true;
models.offsetp = undefined;
const trainOldSection = [models];
store.dispatch('map/updateMapDevices', trainOldSection);
}
train.oldsection = train.physicalCode;
});
const leftPoint = oldmodel.points[0];
const rightPoint = oldmodel.points[oldmodel.points.length - 1];
if (this.triangle) {
this.startX = leftPoint.x + (rightPoint.x - leftPoint.x) * train.offsetp;
this.startY = leftPoint.y + (rightPoint.y - leftPoint.y) * train.offsetp;
const point = {x:this.startX, y:this.startY};
this.triangle.point = point;
this.triangle.updateTriangle(point, train.right);
this.triangle.dirty();
this.dirty();
}
}
}
@ -328,7 +340,7 @@ export default class Train extends Group {
}
}
// 设置状态
setState(model) {
setState(model, object) {
const flag = model.trainWindowModel ? model.trainWindowModel.reversal : false;
if (model) {
this.recover();
@ -347,9 +359,8 @@ export default class Train extends Group {
const style = this.style;
if (style.Section.trainPosition.display) {
this.updateSection();
this.updateSection(object);
}
}
// let points = [];
// if (model) {

View File

@ -93,19 +93,16 @@ export default {
label: '排列进路',
handler: this.arrangementRoute,
cmdType: CMD.Signal.CMD_SIGNAL_SET_ROUTE
// auth: { station: false, center: true }
},
{
label: '取消进路',
handler: this.cancelTrainRoute,
cmdType: CMD.Signal.CMD_SIGNAL_CANCEL_ROUTE
// auth: { station: false, center: true }
},
{
label: '信号重开',
handler: this.reopenSignal,
cmdType: CMD.Signal.CMD_SIGNAL_REOPEN_SIGNAL
// auth: { station: false, center: true }
},
{
type: 'separator'
@ -114,13 +111,11 @@ export default {
label: '进路交人工控',
handler: this.humanControl,
cmdType: CMD.Signal.CMD_SIGNAL_CLOSE_AUTO_SETTING
// auth: { station: false, center: true }
},
{
label: '进路交自动控',
handler: this.atsAutoControl,
cmdType: CMD.Signal.CMD_SIGNAL_OPEN_AUTO_SETTING
// auth: { station: false, center: true }
},
{
label: '查询进路控制状态',

View File

@ -71,14 +71,12 @@ export default {
{
label: '轨道切除',
handler: this.split,
cmdType: CMD.Switch.CMD_SWITCH_CUT_OFF,
auth: { station: true, center: true }
cmdType: CMD.Switch.CMD_SWITCH_CUT_OFF
},
{
label: '轨道激活',
handler: this.active,
cmdType: CMD.Switch.CMD_SWITCH_ACTIVE,
auth: { station: true, center: true }
cmdType: CMD.Switch.CMD_SWITCH_ACTIVE
},
{
type: 'separator'
@ -92,8 +90,7 @@ export default {
{
label: '设置临时限速',
handler: this.setSpeed,
cmdType: CMD.Switch.CMD_SWITCH_SET_LIMIT_SPEED,
auth: { station: false, center: true }
cmdType: CMD.Switch.CMD_SWITCH_SET_LIMIT_SPEED
}
// {
// type: 'separator'