zuobiao.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  7. <title></title>
  8. <link rel="stylesheet" href="/assets/amap/main1119.css"/>
  9. <link rel="stylesheet" href="/assets/amap/AMap.DrivingRender1120.css"/>
  10. <script src="/assets/amap/jquery.min.js"></script>
  11. <style>
  12. #container{
  13. width: 100%;
  14. height: 100%;
  15. position:relative;
  16. overflow: hidden;
  17. float: right;
  18. }
  19. /* #tool{
  20. width: 16%;
  21. height: 100%;
  22. overflow: auto;
  23. box-shadow:0 0 14px rgba(0,0,100,.2);
  24. height: 100%;
  25. background-color: white;
  26. float: right;
  27. z-index: 9999;
  28. } */
  29. #tool{
  30. top:30px;
  31. right: 30px;
  32. background-color: white;
  33. z-index: 9999;
  34. position: fixed;
  35. padding: 14px;
  36. }
  37. #tool #closeMouse, #submit{
  38. font-size: 15px;
  39. color:#fff;
  40. background-color: #009BD8;
  41. border: none;
  42. cursor: pointer;
  43. }
  44. #submit{
  45. margin-top: 10px;
  46. }
  47. </style>
  48. <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.3&key=c4aa94e8e82fe1825d3d34d54a0edfb1&plugin=AMap.Driving,AMap.MouseTool,AMap.PolyEditor,AMap.ToolBar"></script>
  49. <script type="text/javascript" src="/assets/amap/DrivingRender1230.js"></script>
  50. <script type="text/javascript" src="/assets/amap/addToolbar.js"></script>
  51. </head>
  52. <body>
  53. <div id="container"></div>
  54. <div id="tool">
  55. <button id="closeMouse">重置</button>
  56. <button id="submit">提交</button>
  57. </div>
  58. <!--
  59. <div id="tool">
  60. <center>
  61. <button id="circle">画圆</button>
  62. <button id="rectangle">矩形</button>
  63. <button id="polygon">多边形</button>
  64. <button id="closeMouse">清除</button>
  65. <button id="testCircle">判断一个点是否在一个圆里</button>
  66. <button id="testPolygon">判断一个点是否在一个多边形里</button>
  67. </center>
  68. </div> -->
  69. <!--
  70. <div id="panel">
  71. </div> -->
  72. <!-- <div style="height: 10%;float: left"> -->
  73. </div>
  74. <script type="text/javascript">
  75. var status;
  76. var map = new AMap.Map("container", {
  77. center: <?php echo json_encode($center); ?>,
  78. // zoom: 8.8,
  79. resizeEnable: true
  80. });
  81. map.plugin(["AMap.ToolBar"],function(){ //在地图中添加ToolBar插件
  82. toolBar = new AMap.ToolBar();
  83. map.addControl(toolBar);
  84. });
  85. // toolBar.hide();
  86. map.plugin(["AMap.MouseTool"],function(){ //鼠标工具插件
  87. mousetool = new AMap.MouseTool(map);
  88. status = 'polygon';
  89. mousetool.polygon();
  90. });
  91. // $('#circle').click(function(){
  92. // status = 'circle';
  93. // mousetool.circle();
  94. // });
  95. // $('#rectangle').click(function(){
  96. // status = 'rectangle';
  97. // mousetool.rectangle();
  98. // });
  99. // $('#polygon').click(function(){
  100. // status = 'polygon';
  101. // mousetool.polygon();
  102. // });
  103. //初始显示多边形
  104. /*var arr = [
  105. [119.355121, 35.535662],
  106. [119.38602, 35.488712],
  107. [119.450565, 35.554099],
  108. [119.450565, 35.554099],
  109. [119.39838, 35.560802],
  110. ];*/
  111. var arr = <?php echo json_encode($zuobiao); ?>;
  112. function createPolygon(arr){
  113. var polygon1 = new AMap.Polygon({
  114. path: arr,
  115. fillColor: '#ACD5F6',
  116. strokeOpacity: 1,
  117. fillOpacity: 0.6,
  118. strokeColor: '#2598FC',
  119. strokeWeight: 2,
  120. // strokeStyle: 'dashed',
  121. // strokeDasharray: [5, 5],
  122. });
  123. map.add(polygon1);
  124. }
  125. createPolygon(arr);
  126. //监听点击事件
  127. AMap.event.addListener(mousetool, 'draw', function(e) {
  128. clearPolygon(); //只能画一次,清空之前
  129. //arr = e.obj.getPath();//获取路径坐标
  130. if(status == 'circle'){
  131. lng = e.obj.getCenter().lng;
  132. lat = e.obj.getCenter().lat;
  133. radius = e.obj.getRadius();
  134. }else if(status == 'polygon' || status == 'rectangle'){
  135. var path = e.obj.getPath();
  136. arr = [];
  137. clearPolygon();
  138. for(var i=0;i<path.length;i++){
  139. arr.push([path[i].lng,path[i].lat]);
  140. }
  141. // console.log(arr);
  142. createPolygon(arr);
  143. }
  144. //console.log(e.obj.getRadius());
  145. //console.log(e.obj);
  146. });
  147. //重置
  148. $('#closeMouse').click(function(){
  149. clearPolygon();
  150. arr=[];
  151. });
  152. function clearPolygon(){
  153. //清空本次多边形
  154. // mousetool.close(false);
  155. // status = 'polygon';
  156. // mousetool.polygon();
  157. // 清空之前多边形
  158. // var polylines = [polygon1];
  159. // map.remove(polylines);
  160. map.clearMap();
  161. }
  162. //提交
  163. $('#submit').click(function(){
  164. if(arr.length ===0){
  165. alert("请绘制多边形区域")
  166. return;
  167. }
  168. console.log("arr===",arr);
  169. //
  170. $.post(
  171. '/admin.php/storezuobiao/zuobiaosubmit',
  172. {
  173. 'id': {$id},
  174. 'zuobiao': JSON.stringify(arr),
  175. },
  176. function(data){
  177. alert('设置成功');
  178. },
  179. );
  180. /*$.ajax({
  181. type: 'POST',
  182. url: 'storetools/zuobiaosubmit',
  183. dataType: 'json',
  184. contentType: "application/json",
  185. data : {
  186. 'id': 4,
  187. 'zuobiao': JSON.stringify(arr),
  188. },
  189. success : function(data){
  190. alert('设置成功');
  191. },
  192. fail:function(data){
  193. alert('11112');
  194. }
  195. })*/
  196. });
  197. // var lat;
  198. // var lng;
  199. // var radius;
  200. // $('#testCircle').click(function(){
  201. // var myLngLat = new AMap.LngLat(116.403984,39.907535);
  202. // var circle = new AMap.Circle({
  203. // center: new AMap.LngLat(lng,lat),// 圆心位置
  204. // radius: radius //半径
  205. // });
  206. // if(circle.contains(myLngLat)){
  207. // alert('在');
  208. // }else{
  209. // alert('不在');
  210. // }
  211. // });
  212. // var arr = [];
  213. // $('#testPolygon').click(function(){
  214. // var myLngLat = new AMap.LngLat(116.403984,39.907535);
  215. // // 定义一个多边形
  216. // var polygon = new AMap.Polygon({
  217. // path: arr
  218. // });
  219. // if(polygon.contains(myLngLat)){
  220. // alert('在');
  221. // }else{
  222. // alert('不在');
  223. // }
  224. // });
  225. </script>
  226. </body>
  227. </html>