import {
Evented,
Collection,
defaultValue,
getGUID
} from '@mapgis/webclient-common'
/**
*
* @class Zondy.view.UI
* @classdesc UI容器基类
* @extends Evented
* @param {Object} options 构造参数
* @param {String} [options.id] UI容器id
* @param {MapView | SceneView } [options.view] 视图
*/
class UI extends Evented {
constructor(options) {
super()
const opt = defaultValue(options, {})
// id
this._id = defaultValue(opt.id, getGUID())
// 视图
this._view = defaultValue(opt.view, null)
if (!this._view) throw new Error('视图不存在!')
// ui列表
this._collection = new Collection()
}
add(control) {
this._collection.add(control)
control._addView()
}
remove(control) {
this._collection.remove(control)
control._removeView()
if (control && control.destroy) {
control.destroy()
}
}
findControlById(id) {
return this._collection.filter((v) => v._id === id)
}
}
export default UI