HeatMapCesium.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport"
  7. content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
  8. <title>三维热力图</title>
  9. <link rel="stylesheet" href="../../dist/index.css" />
  10. <link href="../../cesium/Source/Widgets/widgets.css" rel="stylesheet">
  11. <script src="../../cesium/Build/Cesium/Cesium.js"></script>
  12. <script src="../../dist/index.js"></script>
  13. <style>
  14. * {
  15. padding: 0;
  16. margin: 0;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <div id="map" style="height: 100vh; width: 100%;">
  22. <div style="position: absolute; top: 0px; left: 0px;z-index: 9;">
  23. <button onclick="drawHeatmap()">热力图</button>
  24. <button onclick="clearHeatmap()">清除图层</button>
  25. </div>
  26. </div>
  27. </body>
  28. <script>
  29. window.CESIUM_BASE_URL = '../../cesium/Build/CesiumUnminified';
  30. Cesium.Ion.defaultAccessToken =
  31. 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI2MjIyODA4ZS0zNmRmLTQwNGMtYjZkNC0wOGY2NDdmODgyZTUiLCJpZCI6ODMyOCwiaWF0IjoxNjA2MjkyNDE1fQ.ZhhxNIJ-TzstpcavQBNL7xRwytBat3G2__3jr7lJ8yg'
  32. var viewer = CTMapOl.thrdime.viewercontrol.globalviewer('map', CTMapOl.thrdime.viewercontrol.globalvieweroptions())
  33. viewer._cesiumWidget._creditContainer.style.display = 'none'
  34. CTMapOl.thrdime.imagerylayercontrol.removeAll(viewer, true)
  35. CTMapOl.thrdime.imagerylayercontrol.addImageryProvider(viewer, CTMapOl.thrdime.imagerylayercontrol.gettdtImagery(
  36. 'img', "img_w"))
  37. CTMapOl.thrdime.imagerylayercontrol.addImageryProvider(viewer, CTMapOl.thrdime.imagerylayercontrol.gettdtImagery(
  38. 'cia', "cia_w"))
  39. CTMapOl.thrdime.viewercontrol.addterrainct(viewer)
  40. var CesiumHeatmap = new CTMapOl.cesiumComponent.CesiumHeatmap(viewer)
  41. var bounds = {
  42. west: 116.13833844,
  43. east: 116.18056899,
  44. south: 37.43582929,
  45. north: 37.47906916
  46. };
  47. var valueMin = 0
  48. var valueMax = 100
  49. CTMapOl.thrdime.cameracontrol.setDEFAULT_VIEW_RECTANGLE(bounds.west, bounds.south, bounds.east, bounds.north)
  50. CTMapOl.thrdime.cameracontrol.setcamera(viewer, CTMapOl.thrdime.cameracontrol.getcameraoptionswithdetile((bounds
  51. .west + bounds.east) / 2,
  52. (bounds.south + bounds.north) / 2, 10000, 0, -90, 0))
  53. function drawHeatmap() {
  54. CesiumHeatmap.create(
  55. bounds, {
  56. // radius: 40,
  57. blur: 0.75,
  58. maxOpacity: 0.85,
  59. minOpacity: 0.16,
  60. "gradient": {
  61. '0.7': '#546AA4',
  62. '0.9': '#0DB212',
  63. '0.95': '#D6CE3B',
  64. '0.96': '#CC9C1B',
  65. '0.998': '#DC0F2A'
  66. },
  67. }
  68. )
  69. var sourceData = getData(300)
  70. // 添加数据 最小值,最大值,数据集
  71. CesiumHeatmap.setWGS84Data(valueMin, valueMax, sourceData)
  72. function getData(len) {
  73. let points = []
  74. for (let i = 0; i < len; i++) {
  75. let point = {
  76. x: Math.random() * (bounds.east - bounds.west) + bounds.west,
  77. y: Math.random() * (bounds.north - bounds.south) + bounds.south,
  78. value: Math.random() * 100,
  79. radius: 100
  80. }
  81. points.push(point)
  82. }
  83. return points
  84. }
  85. // 镜头移动事件
  86. viewer.scene.camera.moveEnd.addEventListener(function () {
  87. var height = viewer.camera.positionCartographic.height
  88. sourceData.forEach(function (v) {
  89. v.radius = height / 50
  90. })
  91. console.log(sourceData, 'sourceData')
  92. CesiumHeatmap.setWGS84Data(valueMin, valueMax, sourceData)
  93. })
  94. }
  95. function clearHeatmap() {
  96. if (CesiumHeatmap) {
  97. CesiumHeatmap.removeLayer()
  98. }
  99. }
  100. </script>
  101. </html>