02thrdimeZoomNum.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. <link href="../cesium/Source/Widgets/widgets.css" rel="stylesheet">
  9. <script src="../cesium/Build/Cesium/Cesium.js"></script>
  10. <script src="../dist/index.js"></script>
  11. </head>
  12. <body style="margin: 0; padding: 0;">
  13. <!-- <div id="map" style="height: 100vh; width: 100vw"></div> -->
  14. <div id="map" class="mapDIV"></div>
  15. <!-- 地图加减号 -->
  16. <div class="add-switch">
  17. <div class="add-s-block" style="margin-top: 2px;" @click="logMapCenter">
  18. <div id="num">5</div>
  19. </div>
  20. <div class="add-s-block">
  21. <div class="add-zoom" onclick="addZoom()"></div>
  22. </div>
  23. <div class="add-s-block">
  24. <div class="sub-zoom" onclick="subZoom()"></div>
  25. </div>
  26. </div>
  27. <div class="input-card">
  28. <div class="input-item">
  29. <button class="btn" id="btn1" onclick="zoom(8)">8级</button>
  30. </div>
  31. <div class="input-item">
  32. <button class="btn" id="btn2" onclick="zoom(3)">3级</button>
  33. </div>
  34. </div>
  35. </body>
  36. <script>
  37. window.CESIUM_BASE_URL = '../cesium/Build/Cesium';
  38. const me=this
  39. Cesium.Ion.defaultAccessToken ='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJmMGRmMzg3My04ZDZiLTQ5ZjktYTM5Ny0zODAxMjgyMzUyNDMiLCJpZCI6ODMyOCwiaWF0IjoxNjM3MzE1MTU3fQ.CCCTuOyf8WB2_nYoumV7IQ6nshgZMR9Xtoxlsx239tc'
  40. var viewer = CTMapOl.thrdime.viewercontrol.globalviewer('map', CTMapOl.thrdime.viewercontrol.globalvieweroptions())
  41. viewer._cesiumWidget._creditContainer.style.display = 'none'
  42. CTMapOl.thrdime.imagerylayercontrol.removeAll(viewer,true)
  43. CTMapOl.thrdime.imagerylayercontrol.addImageryProvider(viewer,CTMapOl.thrdime.imagerylayercontrol.gettdtImagery('vec',"vec_w"))
  44. CTMapOl.thrdime.imagerylayercontrol.addImageryProvider(viewer,CTMapOl.thrdime.imagerylayercontrol.gettdtImagery('cva',"cva_w"))
  45. CTMapOl.thrdime.cameracontrol.setDEFAULT_VIEW_RECTANGLE(116.38, 39.90,116.40, 39.92)
  46. CTMapOl.thrdime.cameracontrol.setcamera(viewer,CTMapOl.thrdime.cameracontrol.getcameraoptionswithdetile(116.39, 39.91,5000,0,-90,0))
  47. CTMapOl.thrdime.cameracontrol.addmoveEndevent(viewer,()=>{
  48. let zoom=CTMapOl.thrdime.cameracontrol.getZoom(viewer)
  49. if(zoom)
  50. document.getElementById("num").innerHTML = zoom;
  51. })
  52. //非严格增加/减少
  53. // function addZoom() {
  54. // console.log('addZoom');
  55. // let postion=CTMapOl.thrdime.cameracontrol.getposition(viewer)
  56. // let cartographic= Cesium.Cartographic.fromCartesian(postion)
  57. // let height=Math.ceil(cartographic.height)
  58. // viewer.camera.moveForward(height * 0.5)
  59. // }
  60. // function subZoom() {
  61. // console.log('subZoom');
  62. // let postion=CTMapOl.thrdime.cameracontrol.getposition(viewer)
  63. // let cartographic= Cesium.Cartographic.fromCartesian(postion)
  64. // let height=Math.ceil(cartographic.height)
  65. // viewer.camera.moveBackward(height * 0.5)
  66. // }
  67. //严格增加/减少
  68. function addZoom() {
  69. console.log('addZoom');
  70. zoom(parseInt(document.getElementById("num").innerHTML) +1.0)
  71. }
  72. function subZoom() {
  73. console.log('subZoom');
  74. zoom(parseInt(document.getElementById("num").innerHTML) -1)
  75. }
  76. function zoom(zoomNum) {
  77. console.log('zoomNum');
  78. CTMapOl.thrdime.cameracontrol.setZoom(viewer,zoomNum)
  79. // CTMapOl.api.setZoom(map, zoomNum);
  80. }
  81. </script>
  82. <style>
  83. /*地图*/
  84. .mapDIV {
  85. height: 100vh;
  86. width: 100vw;
  87. z-index: 1;
  88. }
  89. .add-switch {
  90. position: absolute;
  91. right: 30px;
  92. height: 68px;
  93. width: 30px;
  94. bottom: 112px;
  95. background: #FFFFFF 100%;
  96. color: #172537;
  97. border-radius: 4px;
  98. display: flex;
  99. flex-direction: column;
  100. align-items: center;
  101. z-index: 2;
  102. }
  103. .add-s-block {
  104. height: 20px;
  105. display: flex;
  106. align-items: center;
  107. justify-content: center;
  108. width: 100%;
  109. line-height: 20px;
  110. font-size: 12px;
  111. margin-bottom: 2px;
  112. color: #172537;
  113. }
  114. .add-zoom {
  115. width: 20px;
  116. height: 20px;
  117. background-image: url('../dist/assets/image/ar/switch/add-zoom.svg');
  118. background-size: 100% 100%;
  119. cursor: pointer;
  120. }
  121. .sub-zoom {
  122. width: 20px;
  123. height: 20px;
  124. background-image: url('../dist/assets/image/ar/switch/sub-zoom.svg');
  125. background-size: 100% 100%;
  126. cursor: pointer;
  127. }
  128. .add-zoom-out {
  129. width: 20px;
  130. height: 20px;
  131. background-image: url('../dist/assets/image/ar/switch/add-zoom-out.svg');
  132. background-size: 100% 100%;
  133. }
  134. .sub-zoom-out {
  135. width: 20px;
  136. height: 20px;
  137. background-image: url('../dist/assets/image/ar/switch/sub-zoom-out.svg');
  138. background-size: 100% 100%;
  139. }
  140. .add-s-block.btn-click {
  141. cursor: pointer;
  142. }
  143. .input-card {
  144. position: absolute;
  145. right: 15px;
  146. bottom: 15px;
  147. z-index: 999;
  148. }
  149. </style>
  150. </html>