70 lines
1.8 KiB
JavaScript
70 lines
1.8 KiB
JavaScript
|
import Painter from './painter';
|
||
|
import ProxyHandle from './proxyHandle';
|
||
|
import parser from './parser';
|
||
|
import { copyFile } from 'fs';
|
||
|
|
||
|
const renderer = 'svg';
|
||
|
const devicePixelRatio = 2;
|
||
|
|
||
|
class Jmap {
|
||
|
constructor(opts) {
|
||
|
this.$dom = opts.dom; // 挂载的dom节点
|
||
|
this.renderer = opts.renderer; // 渲染方式
|
||
|
|
||
|
this.data = {}; // 原始数据
|
||
|
|
||
|
this.skinStyle = ''; // 皮肤风格
|
||
|
this.styleDict = {}; // 主题风格字典
|
||
|
this.defaultStatusDict = {}; // 默认状态字典
|
||
|
|
||
|
this.mapDevice = {}; // 设备数据字典
|
||
|
this.proxyData = {}; // 设备数据代理字典
|
||
|
|
||
|
this.$painter = new Painter(this); // 绘图模块
|
||
|
|
||
|
this.mount(opts);
|
||
|
}
|
||
|
|
||
|
mount(opts) {
|
||
|
this.defaultStatusDict = this.loadDefaultStatus();
|
||
|
|
||
|
if (opts.dom) {
|
||
|
let width = opts.dom.clientWidth;
|
||
|
let height = opts.dom.clientHeight;
|
||
|
let config = Object.assign({ renderer, devicePixelRatio, width, height }, opts.config);
|
||
|
|
||
|
this.$painter.mount(opts.dom, config);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
loadData(skinStyle, data) {
|
||
|
// 保存原始数据
|
||
|
this.data = data;
|
||
|
|
||
|
// 加载皮肤配置
|
||
|
this.styleDict = this.loadStyle(skinStyle);
|
||
|
|
||
|
// 解析地图数据
|
||
|
this.mapDevice = parser(data, this.defaultStatusDict, this.styleDict);
|
||
|
|
||
|
// 生成代理对象
|
||
|
this.proxyData = new Proxy(this.mapDevice, new ProxyHandle(this));
|
||
|
|
||
|
// 地图视图渲染
|
||
|
this.$painter.render(this.mapDevice);
|
||
|
}
|
||
|
|
||
|
loadStyle() {
|
||
|
|
||
|
}
|
||
|
|
||
|
loadDefaultStatus() {
|
||
|
|
||
|
}
|
||
|
|
||
|
getPainter() {
|
||
|
return this.$painter;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default Jmap;
|