(function (window, mars3d) { //创建widget类,需要继承BaseWidget class MyWidget extends mars3d.widget.BaseWidget { //初始化[仅执行1次] create() { this.zommControl = new mars3d.control.ToolButton({ title: "常用工具", icon: "fa fa-cubes", insertIndex: 1, //插入的位置顺序, 1是home按钮后面 click: (event) => { if ($("#toolbtn-widget-menuList").is(":hidden")) { $("#toolbtn-widget-menuList").show(300); } else { $("#toolbtn-widget-menuList").hide(300); } }, }); this.map.addControl(this.zommControl); this.bindToolBarMenuView(); this.zommControl = new mars3d.control.ToolButton({ title: "图层控制", icon: "fa fa-tasks", insertIndex: 1, //插入的位置顺序, 1是home按钮后面 click: (event) => { mars3d.widget.activate({ name: event.title, uri: "widgets/manageLayers/widget.js", }); }, }); this.map.addControl(this.zommControl); } //激活插件 activate() { //单击地图事件 this.map.on(mars3d.EventType.clickMap, this.onMapClick, this); } //释放插件 disable() { //释放单击地图事件 this.map.off(mars3d.EventType.clickMap, this.onMapClick, this); } bindToolBarMenuView() { //工具按钮菜单事件 var menuHtml = `
`; $("#mars3dContainer").append(menuHtml); $(".toolbar-dropdown-menu .widget-btn").click(function () { $("#toolbtn-widget-menuList").hide(300); var uri = $(this).attr("data-widget"); if (haoutil.isutil.isNull(uri)) { return; } var name1 = $(this).attr("data-name"); var name2 = $(this).html().replace('', "").replace("", ""); //会覆盖config中配置的名称 mars3d.widget.activate({ uri: uri, name: name1 || name2 }); }); } onMapClick(event) { $("#toolbtn-widget-menuList").hide(300); } } //注册到widget管理器中。 mars3d.widget.bindClass(MyWidget); //每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。 })(window, mars3d);