(function (window, mars3d) {
  //创建widget类，需要继承BaseWidget
  class MyWidget extends mars3d.widget.BaseWidget {
    //初始化[仅执行1次]
    create() {
      var arr = [];
      if (Array.isArray(this.config.layerId)) {
        this.config.layerId.forEach((element) => {
          let layer = this.map.getLayer(element, "id");
          if (layer) {
            arr.push(layer);
          }
        });
      } else {
        let layer = this.map.getLayer(this.config.layerId, "id");
        if (layer) {
          arr.push(layer);
        }
      }
      this.arrLayer = arr;
    }
    //打开激活
    activate() {
      this.arrLayer.forEach((layer) => {
        if (!layer.isAdded) {
          this.map.addLayer(layer, true);
          layer._hasRemoveLayer = true;
        }
        layer.flyTo();
      });
    }
    //关闭释放
    disable() {
      this.arrLayer.forEach((layer) => {
        if (layer._hasRemoveLayer && layer.isAdded) {
          this.map.removeLayer(layer);
          layer._hasRemoveLayer = false;
        }
      });
    }
  }

  //注册到widget管理器中。
  mars3d.widget.bindClass(MyWidget);

  //每个widet之间都是直接引入到index.html中，会存在彼此命名冲突，所以闭包处理下。
})(window, mars3d);
