import Painter from './painter'; import ProxyHandle from './proxyHandle'; import parser from './utils/parser'; import deviceState from './config/deviceState'; import deviceStyle from './config/deviceStyle'; class Jmap { constructor(opts) { // 挂载的dom节点 this.$dom = opts.dom; // 原始数据 this.data = {}; // 默认初始状态 this.defaultStateDict = this.loaddefaultState(); // 皮肤参数 this.skinStyle = ''; // 皮肤风格 this.styleDict = {}; // 设备数据 this.mapDevice = {}; // 设备代理数据 this.proxyData = {}; // 绘图模块 this.$painter = new Painter(this, opts); } /** * 加载数据 * @param {*} data */ loadData(skinStyle, data) { // 保存原始数据 this.data = data; // 加载皮肤 this.styleDict = this.loadStyle(skinStyle); // 解析地图数据 this.mapDevice = parser(data, this.defaultStateDict); // 生成代理对象 this.proxyData = new Proxy(this.mapDevice, new ProxyHandle(this.$painter, this.styleDict)); // 初次渲染视图 this.$painter.render(this.mapDevice, this.styleDict); } loadStyle(skinStyle) { return deviceStyle; } 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(); } } export default Jmap;