f40_diffusion.html 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
  6. <meta name="author" content="火星科技 http://mars3d.cn " />
  7. <meta name="apple-touch-fullscreen" content="yes" />
  8. <meta name="apple-mobile-web-app-capable" content="yes" />
  9. <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  10. <meta name="format-detection" content="telephone=no" />
  11. <meta name="x5-fullscreen" content="true" />
  12. <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
  13. <!-- 标题及搜索关键字 -->
  14. <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
  15. <meta
  16. name="description"
  17. content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型 gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包 地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS"
  18. />
  19. <link rel="shortcut icon" type="image/x-icon" href="" />
  20. <title>危化品扩散效果 </title>
  21. <!--第三方lib-->
  22. <script
  23. type="text/javascript"
  24. src="../lib/include-lib.js"
  25. libpath="../lib/"
  26. include="jquery,font-awesome,bootstrap,bootstrap-checkbox,layer,haoutil,turf,mars3d"
  27. ></script>
  28. <link href="css/style.css" rel="stylesheet" />
  29. </head>
  30. <body class="dark">
  31. <!--加载前进行操作提示,优化用户体验-->
  32. <div id="mask" class="signmask" onclick="removeMask()"></div>
  33. <div id="mars3dContainer" class="mars3d-container"></div>
  34. <div id="tipView" class="info-tips">(1) 加载数据44万条,请耐心等待~</div>
  35. <!-- 面板 -->
  36. <div class="infoview">
  37. <table class="mars-table">
  38. <tr>
  39. <td>
  40. <div class="checkbox checkbox-primary checkbox-inline">
  41. <input id="chk_redSphere" class="styled" type="checkbox" checked />
  42. <label for="chk_redSphere"> 危险圈 </label>
  43. </div>
  44. </td>
  45. </tr>
  46. <tr>
  47. <td>
  48. <div class="checkbox checkbox-primary checkbox-inline">
  49. <input id="chk_yellowSphere" class="styled" type="checkbox" />
  50. <label for="chk_yellowSphere"> 警告圈 </label>
  51. </div>
  52. </td>
  53. </tr>
  54. </table>
  55. </div>
  56. <script src="./js/common.js"></script>
  57. <script type="text/javascript">
  58. "use script"; //开发环境建议开启严格模式
  59. var map;
  60. var center = Cesium.Cartesian3.fromDegrees(117.167848, 31.814011, 46); //事发点
  61. function initMap(options) {
  62. //合并属性参数,可覆盖config.json中的对应配置
  63. var mapOptions = mars3d.Util.merge(options, {
  64. scene: {
  65. center: { lat: 31.805861, lng: 117.158491, alt: 1311, heading: 53, pitch: -45 },
  66. },
  67. });
  68. //创建三维地球场景
  69. map = new mars3d.Map("mars3dContainer", mapOptions);
  70. //创建Graphic图层
  71. var graphicLayer = new mars3d.layer.GraphicLayer();
  72. map.addLayer(graphicLayer);
  73. //半球范围圈
  74. createEllipsoid(graphicLayer);
  75. //火焰效果
  76. createParticle(graphicLayer);
  77. //添加点集
  78. creteaPointPrimitive(graphicLayer);
  79. }
  80. //添加点集
  81. function creteaPointPrimitive(graphicLayer) {
  82. clr.init();
  83. // haoutil.msg('加载数据44万条,请耐心等待~')
  84. var degree = 45; //角度
  85. let hpr = new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(degree), 0, 0);
  86. var resource = new Cesium.Resource({
  87. url: "//data.mars3d.cn/file/apidemo/diffusion.json",
  88. });
  89. resource
  90. .fetchJson()
  91. .then(function (rs) {
  92. console.log("加载数据" + rs.length + "条");
  93. for (var i = 1; i < rs.length; i++) {
  94. var item = rs[i];
  95. var val = item[3];
  96. var par1Position = mars3d.PointUtil.getPositionByHprAndOffset(center, new Cesium.Cartesian3(item[0], item[1], item[2]), hpr);
  97. //加point点
  98. var primitive = new mars3d.graphic.PointPrimitive({
  99. position: par1Position,
  100. style: {
  101. pixelSize: 5,
  102. color: clr.getColor(val),
  103. },
  104. tooltip: "浓度值:" + val,
  105. });
  106. graphicLayer.addGraphic(primitive);
  107. }
  108. haoutil.msg("渲染点数量:" + rs.length);
  109. })
  110. .otherwise(function (error) {
  111. haoutil.alert(error, "加载数据出错");
  112. });
  113. }
  114. //半球范围圈
  115. function createEllipsoid(graphicLayer) {
  116. var radiu = 200;
  117. var redSphere = new mars3d.graphic.EllipsoidEntity({
  118. name: "危险圈",
  119. position: center,
  120. style: {
  121. radii: new Cesium.Cartesian3(radiu, radiu, radiu),
  122. maximumConeDegree: 90,
  123. slicePartitions: 45,
  124. stackPartitions: 45,
  125. color: Cesium.Color.RED.withAlpha(0.3),
  126. outline: true,
  127. outlineColor: Cesium.Color.WHITE.withAlpha(0.8),
  128. },
  129. });
  130. graphicLayer.addGraphic(redSphere);
  131. $("#chk_redSphere").change(function () {
  132. var val = $(this).is(":checked");
  133. redSphere.show = val;
  134. });
  135. radiu = 400;
  136. var yellowSphere = new mars3d.graphic.EllipsoidEntity({
  137. name: "警告圈",
  138. position: center,
  139. style: {
  140. radii: new Cesium.Cartesian3(radiu, radiu, radiu),
  141. maximumConeDegree: 90,
  142. slicePartitions: 45,
  143. stackPartitions: 45,
  144. color: Cesium.Color.YELLOW.withAlpha(0.3),
  145. outline: true,
  146. outlineColor: Cesium.Color.WHITE.withAlpha(0.8),
  147. },
  148. show: false,
  149. });
  150. graphicLayer.addGraphic(yellowSphere);
  151. $("#chk_yellowSphere").change(function () {
  152. var val = $(this).is(":checked");
  153. yellowSphere.show = val;
  154. });
  155. }
  156. //添加火焰粒子效果
  157. function createParticle(graphicLayer) {
  158. var particleSystem = new mars3d.graphic.ParticleSystem({
  159. position: center, //位置
  160. style: {
  161. image: "img/particle/fire.png",
  162. startColor: Cesium.Color.RED.withAlpha(0.7), //粒子出生时的颜色
  163. endColor: Cesium.Color.YELLOW.withAlpha(0.0), //当粒子死亡时的颜色
  164. startScale: 1.0, //粒子出生时的比例,相对于原始大小
  165. endScale: 5.0, //粒子在死亡时的比例
  166. minimumParticleLife: 1.2, //设置粒子寿命的可能持续时间的最小界限(以秒为单位),粒子的实际寿命将随机生成
  167. maximumParticleLife: 1.2, //设置粒子寿命的可能持续时间的最大界限(以秒为单位),粒子的实际寿命将随机生成
  168. minimumSpeed: 1.0, //设置以米/秒为单位的最小界限,超过该最小界限,随机选择粒子的实际速度。
  169. maximumSpeed: 4.0, //设置以米/秒为单位的最大界限,超过该最大界限,随机选择粒子的实际速度。
  170. emissionRate: 50.0, //每秒要发射的粒子数。
  171. lifetime: 16.0, //粒子的生命周期为(以秒为单位)。
  172. bursts: [
  173. //粒子会在5s、10s、15s时分别进行一次粒子大爆发
  174. new Cesium.ParticleBurst({
  175. time: 5.0,
  176. minimum: 10,
  177. maximum: 100,
  178. }), // 当在5秒时,发射的数量为10-100
  179. new Cesium.ParticleBurst({
  180. time: 10.0,
  181. minimum: 50,
  182. maximum: 100,
  183. }), // 当在10秒时,发射的数量为50-100
  184. new Cesium.ParticleBurst({
  185. time: 15.0,
  186. minimum: 200,
  187. maximum: 300,
  188. }), // 当在15秒时,发射的数量为200-300
  189. ],
  190. },
  191. transX: 2.5,
  192. transY: 4.0,
  193. transZ: 1.0,
  194. maxHeight: 1000, //超出该高度后不显示粒子效果
  195. });
  196. graphicLayer.addGraphic(particleSystem);
  197. }
  198. //颜色处理
  199. var clr = {
  200. span: [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07],
  201. colors: ["#FFEDA0", "#FED976", "#FEB24C", "#FD8D3C", "#FC4E2A", "#E31A1C", "#BD0026", "#800026"],
  202. init: function () {
  203. for (var k = 0, length = this.colors.length; k < length; k++) {
  204. this.colors[k] = Cesium.Color.fromCssColorString(this.colors[k]).withAlpha(0.6);
  205. }
  206. },
  207. getColor: function (num) {
  208. var length = this.span.length + 1;
  209. if (length > this.colors.length) {
  210. length = this.colors.length;
  211. }
  212. for (var k = 0; k < length; k++) {
  213. if (num < this.span[k]) {
  214. return this.colors[k];
  215. }
  216. }
  217. return this.colors[length - 1];
  218. },
  219. };
  220. </script>
  221. </body>
  222. </html>