Polygon.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. polygon.remove();
  23. }
  24. function setBig() {
  25. polygon.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 polygon;
  40. function initData() {
  41. let path = [
  42. ['113.38', '29.90'],
  43. ['116.40', '39.92'],
  44. ['108.18', '39.52']
  45. ]
  46. let options = {
  47. path: [path],
  48. fillColor:'#00B2D5',
  49. fillOpacity: 0.5,
  50. zoomto: true,
  51. strokeColor: 'red',
  52. strokeOpacity: 1,
  53. strokeWeight: 11,
  54. }
  55. polygon = new CTMapOl.cesiumComponent.Polygon(options);
  56. console.log('polygon', polygon)
  57. polygon.addTo({ viewer: viewer })
  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>