f70_query_gaodeRoute.html 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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,layer,haoutil,toastr,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. <table class="mars-table">
  36. <tr>
  37. <td>方式</td>
  38. <td colspan="2">
  39. <select id="queryType" class="selectpicker form-control">
  40. <option value="1" selected="selected">步行路线查询</option>
  41. <!-- <option value="2">骑行路线查询</option> -->
  42. <option value="3">驾车路线查询</option>
  43. </select>
  44. </td>
  45. </tr>
  46. <tr>
  47. <td>起点</td>
  48. <td>
  49. <input id="startIpt" type="text" value="" class="form-control" style="width: 200px" />
  50. </td>
  51. <td>
  52. <input type="button" class="btn btn-primary" value="选点" id="startPoint" />
  53. </td>
  54. </tr>
  55. <tr>
  56. <td>终点:</td>
  57. <td>
  58. <input id="endIpt" type="text" value="" class="form-control" style="width: 200px" />
  59. </td>
  60. <td>
  61. <input type="button" class="btn btn-primary" value="选点" id="endPoint" />
  62. </td>
  63. </tr>
  64. <tr>
  65. <td></td>
  66. <td colspan="3">
  67. <input type="button" class="btn btn-primary" value="开始分析" id="FX" />
  68. <input type="button" class="btn btn-primary" value="清除" id="clear" />
  69. </td>
  70. </tr>
  71. </table>
  72. </div>
  73. <div class="infoview result" style="top: 250px; display: none; word-break: break-all; width: 300px">
  74. 总距离:<span id="allDiatance" style="color: #cad1d1"></span><br />
  75. 预计时间:<span id="useTime" style="color: #cad1d1"></span><br />
  76. 导航:<span id="dh" style="color: #cad1d1"></span><br />
  77. </div>
  78. <script src="./js/common.js"></script>
  79. <script type="text/javascript">
  80. "use script"; //开发环境建议开启严格模式
  81. var map;
  82. var routeLayer;
  83. var gaodeRoute;
  84. //当前页面业务相关
  85. var startGraphic, endGraphic;
  86. var lineGraphic;
  87. function initMap(options) {
  88. //合并属性参数,可覆盖config.json中的对应配置
  89. var mapOptions = mars3d.Util.merge(options, {
  90. scene: {
  91. center: { lat: 31.797919, lng: 117.281329, alt: 36236, heading: 358, pitch: -81 },
  92. },
  93. });
  94. //创建三维地球场景
  95. map = new mars3d.Map("mars3dContainer", mapOptions);
  96. //创建矢量数据图层
  97. routeLayer = new mars3d.layer.GraphicLayer();
  98. map.addLayer(routeLayer);
  99. gaodeRoute = new mars3d.query.GaodeRoute({
  100. // key: ['ae29a37307840c7ae4a785ac905927e0'],
  101. });
  102. $("#startPoint").click(function () {
  103. if (startGraphic) {
  104. startGraphic.remove();
  105. startGraphic = null;
  106. }
  107. map.graphicLayer.startDraw({
  108. type: "billboard",
  109. style: {
  110. image: "img/marker/start.png",
  111. horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  112. verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
  113. },
  114. success: function (graphic) {
  115. startGraphic = graphic;
  116. var point = graphic.point;
  117. point.format();
  118. $("#startIpt").val(point.lng + "," + point.lat);
  119. queryRoute();
  120. },
  121. });
  122. });
  123. $("#endPoint").click(function () {
  124. if (endGraphic) {
  125. endGraphic.remove();
  126. endGraphic = null;
  127. }
  128. map.graphicLayer.startDraw({
  129. type: "billboard",
  130. style: {
  131. image: "img/marker/end.png",
  132. horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  133. verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
  134. },
  135. success: function (graphic) {
  136. endGraphic = graphic;
  137. var point = graphic.point;
  138. point.format();
  139. $("#endIpt").val(point.lng + "," + point.lat);
  140. queryRoute();
  141. },
  142. });
  143. });
  144. //开始分析
  145. $("#FX").click(function () {
  146. if (!startGraphic || !endGraphic) {
  147. haoutil.msg("请设置起点和终点");
  148. return;
  149. }
  150. queryRoute();
  151. });
  152. $("#clear").click(function () {
  153. if (startGraphic) {
  154. startGraphic.remove();
  155. startGraphic = null;
  156. }
  157. if (endGraphic) {
  158. endGraphic.remove();
  159. endGraphic = null;
  160. }
  161. $("#startIpt").val("");
  162. $("#endIpt").val("");
  163. routeLayer.clear();
  164. $(".result").hide();
  165. });
  166. }
  167. function queryRoute() {
  168. if (!startGraphic || !endGraphic) {
  169. return;
  170. }
  171. routeLayer.clear();
  172. haoutil.loading.show();
  173. $(".result").hide();
  174. var type = Number($("#queryType").val()); //GaodeRouteType枚举类型
  175. gaodeRoute.query({
  176. type: type,
  177. points: [startGraphic.coordinate, endGraphic.coordinate],
  178. success: function (data) {
  179. haoutil.loading.close();
  180. let lineFirst = data.paths[0];
  181. var points = lineFirst.points;
  182. if (!points || points.length < 1) {
  183. return;
  184. }
  185. var time = haoutil.str.formatTime(lineFirst.allDuration);
  186. var distance = haoutil.str.formatLength(lineFirst.allDistance);
  187. var html = "<div>总距离:" + distance + "<br/>所需时间:" + time + "</div>";
  188. let graphic = new mars3d.graphic.PolylineEntity({
  189. positions: points,
  190. style: {
  191. clampToGround: true,
  192. material: Cesium.Color.AQUA.withAlpha(0.8),
  193. width: 5,
  194. },
  195. popup: html,
  196. });
  197. routeLayer.addGraphic(graphic);
  198. showResult(data);
  199. },
  200. error: function (msg) {
  201. haoutil.loading.close();
  202. window.toastr.error(msg);
  203. },
  204. });
  205. }
  206. function showResult(data) {
  207. $(".result").show();
  208. var allTime = haoutil.str.formatTime(data.paths[0].allDuration);
  209. var allDistance = haoutil.str.formatLength(data.paths[0].allDistance);
  210. var dhHtml = "";
  211. for (var i = 0; i < data.paths[0].steps.length; i++) {
  212. var item = data.paths[0].steps[i];
  213. dhHtml += item.instruction + ";";
  214. }
  215. $("#useTime").html(allTime);
  216. $("#allDiatance").html(allDistance);
  217. $("#dh").html(dhHtml);
  218. }
  219. </script>
  220. </body>
  221. </html>