rt-sim-training-client/src/jmapNew/transformHandleScreen.js

78 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-05-06 16:57:07 +08:00
import {createTransform, createBoundingRect} from './utils/parser';
2020-05-07 13:35:25 +08:00
import Vue from 'vue';
import store from '@/store/index_APP_TARGET';
2020-05-06 16:57:07 +08:00
class TransformHandle {
constructor(painter) {
this.$painter = painter;
2020-05-07 09:04:28 +08:00
this.width = 1600;
2020-05-06 16:57:07 +08:00
this.parentLevel = painter.getParentLevel();
2020-05-07 09:04:28 +08:00
this.rect = { x: 0, y: 0, width: 0, height: 0 };
2020-05-06 16:57:07 +08:00
this.transform = [createTransform({ scaleRate: 1, offsetX: 0, offsetY: 0 })];
}
2020-05-07 09:04:28 +08:00
checkVisible(view) {
2020-05-06 16:57:07 +08:00
return createBoundingRect(view).intersect(this.rect);
}
// 视图进行缩放/平移
transformView(view) {
if (view) {
for (let i = 0; i < this.transform.length; i++) {
view.transform = this.transform[i];
2020-05-07 13:35:25 +08:00
view.decomposeTransform(); // 修改 transform 后同步位置
const propConvert = Vue.prototype.$theme.loadPropConvert(store.state.map.map.skinVO.code);
if (propConvert.handleScreenProps && propConvert.handleScreenProps(view)) {
view.hide();
return;
}
2020-05-06 16:57:07 +08:00
if (this.checkVisible(view)) { view.show(); return; } else { view.hide(); }
}
2020-05-07 13:35:25 +08:00
view.dirty(); // 更新
2020-05-06 16:57:07 +08:00
}
}
// 处理所有视图缩放/平移
transformAll() {
this.traverse(this.transformView, this);
}
// 重新计算显示图形
revisibleAll() {
this.traverse(this.revisibleView, this);
}
// 更新偏移量
2020-05-07 09:04:28 +08:00
updateTransform(list, opts) {
const rightWidth = 80; // 右边空余宽度
this.rect = { x: 0, y: 0, width: opts.width - rightWidth, height: opts.height };
this.width = opts.width - rightWidth;
2020-05-06 16:57:07 +08:00
this.transform = [];
2020-05-07 09:04:28 +08:00
list.forEach((item, index) => {
item['offsetX'] = index * (this.width - 50) - 50;
2020-05-06 16:57:07 +08:00
this.transform.push(createTransform(item));
});
this.transformAll();
}
// 更新画布尺寸
updateZrSize(opts) {
this.rect = { x: 0, y: 0, width: opts.width, height: opts.height };
this.revisibleAll();
}
// 遍历group执行回调
traverse(cb, context) {
this.parentLevel.eachChild(level => {
level.eachChild((view) => {
cb.call(context, view);
}, context);
}, context);
}
}
export default TransformHandle;