/*
* 自定义弹窗
* @Author: Wang jianLei
* @Date: 2022-09-27 17:13:49
* @Last Modified by: Wang JianLei
* @Last Modified time: 2022-09-27 17:21:45
*/
const Cesium = window.Cesium;
class PopupWindow {
constructor(viewer, mapId, popupId, popupList) {
if (!viewer) throw new Error("no viewer object!");
this.viewer = viewer;
this.documentHtml = document.getElementById(popupId).outerHTML;
this.mapContainer = document.getElementById(mapId);
this.popupList = Cesium.defaultValue(popupList, []);
}
newPopup(options) {
const viewer = this.viewer;
let offset_x = Cesium.defaultValue(options.offset_x, 0);
let offset_y = Cesium.defaultValue(options.offset_y, 0);
let name = Cesium.defaultValue(options.name, "newPopup");
let position = options.position;
let pos = Cesium.SceneTransforms.wgs84ToWindowCoordinates(
viewer.scene,
position
);
let left_init = pos.x + offset_x;
let top_init = pos.y + offset_y;
let popDiv = document.createElement("div");
popDiv.style =
"position: absolute;left: " + left_init + "px;top: " + top_init + "px;";
popDiv.innerHTML = this.documentHtml.replace("id=", "name=");
this.mapContainer.appendChild(popDiv);
this.popupList.push({ name: name, documentNode: popDiv });
viewer.scene.postRender.addEventListener(() => {
if (Cesium.defined(position)) {
let changedC = Cesium.SceneTransforms.wgs84ToWindowCoordinates(
viewer.scene,
position
);
let curPos = new Cesium.Cartesian2(changedC.x, changedC.y);
let left = curPos.x + offset_x;
let top = curPos.y + offset_y;
popDiv.style =
"position: absolute;left: " + left + "px;top: " + top + "px;";
}
});
return popDiv;
}
remove(name) {
this.popupList.forEach((element, index) => {
if (element.name === name) {
this.mapContainer.removeChild(element.documentNode);
this.popupList.splice(index, 1);
}
});
}
removeAll() {
this.popupList.forEach((element) => {
this.mapContainer.removeChild(element.documentNode);
});
this.popupList = [];
}
}
export default PopupWindow;


总要学点什么
- 粉丝: 981
最新资源
- 毕设&课设:智慧笔匠在线文档 第十三届“中国软件杯”大学生软件设计大赛 A10 在线编辑器赛道一等奖作品.zip
- 毕设&课设:智慧工地设计方案.zip
- 毕设&课设:智慧记单词,本科Android课程设计.zip
- 毕设&课设:智慧党建项目-中铁一局集团第五工程有限公司-中国兵器工业集团特种能源集团-中铁第一勘察设计院城建院-.zip
- Delphi 12 控件之Delphi-获得打印机列表&打印机状态&打印机详细信息源代码
- 毕设&课设:智慧社区党建积分——毕业设计Android端.zip
- 毕设&课设:智慧零工平台前端系统是一个基于uni-app框架开发的跨平台移动端应用,支持微信小程序和H5双端运行.zip
- 毕设&课设:智慧社区居家养老健康管理系统,计算机毕业设计,毕设,Java毕业设计,SpringBoot,SSM,.zip
- 毕设&课设:智慧社团(毕业设计).zip
- 毕设&课设:智慧外贸平台,计算机毕业设计,毕设,Java毕业设计,SpringBoot,SSM,小程序,Java.zip
- 毕设&课设:智慧图书管理系统设计与实现,计算机毕业设计,毕设,Java毕业设计,SpringBoot,SSM,小.zip
- 毕设&课设:智慧物业平台修改5.5小程序,计算机毕业设计,毕设,Java毕业设计,SpringBoot,SSM,.zip
- 毕设&课设:智慧物业平台小程序,计算机毕业设计,毕设,Java毕业设计,SpringBoot,SSM,小程序,J.zip
- 毕设&课设:智慧物流小程序,计算机毕业设计,毕设,Java毕业设计,SpringBoot,SSM,小程序,Jav.zip
- 毕设&课设:智慧校园云端管理系统的设计和实现.zip
- 毕设&课设:智慧校园管理系统小程序,计算机毕业设计,毕设,Java毕业设计,SpringBoot,SSM,小程序.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



- 1
- 2
- 3
前往页