k15_floodByMaterial.html 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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>淹没分析(globe材质) </title>
  21. <!--第三方lib-->
  22. <script
  23. type="text/javascript"
  24. src="../lib/include-lib.js"
  25. libpath="../lib/"
  26. include="jquery,jquery.range,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. <!-- 面板 -->
  35. <div class="infoview">
  36. <table id="paramView" class="mars-table">
  37. <tr>
  38. <td class="nametd">分析区域</td>
  39. <td>
  40. <button type="button" id="btnDrawExtent" class="btn btn-default">添加矩形</button>
  41. <button type="button" id="btnDraw" class="btn btn-default">添加多边形</button>
  42. <button type="button" id="clearDraw" class="btn btn-default">清除</button>
  43. </td>
  44. </tr>
  45. <tr>
  46. <td class="nametd">最低海拔(米)</td>
  47. <td>
  48. <input id="minHeight" value="" type="number" class="form-control" />
  49. </td>
  50. </tr>
  51. <tr>
  52. <td class="nametd">最高海拔(米)</td>
  53. <td>
  54. <input id="maxHeight" value="" type="number" class="form-control" />
  55. </td>
  56. </tr>
  57. <tr>
  58. <td class="nametd">淹没速度(米/秒)</td>
  59. <td>
  60. <input id="speed" value="80" type="number" class="form-control" />
  61. </td>
  62. </tr>
  63. <tr>
  64. <td colspan="2">
  65. <button type="button" id="begin" class="btn btn-primary">开始分析</button>
  66. </td>
  67. </tr>
  68. </table>
  69. <div id="resultView" style="display: none; text-align: left">
  70. <div class="rowview clearfix">
  71. <span>高度选择:</span>
  72. <input id="range_currHeight" title="时间" type="range" min="0" max="1000" step="0.1" value="0" />
  73. </div>
  74. <div class="rowview clearfix"><span>当前高度:</span><span id="lbl_nowHeight"></span></div>
  75. <input id="btn_start" type="button" class="btn btn-primary" value="自动播放" />
  76. <button type="button" id="clear" class="btn btn-primary">返回</button>
  77. <div class="checkbox checkbox-info checkbox-inline">
  78. <input type="checkbox" id="showElse" value="this" name="jiaodu" checked />
  79. <label for="showElse">显示非淹没区域</label>
  80. </div>
  81. </div>
  82. </div>
  83. <script src="./js/common.js"></script>
  84. <script type="text/javascript">
  85. "use script"; //开发环境建议开启严格模式
  86. var map;
  87. var floodByMaterial;
  88. function initMap(options) {
  89. //合并属性参数,可覆盖config.json中的对应配置
  90. var mapOptions = mars3d.Util.merge(options, {
  91. scene: {
  92. showSun: false,
  93. showMoon: false,
  94. showSkyBox: false,
  95. showSkyAtmosphere: false,
  96. fog: false,
  97. globe: {
  98. showGroundAtmosphere: false,
  99. enableLighting: false,
  100. },
  101. },
  102. });
  103. //创建三维地球场景
  104. map = new mars3d.Map("mars3dContainer", mapOptions);
  105. var speed = Number($("#speed").val());
  106. // 基于地球材质,可以多个区域
  107. floodByMaterial = new mars3d.thing.FloodByMaterial({
  108. speed: speed,
  109. });
  110. map.addThing(floodByMaterial);
  111. floodByMaterial.on(mars3d.EventType.start, function (e) {
  112. console.log("开始分析", e);
  113. });
  114. floodByMaterial.on(mars3d.EventType.change, function (e) {
  115. // console.log('分析中,高度变化了', e)
  116. onChangeHeight(e.height);
  117. });
  118. floodByMaterial.on(mars3d.EventType.end, function (e) {
  119. console.log("结束分析", e);
  120. });
  121. $("#btnDraw").click(function () {
  122. map.graphicLayer.startDraw({
  123. type: "polygon",
  124. style: {
  125. color: "#007be6",
  126. opacity: 0.5,
  127. outline: false,
  128. },
  129. success: function (graphic) {
  130. var positions = graphic.positionsShow;
  131. //更新最大、最小高度值
  132. updateHeightRange(positions);
  133. floodByMaterial.addArea(positions);
  134. },
  135. });
  136. });
  137. $("#btnDrawExtent").click(function () {
  138. map.graphicLayer.startDraw({
  139. type: "rectangle",
  140. style: {
  141. color: "#007be6",
  142. opacity: 0.8,
  143. outline: false,
  144. },
  145. success: function (graphic) {
  146. //绘制成功后回调
  147. var positions = graphic.getOutlinePositions(false);
  148. //更新最大、最小高度值
  149. updateHeightRange(positions);
  150. //区域
  151. floodByMaterial.addArea(positions);
  152. },
  153. });
  154. });
  155. $("#begin").click(function () {
  156. if (floodByMaterial.length == 0) {
  157. haoutil.msg("请首先绘制分析区域!");
  158. return;
  159. }
  160. map.graphicLayer.clear();
  161. var minValue = Number($("#minHeight").val());
  162. var maxValue = Number($("#maxHeight").val());
  163. var speed = Number($("#speed").val());
  164. floodByMaterial.setOptions({
  165. minHeight: minValue,
  166. maxHeight: maxValue,
  167. speed: speed,
  168. });
  169. $("#range_currHeight").attr("min", minValue);
  170. $("#range_currHeight").attr("max", maxValue);
  171. onChangeHeight(minValue);
  172. $("#paramView").hide();
  173. $("#resultView").show();
  174. $("#btn_start").click(); //自动启动
  175. });
  176. //滑动条
  177. $("#range_currHeight").range({
  178. onChange: function (value, bfb) {
  179. floodByMaterial.height = value;
  180. $("#lbl_nowHeight").html(value.toFixed(1));
  181. $("#btn_start").val("自动播放");
  182. },
  183. });
  184. $("#btn_start").click(function () {
  185. if (floodByMaterial.isStart) {
  186. floodByMaterial.stop();
  187. $("#btn_start").val("自动播放");
  188. } else {
  189. floodByMaterial.start();
  190. $("#btn_start").val("暂停");
  191. }
  192. });
  193. $("#clearDraw").click(function () {
  194. clearDraw();
  195. });
  196. $("#clear").click(function () {
  197. $("#resultView").hide();
  198. $("#paramView").show();
  199. $("#btn_start").val("自动播放");
  200. clearDraw();
  201. });
  202. $("#showElse").change(function () {
  203. var val = $(this).is(":checked");
  204. floodByMaterial.showElseArea = val;
  205. });
  206. }
  207. //求最大、最小高度值
  208. function updateHeightRange(positions) {
  209. haoutil.loading.show();
  210. var result = mars3d.PolyUtil.getHeightRange(positions, map.scene);
  211. let minHeight = Math.ceil(result.minHeight);
  212. let maxHeight = Math.floor(result.maxHeight);
  213. if (floodByMaterial.length > 0) {
  214. minHeight = Math.min(minHeight, Number($("#minHeight").val()));
  215. maxHeight = Math.max(maxHeight, Number($("#maxHeight").val()));
  216. }
  217. $("#minHeight").val(minHeight);
  218. $("#maxHeight").val(maxHeight);
  219. haoutil.loading.hide();
  220. }
  221. function onChangeHeight(height) {
  222. $("#range_currHeight").val(height).change();
  223. $("#lbl_nowHeight").html(height.toFixed(1));
  224. }
  225. function clearDraw() {
  226. floodByMaterial.clear();
  227. map.graphicLayer.clear();
  228. $("#showElse").prop("checked", true);
  229. $("#minHeight").val("");
  230. $("#maxHeight").val("");
  231. }
  232. </script>
  233. </body>
  234. </html>