// 创建弹窗对象的方法 var Popup = function(info){ this.constructor(info); } Popup.prototype.id=0; Popup.prototype.dom=[]; Popup.prototype.constructor = function(info){ var _this = this; _this.viewer = info.viewer;//弹窗创建的viewer _this.geometry = info.geometry;//弹窗挂载的位置 _this.id = info.id; _this.entity=info.entity; _this.ctn = $("
"); var entity={"id":_this.id,"dom":_this.ctn}; Popup.prototype.dom.push(entity); $(_this.viewer.container).append( _this.ctn); //测试弹窗内容 var testConfig = { header:_this.entity._name, content:'' } _this.ctn.append(_this.createHtml(testConfig.header,testConfig.content,_this.id)); _this.render(_this.geometry); _this.eventListener = _this.viewer.clock.onTick.addEventListener(function(clock) { _this.render(_this.geometry); }) } // 实时刷新 Popup.prototype.render = function(geometry){ var _this = this; var position = Cesium.SceneTransforms.wgs84ToWindowCoordinates(_this.viewer.scene,geometry) if(position!=null){ _this.ctn.css("left",position.x- _this.ctn.get(0).offsetWidth/2); _this.ctn.css("top",position.y- _this.ctn.get(0).offsetHeight - 10); } } // 动态生成内容 Popup.prototype.createHtml = function(header,content,id){ var html = '
'+ header+ '
'+ '
'+ '
'+ content+ '
'+ '
'+ '
'+ '
'+ '
'+ '
'+ 'X'; return html; } // 关闭弹窗按钮 Popup.prototype.close=function(id){ var _this = this; for(let i=0;i<_this.dom.length;i++){ if(_this.dom[i].id==id){ _this.dom[i].dom.hide(); // _this.dom.splice(i,1) } } }