CesiumBillboard.html 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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>billboard应用</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. <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  12. <style>
  13. * {
  14. padding: 0;
  15. margin: 0;
  16. }
  17. </style>
  18. </head>
  19. <body>
  20. <div style="display: flex;">
  21. <div id="info" style="height: 100vh; width: 30vw;">
  22. <ul>
  23. <li>
  24. <span>scale</span>
  25. <span style="margin-left: 2em;">
  26. 0倍
  27. <input type="range" min="0" max="10" value="1" step="0.01" onchange="changescale(this.value)">
  28. 10倍
  29. </span><br>
  30. </li>
  31. <li>
  32. <span>pixelOffset_x</span>
  33. <span style="margin-left: 2em;">
  34. -50
  35. <input type="range" min="-50" max="50" value="0" step="1" onchange="changepixelOffset_x(this.value)">
  36. 50
  37. </span><br>
  38. </li>
  39. <li>
  40. <span>pixelOffset_y</span>
  41. <span style="margin-left: 2em;">
  42. -50
  43. <input type="range" min="-50" max="50" value="0" step="1" onchange="changepixelOffset_y(this.value)">
  44. 50
  45. </span><br>
  46. </li>
  47. <li>
  48. <span>eyeOffset_x</span>
  49. <span style="margin-left: 2em;">
  50. -50
  51. <input type="range" min="-50" max="50" value="0" step="1" onchange="changeeyeOffset_x(this.value)">
  52. 50
  53. </span><br>
  54. </li>
  55. <li>
  56. <span>eyeOffset_y</span>
  57. <span style="margin-left: 2em;">
  58. -50
  59. <input type="range" min="-50" max="50" value="0" step="1" onchange="changeeyeOffset_y(this.value)">
  60. 50
  61. </span><br>
  62. </li>
  63. <li>
  64. <span>eyeOffset_z</span>
  65. <span style="margin-left: 2em;">
  66. -50
  67. <input type="range" min="-50" max="50" value="0" step="1" onchange="changeeyeOffset_z(this.value)">
  68. 50
  69. </span><br>
  70. </li>
  71. <li>
  72. <select name="selectList" onchange="changehorizontalOrigin(this.value)">
  73. <option value="0">CENTER</option>
  74. <option value="1">LEFT</option>
  75. <option value="2">RIGHT</option>
  76. </select>
  77. </li>
  78. <li>
  79. <select name="selectList" onchange="changeverticalOrigin(this.value)">
  80. <option value="0">CENTER</option>
  81. <option value="1">BOTTOM</option>
  82. <option value="2">BASELINE</option>
  83. <option value="3">TOP</option>
  84. </select>
  85. </li>
  86. <li>
  87. <span>rotation</span>
  88. <span style="margin-left: 2em;">
  89. 0
  90. <input type="range" min="0" max="360" value="0" step="1" onchange="changerotation(this.value)">
  91. 360
  92. </span><br>
  93. </li>
  94. <li>
  95. <span>alignedAxis_x</span>
  96. <span style="margin-left: 2em;">
  97. 0
  98. <input type="range" min="0" max="1" value="0" step="0.01" onchange="changealignedAxis_x(this.value)">
  99. 1
  100. </span><br>
  101. </li>
  102. <li>
  103. <span>alignedAxis_y</span>
  104. <span style="margin-left: 2em;">
  105. 0
  106. <input type="range" min="0" max="1" value="0" step="0.01" onchange="changealignedAxis_y(this.value)">
  107. 1
  108. </span><br>
  109. </li>
  110. <li>
  111. <span>alignedAxis_z</span>
  112. <span style="margin-left: 2em;">
  113. 0
  114. <input type="range" min="0" max="1" value="0" step="0.01" onchange="changealignedAxis_z(this.value)">
  115. 1
  116. </span><br>
  117. </li>
  118. <li>
  119. <span>width</span>
  120. <span style="margin-left: 2em;">
  121. 0
  122. <input type="range" min="0" max="1000" value="0" step="1" onchange="changewidth(this.value)">
  123. 1000
  124. </span><br>
  125. </li>
  126. <li>
  127. <span>height</span>
  128. <span style="margin-left: 2em;">
  129. 0
  130. <input type="range" min="0" max="1000" value="0" step="1" onchange="changeheight(this.value)">
  131. 1000
  132. </span><br>
  133. </li>
  134. </ul>
  135. </div>
  136. <div id="map" style="height: 100vh; width: 70vw;"></div>
  137. </div>
  138. </body>
  139. <script>
  140. window.CESIUM_BASE_URL = '../../cesium/Build/CesiumUnminified';
  141. Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI2MjIyODA4ZS0zNmRmLTQwNGMtYjZkNC0wOGY2NDdmODgyZTUiLCJpZCI6ODMyOCwiaWF0IjoxNjA2MjkyNDE1fQ.ZhhxNIJ-TzstpcavQBNL7xRwytBat3G2__3jr7lJ8yg'
  142. var viewer = CTMapOl.thrdime.viewercontrol.globalviewer('map', CTMapOl.thrdime.viewercontrol.globalvieweroptions())
  143. viewer._cesiumWidget._creditContainer.style.display = 'none'
  144. CTMapOl.thrdime.imagerylayercontrol.removeAll(viewer, true)
  145. CTMapOl.thrdime.imagerylayercontrol.addImageryProvider(viewer, CTMapOl.thrdime.imagerylayercontrol.gettdtImagery('img', "img_w"))
  146. CTMapOl.thrdime.imagerylayercontrol.addImageryProvider(viewer, CTMapOl.thrdime.imagerylayercontrol.gettdtImagery('cia', "cia_w"))
  147. CTMapOl.thrdime.cameracontrol.setDEFAULT_VIEW_RECTANGLE(116.38, 39.90, 116.40, 39.92)
  148. CTMapOl.thrdime.cameracontrol.setcamera(viewer, CTMapOl.thrdime.cameracontrol.getcameraoptionswithdetile(116.38, 39.90, 5000, 0, -90, 0))
  149. CTMapOl.thrdime.viewercontrol.addterrainct(viewer)
  150. let scale = 1
  151. function changescale(value) {
  152. scale = value
  153. }
  154. let pixelOffset_x = 0
  155. let pixelOffset_y = 0
  156. function changepixelOffset_x(value) {
  157. pixelOffset_x = value
  158. }
  159. function changepixelOffset_y(value) {
  160. pixelOffset_y = value
  161. }
  162. let eyeOffset_x = 0
  163. let eyeOffset_y = 0
  164. let eyeOffset_Z = 0
  165. function changeeyeOffset_x(value) {
  166. eyeOffset_x = value
  167. }
  168. function changeeyeOffset_y(value) {
  169. eyeOffset_y = value
  170. }
  171. function changeeyeOffset_z(value) {
  172. eyeOffset_z = value
  173. }
  174. let horizontalOrigin = Cesium.HorizontalOrigin.CENTER
  175. function changehorizontalOrigin(value) {
  176. switch (value) {
  177. case '0':
  178. horizontalOrigin = Cesium.HorizontalOrigin.CENTER
  179. break
  180. case '1':
  181. horizontalOrigin = Cesium.HorizontalOrigin.LEFT
  182. break
  183. case '2':
  184. horizontalOrigin = Cesium.HorizontalOrigin.RIGHT
  185. break
  186. }
  187. }
  188. let verticalOrigin = Cesium.VerticalOrigin.CENTER
  189. function changeverticalOrigin(value) {
  190. switch (value) {
  191. case '0':
  192. verticalOrigin = Cesium.VerticalOrigin.CENTER
  193. break
  194. case '1':
  195. verticalOrigin = Cesium.VerticalOrigin.BOTTOM
  196. break
  197. case '2':
  198. verticalOrigin = Cesium.VerticalOrigin.BASELINE
  199. break
  200. case '3':
  201. verticalOrigin = Cesium.VerticalOrigin.TOP
  202. break
  203. }
  204. }
  205. let rotation = 0
  206. function changerotation(value) {
  207. rotation = value / 180 * Math.PI
  208. }
  209. let alignedAxis_x = 0
  210. let alignedAxis_y = 0
  211. let alignedAxis_z = 0
  212. function changealignedAxis_x(value) {
  213. alignedAxis_x = value
  214. }
  215. function changealignedAxis_y(value) {
  216. alignedAxis_y = value
  217. }
  218. function changealignedAxis_z(value) {
  219. alignedAxis_Z = value
  220. }
  221. let width = 100
  222. function changewidth(value) {
  223. width = value
  224. }
  225. let height = 100
  226. function changeheight(value) {
  227. height = value
  228. }
  229. let Cartographicpos = Cesium.Cartographic.fromDegrees(116.38, 39.90, 0)
  230. let pos = Cesium.Cartographic.toCartesian(Cartographicpos)
  231. this.setTimeout(() => {
  232. var promise = Cesium.sampleTerrainMostDetailed(viewer.terrainProvider, [Cartographicpos]);
  233. promise.then(res => {
  234. console.log(res)
  235. pos = Cesium.Cartographic.toCartesian(res[0])
  236. console.log(pos)
  237. })
  238. }, 1000)
  239. viewer.entities.add({
  240. position: new Cesium.CallbackProperty(() => {
  241. return pos
  242. }),
  243. billboard: {
  244. image: "../assets/monitor-online.png", // default: undefined
  245. show: true, // default
  246. scale: new Cesium.CallbackProperty(() => {
  247. return Number(scale)
  248. }),
  249. pixelOffset: new Cesium.CallbackProperty(() => {
  250. return new Cesium.Cartesian2(Number(pixelOffset_x), Number(pixelOffset_y))
  251. }),
  252. eyeOffset: new Cesium.CallbackProperty(() => {
  253. return new Cesium.Cartesian3(Number(eyeOffset_x), Number(eyeOffset_y), Number(eyeOffset_Z))
  254. }),
  255. horizontalOrigin: new Cesium.CallbackProperty(() => {
  256. return horizontalOrigin
  257. }),
  258. verticalOrigin: new Cesium.CallbackProperty(() => {
  259. return verticalOrigin
  260. }),
  261. rotation: new Cesium.CallbackProperty(() => {
  262. return rotation
  263. }),
  264. alignedAxis: new Cesium.CallbackProperty(() => {
  265. return new Cesium.Cartesian3(Number(alignedAxis_x), Number(alignedAxis_y), Number(alignedAxis_z))
  266. }),
  267. width: new Cesium.CallbackProperty(() => {
  268. return width
  269. }),
  270. height: new Cesium.CallbackProperty(() => {
  271. return height
  272. }),
  273. },
  274. });
  275. </script>
  276. </html>