Text.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>三维-文本标记</title>
  7. <link rel="stylesheet" href="../../dist/index.css" />
  8. <script src="../../dist/index.js"></script>
  9. <link href="../../cesium/Source/Widgets/widgets.css" rel="stylesheet">
  10. <script src="../../cesium/Build/Cesium/Cesium.js"></script>
  11. </head>
  12. <body style="margin: 0; padding: 0;">
  13. <div id="map" style="height: 100vh; width: 100vw;"></div>
  14. <div class="input-card">
  15. <div class="input-item">
  16. <button class="btn" id="btn1" onclick="remove()">移除文本标记</button>
  17. </div>
  18. </div>
  19. </body>
  20. <script>
  21. function remove() {
  22. sText.remove();
  23. }
  24. function setBig() {
  25. sText.setSize();
  26. }
  27. const viewer = new Cesium.Viewer("map", {
  28. // homeButton: false, // 是否显示首页按钮
  29. // geocoder: false, // 是否显示输入地名查找控件
  30. sceneModePicker: false, // 是否显示投影方式控件(包含二维及三维投影)
  31. // baseLayerPicker: false, // 是否显示帮助控件
  32. creditDisplay: false,
  33. // timeline: true,
  34. // infoBox: false, // 是否显示点击要素之后显示的信息
  35. selectionIndicator: false,
  36. imageryProvider: false,
  37. fullscreenButton: false
  38. })
  39. var sText;
  40. function initData() {
  41. let options = {
  42. lng: 116.397428, // text经度 必传字段
  43. lat: 39.90923, // text纬度 必传字段
  44. // height: 100000, // text的高度 必传字段
  45. font: '28px', // text的大小及字体
  46. fillColor: '#ff0000', // text的颜色 必传字段
  47. text: "汉字测试"
  48. }
  49. sText = new CTMapOl.cesiumComponent.Text(viewer, options);
  50. sText.addTo()
  51. }
  52. initData();
  53. </script>
  54. <style>
  55. /*地图*/
  56. .mapDIV {
  57. height: 100vh;
  58. width: 100vw;
  59. z-index: 1;
  60. }
  61. .add-switch {
  62. position: absolute;
  63. right: 30px;
  64. height: 68px;
  65. width: 30px;
  66. bottom: 112px;
  67. background: #FFFFFF 100%;
  68. color: #172537;
  69. border-radius: 4px;
  70. display: flex;
  71. flex-direction: column;
  72. align-items: center;
  73. z-index: 2;
  74. }
  75. .add-s-block {
  76. height: 20px;
  77. display: flex;
  78. align-items: center;
  79. justify-content: center;
  80. width: 100%;
  81. line-height: 20px;
  82. font-size: 12px;
  83. margin-bottom: 2px;
  84. color: #172537;
  85. }
  86. .add-zoom {
  87. width: 20px;
  88. height: 20px;
  89. background-image: url('../../dist/assets/image/ar/switch/add-zoom.svg');
  90. background-size: 100% 100%;
  91. cursor: pointer;
  92. }
  93. .sub-zoom {
  94. width: 20px;
  95. height: 20px;
  96. background-image: url('../../dist/assets/image/ar/switch/sub-zoom.svg');
  97. background-size: 100% 100%;
  98. cursor: pointer;
  99. }
  100. .add-zoom-out {
  101. width: 20px;
  102. height: 20px;
  103. background-image: url('../../dist/assets/image/ar/switch/add-zoom-out.svg');
  104. background-size: 100% 100%;
  105. }
  106. .sub-zoom-out {
  107. width: 20px;
  108. height: 20px;
  109. background-image: url('../../dist/assets/image/ar/switch/sub-zoom-out.svg');
  110. background-size: 100% 100%;
  111. }
  112. .add-s-block.btn-click {
  113. cursor: pointer;
  114. }
  115. .input-card {
  116. position: absolute;
  117. right: 15px;
  118. bottom: 15px;
  119. z-index: 999;
  120. }
  121. </style>
  122. </html>