mapDrivingTrack.cshtml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  4. <title>轨迹回放</title>
  5. <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main.css" />
  6. <link href="~/Content/js/laydate/theme/default/laydate.css" rel="stylesheet" />
  7. <link href="~/Content/js/layui/css/layui.css" rel="stylesheet" />
  8. <script src="http://webapi.amap.com/maps?v=1.3&key=fa36ec6323075f37020083ceffe8eb24"></script>
  9. <script src="~/Content/js/jquery/jquery-1.8.2.min.js"></script>
  10. <script src="~/Content/js/layui/layui.js"></script>
  11. <script src="~/Content/js/laydate/laydate.js"></script>
  12. <style>
  13. #mapContainer {
  14. height: 88%;
  15. width: 98%;
  16. margin: 5px auto;
  17. position: relative;
  18. border: 2px solid rgb(255,255,255)
  19. }
  20. .circle {
  21. border-radius: 50%;
  22. width: 200px;
  23. height: 200px;
  24. /* 宽度和高度需要相等 */
  25. }
  26. #button1 {
  27. width: 100px;
  28. height: 30px;
  29. font-size: 18px;
  30. font-family: 微软雅黑;
  31. letter-spacing: 8px;
  32. padding-left: 12px;
  33. border-radius: 5px;
  34. background: -webkit-linear-gradient(top, #66B5E6, #2e88c0);
  35. background: -moz-linear-gradient(top, #66B5E6, #2e88c0);
  36. background: linear-gradient(top, #66B5E6, #2e88c0);
  37. background: -ms-linear-gradient(top, #66B5E6, #2e88c0);
  38. border: 1px solid #2576A8;
  39. box-shadow: 0 1px 2px #B8DCF1 inset, 0 -1px 0 #316F96 inset;
  40. color: #fff;
  41. text-shadow: 1px 1px 0.5px #22629B;
  42. }
  43. #button1:hover {
  44. background: -webkit-linear-gradient(top, #8DC9EF, #4E9FD1);
  45. background: -moz-linear-gradient(top, #8DC9EF, #4E9FD1);
  46. background: linear-gradient(top, #8DC9EF, #4E9FD1);
  47. background: -ms-linear-gradient(top, #8DC9EF, #4E9FD1);
  48. }
  49. .form-control {
  50. width: 30%;
  51. height: 34px;
  52. padding: 6px 12px;
  53. font-size: 14px;
  54. line-height: 1.428571429;
  55. color: #555555;
  56. vertical-align: middle;
  57. background-color: #ffffff;
  58. border: 1px solid #cccccc;
  59. border-radius: 4px;
  60. -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
  61. box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
  62. -webkit-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
  63. transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
  64. }
  65. .form-control:focus {
  66. border-color: #66afe9;
  67. outline: 0;
  68. -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);
  69. box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6);
  70. }
  71. </style>
  72. <body class="bg">
  73. <div class="main_layout">
  74. <!-- 标题 -->
  75. <div class="title">
  76. <form>
  77. <label>起始时间:</label>
  78. <input id="startdate" class="form-control" type="text" />
  79. <label>结束时间:</label>
  80. <input id="enddate" class="form-control" type="text" />
  81. <input type="button" id="button1" class="btn" value="搜索">
  82. </form>
  83. </div>
  84. <!-- 地图 -->
  85. <div id="mapContainer"></div>
  86. </div>
  87. <script>
  88. layui.use('laydate', function () {
  89. var laydate = layui.laydate;
  90. //日期时间选择器
  91. laydate.render({
  92. elem: '#startdate'
  93. , type: 'datetime'
  94. });
  95. //日期时间选择器
  96. laydate.render({
  97. elem: '#enddate'
  98. , type: 'datetime'
  99. });
  100. });
  101. var map; var urlstr = "http://" + window.location.host + "/";
  102. $(function () {
  103. init();
  104. getAjax("","", "@ViewData["carid"]","");
  105. //绑定事件
  106. $(".title input[type='button']").click(submitSerch);
  107. });
  108. var submitSerch = function () {
  109. var reg = /^([0-9]|[\-])*$/;
  110. var start = $("#startdate").val().trim();
  111. var end = $("#enddate").val().trim();
  112. var name = "@ViewData["carid"]";
  113. //var ehr = $(".ehr").val().trim();
  114. debugger;
  115. if (start) {
  116. getAjax(start, end, name, "");
  117. }
  118. };
  119. function getAjax(start, end, name, ehr) {
  120. $.ajax({
  121. url: urlstr + "sys/Account/getVehicleTrajectory?start=" + start + "&end=" + end + "&carid=" + name,
  122. type: "get",
  123. dataType: "json",
  124. success: function (data) {
  125. //debugger;
  126. //alert(data);
  127. //初始化请求
  128. if (data != null && data.status == 1) {
  129. var result = data.result;
  130. if (result.length == 0) {
  131. alert("抱歉,当前没有行车轨迹记录!");
  132. }
  133. //清楚显示
  134. map.clearMap();
  135. line(result);
  136. // addMarker(result);
  137. } else {
  138. alert("没有行车轨迹记录");
  139. }
  140. },
  141. });
  142. }
  143. function init() {
  144. //创建地图对象
  145. map = new AMap.Map("mapContainer", {
  146. resizeEnable: true,
  147. zoom: 7,
  148. mapStyle: "light"
  149. });
  150. //加载缩放条事件
  151. map.plugin(["AMap.ToolBar"], function () {
  152. toolBar = new AMap.ToolBar();
  153. map.addControl(toolBar);
  154. });
  155. }
  156. function line(data) {
  157. var lineArr = new Array();
  158. $.each(data, function (index, value) {
  159. //debugger;
  160. //var array = (value.position).split(",");
  161. //lineArr.push(new AMap.LngLat(parseFloat(array[1]), parseFloat(array[0])));
  162. //var array = (value.position).split(",");
  163. //加上带有时间的图标标记
  164. //var marker_jz = new AMap.Marker({
  165. // map: map,
  166. // //content: '<div class=\"circle\"></div>', //
  167. // content: '<div class=\"maplocation_red\">' + (index + 1) + '</div>',
  168. // position: new AMap.LngLat(value.lng, value.lat),
  169. // offset: new AMap.Pixel(-3, -3) //相对于基点的位置
  170. //});
  171. lineArr.push(new AMap.LngLat(parseFloat(value.lng), parseFloat(value.lat)));
  172. });
  173. // 绘制轨迹
  174. var polyline = new AMap.Polyline({
  175. map: map,
  176. path: lineArr,
  177. strokeColor: "rgb(104,180,255)", //线颜色
  178. strokeOpacity: 1, //线透明度
  179. strokeWeight: 2, //线宽
  180. strokeStyle: "solid", //线样式
  181. geodesic: true
  182. });
  183. map.setFitView();
  184. }
  185. function addMarker(data) {
  186. $.each(data, function (index, value) {
  187. //var array = (value.position).split(",");
  188. var p0 = parseFloat(value.lng);
  189. var p1 = parseFloat(value.lat);
  190. var action = "AMAP_ANIMATION_DROP";
  191. var point = new AMap.LngLat(p0, p1);
  192. var marker = new AMap.Marker({
  193. id: index,
  194. map: map,
  195. position: point,
  196. //icon: urlstr + "Content/map/tlj.png",
  197. autoRotation: true,
  198. animation: action
  199. });
  200. createInfoWindow(value, marker);
  201. });
  202. }
  203. function createInfoWindow(value, marker) {
  204. var info = [];
  205. /* info.push("<a href='/emplpyer/task/get/"+value.id+"' target='main' ><div style='font-weight:bold;color:#000;font-family:'微软雅黑';text-align:center;font-size:'><div><img src='http://wiscc6911.qnoddns.org.cn:8400/file/web/download/10143.jpg' width='80' height='80'> "); */
  206. info.push("经纬度: " + value.lng + "," + value.lat + "");
  207. info.push("时间 : " + value.taskTime + "");
  208. //info.push("地址 :" + value.taskAddress + "</div></div></a>");
  209. var iw = new AMap.InfoWindow({
  210. content: info.join("<br>"),
  211. offset: new AMap.Pixel(0, -25),
  212. isCustom: false,
  213. autoMove: true
  214. });
  215. AMap.event.addListener(marker, "mouseover", function (e) {
  216. iw.open(map, marker.getPosition());
  217. });
  218. }
  219. </script>
  220. </body>
  221. </html>