类名 Widget/Widget.js
import { Evented, getGUID, defaultValue } from '@mapgis/webclient-common'

/**
 * 部件类
 * @class Zondy.Widget
 * @classdesc 部件基类
 * @extends Evented
 * @param {Object} options 构造参数
 * @param {String | HTMLElement}  [options.container]  部件容器或部件容器id
 * @param {String} [options.id] 部件id
 * @param {Boolean} [options.visible] 部件是否显示
 * @param {MapView|SceneView} [options.view] 部件视图
 */
class Widget extends Evented {
  constructor(options) {
    super()
    const opt = defaultValue(options, {})
    // 部件id
    this._id = defaultValue(opt.id, getGUID())
    // 部件容器
    this._container = this._createContainer(opt.container)
    // 部件是否显示
    this._visible = defaultValue(opt.visible, true)
    // 部件视图
    this._view = defaultValue(opt.view, null)
    if (!this._view) throw new Error('视图不存在!')
  }

  // 添加组件
  _addView() {}

  // 移除组件
  _removeView() {}

  /**
   * @description 销毁控件
   */
  destroy() {}

  _createContainer(container) {
    let _container = container
    if (typeof _container === 'string') {
      _container = document.getElementById(_container)
    }
    if (container instanceof HTMLElement) {
      return _container
    }
    _container = document.createElement('div')
    return _container
  }
}
export default Widget
构造函数
成员变量
方法
事件