/*``
* @Author: tjc
* @Date: 2017-04-20 17:03:05
* @Last Modified by: hydata
* @Last Modified time: 2018-05-10 17:10:27
* @Email: 304861063@qq.com
* @File Path: F:\work\hyMap\src\components\layer\buildingLayer.js
* @File Name: clustersLayer.js
* @Descript:echarts图层
*/
import glMap from '../../plugins/echartCoords/glMap';
/**
* echart扩展层
*
*/
class EchartsLayer {
/**
*
* @param {*} options
*/
constructor(options) {
this.map = options.map;
this.option = options.serie.serie;
let map = this.map;
const mapContainer = map.getCanvasContainer();
this._container = document.createElement('div');
this._container.style.width = map.getCanvas().style.width;
this._container.style.height = map.getCanvas().style.height;
this._container.setAttribute('id', 'echarts');
this._container.setAttribute('class', 'echartMap');
this._map = map;
mapContainer.appendChild(this._container);
this.chart = glMap.echarts.init(this._container);
glMap.echarts.glMap = map;
this.init();
this.resize();
}
/**
* 初始化
*/
init() {
this.chart.setOption(this.option);
}
/**
* 移除
*/
remove() {
var _this = this;
this._map._listeners.move.forEach(function (element) {
if (element.name === 'moveHandler') {
_this._map.off('move', element);
}
});
this._map._listeners.move.forEach(function (element) {
if (element.name === 'zoomEndHandler') {
_this._map.off('zoomend', element);
}
});
// this._map.off('move', this._map._listeners.move[1]);
// this._map.off('zoomend', this._map._listeners.moveend[1]);
this.chart.clear();
if (this._container.parentNode)
this._container.parentNode.removeChild(this._container);
this._map = undefined;
}
/**
* 重置
*/
resize() {
window.onresize = () => {
this._container.style.width = this._map.getCanvas().style.width;
this._container.style.height = this._map.getCanvas().style.height;
this.chart.resize();
};
}
}
export default EchartsLayer;