lp_map.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. var marker, oDrag = document.getElementById("drag");
  2. // 百度地图API功能
  3. var map = new BMap.Map("allmap"); // 创建Map实例
  4. map.enableScrollWheelZoom(true);
  5. map.addControl(new BMap.ScaleControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT})); // 右下比例尺
  6. map.setDefaultCursor("Default");
  7. var ac = new BMap.Autocomplete( //建立一个自动完成的对象
  8. {"input" : "cityName"
  9. ,"location" : map
  10. });
  11. map.addEventListener("click", showInfo);
  12. function showInfo(e){
  13. map.clearOverlays();
  14. marker = new BMap.Marker(new BMap.Point(e.point.lng, e.point.lat)); // 创建标注
  15. map.addOverlay(marker);
  16. }
  17. //获取经纬度
  18. map.addEventListener("click",function(e){
  19. var input = document.getElementById('wd');
  20. var input2 = document.getElementById('jd');
  21. input.value = e.point.lng;
  22. input2.value= e.point.lat;
  23. });
  24. function show() {
  25. map.centerAndZoom('海南', 13); // 初始化地图,设置城市和地图级别。
  26. oDrag.style.display = "block";
  27. }
  28. // $('#ceshiaaa').on('click',function () {
  29. // var aaa = $(this).prop('class');
  30. // console.log(aaa);
  31. // // trIndex = index; //索引
  32. // // console.log(trIndex);
  33. //
  34. // })
  35. // $('#ceshiaaa').click(function () {
  36. //
  37. // })
  38. function peitaoShow(index,idIndex) {
  39. trIndex = index;
  40. if(idIndex > 0) {
  41. trIndex = idIndex;
  42. trNum.push(trIndex);
  43. }
  44. trNum.push(trIndex);
  45. // console.log($(this));
  46. map.centerAndZoom('海南', 13); // 初始化地图,设置城市和地图级别。
  47. oDrag.style.display = "block";
  48. }
  49. function dhide(){
  50. map.clearOverlays();
  51. document.getElementById("lng").value = '';
  52. document.getElementById("lat").value = '';
  53. oDrag.style.display = "none";
  54. }
  55. // 确认添加经纬度
  56. function showMap(){
  57. oDrag.style.display = "none";
  58. var jd=document.getElementById('jd').value;
  59. var wd=document.getElementById('wd').value;
  60. if(wd==""){
  61. document.getElementById('jwd').value="";
  62. }else {
  63. document.getElementById('jwd').value=wd+','+jd;
  64. }
  65. }
  66. //周边配套
  67. function showMapPeitao(){
  68. oDrag.style.display = "none";
  69. var jd=document.getElementById('jd').value;
  70. var wd=document.getElementById('wd').value;
  71. $.each(trNum,function(v,l){
  72. if(l == trIndex){
  73. if(wd==""){
  74. document.getElementById('jwd'+l).value="";
  75. }else {
  76. document.getElementById('jwd'+l).value=jd+','+wd;
  77. }
  78. }
  79. })
  80. }
  81. var local = new BMap.LocalSearch(map, {
  82. renderOptions:{map: map}
  83. });
  84. var cityList = new BMapLib.CityList({
  85. container: 'container',
  86. map: map
  87. });
  88. function theLocation(){ //查找地址
  89. var city = document.getElementById("cityName").value;
  90. if(city != ""){
  91. local.search(city);
  92. }
  93. };
  94. function KeyDown(e){ //回车查找
  95. var event=arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异
  96. if (event.keyCode==13){
  97. theLocation()
  98. }
  99. }
  100. ac.addEventListener("onhighlight", function(e) { //鼠标放在下拉列表上的事件
  101. var str = "";
  102. var _value = e.fromitem.value;
  103. var value = "";
  104. if (e.fromitem.index > -1) {
  105. value = _value.province + _value.city + _value.district + _value.street + _value.business;
  106. }
  107. str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;
  108. value = "";
  109. if (e.toitem.index > -1) {
  110. _value = e.toitem.value;
  111. value = _value.province + _value.city + _value.district + _value.street + _value.business;
  112. }
  113. str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
  114. // G("searchResultPanel").innerHTML = str;
  115. });
  116. var myValue;
  117. ac.addEventListener("onconfirm", function(e) { //鼠标点击下拉列表后的事件
  118. var _value = e.item.value;
  119. myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
  120. // G("searchResultPanel").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
  121. // setPlace();
  122. theLocation()
  123. });
  124. function setPlace(){
  125. map.clearOverlays(); //清除地图上所有覆盖物
  126. function myFun(){
  127. var pp = local.getResults().getPoi(0).point; //获取第一个智能搜索的结果
  128. map.centerAndZoom(pp, 18);
  129. map.addOverlay(new BMap.Marker(pp)); //添加标注
  130. }
  131. var local = new BMap.LocalSearch(map, { //智能搜索
  132. onSearchComplete: myFun
  133. });
  134. local.search(myValue);
  135. }
  136. //地图弹出层居中
  137. $(window).on("scroll resize",function(){
  138. $("#drag").css({
  139. top: ($(window).height()-$("#drag").outerHeight())/2+$(window).scrollTop(),
  140. left: ($(window).width()-$("#drag").outerWidth())/2+$(window).scrollLeft()
  141. });
  142. });
  143. //滚动输入框提示消失
  144. $(window).on("scroll",function(){
  145. $(".tangram-suggestion-main").hide()
  146. });