index.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. $(function(){
  2. /*变量、对象 定义*/
  3. var on_off = true; //用于重新定位筛选开关
  4. var cityString = new Object();
  5. var page = 1;
  6. /*
  7. * 一、以下为地图页面的功能;
  8. * 1、地图默认进来的时候,获取所有城市以AJAX请求数据,返回所在城市的主推楼盘信息,把返回的数据在地图上显示并在列表中显示所返回楼盘信息;
  9. * 2、点击筛选条件时,把条件存储在对象 dataAjax 对象中并提交,返回的数据遍历在地图上与列表中,筛选的条件内容在条件列表中显示;
  10. * 3、在条件列表中,每删除一个条件都会重新请求一个数据,列表中显示的条件都为再次请求的条件;
  11. * 4、每删除一个条件时,都会在存储对象中删除对应的属性与值;
  12. * 5、输入检索时,去除所有的空格与HMTL标签;
  13. *
  14. */
  15. // 设置地图展示框的高度
  16. var _h = $(window).height();
  17. $('.max_box').css({'height':_h,'position':'relative','top':'-20px'}); //最外层盒子高度
  18. $('#allmap').css('height',_h); //地图高度
  19. $('.m_qhcs_box').css('height',_h); //区域选择盒子高度
  20. // 选择请选择查看区域 选择
  21. $('.m_City_ul_li').on('touchstart','div.m_City_province',function(){
  22. $(this).addClass('on').siblings().removeClass('on'),
  23. on_off = true; //开启重新定位
  24. var _this = $(this);
  25. var txt = _this.text();
  26. var city_id = _this.attr('data-id');
  27. FnAera(city_id); //区域请求数据
  28. page = 1;
  29. $('.batch').fadeOut(); //不喜欢按钮隐藏
  30. $('.map_aera a').html(txt);
  31. $('.m_qhcs_box').animate({top:"-"+_h+"px"});
  32. $('.m_qhcs_box').fadeOut();
  33. })
  34. // 选择区域
  35. $('.map_aera').on('touchstart',function(){
  36. $('.m_qhcs_box').fadeIn();
  37. $('.m_qhcs_box').animate({top:"0px"});
  38. $('.batch').fadeOut(); //不喜欢按钮隐藏
  39. })
  40. // 展示区域数据请求
  41. function FnAera(cityN){
  42. $.ajax({
  43. url:"/map/getcity",
  44. type:"post",
  45. data:{city:cityN,csrf_token_m:csrfToken},
  46. dataType:"json",
  47. success:function(data){
  48. remove_overlay(); // 清除地图上所有的覆盖物 每切换一次都要消除
  49. if(data.code == 200){
  50. $.each(data.data,function(k,v){
  51. labelFu(v);
  52. })
  53. }
  54. },
  55. error:function(request){
  56. console.log('加载失败!');
  57. }
  58. })
  59. }
  60. // 不喜欢换一批
  61. $('.batch').on('touchstart',function(){
  62. ++page;
  63. if(cityString.hasOwnProperty('page')){
  64. page = cityString.page;
  65. delete cityString.page;
  66. }
  67. $('.max_box').append('<div class="load"><img src="/map/image/loading1.gif" alt="" /></div>')
  68. var prov = cityString.city;
  69. fuAjaxLabel(prov,page); // 请求当前城市的数据
  70. })
  71. /*------------------以上为页面功能 * 以下为地图功能----------------------*/
  72. /*
  73. * 二、以下为地图展示模块
  74. * 1、创建地图实例,设置默认位置、城市;
  75. * 2、进入地图时,浏览器获取当前城市,并发出请求;
  76. * 3、自定义显示标签;
  77. * 4、根据返回数据的经纬度,以自定义标签把楼盘信息显示在地图上;
  78. * 5、给地图上每个标签绑定对应楼盘首页地址,点击时跳转楼盘首页;
  79. * 6、
  80. *
  81. */
  82. /*默认初起化数据*/
  83. var currentLocation,cityName,map,point;
  84. var cityObject = {cityName:'海口',cityPoint:{lng:'110.300805',lat:'20.003838'}} //默认初始化位置
  85. // 创建地图
  86. map = new BMap.Map("allmap"); // 创建Map实例
  87. point=new BMap.Point(cityObject.cityPoint.lng,cityObject.cityPoint.lat);
  88. map.centerAndZoom(point, 8); // 初始化地图,设置中心点坐标和地图级别
  89. map.setCurrentCity(cityObject.cityName); // 设置地图显示的城市 此项是必须设置的
  90. map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
  91. var geoc = new BMap.Geocoder();
  92. //添加缩放控件,anchor默认定位 offset 设置偏移值
  93. var top_left_navigation = new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT,offset: new BMap.Size(10, 50)}); //左上角,添加默认缩放平移控件
  94. map.addControl(top_left_navigation);
  95. // 省、市、县覆盖物
  96. function labelFu(data){
  97. var datacenter = data; //数据重新赋值
  98. var text = datacenter.name; //获取城市
  99. // var pid = datacenter.id; //省份iD
  100. var count = datacenter.number; //获取城市楼盘数量
  101. var point = newPoint(datacenter.point);
  102. var _points = new BMap.Point(point[0],point[1]); //经纬度处理
  103. if(on_off){
  104. map.centerAndZoom(_points, 8); //重新定位
  105. on_off = false; //开关,每次检索或筛选要重新定位第一个楼盘位置;
  106. }
  107. // 复杂的自定义覆盖物
  108. /*添加图标*/
  109. function ComplexCustomOverlays(point){
  110. this._point = point;
  111. }
  112. ComplexCustomOverlays.prototype = new BMap.Overlay();
  113. ComplexCustomOverlays.prototype.initialize = function(map){
  114. this._map = map;
  115. var div = this._div = document.createElement("div");
  116. div.style.position = "absolute";
  117. div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);//聚合功能?
  118. div.style.height = "45px";
  119. div.style.width="45px";
  120. div.style.cursor="pointer";
  121. div.style.zIndex = 0;
  122. // div.setAttribute("pointX", this._point.lng);
  123. // div.setAttribute("pointY", this._point.lat);
  124. // div.setAttribute("pid", pid);
  125. // console.log(rank);
  126. var arrow = this._arrow = document.createElement("p");
  127. arrow.style.background = "url(/map/image/yuan1.png) no-repeat 0px 0px/62px 117px";
  128. arrow.style.backgroundPosition = "8px -54px";
  129. arrow.style.width = "70px";
  130. arrow.style.height = "55px";
  131. arrow.style.lineHeight = "20px";
  132. arrow.style.marginTop = "-8px";
  133. arrow.style.textAlign = "center";
  134. arrow.style.top = "30px";
  135. arrow.style.padding = "10px 0";
  136. arrow.style.left = "68px";
  137. arrow.style.color = "#FFF";
  138. arrow.style.fontSize="0.75rem";
  139. // arrow.innerHTML = text;
  140. var _ew = this.arow = document.createElement("em");
  141. _ew.innerHTML = text;
  142. var _arow = this.arow = document.createElement("span");
  143. _arow.style.display = " block";
  144. _arow.innerHTML = count;
  145. arrow.appendChild(_ew);
  146. div.appendChild(arrow);
  147. arrow.appendChild(_arow);
  148. div.onmouseover = function(){
  149. arrow.style.background = "url(/map/image/yuan1.png) no-repeat center/62px 117px";
  150. arrow.style.backgroundPosition = "8px 1px";
  151. this.style.zIndex = 99990;
  152. }
  153. div.onmouseout = function(){
  154. arrow.style.background = "url(/map/image/yuan1.png) no-repeat center/62px 117px";
  155. arrow.style.backgroundPosition = "8px -54px";
  156. this.style.zIndex = 0;
  157. }
  158. /*
  159. * 给覆盖物添加点击事件
  160. */
  161. div.addEventListener("touchstart", function () {
  162. var province = $(this).find('em').text();
  163. on_off = true; //开启重新定位
  164. cityString.city = province;
  165. $('.batch').fadeIn(); //不喜欢按钮显示
  166. fuAjaxLabel(province,page); // 请求当前城市的数据
  167. });
  168. map.getPanes().labelPane.appendChild(div); //getPanes(),返回值:MapPane,返回地图覆盖物容器列表 labelPane呢???
  169. return div;
  170. }
  171. ComplexCustomOverlays.prototype.draw = function(){
  172. var map = this._map;
  173. var pixel = map.pointToOverlayPixel(this._point);
  174. this._div.style.left = pixel.x - parseInt(this._arrow.style.left) + "px";
  175. this._div.style.top = pixel.y - 30 + "px";
  176. }
  177. var myCompOverlay = new ComplexCustomOverlays(_points); //添加覆盖物的经纬度
  178. map.addOverlay(myCompOverlay); //将标注添加到地图中
  179. }
  180. //点击城市获取楼盘数据展示
  181. function fuAjaxLabel(cityName,page){
  182. $.ajax({
  183. url:"/map/houselist",
  184. type:"post",
  185. data:{city:cityName,page:page,csrf_token_m:csrfToken},
  186. dataType:"json",
  187. success:function(data){
  188. setTimeout(function(){
  189. $('.load').remove();
  190. },300);
  191. setTimeout(function(){
  192. if(data.code == 200){
  193. remove_overlay(); // 清除地图上所有的覆盖物 请求成功
  194. /*返回区域主推楼盘先*/
  195. $.each(data.data.data,function(k,v){
  196. addCover(v); //添加覆盖物的方法
  197. })
  198. if(data.data.data.length < 20){
  199. cityString.page = 1;
  200. }
  201. }else if(data.code == 300){
  202. cityString.page = 1;
  203. }
  204. },350);
  205. },
  206. error:function(request){
  207. console.log('加载失败!');
  208. }
  209. })
  210. }
  211. /*市县楼盘展示*/
  212. function addCover(objData){
  213. // console.log(objData)
  214. var pic = objData.price;
  215. var _pic = (pic != '0' && pic != null && pic != '' && pic != 'null' ) ? objData.price : "待定";
  216. var txt = objData.name, mouseoverTxt ="";
  217. var information = objData;
  218. var coordinate = newPoint(objData.longitude_latitude); // 转换经纬度
  219. // console.log(coordinate)
  220. var _point = new BMap.Point(coordinate[0],coordinate[1]);
  221. var myCompOverlay = new ComplexCustomOverlay(_point, txt,mouseoverTxt,information);
  222. map.addOverlay(myCompOverlay);
  223. if(on_off){
  224. map.centerAndZoom(_point, 11); //重新定位
  225. on_off = false; //开关,每次检索或筛选要重新定位第一个楼盘位置;
  226. }
  227. }
  228. // 复杂的自定义覆盖物
  229. function ComplexCustomOverlay(point, text, mouseoverText,information){
  230. this._point = point;
  231. this._text = text;
  232. this._overText = mouseoverText;
  233. this.information = information;
  234. // console.log(this.information.id)
  235. }
  236. ComplexCustomOverlay.prototype = new BMap.Overlay();
  237. ComplexCustomOverlay.prototype.initialize = function(map){
  238. this._map = map;
  239. var div = this._div = document.createElement("div");
  240. div.style.position = "absolute";
  241. div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
  242. div.style.backgroundColor = "#33C0D0";
  243. div.style.border = "1px solid #33C0D0";
  244. div.style.color = "white";
  245. // div.style.height = "18px";
  246. div.style.padding = "5px 15px";
  247. div.style.lineHeight = "18px";
  248. div.style.whiteSpace = "nowrap";
  249. div.style.MozUserSelect = "none";
  250. div.style.fontSize = "12px";
  251. div.setAttribute("class","shadow");
  252. div.setAttribute("pid", this.information.id); //存储ID
  253. var span = this._span = document.createElement("span");
  254. div.appendChild(span);
  255. span.appendChild(document.createTextNode(this._text));
  256. var that = this;
  257. var arrow = this._arrow = document.createElement("div");
  258. arrow.style.background = "url(/map/image/label.png) no-repeat";
  259. arrow.style.position = "absolute";
  260. arrow.style.width = "11px";
  261. arrow.style.height = "10px";
  262. arrow.style.top = "28px";
  263. arrow.style.left = "10px";
  264. arrow.style.backgroundPosition = "0 -19px";
  265. arrow.style.overflow = "hidden";
  266. div.appendChild(arrow);
  267. /*手机端页面添加 点击事件*/
  268. div.addEventListener("touchstart", function(){
  269. var hid = $(this).attr('pid');
  270. FnInfo(hid); //传楼盘ID;
  271. // console.log(hid)
  272. });
  273. div.onmouseover = function(){
  274. this.style.backgroundColor = "#6BADCA";
  275. this.style.borderColor = "#0000ff";
  276. this.getElementsByTagName("span")[0].innerHTML = that._text;
  277. arrow.style.backgroundPosition = "0px -20px";
  278. }
  279. div.onmouseout = function(){
  280. this.style.backgroundColor = "#EE5D5B";
  281. this.style.borderColor = "#BC3B3A";
  282. this.getElementsByTagName("span")[0].innerHTML = that._text;
  283. arrow.style.backgroundPosition = "0px 0px";
  284. }
  285. map.getPanes().labelPane.appendChild(div);
  286. return div;
  287. }
  288. ComplexCustomOverlay.prototype.draw = function(){
  289. var map = this._map;
  290. var pixel = map.pointToOverlayPixel(this._point);
  291. this._div.style.left = pixel.x - parseInt(this._arrow.style.left) + "px";
  292. this._div.style.top = pixel.y - 30 + "px";
  293. }
  294. // 弹窗
  295. function FnInfo(id){
  296. $.ajax({
  297. url:"/map/details",
  298. type:"get",
  299. data:{hid:id},
  300. dataType:"json",
  301. success:function(data){
  302. var v =data.data;
  303. if(data.code == 200){
  304. // 修改数据
  305. var price = '<span style="font-size:1rem;color:red;">待定</span>'
  306. if(v.sale_price != 0 && v.sale_price != "" && v.sale_price != null){
  307. price = '价格:<span><em>'+v.sale_price+'</em><i>'+v.price_unit+'</i></span>';
  308. }
  309. // var main_units = (v.main_units !='') ? v.main_units : '<span style="color:#999;">暂无信息</span>';
  310. $('.w_info_box').find('.w_house_img img').attr('src',v.thumb);
  311. $('.w_info_box').find('.w_house_img > a').attr('href','/house/sanyashi-'+v.id+'/');
  312. $('.w_info_box').find('.w_house_img a > span').html(v.city_name);
  313. $('.w_info_box').find('.w_title').html('<span>'+v.name+'</span>');
  314. // $('.w_info_box').find('.w_map_hu i').html(main_units);
  315. $('.w_info_box').find('.w_price').html(price);
  316. var _li =""
  317. $.each(v.characteristic,function(k,j){
  318. _li += '<i>'+j+'</i>'
  319. })
  320. $('.w_info_box').find('.w_feature').html(_li);
  321. // 特效
  322. $('.w_info_box').fadeIn();
  323. $('.w_info_box').animate({top:'20%'});
  324. $('.cover').fadeIn();
  325. }
  326. },
  327. error:function(request){
  328. console.log('加载失败!');
  329. }
  330. })
  331. }
  332. // 弹窗关闭按钮
  333. $('.w_btn').on('touchstart',function(){
  334. $('.w_info_box').animate({top:'-100%'});
  335. $('.cover').fadeOut();
  336. })
  337. // 遮挡层
  338. $('.cover').on('touchstart',function(){
  339. $('.w_info_box').animate({top:'-100%'});
  340. $(this).fadeOut();
  341. })
  342. //清除覆盖物
  343. function remove_overlay(){
  344. map.clearOverlays();
  345. }
  346. /*转换经纬度*/
  347. function newPoint(_point){
  348. var pointArr = [];
  349. if(_point != null){
  350. if(_point.indexOf(',') !== -1){
  351. var _pointx = _point.split(',')[0];
  352. var _pointy = _point.split(',')[1];
  353. }else if(_point.indexOf('|') !== -1){
  354. var _pointx = _point.split('|')[0];
  355. var _pointy = _point.split('|')[1];
  356. }
  357. pointArr.push(_pointx,_pointy);
  358. return pointArr;
  359. }
  360. }
  361. setInterval(function(){
  362. $('#LXB_CONTAINER_SHOW').hide();
  363. $('#LRMINIBar').hide();
  364. },80);
  365. })