修改代码

This commit is contained in:
ival 2019-07-18 17:21:18 +08:00
parent 257945d203
commit 3a0e467221
4 changed files with 18 additions and 46 deletions

View File

@ -2,7 +2,6 @@ import * as zrUtil from 'zrender/src/core/util';
import zrender from 'zrender'; import zrender from 'zrender';
import Painter from './painter'; import Painter from './painter';
import Options from './options'; import Options from './options';
import ProxyHandle from './proxyHandle';
import MouseController from './mouseController'; import MouseController from './mouseController';
import deviceState from './constant/deviceState'; import deviceState from './constant/deviceState';
import { selectSkinStyle } from './config/deviceStyle'; import { selectSkinStyle } from './config/deviceStyle';
@ -32,9 +31,6 @@ class Jmap {
// 设备数据 // 设备数据
this.mapDevice = {}; this.mapDevice = {};
// 代理数据
this.proxyData = {};
// 默认状态 // 默认状态
this.defaultStateDict = this.loadDefaultState(); this.defaultStateDict = this.loadDefaultState();
@ -75,9 +71,6 @@ class Jmap {
// 解析地图数据 // 解析地图数据
this.mapDevice = parser(data, this); this.mapDevice = parser(data, this);
// 生成代理对象
this.proxyData = new Proxy(this.mapDevice, new ProxyHandle(this.$painter));
// 数据加载完成 // 数据加载完成
if (this.methods.dataLoaded instanceof Function) { this.methods.dataLoaded(); } if (this.methods.dataLoaded instanceof Function) { this.methods.dataLoaded(); }
@ -151,11 +144,13 @@ class Jmap {
(list || []).forEach(elem => { (list || []).forEach(elem => {
const type = elem.type; const type = elem.type;
const code = elem.code; const code = elem.code;
const device = this.proxyData[code] || deviceFactory(type, this.styleDict[type], elem); const oDevice = this.mapDevice[code] || deviceFactory(type, this.styleDict[type], elem);
const model = Object.assign(device.model || {}, elem); const model = Object.assign(oDevice.model || {}, elem);
delete this.proxyData[code]; this.$painter.delete(oDevice);
if (!elem._dispose) { if (!elem._dispose) {
this.proxyData[code] = Object.assign(device, { model }); const nDevice = Object.assign(oDevice, { model });
this.mapDevice[code] = nDevice;
this.$painter.add(nDevice);
} }
this.dataSync(model); this.dataSync(model);
@ -168,11 +163,13 @@ class Jmap {
(list || []).forEach(elem => { (list || []).forEach(elem => {
const code = elem.code; const code = elem.code;
if (elem._dispose) { if (elem._dispose) {
delete this.proxyData[code]; delete this.mapDevice[code];
} else { } else {
const device = this.proxyData[code] || {}; const oDevice = this.mapDevice[code] || {};
const state = Object.assign(device.state || {}, elem); const state = Object.assign(oDevice.state || {}, elem);
this.proxyData[code] = Object.assign(device, { state }); const nDevice = Object.assign(oDevice, { state });
this.mapDevice[code] = nDevice;
this.$painter.update(nDevice);
} }
}); });
@ -263,7 +260,6 @@ class Jmap {
this.skinStyle = ''; this.skinStyle = '';
this.styleDict = {}; this.styleDict = {};
this.mapDevice = {}; this.mapDevice = {};
this.proxyData = {};
this.$mouseController.dispose(); this.$mouseController.dispose();
this.$zr && zrender.dispose(this.$zr); this.$zr && zrender.dispose(this.$zr);

View File

@ -2,7 +2,7 @@ import * as zrUtil from 'zrender/src/core/util';
import Group from 'zrender/src/container/Group'; import Group from 'zrender/src/container/Group';
import deviceType from './constant/deviceType'; import deviceType from './constant/deviceType';
import shapefactory from './shape/factory'; import shapefactory from './shape/factory';
import ZoomHandle from './zoomHandle'; import Transform from './transform';
class Painter { class Painter {
constructor(jmap) { constructor(jmap) {
@ -11,7 +11,7 @@ class Painter {
this.$zr = jmap.getZr(); this.$zr = jmap.getZr();
// 视图控制器 // 视图控制器
this.$zoomHandle = new ZoomHandle(this, this.$zr); this.$transform = new Transform(this, this.$zr);
// 图层数据 // 图层数据
this.mapInstanceLevel = {}; this.mapInstanceLevel = {};
@ -63,7 +63,7 @@ class Painter {
const type = device._type; const type = device._type;
const instance = shapefactory(type, device, this.$jmap); const instance = shapefactory(type, device, this.$jmap);
if (instance) { if (instance) {
this.$zoomHandle.transformView(instance); this.$transform.transformView(instance);
device.instance = instance; device.instance = instance;
this.mapInstanceLevel[type].add(instance); this.mapInstanceLevel[type].add(instance);
} }
@ -97,7 +97,7 @@ class Painter {
* @param {*} zoom * @param {*} zoom
*/ */
updateZoomTransform(zoom) { updateZoomTransform(zoom) {
this.$zoomHandle.updateTransform(zoom); this.$transform.updateTransform(zoom);
} }
/** /**

View File

@ -1,24 +0,0 @@
class ProxyHandle {
constructor(painter) {
this.$painter = painter;
}
set(target, code, device) {
if (device.instance) {
this.$painter.update(device);
} else {
this.$painter.add(device);
}
return Reflect.set(target, code, device);
}
deleteProperty(target, code) {
const device = target[code];
if (device) {
this.$painter.delete(target[code]);
}
return Reflect.deleteProperty(target, code);
}
}
export default ProxyHandle;

View File

@ -19,7 +19,7 @@ function createBoundingRect(view) {
return rect; return rect;
} }
class ZoomHandle { class TransformHandle {
constructor(painter, zr) { constructor(painter, zr) {
this.$painter = painter; this.$painter = painter;
this.$zr = zr; this.$zr = zr;
@ -83,4 +83,4 @@ class ZoomHandle {
} }
} }
export default ZoomHandle; export default TransformHandle;