k10_measure_section.html 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <!-- 2017-12-4 14:24:12 | 修改 木遥(微信: http://marsgis.cn/weixin.html ) -->
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
  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. <script
  22. type="text/javascript"
  23. src="../lib/include-lib.js"
  24. libpath="../lib/"
  25. include="jquery,font-awesome,bootstrap,layer,haoutil,turf,mars3d,echarts"
  26. ></script>
  27. <link href="css/style.css" rel="stylesheet" />
  28. <style>
  29. .sectionChars {
  30. display: none;
  31. width: calc(100% - 220px);
  32. height: 200px;
  33. top: auto;
  34. left: 100px;
  35. right: 100px;
  36. bottom: 30px;
  37. }
  38. </style>
  39. </head>
  40. <body class="dark">
  41. <!--加载前进行操作提示,优化用户体验-->
  42. <div id="mask" class="signmask" onclick="removeMask()"></div>
  43. <div id="mars3dContainer" class="mars3d-container"></div>
  44. <!-- 面板 -->
  45. <div class="infoview">
  46. <span style="color: #cad1d1">提示:单击下面按钮激活绘制,按提示操作即可。</span>
  47. <br />
  48. <input type="button" class="btn btn-primary" value="剖面" onclick="measureSection()" />
  49. <input type="button" class="btn btn-info" value="清除" onclick="removeAll()" />
  50. </div>
  51. <div id="sectionChars" class="infoview sectionChars">
  52. <div id="echartsView1" style="width: 100%; height: 100%"></div>
  53. </div>
  54. <!-- 切换视角到模型或地形(山区)的快捷按钮 -->
  55. <script type="text/javascript" src="js/center_terrain_3dtiles.js"></script>
  56. <script src="./js/common.js"></script>
  57. <script type="text/javascript">
  58. "use script"; //开发环境建议开启严格模式
  59. var map;
  60. var measureObj;
  61. function initMap(options) {
  62. //合并属性参数,可覆盖config.json中的对应配置
  63. var mapOptions = mars3d.Util.merge(options, {
  64. scene: {
  65. center: { lat: 30.715648, lng: 116.300527, alt: 10727, heading: 3, pitch: -25 },
  66. },
  67. });
  68. //创建三维地球场景
  69. map = new mars3d.Map("mars3dContainer", mapOptions);
  70. measureObj = new mars3d.thing.Measure({
  71. //设置文本样式
  72. label: {
  73. color: "#ffffff",
  74. font_family: "楷体",
  75. font_size: 20,
  76. },
  77. });
  78. map.addThing(measureObj);
  79. measureObj.on(mars3d.EventType.start, function (e) {
  80. console.log("开始分析", e);
  81. //开始分析前回调(异步)
  82. haoutil.loading.show();
  83. });
  84. measureObj.on(mars3d.EventType.end, function (e) {
  85. console.log("分析结束", e);
  86. //分析完成后回调(异步)
  87. haoutil.loading.hide();
  88. if (e.graphic?.type === mars3d.graphic.SectionMeasure.type) {
  89. setEchartsData(e);
  90. }
  91. });
  92. measureObj.on(mars3d.EventType.click, function (e) {
  93. // console.log('单击了对象', e)
  94. let result = e.graphic?.measured;
  95. if (e.graphic?.type === mars3d.graphic.SectionMeasure.type && result) {
  96. setEchartsData(result);
  97. }
  98. });
  99. map.on(mars3d.EventType.click, function (e) {
  100. hideTipMarker();
  101. });
  102. }
  103. function removeAll() {
  104. $("#sectionChars").hide();
  105. measureObj.clear();
  106. hideTipMarker();
  107. }
  108. function measureSection() {
  109. measureObj.section({
  110. // maxPointNum:2,
  111. splitNum: 300, //插值次数
  112. });
  113. }
  114. var tipGraphic;
  115. function showTipMarker(point, z, inthtml) {
  116. var _position_draw = Cesium.Cartesian3.fromDegrees(point.lng, point.lat, z);
  117. if (!tipGraphic) {
  118. tipGraphic = new mars3d.graphic.BillboardEntity({
  119. name: "当前点",
  120. position: _position_draw,
  121. style: {
  122. image: "img/marker/mark3.png",
  123. scale: 1,
  124. horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  125. verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
  126. scaleByDistance: new Cesium.NearFarScalar(10000, 1.0, 500000, 0.2),
  127. },
  128. }).addTo(map.graphicLayer);
  129. tipGraphic._setPositionsToCallback();
  130. }
  131. tipGraphic._position_draw = _position_draw;
  132. tipGraphic.bindPopup(inthtml).openPopup();
  133. }
  134. function hideTipMarker() {
  135. if (!tipGraphic) {
  136. return;
  137. }
  138. tipGraphic.remove(true);
  139. tipGraphic = null;
  140. }
  141. //图表
  142. var myChart1;
  143. //剖面分析 图表
  144. function setEchartsData(data) {
  145. if (data == null || data.arrPoint == null) {
  146. return;
  147. }
  148. var arrPoint = data.arrPoint;
  149. $("#sectionChars").show();
  150. if (myChart1 == null) {
  151. myChart1 = echarts.init(document.getElementById("echartsView1"), "dark");
  152. }
  153. var option = {
  154. grid: {
  155. left: 10,
  156. right: 10,
  157. bottom: 10,
  158. containLabel: true,
  159. },
  160. dataZoom: [
  161. {
  162. type: "inside",
  163. throttle: 50,
  164. },
  165. ],
  166. tooltip: {
  167. trigger: "axis",
  168. //position: function (point, params, dom, rect, size) {
  169. // return [10, 20];
  170. //},
  171. formatter: function (params) {
  172. var inhtml = "";
  173. if (params.length === 0) {
  174. hideTipMarker();
  175. return inhtml;
  176. }
  177. var hbgd = params[0].value; //海拔高度
  178. var point = arrPoint[params[0].dataIndex]; //所在经纬度
  179. var len = haoutil.str.formatLength(Number(params[0].axisValue));
  180. var hbgdStr = haoutil.str.formatLength(Number(params[0].value));
  181. inhtml = `当前位置<br />
  182. 距起点:${len}<br />
  183. 海拔:<span style='color:${params[0].color};'>${hbgdStr}</span><br />
  184. 经度:${point.lng}<br />
  185. 纬度:${point.lat}`;
  186. showTipMarker(point, hbgd, inhtml);
  187. return inhtml;
  188. },
  189. },
  190. xAxis: [
  191. {
  192. name: "行程",
  193. type: "category",
  194. boundaryGap: false,
  195. axisLine: {
  196. show: true,
  197. },
  198. axisLabel: {
  199. show: true,
  200. formatter: "{value} 米",
  201. },
  202. data: data.arrLen,
  203. },
  204. ],
  205. yAxis: [
  206. {
  207. name: "高程",
  208. type: "value",
  209. min: getMinZ(arrPoint),
  210. axisLabel: {
  211. formatter: "{value} 米",
  212. },
  213. },
  214. ],
  215. series: [
  216. {
  217. name: "高程值",
  218. type: "line",
  219. smooth: true,
  220. symbol: "none",
  221. sampling: "average",
  222. itemStyle: {
  223. normal: {
  224. color: "rgb(255, 70, 131)",
  225. },
  226. },
  227. areaStyle: {
  228. normal: {
  229. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  230. {
  231. offset: 0,
  232. color: "rgb(255, 158, 68)",
  233. },
  234. {
  235. offset: 1,
  236. color: "rgb(255, 70, 131)",
  237. },
  238. ]),
  239. },
  240. },
  241. data: data.arrHB,
  242. },
  243. ],
  244. };
  245. myChart1.setOption(option);
  246. }
  247. function getMinZ(arr) {
  248. var minz = "dataMin";
  249. if (arr == null || arr.length === 0) {
  250. return minz;
  251. }
  252. minz = arr[0].alt;
  253. for (var i = 0; i < arr.length; i++) {
  254. if (arr[i].alt < minz) {
  255. minz = arr[i].alt;
  256. }
  257. }
  258. return minz;
  259. }
  260. </script>
  261. </body>
  262. </html>