(function (window, mars3d) { //创建widget类,需要继承BaseWidget class MyWidget extends mars3d.widget.BaseWidget { //弹窗配置 get view() { return { type: "window", url: "view.html", windowOptions: { width: 250, height: 270, }, }; } //初始化[仅执行1次] create() { this.floodByGraphic = new mars3d.thing.FloodByGraphic({ style: { color: "#007be6", opacity: 0.5, outline: false, }, }); this.map.addThing(this.floodByGraphic); this.floodByGraphic.on(mars3d.EventType.change, (e) => { //分析中,高度变化了 if (this.viewWindow) { this.viewWindow.onChangeHeight(e.height); } }); } //每个窗口创建完成后调用 winCreateOK(opt, result) { this.viewWindow = result; } //打开激活 activate() {} //关闭释放 disable() { this.viewWindow = null; this.clear(); } drawPolygon() { this.clear(); this.map.graphicLayer.startDraw({ type: "polygon", style: { color: "#007be6", opacity: 0.5, outline: false, }, success: (graphic) => { var positions = graphic.positionsShow; this.map.graphicLayer.clear(); this.drawOk(positions); }, }); } drawOk(positions) { if (this.viewWindow == null) { return; } haoutil.loading.show(); var result = mars3d.PolyUtil.getHeightRange(positions, this.map.scene); //求最大、最小高度值 this.viewWindow.updateHeightForDraw(result.minHeight, result.maxHeight); this.floodByGraphic.positions = positions; haoutil.loading.hide(); } clear() { this.floodByGraphic.clear(); this.map.graphicLayer.clear(); } } //注册到widget管理器中。 mars3d.widget.bindClass(MyWidget); //每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。 })(window, mars3d);