2019-07-03 14:29:09 +08:00
|
|
|
import Painter from './painter';
|
|
|
|
import ProxyHandle from './proxyHandle';
|
2019-07-03 18:41:00 +08:00
|
|
|
import parser from './utils/parser';
|
|
|
|
import deviceState from './config/deviceState';
|
2019-07-03 14:29:09 +08:00
|
|
|
|
|
|
|
class Jmap {
|
2019-07-04 10:59:40 +08:00
|
|
|
constructor(opts) {
|
|
|
|
// 挂载的dom节点
|
|
|
|
this.$dom = opts.dom;
|
2019-07-03 14:29:09 +08:00
|
|
|
|
2019-07-04 10:59:40 +08:00
|
|
|
// 原始数据
|
|
|
|
this.data = {};
|
2019-07-03 14:29:09 +08:00
|
|
|
|
2019-07-04 10:59:40 +08:00
|
|
|
// 默认初始状态
|
|
|
|
this.defaultStateDict = this.loaddefaultState();
|
2019-07-03 14:29:09 +08:00
|
|
|
|
2019-07-04 10:59:40 +08:00
|
|
|
// 皮肤参数
|
|
|
|
this.skinStyle = '';
|
2019-07-03 14:29:09 +08:00
|
|
|
|
2019-07-04 10:59:40 +08:00
|
|
|
// 皮肤风格
|
|
|
|
this.styleDict = {};
|
2019-07-03 14:29:09 +08:00
|
|
|
|
2019-07-04 10:59:40 +08:00
|
|
|
// 设备数据
|
|
|
|
this.mapDevice = {};
|
2019-07-03 14:29:09 +08:00
|
|
|
|
2019-07-04 10:59:40 +08:00
|
|
|
// 设备代理数据
|
|
|
|
this.proxyData = {};
|
2019-07-03 14:29:09 +08:00
|
|
|
|
2019-07-04 10:59:40 +08:00
|
|
|
// 绘图模块
|
|
|
|
this.$painter = new Painter(this, opts);
|
|
|
|
}
|
2019-07-03 14:29:09 +08:00
|
|
|
|
2019-07-04 10:59:40 +08:00
|
|
|
/**
|
2019-07-03 18:41:00 +08:00
|
|
|
* 加载数据
|
2019-07-04 10:59:40 +08:00
|
|
|
* @param {*} data
|
2019-07-03 18:41:00 +08:00
|
|
|
*/
|
2019-07-04 10:59:40 +08:00
|
|
|
loadData(skinStyle, data) {
|
|
|
|
// 保存原始数据
|
|
|
|
this.data = data;
|
|
|
|
|
|
|
|
// 解析地图数据
|
|
|
|
this.mapDevice = parser(data, this.defaultStateDict);
|
|
|
|
|
|
|
|
// 生成代理对象
|
|
|
|
this.proxyData = new Proxy(this.mapDevice, new ProxyHandle(this));
|
|
|
|
|
|
|
|
// 初次渲染视图
|
|
|
|
this.$painter.render(this.mapDevice);
|
|
|
|
}
|
|
|
|
|
|
|
|
loaddefaultState() {
|
|
|
|
const defaultStateDict = {};
|
|
|
|
|
|
|
|
Object.keys(deviceState).forEach(type => {
|
|
|
|
defaultStateDict[type] = {};
|
|
|
|
Object.keys(deviceState[type] || {}).forEach(state => {
|
|
|
|
defaultStateDict[type][state] = deviceState[type][state].Default;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return defaultStateDict;
|
|
|
|
}
|
|
|
|
|
|
|
|
getPainter() {
|
|
|
|
return this.$painter;
|
|
|
|
}
|
|
|
|
|
|
|
|
clear() {
|
|
|
|
this.$painter.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
dispose() {
|
|
|
|
this.skinStyle = '';
|
|
|
|
this.styleDict = {};
|
|
|
|
this.mapDevice = {};
|
|
|
|
this.proxyData = {};
|
|
|
|
this.$painter.dispose();
|
|
|
|
}
|
2019-07-03 14:29:09 +08:00
|
|
|
}
|
|
|
|
|
2019-07-04 10:59:40 +08:00
|
|
|
export default Jmap;
|