截流自动化的商城平台
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. layui.define(["jquery", "form"], function (exports) {
  2. var center,map,marker,geocoder,address = null;
  3. var obj = {
  4. init: function (init_lat, init_log) {
  5. var lat = 39.9088;
  6. var log = 116.3987;
  7. if(init_log && init_lat){
  8. log = init_log;
  9. lat = init_lat;
  10. }
  11. center = new qq.maps.LatLng(lat, log);
  12. map = new qq.maps.Map("map-container", {
  13. center: center, //设置中心位置
  14. zoom:14, //设置地图缩放级别
  15. draggableCursor : 'https://mapapi.qq.com/web/lbs/javascriptV2/demo/img/c1.cur', //设置鼠标拖拽元素样式
  16. draggingCursor : 'https://mapapi.qq.com/web/lbs/javascriptV2/demo/img/c2.cur' //设置鼠标移动样式
  17. });
  18. if(init_log && init_lat){
  19. marker = new qq.maps.Marker({
  20. position:center,
  21. map:map,
  22. animation: qq.maps.MarkerAnimation.BOUNCE,
  23. icon:'https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/markerNew.png'
  24. });
  25. }
  26. obj.click_map();
  27. obj.search_map();
  28. },
  29. click_map:function () {
  30. //地址和经纬度之间进行转换服务
  31. geocoder = new qq.maps.Geocoder();
  32. // //添加监听事件 获取鼠标点击事件
  33. qq.maps.event.addListener(map, 'click', function(event) {
  34. geocoder.getAddress(event.latLng);
  35. });
  36. //解析地址
  37. geocoder.setComplete(function(result) {
  38. map.setCenter(result.detail.location);
  39. var address_detail = '';
  40. if(result.detail.addressComponents.streetNumber){
  41. address_detail = result.detail.addressComponents.streetNumber
  42. }else{
  43. address_detail = result.detail.addressComponents.street
  44. }
  45. $("input[name='address']").val(address_detail);
  46. //设置标记点
  47. if(!marker) {
  48. marker = new qq.maps.Marker({
  49. position:result.detail.location,
  50. map:map,
  51. animation: qq.maps.MarkerAnimation.BOUNCE,
  52. icon:'https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/markerNew.png'
  53. });
  54. }else{
  55. marker.setPosition(result.detail.location);
  56. }
  57. $("input[name='longitude']").val(result.detail.location.lng);
  58. $("input[name='latitude']").val(result.detail.location.lat);
  59. });
  60. //解析失败
  61. geocoder.setError(function() {
  62. layui.layer.msg("地址解析错误,请重新选择");
  63. });
  64. },
  65. search_map:function () {
  66. $(document).on('click', '#searchMap', function() {
  67. var province_id = $("#province");
  68. var city_id = $("#city");
  69. var district_id = $("#district");
  70. var shop_address = $("input[name='address']").val();
  71. if(province_id.val() === null){
  72. layer.open({icon:2,time:2000,content:"请选择省份"});
  73. return;
  74. }
  75. if(city_id.val() === null){
  76. layer.open({icon:2,time:2000,content:"请选择市"});
  77. return;
  78. }
  79. if(district_id.val() === null){
  80. layer.open({icon:2,time:2000,content:"请选择镇/区"});
  81. return;
  82. }
  83. address = province_id.find("option:selected").text() + city_id.find("option:selected").text() + district_id.find("option:selected").text() + shop_address;
  84. searchService.search(address);
  85. })
  86. var searchService = new qq.maps.SearchService({
  87. complete : function(results){
  88. if(results.type === "CITY_LIST") {
  89. searchService.setLocation(results.detail.cities[0].cityName);
  90. searchService.search(address);
  91. return;
  92. }
  93. var pois = results.detail.pois;
  94. var latlngBounds = new qq.maps.LatLngBounds();
  95. for(var i = 0,l = pois.length;i < l; i++){
  96. var poi = pois[i];
  97. latlngBounds.extend(poi.latLng);
  98. var markers = new qq.maps.Marker({
  99. map:map,
  100. position: poi.latLng,
  101. icon:'https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/markerDefault.png'
  102. });
  103. markers.setTitle(poi.name);
  104. }
  105. map.fitBounds(latlngBounds);
  106. }
  107. });
  108. }
  109. };
  110. exports("txMap", obj);
  111. });