diff --git a/src/iscs_new/controller.js b/src/iscs_new/controller.js index 27d037484..26a5fe083 100644 --- a/src/iscs_new/controller.js +++ b/src/iscs_new/controller.js @@ -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); } diff --git a/src/iscs_new/factory/compose.js b/src/iscs_new/factory/compose.js index 90bfd6fed..0faadaaa9 100644 --- a/src/iscs_new/factory/compose.js +++ b/src/iscs_new/factory/compose.js @@ -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; } diff --git a/src/iscs_new/factory/element.js b/src/iscs_new/factory/element.js index 0978a6eac..762f299d6 100644 --- a/src/iscs_new/factory/element.js +++ b/src/iscs_new/factory/element.js @@ -134,7 +134,7 @@ class Element extends AbstractShape { // 获取依赖图形 getDepShapes() { - return [] + return [this]; } diff --git a/src/iscs_new/map.js b/src/iscs_new/map.js index 41abba72c..1cd106212 100644 --- a/src/iscs_new/map.js +++ b/src/iscs_new/map.js @@ -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) { diff --git a/src/views/test/index.vue b/src/views/test/index.vue index 462a1d478..6db3a4ce5 100644 --- a/src/views/test/index.vue +++ b/src/views/test/index.vue @@ -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: '' } ] }, {