• cesium 自定义气泡 类


    1. class CesiumPopupClass {
    2. constructor(viewer, options) {
    3. this.viewer = viewer
    4. this.position = options.position;
    5. this.options = this.extend({}, options);
    6. var popupContainer = document.createElement("div");
    7. popupContainer.classList.add('popup');
    8. var popupInner = '';
    9. popupContainer.innerHTML = popupInner;
    10. popupContainer.style.display = 'none';
    11. viewer.cesiumWidget.container.appendChild(popupContainer);
    12. popupContainer.style.cssText = "display: none;position: absolute;left: 0;top: 0;min-width: 200px;z-index:9999;";
    13. this.popupContainer = popupContainer;
    14. // 初始化
    15. this.init();
    16. }
    17. init() {
    18. if (this.position) {
    19. this.popupContainer.style.display = 'block'
    20. this.renderListener = this.viewer.scene.postRender.addEventListener(this.render, this)
    21. }
    22. }
    23. render() {
    24. var ellipsoid = this.viewer.scene.globe.ellipsoid;
    25. var geometry = Cesium.Cartesian3.fromDegrees(
    26. this.position[0],
    27. this.position[1],
    28. 0,
    29. ellipsoid
    30. );
    31. if (!geometry) return
    32. var position = Cesium.SceneTransforms.wgs84ToWindowCoordinates(this.viewer.scene, geometry)
    33. if (!position) {
    34. return
    35. }
    36. if (this.popupContainer) {
    37. this.popupContainer.style.left = position.x - this.popupContainer.offsetWidth / 2 + 'px'
    38. this.popupContainer.style.top = position.y - this.popupContainer.offsetHeight - 10 + 'px'
    39. }
    40. }
    41. remove() {
    42. if (this.popupContainer) {
    43. this.popupContainer.parentNode.removeChild(this.popupContainer)
    44. this.popupContainer = null
    45. }
    46. if (this.renderListener) {
    47. this.renderListener()
    48. this.renderListener = null
    49. }
    50. if (this.viewer) {
    51. this.viewer = null
    52. }
    53. }
    54. extend(obj, obj2) {
    55. for (var k in obj2) {
    56. obj[k] = obj2[k];
    57. }
    58. return obj;
    59. }
    60. }
    61. let p1 = new CesiumPopupClass(viewer, {
    62. position: [112.57482863, 26.81853529]
    63. })
    64. let p2 = new CesiumPopupClass(viewer, {
    65. position: [112.57524924, 26.81874033]
    66. })
    67. p2.remove();

  • 相关阅读:
    PHP 实现 SHA256 with RSA 签名 (实例讲解)
    防火墙设置
    platformIO开发arduino
    使用Apache ECharts同时绘制多个统计图表
    无涯教程-JavaScript - FACT函数
    python生成PDF报告
    论文阅读:HarDNet: A Low Memory Traffic Network
    【RapidAI】P1 中文文本切割程序
    142.创建序列化类、序列化测试、反序列化测试
    c语言结构体中的一个char数组怎么赋值?
  • 原文地址:https://blog.csdn.net/songJunFeng1/article/details/134527237