diff --git a/src/iscs_new/controller.js b/src/iscs_new/controller.js index ef296a416..61ddb05f8 100644 --- a/src/iscs_new/controller.js +++ b/src/iscs_new/controller.js @@ -182,8 +182,8 @@ export default class Controller extends Eventful { this._target = this.$map.getShapeByCode(event.code); zr.dom.focus(); - this._isNotLeftMouse = eventTool.isMiddleOrRightButtonOnMouseUpDown(e); + this.trigger(events.Selected, this._target); if (this._isNotLeftMouse) { this.setCursorStyle('grab'); @@ -284,8 +284,6 @@ export default class Controller extends Eventful { click(e) { const event = new MouseEvent(this, e); - this.trigger(events.Selected, event); - if (!event.code) { this.selectHandle.clear(); this.selectingHandle.clear(); diff --git a/src/iscs_new/core/abstractShape.js b/src/iscs_new/core/abstractShape.js index 67eceb774..d67d5481d 100644 --- a/src/iscs_new/core/abstractShape.js +++ b/src/iscs_new/core/abstractShape.js @@ -18,7 +18,7 @@ function shapeStyleBuilder(model) { style: { lineWidth: 1, stroke: 'rgba(255,255,255,0.5)', - fill: 'rgba(200,200,200,0.3)' + fill: 'rgba(200,200,200,0.5)' } } } diff --git a/src/iscs_new/factory/element.js b/src/iscs_new/factory/element.js index 0cdbfabc7..9bae29a6c 100644 --- a/src/iscs_new/factory/element.js +++ b/src/iscs_new/factory/element.js @@ -17,7 +17,7 @@ class Element extends AbstractShape { if (elementBuilder) { // mouse进入事件 function onmouseover(e) { - that.shapeFactory.trigger(shapeEvent.ShowTips, {...that.instance.getBoundingRect(), text: 'text for test'}); + that.shapeFactory.trigger(shapeEvent.ShowTips, e, 'text for test'); } // mouse移动事件 @@ -27,7 +27,7 @@ class Element extends AbstractShape { // mouse离开事件 function onmouseout(e) { - that.shapeFactory.trigger(shapeEvent.HideTips, that.instance.getBoundingRect()); + that.shapeFactory.trigger(shapeEvent.HideTips, e); } this.instance = new elementBuilder({ diff --git a/src/iscs_new/factory/tipsHandle.js b/src/iscs_new/factory/tipsHandle.js index 4bd826c28..0d0eb98b3 100644 --- a/src/iscs_new/factory/tipsHandle.js +++ b/src/iscs_new/factory/tipsHandle.js @@ -36,10 +36,12 @@ export default class TipsHandle { this.message = new graphic.Text(shapeStyleBuilder()); } - onShow(e) { - const {x, y, text} = e; + onShow(e, text) { + const {offsetX, offsetY} = e; const painter = this.$map.getPainter(); - + const option = this.$map.getOption(); + const x = (offsetX + option.offsetX) / option.scaleRate; + const y = (offsetY + option.offsetY) / option.scaleRate; this.message.setStyle({ x, y, text }); painter.addToLayer(shapeLayer.Tips)(this.message); } diff --git a/src/iscs_new/map.js b/src/iscs_new/map.js index 3ae642e83..99eeaeb3c 100644 --- a/src/iscs_new/map.js +++ b/src/iscs_new/map.js @@ -93,7 +93,7 @@ class JMap { this.$eventEmitter.trigger(events.ViewLoaded); // 返回视图缩放偏移 - this.$option.trigger(this.$option); + this.$option.notice(this.$option); return this; } diff --git a/src/iscs_new/option.js b/src/iscs_new/option.js index 1242c9dfc..75f2fa9d9 100644 --- a/src/iscs_new/option.js +++ b/src/iscs_new/option.js @@ -1,27 +1,14 @@ class Option { - constructor(opts, trigger) { - this.scaleIndex = 0; - this.scaleList = [ - 0.2, 0.3, 0.4, 0.5, - 0.6, 0.7, 0.8, 0.9, - 1, 1.2, 1.4, 1.6, 1.8, - 2, 2.2, 2.4, 2.6, 2.8, - 3, 3.2, 3.4, 3.6, 3.8, - 4, 4.2, 4.4, 4.6, 4.8, - 5, 5.2, 5.4, 5.6, 5.8, - 6, 6.2, 6.4, 6.6, 6.8, - 7, 7.2, 7.4, 7.6, 7.8, - 8, 8.2, 8.4, 8.6, 8.8 - ]; + constructor(opts, notice) { + this.ratio = 10; - if (Number.isFinite(opts.scaleRate)) { - const idx = this.scaleList.indexOf(opts.scaleRate); - if (idx >= 0) { - this.scaleIndex = idx; - } - } + this.step = 1/this.ratio; - this.scaleRate = opts.scaleRate || this.scaleList[this.scaleIndex]; // 缩放 + this.scaleMin = 0.2; + + this.scaleMax = 10; + + this.scaleRate = opts.scaleRate || 1; // 缩放 this.offsetX = opts.offsetX || 0; // x偏移 @@ -31,11 +18,9 @@ class Option { this.throttle = opts.throttle || 100; // 刷新频率 - this.disabled = false; - this.preventDefaultMouseMove = true; - this.trigger = trigger; + this.notice = notice; } update(payload) { @@ -54,33 +39,23 @@ class Option { } if (Number.isFinite(payload.scale)) { - if (Number.isFinite(payload.scale)) { - if ((this.scaleIndex + payload.scale) >= 0 && (this.scaleIndex + payload.scale) < this.scaleList.length) { - this.scaleIndex = this.scaleIndex + payload.scale; - } - } - this.scaleRate = this.scaleList[this.scaleIndex]; + this.scaleRate = this.getScaleRate(payload.scale); } if (Number.isFinite(payload.scaleRate)) { - const idx = this.scaleList.indexOf(payload.scaleRate); - if (idx < 0) { - return; - } - this.scaleIndex = idx; this.scaleRate = payload.scaleRate; } - if (this.trigger instanceof Function) { this.trigger(this); } + if (this.notice instanceof Function) { this.notice(this); } } getScaleRate(scale) { if (Number.isFinite(scale)) { - if ((this.scaleIndex + scale) >= 0 && (this.scaleIndex + scale) < this.scaleList.length) { - return this.scaleList[this.scaleIndex + scale]; - } + const sumScaleNum = (this.scaleRate - this.scaleMin + scale * this.step) * this.ratio; + const maxScaleNum = (this.scaleMax * this.ratio); + return (sumScaleNum%maxScaleNum) / this.ratio + this.scaleMin; } - return this.scaleList[this.scaleIndex]; + return this.scaleRate; } } diff --git a/src/views/test/index.vue b/src/views/test/index.vue index 25159190a..41fcd077b 100644 --- a/src/views/test/index.vue +++ b/src/views/test/index.vue @@ -57,7 +57,7 @@ export default { }, watch: { '$store.state.config.canvasSizeCount': function (val) { - this.reSize(); + this.resize(); }, '$store.state.socket.equipmentStatus': function (val) { if (val.length) { @@ -317,18 +317,15 @@ export default { }, // 点击选择事件 onSelected(em) { - if (em) { - this.selected = this.$iscs.getShapeByCode(em.code) - console.log(em, this.selected); - } + this.selected = em; + console.log(em, 'selected'); }, // 右键点击事件 onContextMenu(em) { - if (em) { - this.selected = this.$iscs.getShapeByCode(em.code) - } + this.selected = em; + console.log(em, 'contextMenu'); }, - reSize() { + resize() { this.$nextTick(() => { this.$iscs && this.$iscs.resize({ width: this.width, height: this.height }); });