Fei_Xian_Lin_Ye_Fang_Huo/public/widgets/showLayer/widget.js

48 lines
1.3 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

(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);