06thrdimeregionmap.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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: 100vh; width: 100vw;"></div>
  21. </body>
  22. <script>
  23. window.CESIUM_BASE_URL = '../cesium/Build/Cesium';
  24. Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI2MjIyODA4ZS0zNmRmLTQwNGMtYjZkNC0wOGY2NDdmODgyZTUiLCJpZCI6ODMyOCwiaWF0IjoxNjA2MjkyNDE1fQ.ZhhxNIJ-TzstpcavQBNL7xRwytBat3G2__3jr7lJ8yg'
  25. let op = CTMapOl.thrdime.viewercontrol.globalvieweroptions()
  26. op.sceneMode = Cesium.SceneMode.COLUMBUS_VIEW
  27. var viewer = CTMapOl.thrdime.viewercontrol.globalviewer('map', op)
  28. viewer._cesiumWidget._creditContainer.style.display = 'none'
  29. CTMapOl.thrdime.imagerylayercontrol.removeAll(viewer, true)
  30. CTMapOl.thrdime.cameracontrol.setcamera(viewer, CTMapOl.thrdime.cameracontrol.getcameraoptionswithdetile(116.39, 39.91, 5000, 0, -90, 0))
  31. viewer.scene.globe.showGroundAtmosphere = false;
  32. viewer.scene.globe.baseColor = Cesium.Color.TRANSPARENT;
  33. viewer.scene.globe.translucency.enabled = true;
  34. viewer.scene.globe.undergroundColor = undefined;
  35. async function fullfillregion() {
  36. let regiondata = await CTMapOl.getRegionGeojson('110000')
  37. var bbox = CTMapOl.turf.bbox(regiondata.thisregion);
  38. let rec = new Cesium.Rectangle(Cesium.Math.toRadians(bbox[0]), Cesium.Math.toRadians(bbox[1]), Cesium.Math.toRadians(bbox[2]), Cesium.Math.toRadians(bbox[3]))
  39. let lengthrect = Cesium.Cartesian3.distance(Cesium.Cartographic.toCartesian(Cesium.Rectangle.northeast(rec)), Cesium.Cartographic.toCartesian(Cesium.Rectangle.southwest(rec)))
  40. let postemp = viewer.scene.camera.getRectangleCameraCoordinates(rec)
  41. viewer.scene.camera.position = postemp
  42. let op1 = CTMapOl.thrdime.datasourcecontrol.GeoJsonoptions()
  43. op1.fill = new Cesium.Color(0 / 255, 58 / 255, 255 / 255, 1),
  44. op1.clampToGround = false
  45. let data1 = await CTMapOl.thrdime.datasourcecontrol.addDataSource(viewer, regiondata.thisregion, op1)
  46. let wall1entitys = data1.entities.values
  47. for (let i = 0; i < wall1entitys.length; i++) {
  48. let coods = wall1entitys[i].polygon.hierarchy._value.positions
  49. let minimumHeights = []
  50. let maximumHeights = []
  51. let maximumHeights2 = []
  52. for (let j = 0; j < coods.length; j++) {
  53. minimumHeights.push(0)
  54. maximumHeights.push(lengthrect / 50)
  55. maximumHeights2.push(lengthrect / 25)
  56. }
  57. viewer.entities.add(new Cesium.Entity({
  58. wall: {
  59. show: true,
  60. //墙折线
  61. positions: coods,
  62. //下墙体高程
  63. minimumHeights: minimumHeights,
  64. //上墙体高程
  65. maximumHeights: maximumHeights,
  66. //弧度采样
  67. granularity: Cesium.Math.RADIANS_PER_DEGREE,
  68. //填充
  69. fill: true,
  70. //材质
  71. material: getColorRamp([0.0, 1.0], true),
  72. //轮廓线
  73. outline: false,
  74. //轮廓线材质
  75. outlineColor: Cesium.Color.BLACK,
  76. //轮廓线宽
  77. outlineWidth: 1.0,
  78. //造影模式
  79. shadows: Cesium.ShadowMode.ENABLED,
  80. //距离放缩回调
  81. distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, Number.max)
  82. }
  83. }))
  84. viewer.entities.add(new Cesium.Entity({
  85. wall: {
  86. show: true,
  87. //墙折线
  88. positions: coods,
  89. //下墙体高程
  90. minimumHeights: maximumHeights,
  91. //上墙体高程
  92. maximumHeights: maximumHeights2,
  93. //弧度采样
  94. granularity: Cesium.Math.RADIANS_PER_DEGREE,
  95. //填充
  96. fill: true,
  97. //材质
  98. material: getColorRamp2([0.0, 1.0], true),
  99. //轮廓线
  100. outline: false,
  101. //轮廓线材质
  102. outlineColor: Cesium.Color.BLACK,
  103. //轮廓线宽
  104. outlineWidth: 1.0,
  105. //造影模式
  106. shadows: Cesium.ShadowMode.ENABLED,
  107. //距离放缩回调
  108. distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, Number.max)
  109. }
  110. }))
  111. }
  112. let op2 = CTMapOl.thrdime.datasourcecontrol.GeoJsonoptions()
  113. op2.fill = new Cesium.Color(0 / 255, (2 * 16 + 6) / 255, (7 * 16 + 0) / 255, 1),
  114. op2.clampToGround = false
  115. let data2 = await CTMapOl.thrdime.datasourcecontrol.addDataSource(viewer, regiondata.thisregion, op2)
  116. for (let i = 0; i < data2.entities.values.length; i++) {
  117. let temptar = data2.entities.values[i].polygon
  118. temptar.height = lengthrect / 50
  119. }
  120. let op3 = CTMapOl.thrdime.datasourcecontrol.GeoJsonoptions()
  121. op3.fill = new Cesium.Color(3 / 255, (1 * 16 + 11) / 255, (4 * 16 + 7) / 255, 1),
  122. op3.clampToGround = false
  123. let data3 = await CTMapOl.thrdime.datasourcecontrol.addDataSource(viewer, regiondata.childregion, op3)
  124. for (let i = 0; i < data3.entities.values.length; i++) {
  125. let temptar = data3.entities.values[i].polygon
  126. temptar.height = lengthrect / 25
  127. }
  128. }
  129. function getColorRamp(elevationRamp) {
  130. var ramp = document.createElement('canvas');
  131. ramp.width = 1;
  132. ramp.height = 100;
  133. var ctx = ramp.getContext('2d');
  134. var values = elevationRamp;
  135. var grd = ctx.createLinearGradient(0, 0, 0, 100);
  136. grd.addColorStop(values[0], '#002670');
  137. grd.addColorStop(values[1], '#0030ff');
  138. ctx.fillStyle = grd;
  139. ctx.fillRect(0, 0, 1, 100);
  140. return ramp;
  141. }
  142. function getColorRamp2(elevationRamp) {
  143. var ramp = document.createElement('canvas');
  144. ramp.width = 1;
  145. ramp.height = 100;
  146. var ctx = ramp.getContext('2d');
  147. var values = elevationRamp;
  148. var grd = ctx.createLinearGradient(0, 0, 0, 100);
  149. grd.addColorStop(values[0], '#031b47');
  150. grd.addColorStop(values[1], '#002670');
  151. ctx.fillStyle = grd;
  152. ctx.fillRect(0, 0, 1, 100);
  153. return ramp;
  154. }
  155. fullfillregion()
  156. </script>
  157. </html>