f35_dynamicRiver.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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,bootstrap-slider,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 class="infoview">
  35. <span style="color: #cad1d1">建议:顺着水流方向选点,直线时多采集点</span>
  36. <table class="mars-table">
  37. <tr>
  38. <td class="nametd">河宽度(米):</td>
  39. <td>
  40. <input type="number" class="form-control" id="txtWidth" value="280" />
  41. </td>
  42. </tr>
  43. <tr>
  44. <td class="nametd">河高度(米):</td>
  45. <td>
  46. <input type="number" class="form-control" id="txtHeight" value="30" />
  47. </td>
  48. </tr>
  49. <tr>
  50. <td class="nametd">水流速(米/秒):</td>
  51. <td>
  52. <input id="txtSpeed" type="text" />
  53. </td>
  54. </tr>
  55. <tr>
  56. <td colspan="2">
  57. <input id="btnDrawLine" type="button" class="btn btn-primary" value="绘制河流" />
  58. <input id="btnAddHeight" type="button" class="btn btn-primary" value="升高30米动画" />
  59. <input id="btnLowerHeight" type="button" class="btn btn-primary" value="降低30米动画" />
  60. <input id="btnClear" type="button" class="btn btn-danger" value="清除" />
  61. </td>
  62. </tr>
  63. </table>
  64. </div>
  65. <script src="./js/common.js"></script>
  66. <script type="text/javascript">
  67. "use script"; //开发环境建议开启严格模式
  68. var map;
  69. function initMap(options) {
  70. //合并属性参数,可覆盖config.json中的对应配置
  71. var mapOptions = mars3d.Util.merge(options, {
  72. scene: {
  73. center: { lat: 30.422407, lng: 115.820222, alt: 3498, heading: 67, pitch: -32 },
  74. globe: {
  75. depthTestAgainstTerrain: true,
  76. },
  77. },
  78. });
  79. //创建三维地球场景
  80. map = new mars3d.Map("mars3dContainer", mapOptions);
  81. //创建Graphic图层
  82. var graphicLayer = new mars3d.layer.GraphicLayer();
  83. map.addLayer(graphicLayer);
  84. //2.在layer上绑定监听事件
  85. graphicLayer.on(mars3d.EventType.click, function (event) {
  86. console.log("监听layer,单击了矢量对象", event);
  87. });
  88. graphicLayer.on(mars3d.EventType.mouseOver, function (event) {
  89. console.log("监听layer,鼠标移入了矢量对象", event);
  90. });
  91. graphicLayer.on(mars3d.EventType.mouseOut, function (event) {
  92. console.log("监听layer,鼠标移出了矢量对象", event);
  93. });
  94. //可在图层上绑定popup,对所有加到这个图层的矢量数据都生效
  95. graphicLayer.bindPopup("我是layer上绑定的Popup");
  96. //可在图层上绑定tooltip,对所有加到这个图层的矢量数据都生效
  97. // graphicLayer.bindTooltip('我是layer上绑定的Tooltip')
  98. //可在图层绑定右键菜单,对所有加到这个图层的矢量数据都生效
  99. graphicLayer.bindContextMenu([
  100. {
  101. text: "删除对象",
  102. iconCls: "fa fa-trash-o",
  103. callback: function (e) {
  104. var primitive = e.graphic;
  105. if (primitive) {
  106. graphicLayer.removeGraphic(primitive);
  107. }
  108. },
  109. },
  110. ]);
  111. //加一些演示数据
  112. var dynamicRiver = new mars3d.graphic.DynamicRiver({
  113. positions: [
  114. [115.906607, 30.441582, 555.9],
  115. [115.899964, 30.438543, 467.3],
  116. [115.893105, 30.440714, 374.6],
  117. [115.88362, 30.443924, 340.7],
  118. [115.873948, 30.444827, 299],
  119. [115.864003, 30.442111, 292.2],
  120. [115.850741, 30.438108, 189.9],
  121. ],
  122. style: {
  123. image: "./img/textures/movingRiver.png",
  124. width: 280,
  125. height: 30,
  126. speed: 10,
  127. },
  128. });
  129. graphicLayer.addGraphic(dynamicRiver);
  130. console.log(dynamicRiver);
  131. //属性动态更新
  132. $("#txtWidth").change(function (e) {
  133. if (!dynamicRiver) {
  134. return;
  135. }
  136. var value = Number($(this).val());
  137. dynamicRiver.width = value;
  138. });
  139. $("#txtHeight").change(function (e) {
  140. if (!dynamicRiver) {
  141. return;
  142. }
  143. var value = Number($(this).val());
  144. dynamicRiver.height = value;
  145. });
  146. $("#txtSpeed")
  147. .slider({ min: 0, max: 50, step: 1, value: 10 })
  148. .on("change", (e) => {
  149. if (dynamicRiver && e && e.value) {
  150. dynamicRiver.speed = e.value.newValue;
  151. }
  152. });
  153. //清除
  154. $("#btnClear").click(function (e) {
  155. graphicLayer.clear();
  156. dynamicRiver = null;
  157. });
  158. $("#btnAddHeight").click(function (e) {
  159. if (!dynamicRiver) {
  160. return;
  161. }
  162. dynamicRiver.offsetHeight(30, 5); //5秒内抬高30米
  163. });
  164. $("#btnLowerHeight").click(function (e) {
  165. if (!dynamicRiver) {
  166. return;
  167. }
  168. dynamicRiver.offsetHeight(-30, 5); //5秒内降低30米
  169. });
  170. $("#btnDrawLine").click(function (e) {
  171. map.graphicLayer.startDraw({
  172. type: "polyline",
  173. style: {
  174. color: "#55ff33",
  175. width: 3,
  176. },
  177. success: (graphic) => {
  178. var points = graphic.points;
  179. console.log(JSON.stringify(graphic.coordinates)); //打印下边界
  180. graphic.remove(); //删除绘制的线
  181. var width = Number($("#txtWidth").val());
  182. var height = Number($("#txtHeight").val());
  183. var speed = Number($("#txtSpeed").val());
  184. dynamicRiver = new mars3d.graphic.DynamicRiver({
  185. positions: points,
  186. style: {
  187. image: "./img/textures/movingRiver.png",
  188. width: width,
  189. height: height,
  190. speed: speed,
  191. },
  192. });
  193. graphicLayer.addGraphic(dynamicRiver);
  194. },
  195. });
  196. });
  197. }
  198. </script>
  199. </body>
  200. </html>