03coodspick.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. <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 id="map" style="height: 90vh; width: 100vw;">
  21. </div>
  22. <div id="funcs" style="width:100%;position: fixed;top: 0;z-index: 999;">
  23. <button onclick="startpick()">开始拾取</button>
  24. <button onclick="endpick()">结束拾取</button>
  25. <p>lon:<span id="coodlon"></span></p>
  26. <p>lat:<span id="coodlat"></span></p>
  27. <p>h:<span id="coodh"></span></p>
  28. <p>字符串</p><input type="text" name="str" value="标记点1" onchange="changestr(this.value)" />
  29. <button onclick="drawstr()">添加实体显示字符串</button>
  30. <button onclick="drawimg()">添加实体显示图片</button>
  31. <button onclick="drawsvg(1)">添加实体显示svg图片1</button>
  32. <button onclick="drawsvg(2)">添加实体显示svg图片2</button>
  33. <button onclick="drawsvg(3)">添加实体显示svg图片3</button>
  34. <button onclick="drawoverlay()">添加实体地表覆盖物</button>
  35. <button onclick="flyto()">飞行至</button>
  36. <button onclick="SaveSceneToImg()">截图</button>
  37. <div id="popup" style="width: 100px;height: 100px;">
  38. <img src="/example/assets/sxt.png" />
  39. 这是一个覆盖物
  40. </div>
  41. <img src="../dist/assets/image/ar/switch/add-zoom-out.svg" />
  42. <img id="tarimg" />
  43. </div>
  44. </body>
  45. <script>
  46. window.CESIUM_BASE_URL = '../cesium/Build/Cesium';
  47. Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI2MjIyODA4ZS0zNmRmLTQwNGMtYjZkNC0wOGY2NDdmODgyZTUiLCJpZCI6ODMyOCwiaWF0IjoxNjA2MjkyNDE1fQ.ZhhxNIJ-TzstpcavQBNL7xRwytBat3G2__3jr7lJ8yg'
  48. var viewer = CTMapOl.thrdime.viewercontrol.globalviewer('map', CTMapOl.thrdime.viewercontrol.globalvieweroptions())
  49. viewer._cesiumWidget._creditContainer.style.display = 'none'
  50. CTMapOl.thrdime.imagerylayercontrol.removeAll(viewer, true)
  51. CTMapOl.thrdime.imagerylayercontrol.addImageryProvider(viewer, CTMapOl.thrdime.imagerylayercontrol.gettdtImagery('vec', "vec_w"))
  52. CTMapOl.thrdime.imagerylayercontrol.addImageryProvider(viewer, CTMapOl.thrdime.imagerylayercontrol.gettdtImagery('cva', "cva_w"))
  53. CTMapOl.thrdime.cameracontrol.setDEFAULT_VIEW_RECTANGLE(116.38, 39.90, 116.40, 39.92)
  54. CTMapOl.thrdime.cameracontrol.setcamera(viewer, CTMapOl.thrdime.cameracontrol.getcameraoptionswithdetile(116.39, 39.91, 5000, 0, -90, 0))
  55. let me = this
  56. let CesiumEventHandlerclick = null
  57. let tarstr = "标记点1"
  58. function startpick() {
  59. if (CesiumEventHandlerclick) {
  60. endpick()
  61. }
  62. CesiumEventHandlerclick = CTMapOl.thrdime.cameracontrol.startpickcood(viewer, (e, f) => {
  63. console.log(e, f)
  64. let dom1 = document.getElementById("coodlon")
  65. dom1.innerHTML = f.longitude / Math.PI * 180
  66. let dom2 = document.getElementById("coodlat")
  67. dom2.innerHTML = f.latitude / Math.PI * 180
  68. let dom3 = document.getElementById("coodh")
  69. dom3.innerHTML = f.height
  70. })
  71. }
  72. function endpick() {
  73. CTMapOl.thrdime.cameracontrol.stoppickcood(viewer, CesiumEventHandlerclick)
  74. }
  75. function changestr(str) {
  76. tarstr = str
  77. }
  78. function drawstr() {
  79. let pos = new Cesium.Cartesian3.fromDegrees(Number.parseFloat(document.getElementById("coodlon").innerHTML), Number.parseFloat(document.getElementById("coodlat").innerHTML), Number.parseFloat(document.getElementById("coodh").innerHTML))
  80. CTMapOl.thrdime.entitycontrol.addlable(viewer, pos, tarstr, Cesium.Color.BLACK, [0, -20], 0.5)
  81. }
  82. function drawimg() {
  83. let pos = new Cesium.Cartesian3.fromDegrees(Number.parseFloat(document.getElementById("coodlon").innerHTML), Number.parseFloat(document.getElementById("coodlat").innerHTML), Number.parseFloat(document.getElementById("coodh").innerHTML))
  84. CTMapOl.thrdime.entitycontrol.addimg(viewer, pos, '/example/assets/camera-cluster-2.png', [0, -20], 0.5)
  85. }
  86. async function drawsvg(type) {
  87. let pos = new Cesium.Cartesian3.fromDegrees(Number.parseFloat(document.getElementById("coodlon").innerHTML), Number.parseFloat(document.getElementById("coodlat").innerHTML), Number.parseFloat(document.getElementById("coodh").innerHTML))
  88. switch (type) {
  89. case 1:
  90. CTMapOl.thrdime.entitycontrol.addimg(viewer, pos, '../dist/assets/image/locus/point_selected.svg', [0, -20], 0.5)
  91. break
  92. case 2:
  93. CTMapOl.thrdime.entitycontrol.addimg(viewer, pos, '../dist/assets/image/locus/point_begin.svg', [0, -20], 0.5)
  94. break
  95. case 3:
  96. let svg1 = await axios({ url: '../dist/assets/image/locus/point_selected.svg', method: 'get' })
  97. let svg2 = await axios({ url: '../dist/assets/image/locus/point_begin.svg', method: 'get' })
  98. let xmlDoc1 = new DOMParser().parseFromString(svg1.data, "text/xml");
  99. let xmlDoc2 = new DOMParser().parseFromString(svg2.data, "text/xml");
  100. let svgdom1=xmlDoc1.getElementsByTagName('svg')[0];
  101. let svgdom2=xmlDoc2.getElementsByTagName('svg')[0];
  102. svgdom1.innerHTML=svgdom1.innerHTML+svgdom2.innerHTML
  103. // for(let i=0;i<svgdom2.childNodes.length;i++)
  104. // {
  105. // svgdom1.childNodes.push(svgdom2.childNodes[i])
  106. // }
  107. CTMapOl.thrdime.entitycontrol.addimg(viewer, pos,'data:image/svg+xml;base64,' + window.btoa((new XMLSerializer()).serializeToString(svgdom1)), [0, -20], 0.5)
  108. break
  109. }
  110. }
  111. function drawoverlay() {
  112. let pos = new Cesium.Cartesian3.fromDegrees(Number.parseFloat(document.getElementById("coodlon").innerHTML), Number.parseFloat(document.getElementById("coodlat").innerHTML), Number.parseFloat(document.getElementById("coodh").innerHTML))
  113. let scrposition = Cesium.SceneTransforms.wgs84ToWindowCoordinates(viewer.scene, pos)
  114. const pop = document.getElementById("popup");
  115. pop.style.position = "absolute";
  116. pop.style.top = scrposition.y - 100 / 2 + "px";
  117. pop.style.left = scrposition.x - 100 / 2 + "px";
  118. pop.style.zIndex = 99;
  119. viewer.scene.postRender.addEventListener(() => {
  120. scrposition = Cesium.SceneTransforms.wgs84ToWindowCoordinates(viewer.scene, pos)
  121. pop.style.top = scrposition.y - 100 / 2 + "px";
  122. pop.style.left = scrposition.x - 100 / 2 + "px";
  123. });
  124. }
  125. function flyto() {
  126. let pos = new Cesium.Cartesian3.fromDegrees(Number.parseFloat(document.getElementById("coodlon").innerHTML), Number.parseFloat(document.getElementById("coodlat").innerHTML), Number.parseFloat(document.getElementById("coodh").innerHTML) + 500)
  127. CTMapOl.thrdime.cameracontrol.flyTo(viewer, CTMapOl.thrdime.cameracontrol.getflyTooptions(pos, {
  128. /**\
  129. * 朝向
  130. */
  131. heading: Cesium.Math.toRadians(0),
  132. /**
  133. * 仰俯
  134. */
  135. pitch: Cesium.Math.toRadians(-90.0)
  136. }, 20, () => { alert('飞行完成') }))
  137. }
  138. function SaveSceneToImg() {
  139. viewer.render()
  140. let canvas = viewer.scene.canvas;
  141. var base64 = canvas.toDataURL('image/png');
  142. document.getElementById("tarimg").src = base64
  143. // 去除头部信息
  144. console.log(base64)
  145. }
  146. </script>
  147. </html>