Polyline.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 class="input-item">
  19. <button class="btn" id="setOptions" onclick="setOptions()">修改颜色</button>
  20. </div>
  21. </div>
  22. </body>
  23. <script>
  24. function remove() {
  25. polyline.remove();
  26. }
  27. function setOptions() {
  28. polyline.setOptions({
  29. strokeOpacity:1,
  30. strokeColor:'#1BAC2E'
  31. })
  32. }
  33. const viewer = new Cesium.Viewer("map", {
  34. // homeButton: false, // 是否显示首页按钮
  35. // geocoder: false, // 是否显示输入地名查找控件
  36. sceneModePicker: false, // 是否显示投影方式控件(包含二维及三维投影)
  37. // baseLayerPicker: false, // 是否显示帮助控件
  38. creditDisplay: false,
  39. // timeline: true,
  40. // infoBox: false, // 是否显示点击要素之后显示的信息
  41. selectionIndicator: false,
  42. imageryProvider: false,
  43. fullscreenButton: false
  44. })
  45. var polyline;
  46. function initData() {
  47. let options = {
  48. path: [[116.43, 55.92, 100], [117.43, 55.92, 50], [106.43, 29.92, 100000],[128.43, 55.92, 100000]],
  49. zoomto: true,
  50. strokeOpacity: 0.8,
  51. strokeWeight: 5
  52. }
  53. polyline = new CTMapOl.cesiumComponent.Polyline(options);
  54. polyline.addTo({ viewer })
  55. polyline.on('click', e => {
  56. console.log('click', e)
  57. })
  58. }
  59. initData();
  60. </script>
  61. <style>
  62. /*地图*/
  63. .mapDIV {
  64. height: 100vh;
  65. width: 100vw;
  66. z-index: 1;
  67. }
  68. .add-switch {
  69. position: absolute;
  70. right: 30px;
  71. height: 68px;
  72. width: 30px;
  73. bottom: 112px;
  74. background: #FFFFFF 100%;
  75. color: #172537;
  76. border-radius: 4px;
  77. display: flex;
  78. flex-direction: column;
  79. align-items: center;
  80. z-index: 2;
  81. }
  82. .add-s-block {
  83. height: 20px;
  84. display: flex;
  85. align-items: center;
  86. justify-content: center;
  87. width: 100%;
  88. line-height: 20px;
  89. font-size: 12px;
  90. margin-bottom: 2px;
  91. color: #172537;
  92. }
  93. .add-zoom {
  94. width: 20px;
  95. height: 20px;
  96. background-image: url('../../dist/assets/image/ar/switch/add-zoom.svg');
  97. background-size: 100% 100%;
  98. cursor: pointer;
  99. }
  100. .sub-zoom {
  101. width: 20px;
  102. height: 20px;
  103. background-image: url('../../dist/assets/image/ar/switch/sub-zoom.svg');
  104. background-size: 100% 100%;
  105. cursor: pointer;
  106. }
  107. .add-zoom-out {
  108. width: 20px;
  109. height: 20px;
  110. background-image: url('../../dist/assets/image/ar/switch/add-zoom-out.svg');
  111. background-size: 100% 100%;
  112. }
  113. .sub-zoom-out {
  114. width: 20px;
  115. height: 20px;
  116. background-image: url('../../dist/assets/image/ar/switch/sub-zoom-out.svg');
  117. background-size: 100% 100%;
  118. }
  119. .add-s-block.btn-click {
  120. cursor: pointer;
  121. }
  122. .input-card {
  123. position: absolute;
  124. right: 15px;
  125. bottom: 15px;
  126. z-index: 999;
  127. }
  128. </style>
  129. </html>