Ei kuvausta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

map.htm 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  6. <link rel="stylesheet" href="__PUBLIC__/plugins/layui/css/layui.css?v={$version}">
  7. <title>地图标注</title>
  8. <style>
  9. #map{width:100%;height:800px;}
  10. .layui-form-item{position:absolute;top:10px;z-index: 999999;}
  11. </style>
  12. </head>
  13. <body>
  14. <div class="layui-form-item">
  15. <div class="layui-inline">
  16. <label class="layui-form-label"></label>
  17. <div class="layui-input-inline" style="width: 220px;">
  18. <input name="keyword" id="keyword" type="text" placeholder="输入地址搜索,可以移动标注点" title="输入地址搜索,可以移动标注点更改位置确定保存" class="layui-input" autocomplete="off" size="25" value="{$field.mapConf.keyword}" />
  19. </div>
  20. <input type="hidden" id="alladdress" value="">
  21. <button class="layui-btn layui-btn-normal" id="search">搜索</button>
  22. <button class="layui-btn layui-btn-danger" id="sure">确定</button>
  23. <form class="form-horizontal" id="post_form" onsubmit="return check_submit();">
  24. <input type="hidden" name="location" id="location" value="{$field.mapConf.lng},{$field.mapConf.lat}">
  25. <input type="hidden" name="zoom" id="zoom" value="{$field.mapConf.zoom|default='13'}">
  26. <input type="hidden" name="id" value="{$field.id|default=''}">
  27. <input type="hidden" name="type" value="{$field.type|default=''}">
  28. <input type="hidden" name="page" value="{$field.page|default=''}">
  29. <input type="hidden" name="v" value="{$v|default='pc'}">
  30. <input type="hidden" name="lang" value="{$field.lang|default='cn'}">
  31. <input type="hidden" name="idcode" value="{$field.idcode|default=''}">
  32. </form>
  33. </div>
  34. </div>
  35. <div id="map">
  36. </div>
  37. <script src="__PUBLIC__/plugins/layui/layui.js?v={$version}"></script>
  38. <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak={$field.mapConf.ak}"></script>
  39. <script type="text/javascript">
  40. // 百度地图API功能
  41. var lng = "{$field.mapConf.lng}",lat = "{$field.mapConf.lat}",keyword = "{$field.mapConf.keyword}";
  42. var map = new BMap.Map("map",{enableMapClick:false});
  43. // 创建地址解析器实例
  44. var myGeo = new BMap.Geocoder();
  45. if(lng*1 && lat*1)
  46. {
  47. var point = new BMap.Point(lng,lat);
  48. map.centerAndZoom(point, 15);
  49. var marker = new BMap.Marker(point);// 创建标注
  50. map.addOverlay(marker); // 将标注添加到地图中
  51. marker.enableDragging(); // 可拖拽
  52. marker.addEventListener('dragend',getMarkerPoint);
  53. getMarkerPoint(point);
  54. }else{
  55. //new BMap.Point(110.211023,20.007536);
  56. // map.centerAndZoom(keyword,14);
  57. // 将地址解析结果显示在地图上,并调整地图视野
  58. myGeo.getPoint(keyword, function(point){
  59. if (point) {
  60. map.centerAndZoom(point, 15);
  61. var marker = new BMap.Marker(point);
  62. map.addOverlay(marker);
  63. marker.enableDragging(); // 可拖拽
  64. marker.addEventListener('dragend',getMarkerPoint);
  65. getMarkerPoint(point);
  66. }
  67. }, "海口市");
  68. }
  69. map.addControl(new BMap.NavigationControl());
  70. map.enableScrollWheelZoom(true);
  71. map.addEventListener("zoomend", function(e){
  72. var zoom = map.getZoom();
  73. document.getElementById('zoom').value = zoom;
  74. });
  75. window.onload = function(){
  76. var h = document.documentElement.clientHeight - 20;
  77. document.getElementById('map').style.height = h+'px';
  78. };
  79. function getMarkerPoint(e)
  80. {
  81. //通过点击百度地图,可以获取到对应的point, 由point的lng、lat属性就可以获取对应的经度纬度
  82. var pot = '';
  83. if (!e.point) {
  84. pot = e;
  85. } else {
  86. pot = e.point;
  87. }
  88. myGeo.getLocation(pot, function(rs){
  89. //addressComponents对象可以获取到详细的地址信息
  90. var addComp = rs.addressComponents;
  91. var alladdress = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber;
  92. document.getElementById("alladdress").value = alladdress; //详细地址
  93. document.getElementById("location").value = pot.lng + ',' + pot.lat; // 经度 纬度
  94. });
  95. }
  96. </script>
  97. <script>
  98. layui.use(['layer','jquery'], function(){
  99. var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
  100. $(document).keydown(function(event){
  101. if(event.keyCode ==13){
  102. $('#search').trigger("click");
  103. }
  104. });
  105. $("#search").on('click',function(){
  106. var keyword = $("#keyword").val();
  107. var url = "{:url('api/Uiset/mapGetLocationByAddress')}";
  108. var param = {
  109. address : keyword,
  110. _ajax:1,
  111. };
  112. $.get(url,param,function(res){
  113. if(res.code == 1)
  114. {
  115. map.clearOverlays();
  116. var point = new BMap.Point(res.data.lng,res.data.lat);
  117. map.centerAndZoom(point, 15);
  118. var marker = new BMap.Marker(point);// 创建标注
  119. map.addOverlay(marker);
  120. marker.enableDragging();
  121. marker.addEventListener('dragend',getMarkerPoint);
  122. getMarkerPoint(point);
  123. }
  124. });
  125. });
  126. var parentObj = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  127. $("#sure").on('click',function(){
  128. if ($('input[name=id]').val() == '' || $('input[name=id]').val() == undefined || $('input[name=type]').val() == '' || $('input[name=page]').val() == '') {
  129. parent.showErrorMsg('缺少系统参数:id、type、page,尝试请求技术支持!');
  130. return false;
  131. }
  132. layer_loading('正在处理');
  133. var url = "{:url('api/Uiset/submit', ['_ajax'=>1])}";
  134. $.ajax({
  135. url: url,
  136. type: 'POST',
  137. dataType: 'JSON',
  138. data: $('#post_form').serialize(),
  139. success: function(res){
  140. layer.closeAll();
  141. if (res.code == 1) {
  142. var _parent = parent;
  143. _parent.layer.close(parentObj);
  144. _parent.layer.msg(res.msg, {icon: 1, shade: 0.3, time: 1000}, function(){
  145. _parent.window.location.reload();
  146. });
  147. } else {
  148. parent.eyou_showErrorAlert(res.msg);
  149. }
  150. },
  151. error: function(e){
  152. layer.closeAll();
  153. parent.eyou_showErrorAlert(e.responseText);
  154. }
  155. });
  156. });
  157. /**
  158. * 封装的加载层
  159. */
  160. function layer_loading(msg){
  161. var loading = layer.msg(
  162. msg+'...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请勿刷新页面',
  163. {
  164. icon: 1,
  165. time: 3600000,
  166. shade: [0.2]
  167. });
  168. var index = layer.load(3, {
  169. shade: [0.1,'#fff']
  170. });
  171. return loading;
  172. }
  173. });
  174. </script>
  175. </body>
  176. </html>