修改代码

This commit is contained in:
ival 2019-07-19 13:54:23 +08:00
parent 9bdd8e15c5
commit 452c9fe7d7
6 changed files with 44 additions and 22 deletions

View File

@ -42,15 +42,14 @@ class Jmap {
const width = opts.dom.clientWidth;
const height = opts.dom.clientHeight;
this.optionsHandler = this.setOptions.bind(this);
this.$zr = zrender.init(opts.dom, Object.assign({ renderer, devicePixelRatio, width, height }, opts.config));
this.$options = new Options(Object.assign({ scaleRate: 1, offsetX: 0, offsetY: 0 }, opts.options || {})); // 缩放
this.$painter = new Painter(this);
this.$painter.updateTransform(this.$options);
this.optionsHandler = this.setOptions.bind(this);
this.$mouseController = new MouseController(this);
this.$mouseController.enable();
@ -130,10 +129,15 @@ class Jmap {
return payload || {};
}
setOptions(zoom) {
this.$options.update(this.pullBack(zoom));
setOptions(opts) {
this.$options.update(this.pullBack(opts));
this.$painter.updateTransform(this.$options);
if (this.methods.optionsUpdate instanceof Function) { this.methods.optionsUpdate(); }
if (this.$options.disabled == true) {
this.$mouseController.disable();
} else {
this.$mouseController.enable(opts);
}
}
setLevelVisible(list, show) {

View File

@ -26,7 +26,15 @@ class Options {
this.offsetY = opts.offsetY || 0; // y偏移
this.throttle = opts.throttle || 17; // 刷新频率
this.throttle = opts.throttle || 100; // 刷新频率
this.disabled = false;
this.moveOnMouseMove = true;
this.zoomOnMouseWheel = false;
this.preventDefaultMouseMove = true;
}
update(payload) {
@ -61,6 +69,18 @@ class Options {
this.scaleIndex = idx;
this.scaleRate = payload.scaleRate;
}
if (payload.disabled === true || payload.disabled === false) {
this.disabled = payload.disabled;
}
if (payload.moveOnMouseMove === true || payload.moveOnMouseMove === false) {
this.moveOnMouseMove = payload.moveOnMouseMove;
}
if (payload.zoomOnMouseWheel === true || payload.zoomOnMouseWheel === false) {
this.zoomOnMouseWheel = payload.zoomOnMouseWheel;
}
}
getScaleRate(scale) {

View File

@ -16,9 +16,6 @@ class Painter {
// 图层数据
this.mapInstanceLevel = {};
// 父级图层
this.parentLevel = null;
// 初始图层
this.initPainterLevels();
}
@ -142,8 +139,8 @@ class Painter {
}
/**
* 销毁图层
*/
* 销毁图层
*/
dispose() {
this.mapInstanceLevel = {};
this.parentLevel = null;

View File

@ -9,7 +9,7 @@ import JTriangle from '../../utils/JTriangle';
/** 区段*/
export default class Section extends Group {
constructor({ _code, _type, zlevel, model, state }, style, jmap) {
constructor({ _code, _type, zlevel, model, state }, style) {
super();
this._code = _code;
this._type = _type;
@ -19,7 +19,6 @@ export default class Section extends Group {
this.state = state;
this.style = style;
this.selected = false;
this.jmap = jmap;
this._create();
}

View File

@ -38,7 +38,7 @@ function shapefactory(type, device, jmap) {
const shape = mapShape[type];
if (shape instanceof Function) {
// eslint-disable-next-line
return new shape(device, style, jmap);
return new shape(device, style);
}
}

View File

@ -1,3 +1,4 @@
import Group from 'zrender/src/container/Group';
import * as matrix from 'zrender/src/core/matrix';
function createTransform(zoom) {
@ -25,7 +26,7 @@ class TransformHandle {
this.$zr = zr;
this.rect = { x: 0, y: 0, width: this.$zr.getWidth(), height: this.$zr.getHeight() };
this.transform = createTransform({ scale: 1, offsetX: 0, offsetY: 0 });
this.transform = createTransform({ scaleRate: 1, offsetX: 0, offsetY: 0 });
}
checkVisible(view) {
@ -38,6 +39,7 @@ class TransformHandle {
} else {
view.hide();
}
view.dirty();
}
@ -55,7 +57,7 @@ class TransformHandle {
// 处理所有视图缩放/平移
transformAll() {
const parentLevel = this.$painter.getParentLevel();
if (parentLevel) {
if (parentLevel instanceof Group) {
parentLevel.eachChild((level) => {
level.eachChild((view) => {
this.transformView(view);
@ -67,7 +69,7 @@ class TransformHandle {
// 重新计算显示图形
revisibleAll() {
const parentLevel = this.$painter.getParentLevel();
if (parentLevel) {
if (parentLevel instanceof Group) {
parentLevel.eachChild((level) => {
level.eachChild((view) => {
this.revisibleView(view);
@ -77,15 +79,15 @@ class TransformHandle {
}
// 更新偏移量
updateTransform(opt) {
this.transform = createTransform(opt);
updateTransform(opts) {
this.transform = createTransform(opts);
this.transformAll();
}
// 更新画布尺寸
updateZrSize(opt) {
this.rect = { x: 0, y: 0, width: opt.width, height: opt.height };
this.transformAll();
updateZrSize(opts) {
this.rect = { x: 0, y: 0, width: opts.width, height: opts.height };
this.revisibleAll();
}
}