2021-01-25 17:21:24 +08:00
|
|
|
import store from '@/store/index';
|
2019-11-29 12:51:58 +08:00
|
|
|
import {createTransform, createBoundingRect} from './utils/parser';
|
|
|
|
|
|
|
|
class TransformHandle {
|
|
|
|
constructor(painter) {
|
|
|
|
this.$painter = painter;
|
|
|
|
|
2021-01-25 17:21:24 +08:00
|
|
|
this.stationFlag = false;
|
|
|
|
|
2019-11-29 12:51:58 +08:00
|
|
|
this.parentLevel = painter.getParentLevel();
|
|
|
|
|
|
|
|
this.rect = { x: 0, y: 0, width: 0, height: 0 };
|
|
|
|
|
|
|
|
this.transform = createTransform({ scaleRate: 1, offsetX: 0, offsetY: 0 });
|
|
|
|
}
|
|
|
|
|
|
|
|
checkVisible(view) {
|
2020-11-24 16:53:13 +08:00
|
|
|
// console.log(view);
|
2019-12-05 10:25:07 +08:00
|
|
|
return createBoundingRect(view).intersect(this.rect);
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
revisibleView(view) {
|
|
|
|
if (this.checkVisible(view)) {
|
|
|
|
view.show();
|
|
|
|
} else {
|
|
|
|
view.hide();
|
|
|
|
}
|
|
|
|
view.dirty();
|
|
|
|
}
|
2021-01-25 17:21:24 +08:00
|
|
|
setStationFlag(stationCode) {
|
|
|
|
this.stationFlag = !!stationCode;
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
// 视图进行缩放/平移
|
|
|
|
transformView(view) {
|
|
|
|
if (view) {
|
|
|
|
view.transform = this.transform;
|
2021-01-25 17:21:24 +08:00
|
|
|
if (this.stationFlag) {
|
|
|
|
this.handleStationShow(view);
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
view.decomposeTransform();
|
|
|
|
this.revisibleView(view);
|
|
|
|
}
|
|
|
|
}
|
2021-01-25 17:21:24 +08:00
|
|
|
handleStationShow(view) {
|
|
|
|
if (view.model && view.model._type === 'Station') {
|
|
|
|
const station = view.model;
|
|
|
|
this.handleStationViewTransform(view, station);
|
|
|
|
} else if (view.model && view.model._type === 'StationStand') {
|
|
|
|
const station = store.getters['map/getDeviceByCode'](view.model.stationCode);
|
|
|
|
this.handleStationViewTransform(view, station);
|
|
|
|
} else if (view.model && view.model._type === 'Psd') {
|
|
|
|
const stand = store.getters['map/getDeviceByCode'](view.model.standCode);
|
|
|
|
const station = store.getters['map/getDeviceByCode'](stand.stationCode);
|
|
|
|
this.handleStationViewTransform(view, station);
|
2021-01-26 13:07:02 +08:00
|
|
|
} else if (view.model && view.model._type === 'Train' && view.model.sectionModel) {
|
|
|
|
const belongStation = view.model.sectionModel.belongStation;
|
|
|
|
const station = store.getters['map/getDeviceByCode'](belongStation);
|
|
|
|
this.handleStationViewTransform(view, station);
|
2021-01-25 17:21:24 +08:00
|
|
|
} else if (view.model && (view.model.belongStation || view.model.belongStationCode)) {
|
|
|
|
const belongStation = view.model.belongStation || view.model.belongStationCode;
|
|
|
|
const station = store.getters['map/getDeviceByCode'](belongStation);
|
|
|
|
this.handleStationViewTransform(view, station);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
handleStationViewTransform(view, station) {
|
2021-01-27 09:27:44 +08:00
|
|
|
if (station && station.foldLine) {
|
2021-01-25 17:21:24 +08:00
|
|
|
view.transform = createTransform({
|
|
|
|
scaleRate: this.$painter.$jmap.$options.scaleRate,
|
|
|
|
offsetX: this.$painter.$jmap.$options.offsetX + station.foldLineOffset.x * this.$painter.$jmap.$options.scaleRate,
|
|
|
|
offsetY: this.$painter.$jmap.$options.offsetY - station.foldLineOffset.y * this.$painter.$jmap.$options.scaleRate
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
// 处理所有视图缩放/平移
|
|
|
|
transformAll() {
|
|
|
|
this.traverse(this.transformView, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 重新计算显示图形
|
|
|
|
revisibleAll() {
|
|
|
|
this.traverse(this.revisibleView, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 更新偏移量
|
|
|
|
updateTransform(opts) {
|
|
|
|
this.transform = createTransform(opts);
|
|
|
|
this.transformAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 更新画布尺寸
|
|
|
|
updateZrSize(opts) {
|
|
|
|
this.rect = { x: 0, y: 0, width: opts.width, height: opts.height };
|
2020-11-24 16:53:13 +08:00
|
|
|
if (opts.isUpdate) { this.revisibleAll(); }
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 遍历group执行回调
|
|
|
|
traverse(cb, context) {
|
|
|
|
this.parentLevel.eachChild(level => {
|
|
|
|
level.eachChild((view) => {
|
|
|
|
cb.call(context, view);
|
|
|
|
}, context);
|
|
|
|
}, context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TransformHandle;
|