2019-11-29 12:51:58 +08:00
|
|
|
import * as zrUtil from 'zrender/src/core/util';
|
|
|
|
import * as matrix from 'zrender/src/core/matrix';
|
|
|
|
import deviceType from '../constant/deviceType';
|
|
|
|
import deviceRender from '../constant/deviceRender';
|
|
|
|
import Vue from 'vue';
|
|
|
|
import { deepClone } from '@/utils/index';
|
|
|
|
|
|
|
|
export function createTransform(opts) {
|
|
|
|
let transform = matrix.create();
|
|
|
|
transform = matrix.scale(matrix.create(), transform, [opts.scaleRate, opts.scaleRate]);
|
|
|
|
transform = matrix.translate(matrix.create(), transform, [-opts.offsetX, -opts.offsetY]);
|
|
|
|
return transform;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createBoundingRect(view) {
|
2019-12-18 09:49:44 +08:00
|
|
|
const rect = view.getBoundingRect().clone();
|
2019-11-29 12:51:58 +08:00
|
|
|
const scale = view.scale[0];
|
|
|
|
const offsetX = view.position[0];
|
|
|
|
const offsetY = view.position[1];
|
|
|
|
rect.x = rect.x * scale + offsetX;
|
|
|
|
rect.y = rect.y * scale + offsetY;
|
|
|
|
rect.width = rect.width * scale;
|
|
|
|
rect.height = rect.height * scale;
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function calculateDCenter(viewRect, zrbound) {
|
|
|
|
var dx = (zrbound.width - viewRect.width) / 2 - viewRect.x;
|
|
|
|
var dy = 0;
|
|
|
|
return { dx: dx, dy: dy };
|
|
|
|
}
|
|
|
|
|
|
|
|
export function deviceFactory(type, elem) {
|
|
|
|
return {...deviceRender[type], ...elem};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createDevice(type, elem, propConvert) {
|
|
|
|
const device = deviceFactory(type, Object.assign(elem, { _type: type } ));
|
|
|
|
return propConvert ? propConvert.initPrivateProps(device) : device;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function parser(data, skinCode) {
|
|
|
|
var mapDevice = {};
|
|
|
|
var propConvert = skinCode ? Vue.prototype.$theme.loadPropConvert(skinCode) : null;
|
|
|
|
if (data) {
|
|
|
|
zrUtil.each(data.sectionList || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.Section, elem, propConvert);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
zrUtil.each(data.signalList || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.Signal, elem, propConvert);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
zrUtil.each(data.stationList || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.Station, elem, propConvert);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
zrUtil.each(data.stationStandList || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.StationStand, elem, propConvert);
|
|
|
|
}, this);
|
|
|
|
|
2020-01-07 10:52:44 +08:00
|
|
|
zrUtil.each(data.stationControlList || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.StationControl, elem, propConvert);
|
|
|
|
}, this);
|
2019-11-29 12:51:58 +08:00
|
|
|
|
|
|
|
zrUtil.each(data.counterList || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.StationCounter, elem, propConvert);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
zrUtil.each(data.delayShowList || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.StationDelayUnlock, elem, propConvert);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
zrUtil.each(data.lineList || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.Line, elem, propConvert);
|
|
|
|
}, this);
|
|
|
|
|
2019-12-06 18:03:13 +08:00
|
|
|
zrUtil.each(data.espList || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.Esp, elem, propConvert);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
zrUtil.each(data.psdList || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.Psd, elem, propConvert);
|
|
|
|
}, this);
|
|
|
|
|
2019-11-29 12:51:58 +08:00
|
|
|
zrUtil.each(data.textList || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.Text, elem, propConvert);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
zrUtil.each(data.zcList || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.ZcControl, elem, propConvert);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
zrUtil.each(data.lcList || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.LcControl, elem, propConvert);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
zrUtil.each(data.tempSpeedLimitList || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.LimitControl, elem, propConvert);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
zrUtil.each(data.resourceList || [], elem => {
|
2019-12-23 10:53:25 +08:00
|
|
|
mapDevice[elem.code] = createDevice(deviceType.Resource, elem, propConvert);
|
2019-11-29 12:51:58 +08:00
|
|
|
}, this);
|
|
|
|
|
|
|
|
zrUtil.each(data.trainList || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.Train, elem, propConvert);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
zrUtil.each(data.Line || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.Line, elem, propConvert);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
zrUtil.each(data.Text || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.Text, elem, propConvert);
|
|
|
|
}, this);
|
|
|
|
|
2020-03-05 15:48:51 +08:00
|
|
|
zrUtil.each(data.cycleButtonList || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.MapCycleButtonVO, elem, propConvert);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
zrUtil.each(data.outFrameList || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.OutFrame, elem, propConvert);
|
2020-03-04 20:59:16 +08:00
|
|
|
}, this);
|
|
|
|
|
2019-11-29 12:51:58 +08:00
|
|
|
zrUtil.each(data.trainWindowList || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.TrainWindow, elem, propConvert);
|
|
|
|
if (elem.sectionCode) {
|
|
|
|
const section = mapDevice[elem.sectionCode];
|
|
|
|
if (section) {
|
|
|
|
section['trainWindowCode'] = elem.code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
zrUtil.each(data.switchList || [], elem => {
|
|
|
|
mapDevice[elem.code] = createDevice(deviceType.Switch, elem, propConvert);
|
|
|
|
const cnodeSection = mapDevice[mapDevice[elem.code].sectionACode];
|
|
|
|
const lnodeSection = mapDevice[mapDevice[elem.code].sectionBCode];
|
|
|
|
const rnodeSection = mapDevice[mapDevice[elem.code].sectionCCode];
|
|
|
|
|
|
|
|
if (cnodeSection && lnodeSection && rnodeSection) {
|
|
|
|
cnodeSection['switch'] = lnodeSection['switch'] = rnodeSection['switch'] = mapDevice[elem.code];
|
2019-12-03 14:42:00 +08:00
|
|
|
if (cnodeSection.points[0].x == lnodeSection.points[lnodeSection.points.length - 1].x && cnodeSection.points[0].y == lnodeSection.points[lnodeSection.points.length - 1].y) {
|
2019-11-29 12:51:58 +08:00
|
|
|
mapDevice[elem.code].intersection = {
|
|
|
|
x: cnodeSection.points[0].x,
|
|
|
|
y: cnodeSection.points[0].y
|
|
|
|
};
|
|
|
|
mapDevice[elem.code].skew = {
|
|
|
|
x: rnodeSection.points[rnodeSection.points.length - 2].x,
|
|
|
|
y: rnodeSection.points[rnodeSection.points.length - 2].y
|
|
|
|
};
|
2019-12-03 14:42:00 +08:00
|
|
|
} else if (cnodeSection.points[cnodeSection.points.length - 1].x == lnodeSection.points[0].x && cnodeSection.points[cnodeSection.points.length - 1].y == lnodeSection.points[0].y) {
|
2019-11-29 12:51:58 +08:00
|
|
|
mapDevice[elem.code].intersection = {
|
|
|
|
x: cnodeSection.points[cnodeSection.points.length - 1].x,
|
|
|
|
y: cnodeSection.points[cnodeSection.points.length - 1].y
|
|
|
|
};
|
|
|
|
mapDevice[elem.code].skew = {
|
|
|
|
x: rnodeSection.points[1].x,
|
|
|
|
y: rnodeSection.points[1].y
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const section = mapDevice[cnodeSection.parentCode];
|
|
|
|
if (section) {
|
|
|
|
mapDevice[elem.code].sectionName = section.name;
|
|
|
|
section['relSwitchCode'] = elem.code;
|
|
|
|
}
|
|
|
|
|
|
|
|
rnodeSection['layer'] = -1;
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mapDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 同步绘制数据到原始数据
|
|
|
|
export function updateForList(model, state, liststr) {
|
|
|
|
const list = state.map[liststr];
|
|
|
|
if (list && list instanceof Array) {
|
|
|
|
const i = list.findIndex(elem => { return elem.code == model.code; });
|
|
|
|
if (model._dispose) {
|
|
|
|
i >= 0 && list.splice(i, 1); // 删除
|
|
|
|
} else if (!list[i]) {
|
|
|
|
list.push(deepClone(model)); // 新增
|
|
|
|
} else if (i >= 0) {
|
|
|
|
list[i] = deepClone(model); // item map 数据 model 页面表单数据
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
state.map[liststr] = [model];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function updateMapData(state, model) {
|
|
|
|
if (state.map && model) {
|
|
|
|
switch (model._type) {
|
|
|
|
case deviceType.Section: updateForList(model, state, 'sectionList'); break;
|
|
|
|
case deviceType.Switch: updateForList(model, state, 'switchList'); break;
|
|
|
|
case deviceType.Signal: updateForList(model, state, 'signalList'); break;
|
|
|
|
case deviceType.Station: updateForList(model, state, 'stationList'); break;
|
|
|
|
case deviceType.StationStand: updateForList(model, state, 'stationStandList'); break;
|
|
|
|
case deviceType.StationControl: updateForList(model, state, 'stationControlList'); break;
|
|
|
|
case deviceType.StationCounter: updateForList(model, state, 'stationCounterList'); break;
|
2019-12-17 19:03:38 +08:00
|
|
|
case deviceType.ZcControl: updateForList(model, state, 'zcList'); break;
|
2019-11-29 12:51:58 +08:00
|
|
|
case deviceType.StationDelayUnlock:updateForList(model, state, 'stationDelayUnlockList'); break;
|
2020-03-05 12:21:28 +08:00
|
|
|
case deviceType.LcControl: updateForList(model, state, 'lcList'); break;
|
2019-11-29 12:51:58 +08:00
|
|
|
case deviceType.LimitControl: updateForList(model, state, 'tempSpeedLimitList'); break;
|
2019-12-23 10:53:25 +08:00
|
|
|
case deviceType.Resource: updateForList(model, state, 'resourceList'); break;
|
2019-11-29 12:51:58 +08:00
|
|
|
case deviceType.Train: updateForList(model, state, 'trainList'); break;
|
|
|
|
case deviceType.TrainWindow: updateForList(model, state, 'trainWindowList'); break;
|
|
|
|
case deviceType.Line: updateForList(model, state, 'lineList'); break;
|
|
|
|
case deviceType.Text: updateForList(model, state, 'textList'); break;
|
2019-12-06 18:03:13 +08:00
|
|
|
case deviceType.Psd: updateForList(model, state, 'psdList'); break;
|
|
|
|
case deviceType.Esp: updateForList(model, state, 'espList'); break;
|
2020-03-05 15:48:51 +08:00
|
|
|
case deviceType.MapCycleButtonVO: updateForList(model, state, 'cycleButtonList'); break;
|
|
|
|
case deviceType.OutFrame: updateForList(model, state, 'outFrameList'); break;
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|