组合可以嵌套处理组合

This commit is contained in:
ival 2021-04-01 12:54:03 +08:00
parent abbc3b96d2
commit a56598888d
5 changed files with 50 additions and 41 deletions

View File

@ -8,18 +8,23 @@ import KeyBoardHandle from './keyboardHandle';
import events from './utils/events';
class MouseEvent {
constructor(e) {
constructor(controller, e) {
const shapeFactory = controller.$map.getShapeFactory();
const view = e.target;
this.clientX = e.event.clientX;
this.clientY = e.event.clientY;
if (view && !['__selecting__', '__drag__'].includes(view.subType)) {
if (view.code) {
this.code = view.code;
if (view.composeCode) {
this.code = view.composeCode;
let composeCode = view.composeCode;
let compose = null;
while(composeCode) {
compose = shapeFactory.getShapeByCode(composeCode);
composeCode = compose.model.composeCode;
}
this.code = compose? compose.model.code: view.code;
}
if (view.subType) {
@ -167,7 +172,7 @@ export default class Controller extends Eventful {
}
mousedown(e) {
const event = new MouseEvent(e);
const event = new MouseEvent(this, e);
const zr = this.$map.getZr();
this._x = e.offsetX;
@ -273,7 +278,7 @@ export default class Controller extends Eventful {
}
click(e) {
const event = new MouseEvent(e);
const event = new MouseEvent(this, e);
this.trigger(events.Selected, event);
if (event.code) {
@ -288,7 +293,7 @@ export default class Controller extends Eventful {
contextmenu(e) {
eventTool.stop(e.event);
const event = new MouseEvent(e);
const event = new MouseEvent(this, e);
if (!this._pan) {
this.trigger(events.ContextMenu, event);
}

View File

@ -10,9 +10,9 @@ class Compose extends AbstractShape {
// 拖动
draft({dx, dy}) {
this.model.elementCodes.forEach(code => {
const element = this.shapeFactory.getShapeByCode(code);
if (element) {
element.draft({dx, dy});
const el = this.shapeFactory.getShapeByCode(code);
if (el) {
el.draft({dx, dy});
}
})
}
@ -41,11 +41,11 @@ class Compose extends AbstractShape {
this.inactive();
this.shapeFactory.hideHightLight(this);
this.model.elementCodes.forEach(code => {
const element = this.shapeFactory.getShapeByCode(code);
if (element &&
element.model) {
element.model.composeCode = this.model.code;
element.instance.attr(element.model)
const el = this.shapeFactory.getShapeByCode(code);
if (el &&
el.model) {
el.model.composeCode = this.model.code;
el.attr(el.model)
}
})
}
@ -55,11 +55,12 @@ class Compose extends AbstractShape {
this.inactive();
this.shapeFactory.hideHightLight(this);
this.model.elementCodes.forEach(code => {
const element = this.shapeFactory.getShapeByCode(code);
if (element &&
element.model) {
element.model.composeCode = '';
element.instance.attr(element.model);
const el = this.shapeFactory.getShapeByCode(code);
if (el &&
el.model &&
el.model.composeCode) {
el.model.composeCode = '';
el.attr(el.model);
}
})
this.model.elementCodes = [];
@ -68,28 +69,30 @@ class Compose extends AbstractShape {
// 修改属性
attr(attrs) {
this.model.elementCodes.forEach(code => {
const element = this.shapeFactory.getShapeByCode(code);
if (element &&
element.instance) {
element.instance.attr(attrs);
const el = this.shapeFactory.getShapeByCode(code);
if (el &&
el) {
el.attr(attrs);
}
})
}
// 获取依赖图形
getDepShapes() {
return this.model.elementCodes.map(code => this.shapeFactory.getShapeByCode(code)).filter(el => el)
return this.model.elementCodes.reduce((shapes, code) => shapes.concat(this.shapeFactory.getShapeByCode(code).getDepShapes()), [this]);
}
// 获取包围框
getBoundingRect() {
let unionRect = null;
this.model.elementCodes.forEach(code => {
const element = this.shapeFactory.getShapeByCode(code)
if (element && element.instance && !element.instance.invisible) {
const rect = element.instance.getBoundingRect().clone();
unionRect ? unionRect.union(rect): (unionRect = rect);
}
const el = this.shapeFactory.getShapeByCode(code)
const rect = el.getBoundingRect().clone();
rect
? unionRect
? unionRect.union(rect)
: (unionRect = rect)
: null;
})
return unionRect;
}

View File

@ -134,7 +134,7 @@ class Element extends AbstractShape {
// 获取依赖图形
getDepShapes() {
return []
return [this];
}

View File

@ -167,7 +167,6 @@ class JMap {
break;
case orders.DELETE:
oldShape = this.$shapeFactory.removeShape(shape);
this.$painter.remove(oldShape);
deps.forEach(shape => {
this.$shapeFactory.updateSource(shape.model, {...action, shapeType: shapeType.Element});
this.$painter.remove(shape);
@ -214,6 +213,10 @@ class JMap {
return payload||{};
}
getEvents() {
return this.events;
}
getZr() {
return this.$zr;
}
@ -230,12 +233,8 @@ class JMap {
return this.$controller;
}
getEvents() {
return this.events;
}
getDefaultState() {
return this.defaultState;
getShapeFactory() {
return this.$shapeFactory;
}
getShapeByCode(code) {

View File

@ -226,12 +226,14 @@ export default {
{
code: '100',
type: 'Device',
elementCodes: ['1', '2']
elementCodes: ['1', '2'],
composeCode: '101',
},
{
code: '101',
type: 'Device',
elementCodes: ['3', '4']
elementCodes: ['3', '4', '100'],
composeCode: ''
}
]
}, {