修改代码
This commit is contained in:
parent
c912074739
commit
058e688602
@ -130,7 +130,8 @@ class Jmap {
|
||||
}
|
||||
|
||||
setOptions(opts) {
|
||||
this.$options.update(this.pullBack(opts));
|
||||
const options = this.pullBack(opts);
|
||||
this.$options.update(options);
|
||||
this.$painter.updateTransform(this.$options);
|
||||
if (this.methods.optionsUpdate instanceof Function) { this.methods.optionsUpdate(); }
|
||||
if (this.$options.disabled == true) {
|
||||
|
@ -37,14 +37,14 @@ class MouseController extends Eventful {
|
||||
|
||||
initHandler(zr) {
|
||||
if (zr) {
|
||||
const clickHandler = this.click.bind(this);
|
||||
const contextmenuHandler = this.contextmenu.bind(this);
|
||||
const moveEventHandler = this.moveEvent.bind(this);
|
||||
const clickHandler = click.bind(this);
|
||||
const contextmenuHandler = contextmenu.bind(this);
|
||||
const moveEventHandler = moveEvent.bind(this);
|
||||
|
||||
const mousedownHandler = this.mousedown.bind(this);
|
||||
const mousemoveHandler = this.mousemove.bind(this);
|
||||
const mouseupHandler = this.mouseup.bind(this);
|
||||
const mousewheelHandler = this.mousewheel.bind(this);
|
||||
const mousedownHandler = mousedown.bind(this);
|
||||
const mousemoveHandler = mousemove.bind(this);
|
||||
const mouseupHandler = mouseup.bind(this);
|
||||
const mousewheelHandler = mousewheel.bind(this);
|
||||
|
||||
zr.on('click', clickHandler);
|
||||
zr.on('contextmenu', contextmenuHandler);
|
||||
@ -81,86 +81,88 @@ class MouseController extends Eventful {
|
||||
this.isDragging = function () { return this._dragging; };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mousedown(e) {
|
||||
if (eventTool.notLeftMouse(e)) {
|
||||
return;
|
||||
function mousedown(e) {
|
||||
if (eventTool.notLeftMouse(e)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var x = e.offsetX;
|
||||
var y = e.offsetY;
|
||||
|
||||
this._x = x;
|
||||
this._y = y;
|
||||
this._dragging = true;
|
||||
}
|
||||
|
||||
function mousemove(e) {
|
||||
if (eventTool.notLeftMouse(e) ||
|
||||
!this._moveOnMouseMove ||
|
||||
!this._dragging
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const oldX = this._x;
|
||||
const oldY = this._y;
|
||||
|
||||
const dx = e.offsetX - oldX;
|
||||
const dy = e.offsetY - oldY;
|
||||
|
||||
this._x = e.offsetX;
|
||||
this._y = e.offsetY;
|
||||
|
||||
this._preventDefaultMouseMove && eventTool.stop(e.event);
|
||||
|
||||
this.trigger(this.events.Pan, { dx, dy, oldX, oldY, newX: this._x, newY: this._y });
|
||||
}
|
||||
|
||||
function mouseup(e) {
|
||||
if (!eventTool.notLeftMouse(e)) {
|
||||
this._dragging = false;
|
||||
}
|
||||
}
|
||||
|
||||
function mousewheel(e) {
|
||||
const shouldZoom = this._zoomOnMouseWheel;
|
||||
const wheelDelta = e.wheelDelta;
|
||||
const originX = e.offsetX;
|
||||
const originY = e.offsetY;
|
||||
|
||||
if (wheelDelta === 0 || !shouldZoom) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldZoom) {
|
||||
eventTool.stop(e.event);
|
||||
let scale = 1;
|
||||
if (wheelDelta > 0) {
|
||||
scale = 1;
|
||||
} else if (wheelDelta < 0) {
|
||||
scale = -1;
|
||||
}
|
||||
|
||||
this._x = e.offsetX;
|
||||
this._y = e.offsetY;
|
||||
this._dragging = true;
|
||||
this.trigger(this.events.Zoom, {type: 'zoom', scale, originX, originY });
|
||||
}
|
||||
}
|
||||
|
||||
mousemove(e) {
|
||||
if (eventTool.notLeftMouse(e) ||
|
||||
!this._moveOnMouseMove ||
|
||||
!this._dragging
|
||||
) {
|
||||
return;
|
||||
}
|
||||
function click(e) {
|
||||
var em = checkEvent(e);
|
||||
this.trigger(this.events.Selected, em);
|
||||
}
|
||||
|
||||
const oldX = this._x;
|
||||
const oldY = this._y;
|
||||
function contextmenu(e) {
|
||||
var em = checkEvent(e);
|
||||
this.trigger(this.events.Contextmenu, em);
|
||||
}
|
||||
|
||||
const dx = e.offsetX - oldX;
|
||||
const dy = e.offsetY - oldY;
|
||||
|
||||
this._x = e.offsetX;
|
||||
this._y = e.offsetY;
|
||||
|
||||
this._preventDefaultMouseMove && eventTool.stop(e.event);
|
||||
|
||||
this.trigger(this.events.Pan, { dx, dy, oldX, oldY, newX: this._x, newY: this._y });
|
||||
}
|
||||
|
||||
mouseup(e) {
|
||||
if (!eventTool.notLeftMouse(e)) {
|
||||
this._dragging = false;
|
||||
}
|
||||
}
|
||||
|
||||
mousewheel(e) {
|
||||
const shouldZoom = this._zoomOnMouseWheel;
|
||||
const wheelDelta = e.wheelDelta;
|
||||
const originX = e.offsetX;
|
||||
const originY = e.offsetY;
|
||||
|
||||
if (wheelDelta === 0 || !shouldZoom) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldZoom) {
|
||||
eventTool.stop(e.event);
|
||||
let scale = 1;
|
||||
if (wheelDelta > 0) {
|
||||
scale = 1;
|
||||
} else if (wheelDelta < 0) {
|
||||
scale = -1;
|
||||
}
|
||||
|
||||
this.trigger(this.events.Zoom, {type: 'zoom', scale, originX, originY });
|
||||
}
|
||||
}
|
||||
|
||||
click(e) {
|
||||
var em = this.checkEvent(e);
|
||||
this.trigger(this.events.Selected, em);
|
||||
}
|
||||
|
||||
contextmenu(e) {
|
||||
var em = this.checkEvent(e);
|
||||
this.trigger(this.events.Contextmenu, em);
|
||||
}
|
||||
|
||||
moveEvent(e) {
|
||||
return new EventModel(e);
|
||||
}
|
||||
|
||||
checkEvent(e) {
|
||||
return new EventModel(e);
|
||||
}
|
||||
function moveEvent(e) {
|
||||
return new EventModel(e);
|
||||
}
|
||||
|
||||
function checkEvent(e) {
|
||||
return new EventModel(e);
|
||||
}
|
||||
|
||||
export default MouseController;
|
||||
|
@ -10,14 +10,14 @@ class Painter {
|
||||
this.$jmap = jmap;
|
||||
this.$zr = jmap.getZr();
|
||||
|
||||
// 视图控制器
|
||||
this.$transformHandle = new TransformHandle(this, this.$zr);
|
||||
|
||||
// 图层数据
|
||||
this.mapInstanceLevel = {};
|
||||
|
||||
// 初始图层
|
||||
this.initPainterLevels();
|
||||
|
||||
// 视图控制器
|
||||
this.$transformHandle = new TransformHandle(this, this.$zr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Group from 'zrender/src/container/Group';
|
||||
// import Group from 'zrender/src/container/Group';
|
||||
import * as matrix from 'zrender/src/core/matrix';
|
||||
|
||||
function createTransform(zoom) {
|
||||
@ -25,6 +25,10 @@ class TransformHandle {
|
||||
this.$painter = painter;
|
||||
this.$zr = zr;
|
||||
|
||||
this.parentLevel = this.$painter.getParentLevel();
|
||||
|
||||
console.log(this.parentLevel, 1111);
|
||||
|
||||
this.rect = { x: 0, y: 0, width: this.$zr.getWidth(), height: this.$zr.getHeight() };
|
||||
this.transform = createTransform({ scaleRate: 1, offsetX: 0, offsetY: 0 });
|
||||
}
|
||||
@ -56,26 +60,26 @@ class TransformHandle {
|
||||
|
||||
// 处理所有视图缩放/平移
|
||||
transformAll() {
|
||||
const parentLevel = this.$painter.getParentLevel();
|
||||
if (parentLevel instanceof Group) {
|
||||
parentLevel.eachChild((level) => {
|
||||
level.eachChild((view) => {
|
||||
this.transformView(view);
|
||||
});
|
||||
});
|
||||
}
|
||||
// const parentLevel = this.$painter.getParentLevel();
|
||||
// if (parentLevel instanceof Group) {
|
||||
this.parentLevel.eachChild((level) => {
|
||||
level.eachChild((view) => {
|
||||
this.transformView(view);
|
||||
}, this);
|
||||
}, this);
|
||||
// }
|
||||
}
|
||||
|
||||
// 重新计算显示图形
|
||||
revisibleAll() {
|
||||
const parentLevel = this.$painter.getParentLevel();
|
||||
if (parentLevel instanceof Group) {
|
||||
parentLevel.eachChild((level) => {
|
||||
level.eachChild((view) => {
|
||||
this.revisibleView(view);
|
||||
});
|
||||
});
|
||||
}
|
||||
// const parentLevel = this.$painter.getParentLevel();
|
||||
// if (parentLevel instanceof Group) {
|
||||
this.parentLevel.eachChild((level) => {
|
||||
level.eachChild((view) => {
|
||||
this.revisibleView(view);
|
||||
}, this);
|
||||
}, this);
|
||||
// }
|
||||
}
|
||||
|
||||
// 更新偏移量
|
||||
|
Loading…
Reference in New Issue
Block a user