map - 副本 (2).js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. //地图盒子的高度
  2. var windheight=$(window).height();
  3. var divheight=$('.y_maphead').height();
  4. var navheight=$('.y_puicdh_c').height();
  5. var windwidth=$(window).width();
  6. var divwidth=$('.y_mapcenter_left').width();
  7. var _height= windheight-300;
  8. $('.y_mapcenter_list').css('height',_height)
  9. $('.y_mapcenter').css({'height':(windheight-divheight-navheight)+'px'});
  10. $('.y_mapcenter_main').css({'width':(windwidth-divwidth-20)+'px'});
  11. // $('.y_mapcond_main .y_mapcond_right span a').hide();
  12. // 地图找房 区域效果
  13. var dataID={};
  14. var dataTitle={};
  15. $(function(){
  16. /*----------------------------------检索------------------------------------------------*/
  17. /* 搜索框检索 */
  18. var text; //用于存放检索内容
  19. var _txt=''; //用于存放点击搜索之前的值 用意在于不能每点击或回车一次发送请求
  20. var dataTxt = {};
  21. $('.y_maptop_scr').keyup(function(event) {
  22. if(event.keyCode==13){
  23. fuInput();
  24. }
  25. });
  26. /* 点击搜索按钮 */
  27. $('.y_maptop_sub').click(function(){
  28. fuInput();
  29. });
  30. /* 获取input框的值 */
  31. function fuInput(){
  32. var txt = $('.y_maptop_scr').val().replace(/\s/g,""); //获取input 内容并去掉所有的空格
  33. if(txt !== _txt){
  34. _txt=txt;
  35. dataTxt.content=_txt;
  36. $('.y_mapcond_right').html(""); //清空里面所有的标签
  37. getData(1,dataTxt,false);
  38. $('.y_mapcenter_list ul li').eq(0).click();
  39. }
  40. }
  41. /*----------------------------------筛选--------------------------------------------------*/
  42. // 区域、预算、户型、特色点击获取筛选条件
  43. $('.y_maptop_sel .y_leixing').on('click','a',function(){
  44. var _type = $(this).attr('data-type');
  45. var _thisID = $(this).attr('data-id');
  46. var _thisTitle = $(this).text();
  47. $(this).parents('.y_maptop_sel').find('.dataText').html(_thisTitle);
  48. switch(_type)
  49. {
  50. case "city":
  51. dataID.city=_thisID;
  52. dataTitle.city = _thisTitle;
  53. break;
  54. case "price":
  55. dataID.price= _thisTitle;
  56. // _thisID;
  57. dataTitle.price = _thisTitle;
  58. break;
  59. case "houseType":
  60. dataID.houseType=_thisID;
  61. dataTitle.houseType = _thisTitle;
  62. break;
  63. case "trait":
  64. dataID.trait=_thisID;
  65. dataTitle.trait = _thisTitle;
  66. break;
  67. }
  68. getData(1,dataID); //选择筛选条件时候,把条件通过Ajax提交返回数据
  69. // console.log(dataID);
  70. //筛选条件的显示
  71. var _htm="";
  72. for(i in dataTitle){
  73. _htm +='<span class="yusuan"><em>'+ dataTitle[i] +'</em><a data-type="'+i+'" href="javascript:;"><img src="/map/image/ico_map4.png" alt=""></a></span>';
  74. }
  75. $('.y_mapcond_right').html("");
  76. $('.y_mapcond_right').append(_htm); //插入前先进行清空再插入
  77. })
  78. // 显示筛选条件处的删除功能
  79. var module = {city:"区域",price:"价格",houseType:"户型",trait:"特色"};
  80. $('.y_mapcond_right').on('click','.yusuan a',function(){
  81. var property = $(this).attr('data-type');
  82. //删除对象中的数据
  83. delete dataID[property];
  84. delete dataTitle[property];
  85. // 实现删除当前标签时,对应的数据修改为默认值
  86. $('.dataText[data-id="'+property+'"]').html(module[property]);
  87. $(this).parent('.yusuan').remove(); //删除当前的标签内容
  88. getData(1,dataID); //选择筛选条件时候,把条件通过Ajax提交返回数据
  89. })
  90. //清空条件
  91. $('.y_mapcond_left').on('click',function(){
  92. dataID={}; //清空对象
  93. dataTitle={}; //清空对象
  94. $('.y_mapcond_right').html(""); //清空里面所有的标签
  95. //把所有的筛选条件修改为默认值
  96. for(i in module){
  97. $('.dataText[data-id="'+i+'"]').html(module[i]);
  98. }
  99. getData(1,dataID); //选择筛选条件时候,把条件通过Ajax提交返回数据
  100. })
  101. //区域 点击筛选
  102. $('#y_maptop_sel1 .y_left a').on('click',function(){
  103. var cyit=$(this).attr('city');
  104. var sjtitle=$(this).text();
  105. $(this).css({'color':'#f00'}).siblings().css({'color':'#666'});
  106. $('#y_maptop_sel1 p.y_right').attr('sj-city',''+sjtitle+'')
  107. $.post('/map/pidcity',{id:cyit,'csrf_token_f':csrfToken},function(data){
  108. var echodataUl = $('#y_maptop_sel1 p.y_right');
  109. echodataUl.html('');
  110. var data = data.data;
  111. var html = '';
  112. $.each(data,function(key,val){
  113. html ='<a data-type="city" data-id="'+val.id+'" href="javascript:;">';
  114. html+=''+val.city_name+'';
  115. html+='</a>';
  116. echodataUl.append(html);
  117. })
  118. })
  119. });
  120. // 区域 预算 户型 特色 显示隐藏
  121. navMouseleave(".y_maptop_sel");
  122. })
  123. /* 显示隐藏方法封装 */
  124. function navMouseleave (oid){
  125. $(oid).on({
  126. mouseover: function() {
  127. $(this).find('.y_qysf').show();
  128. },
  129. mouseleave: function() {
  130. $(this).find('.y_qysf').hide();
  131. }
  132. });
  133. }
  134. /*
  135. * 区域点击事件,当点击某个区域时,跳转到相应的区域位置
  136. */
  137. $('#y_maptop_sel1 .y_left a').on('click',function(){
  138. $('#y_maptop_sel1 p.y_city span').text($(this).text());
  139. var post=$(this).attr('post')
  140. var _point = newPoint(post);
  141. point=new BMap.Point(_point[0],_point[1]);
  142. mp.centerAndZoom(point, 8);
  143. mp.enableScrollWheelZoom();
  144. // lplist();
  145. })
  146. /*------------------------------------百度地图----------------------------------------------------------------------*/
  147. var mp = new BMap.Map("allmap",{minZoom:5,maxZoom:16});
  148. mp.addControl(new BMap.OverviewMapControl()); //添加默认缩略地图控件
  149. // mp.addControl(new BMap.OverviewMapControl({isOpen:true, anchor: BMAP_ANCHOR_BOTTOM_RIGHT})); //右下角,打开
  150. mp.addControl(new BMap.ScaleControl()); // 添加默认比例尺控件
  151. mp.addControl(new BMap.ScaleControl({anchor: BMAP_ANCHOR_BOTTOM_LEFT})); // 左下
  152. mp.addControl(new BMap.NavigationControl()); //添加默认缩放平移控件
  153. mp.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_LEFT, type: BMAP_NAVIGATION_CONTROL_SMALL})); //右上角,仅包含平移和缩放按钮
  154. // point=new BMap.Point(110.483789,19.119914);
  155. point=new BMap.Point(106.367394,34.111821);
  156. mp.centerAndZoom(point, 5);
  157. mp.enableScrollWheelZoom();
  158. var geoc = new BMap.Geocoder();
  159. // console.log(geoc);
  160. // 复杂的自定义覆盖物
  161. function ComplexCustomOverlays(point, text, mouseoverText){
  162. this._point = point;
  163. this._text = text;
  164. this._overText = mouseoverText;
  165. }
  166. ComplexCustomOverlays.prototype = new BMap.Overlay();
  167. ComplexCustomOverlays.prototype.initialize = function(map){
  168. this._map = map;
  169. var div = this._div = document.createElement("div");
  170. div.style.position = "absolute";
  171. div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
  172. var span = this._span = document.createElement("span");
  173. var that = this;
  174. var arrows = this._arrows = document.createElement("div");
  175. arrows.style.background = "url(../map/image/ico_map9.png) no-repeat";
  176. arrows.style.position = "absolute";
  177. arrows.style.width = "24px";
  178. arrows.style.height = "28px";
  179. arrows.style.top = "10px";
  180. arrows.style.left = "0px";
  181. arrows.style.overflow = "hidden";
  182. arrows.style.cursor = "default";
  183. div.appendChild(arrows);
  184. div.onmouseover = function(){
  185. this.style.background = "url(../map/image/ico_map9.png) no-repeat";
  186. arrows.style.backgroundPosition = "0px -35px";
  187. this.style.zIndex = 999999;
  188. // this.style.cursor="pointer";
  189. }
  190. div.onmouseout = function(){
  191. this.style.background = "url(../map/image/ico_map9.png) no-repeat";
  192. arrows.style.backgroundPosition = "0px 0px";
  193. this.style.zIndex = 0;
  194. }
  195. mp.getPanes().labelPane.appendChild(div);
  196. return div;
  197. }
  198. ComplexCustomOverlays.prototype.draw = function(){
  199. var map = this._map;
  200. var pixel = map.pointToOverlayPixel(this._point);
  201. this._div.style.left = pixel.x - parseInt(this._arrows.style.left) - 8 + "px";
  202. this._div.style.top = pixel.y - 35+ "px";
  203. };
  204. ComplexCustomOverlays.prototype.addEventListener = function(event,fun){
  205. this._div['on'+event] = fun;
  206. };
  207. /*---------------------------------------新添加的省、区域-------------------------------------------------------------*/
  208. function labelFu(data){
  209. var datacenter = data; //数据重新赋值
  210. var rank = datacenter.rank; //获取级别
  211. var text = datacenter.city; //获取城市
  212. var pid = datacenter.pid; //省份iD
  213. var count = datacenter.count; //获取城市楼盘数量
  214. var point = newPoint(datacenter.point);
  215. var _points = new BMap.Point(point[0],point[1]); //经纬度处理
  216. // 复杂的自定义覆盖物
  217. /*添加图标*/
  218. function ComplexCustomOverlay(point){
  219. this._point = point;
  220. }
  221. ComplexCustomOverlay.prototype = new BMap.Overlay();
  222. ComplexCustomOverlay.prototype.initialize = function(map){
  223. this._map = map;
  224. var div = this._div = document.createElement("div");
  225. div.style.position = "absolute";
  226. div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);//聚合功能?
  227. div.style.height = "45px";
  228. div.style.width="45px";
  229. div.style.cursor="pointer";
  230. div.style.zIndex = 0;
  231. div.setAttribute("pointX", this._point.lng);
  232. div.setAttribute("pointY", this._point.lat);
  233. div.setAttribute("rank", rank);
  234. div.setAttribute("pid", pid);
  235. // console.log(rank)
  236. var arrow = this._arrow = document.createElement("p");
  237. arrow.style.background = "url(/image/yuan.png) no-repeat 0px 0px/55px 110px";
  238. arrow.style.backgroundPosition = "0px 0x";
  239. arrow.style.width = "55px";
  240. arrow.style.height = "55px";
  241. arrow.style.lineHeight = "20px";
  242. arrow.style.textAlign = "center";
  243. arrow.style.top = "30px";
  244. arrow.style.padding = "10px 0";
  245. arrow.style.left = "30px";
  246. // arrow.innerHTML = text;
  247. var _ew = this.arow = document.createElement("em");
  248. _ew.innerHTML = text;
  249. var _arow = this.arow = document.createElement("span");
  250. _arow.style.display = " block";
  251. _arow.innerHTML = count;
  252. arrow.appendChild(_ew);
  253. div.appendChild(arrow);
  254. arrow.appendChild(_arow);
  255. div.onmouseover = function(){
  256. arrow.style.background = "url(/image/yuan.png) no-repeat center/55px 110px";
  257. arrow.style.backgroundPosition = "0px -55px";
  258. this.style.zIndex = 99990;
  259. }
  260. div.onmouseout = function(){
  261. arrow.style.background = "url(/image/yuan.png) no-repeat center/55px 110px";
  262. arrow.style.backgroundPosition = "0px 0px";
  263. this.style.zIndex = 0;
  264. }
  265. /*
  266. * 给覆盖物添加点击事件
  267. */
  268. div.addEventListener("click", function () {
  269. /*获取当前的经纬度*/
  270. var _x = $(this).attr("pointX");
  271. var _y = $(this).attr("pointY");
  272. Apoint=new BMap.Point(_x,_y);
  273. /*获取级别*/
  274. var _rank = $(this).attr("rank");
  275. var _pid = $(this).attr("pid");
  276. var mapRank = 14;
  277. if(_rank == 1){
  278. mapRank = 10;
  279. fuAjaxRegion(_pid); // 把区域遍历
  280. // getData(1,_pid); //选择筛选条件时候,把条件通过Ajax提交返回数据
  281. }else if(_rank == 2){
  282. mapRank = 15;
  283. fuAjaxLabel(_pid);
  284. // getData(1,_pid); //选择筛选条件时候,把条件通过Ajax提交返回数据
  285. }
  286. // console.log(Apoint)
  287. mp.centerAndZoom(Apoint, mapRank); // 点击当前覆盖物跳转到当前省份上,放大到10级
  288. mp.clearOverlays(); // 清除地图上所有的覆盖物
  289. // 获取当省份
  290. var province = $(this).find('em').text();
  291. // console.log(province)
  292. });
  293. mp.getPanes().labelPane.appendChild(div); //getPanes(),返回值:MapPane,返回地图覆盖物容器列表 labelPane呢???
  294. return div;
  295. }
  296. ComplexCustomOverlay.prototype.draw = function(){
  297. var map = this._map;
  298. var pixel = map.pointToOverlayPixel(this._point);
  299. this._div.style.left = pixel.x - parseInt(this._arrow.style.left) + "px";
  300. this._div.style.top = pixel.y - 30 + "px";
  301. }
  302. var myCompOverlay = new ComplexCustomOverlay(_points); //添加覆盖物的经纬度
  303. mp.addOverlay(myCompOverlay); //将标注添加到地图中
  304. }
  305. /*遍历所有省份*/
  306. function fuAjax(){
  307. $.ajax({
  308. url:"/map/province",
  309. type:"GET",
  310. dataType:"json",
  311. success:function(data){
  312. if(data.code == 200){
  313. // console.log(data.data)
  314. $.each(data.data,function(key,val){
  315. labelFu(val);
  316. })
  317. }
  318. },
  319. error:function(request){
  320. console.log('加载失败!');
  321. }
  322. })
  323. };
  324. fuAjax();
  325. /*遍历所有区域*/
  326. function fuAjaxRegion(pid =null){
  327. $.ajax({
  328. url:"/map/city",
  329. type:"GET",
  330. data:{pid:pid},
  331. dataType:"json",
  332. success:function(data){
  333. if(data.code == 200){
  334. // console.log(data.region)
  335. $.each(data.data,function(key,val){
  336. labelFu(val);
  337. })
  338. }
  339. },
  340. error:function(request){
  341. console.log('加载失败!');
  342. }
  343. })
  344. };
  345. // fuAjaxRegion();
  346. /*
  347. * 新添加标注物
  348. */
  349. function fuAjaxLabel(pid =null){
  350. $.ajax({
  351. url:"/map/cityhouse",
  352. type:"GET",
  353. data:{pid:pid},
  354. dataType:"json",
  355. success:function(data){
  356. if(data.code == 200){
  357. $.each(data.data,function(key,val){
  358. var point = newPoint(val.point); //把经纬度进行转化
  359. var _points = new BMap.Point(point[0],point[1]); //经纬度处理
  360. var txt = "",mouseoverTxt="";
  361. var _iw = createInfoWindow(val); //把当前的数据添加到标签中
  362. var o = scope(_points);
  363. if(o != undefined){
  364. var myCompOverlay = new ComplexCustomOverlays(o,txt, mouseoverTxt); //将覆盖物存到变量,以便下面使用。
  365. mp.addOverlay(myCompOverlay); //把标签到地图上
  366. myCompOverlay.addEventListener("click", function () { //点击出现对应自定义覆盖物
  367. mp.openInfoWindow(_iw, _points) // 点击标签弹出标签
  368. });
  369. }
  370. })
  371. }
  372. },
  373. error:function(request){
  374. console.log('加载失败!');
  375. }
  376. })
  377. }
  378. /*监听地图移动事件*/
  379. mp.addEventListener("dragend", function(e){
  380. // var delta = -e.originalEvent.wheelDelta || e.originalEvent.detail;//firefox使用detail:下3上-3,其他浏览器使用wheelDelta:下-120上120
  381. // e=e || window.event;
  382. var u = mp.getZoom(); // 定义地图缩放等级的变量
  383. if(u>12){
  384. var center =mp.getCenter();
  385. mp.clearOverlays(); //清除地图上所有的覆盖物
  386. fuAjaxLabel();
  387. }
  388. })
  389. /*获取可视区域*/
  390. function scope(_point){
  391. var bs = mp.getBounds(); //获取可视区域
  392. var bssw = bs.getSouthWest(); //可视区域左下角
  393. var bsne = bs.getNorthEast(); //可视区域右上角
  394. // console.log(1)
  395. if(_point.lng >= bssw.lng && _point.lng <= bsne.lng && _point.lat >= bssw.lat && _point.lat <= bsne.lat ){
  396. // console.log(_point)
  397. return _point
  398. }
  399. // console.log("当前地图可视范围是:" + bssw.lng + "," + bssw.lat + "到" + bsne.lng + "," + bsne.lat);
  400. }
  401. // 方法2:用于监听滚轮事件
  402. //firefox使用DOMMouseScroll,其他浏览器使用mousewheel
  403. $('#allmap').bind('mousewheel DOMMouseScroll',fullscreenScroll);
  404. function fullscreenScroll(e){
  405. var u = mp.getZoom(); // 定义地图缩放等级的变量
  406. console.log(u)
  407. if(u>6 && u <= 9){
  408. mp.clearOverlays(); //清除地图上所有的覆盖物
  409. fuAjax();
  410. }else if(u > 9 && u <= 11) {
  411. fuAjaxRegion();
  412. mp.clearOverlays(); //清除地图上所有的覆盖物
  413. }else if(u > 11){
  414. mp.clearOverlays(); //清除地图上所有的覆盖物
  415. fuAjaxLabel();
  416. }
  417. }
  418. /*--------------------------------------- 新添加的省、区域 END -------------------------------------------------------------*/
  419. // 遍历覆盖楼盘名称
  420. function labal(obj){
  421. // console.log(obj)
  422. $.each(obj.data, function (i, obj) {
  423. var txt = obj.name;
  424. var mouseoverTxt = txt + '&nbsp;&nbsp;|&nbsp;&nbsp;' + obj.sale_price;
  425. var pintx = obj.longitude_latitude.split(',')[0];
  426. var pinty = obj.longitude_latitude.split(',')[1];
  427. var _points = new BMap.Point(pintx, pinty);
  428. var o = scope(_points);
  429. if(o != undefined){
  430. var myCompOverlay = new ComplexCustomOverlays(o,txt, mouseoverTxt); //将覆盖物存到变量,以便下面使用。
  431. mp.addOverlay(myCompOverlay); //把标签到地图上
  432. }else{
  433. var myCompOverlay = new ComplexCustomOverlays(new BMap.Point(pintx, pinty), txt, mouseoverTxt); //将覆盖物存到变量,以便下面使用。
  434. mp.addOverlay(myCompOverlay);
  435. }
  436. var point = new BMap.Point(pintx, pinty);
  437. var _iw = createInfoWindow(obj);
  438. var _marker = myCompOverlay; //当初存的覆盖物变量
  439. _marker.addEventListener("click", function () { //点击出现对应自定义覆盖物
  440. mp.openInfoWindow(_iw, point);
  441. });
  442. });
  443. }
  444. /*--------------------------------- Ajax 分页功能 ----------------------------------------*/
  445. var curPage = 1; //当前页码
  446. var total,pageSize = 10,totalPage; //总记录数,每页显示数,总页数
  447. //获取数据
  448. function getData(page,arr = null,async){
  449. if(async == undefined){
  450. async= true;
  451. }
  452. $.ajax({
  453. type: 'post',
  454. url: "/map/houselist",
  455. data: {'page':page,'limit':pageSize,'csrf_token_f':csrfToken,'data':arr},
  456. dataType:'json',
  457. async:async, //为了解决检索时,点击对应的楼盘
  458. beforeSend:function(){
  459. $(".y_mapcenter_list ul").append("<li id='loading'>loading...</li>");//显示加载动画
  460. },
  461. success:function(json){
  462. $(".y_mapcenter_list ul").html('');//清空数据区
  463. if(json.code == 200){
  464. total = json.count; //总记录数
  465. $('.housenum em').html(total);
  466. // pageSize = json.pageSize; //每页显示条数
  467. curPage = page; //当前页
  468. totalPage = parseInt((parseInt(total) + parseInt(pageSize) - 1) / pageSize); //总页数
  469. var html = '';
  470. var list = json.data;
  471. $.each(list,function(index,array){ //遍历json数据列
  472. var jg=array.sale_price;
  473. if (jg!=0) {
  474. jg=array.sale_price+array.price_unit;
  475. }else{
  476. jg='待定';
  477. };
  478. html+= '<li class="c" data-id="'+array.longitude_latitude+'">';
  479. html+= '<div class="y_tu"><a href="javascript:;"><img src="'+array.thumb+'" alt=""></a></div>';
  480. html+= '<div class="y_textmain">';
  481. html+= '<div class="y_text c">';
  482. html+= '<a href="javascript:;">'+(array.name.length > 6 ? array.name.slice(0,5)+'...' : array.name)+'</a>';
  483. html+= '<span><em>'+jg+'</em></span>';
  484. html+= '</div>';
  485. html+= '<div class="y_qixian">(有效期:2017年2月11日-2018年2月11日)</div>';
  486. html+= '<div class="y_hx">户型:'+array.main_units+'</div>';
  487. html+= '<div class="y_tese c">';
  488. // console.log(array.characteristic);
  489. if(array.characteristic != null){
  490. $.each(array.characteristic,function (k,v) {
  491. html+= '<i>'+(v.length > 4 ? v.slice(0,3)+'...' : v)+'</i>';
  492. })
  493. }
  494. html+= '</div>';
  495. html+= '</div> ';
  496. html+= '</li>';
  497. });
  498. $(".y_mapcenter_list ul").append('<li id="loading"><img src="/map/image/load.gif" alt="" />数据加载中...</li>');//显示加载动画
  499. setTimeout(function(){
  500. $(".y_mapcenter_list ul").html('');//清空数据区
  501. $(".y_mapcenter_list ul").append(html);
  502. }, 300);
  503. $(".y_mapcenter_list ul").on('click','li',function(){ //点击列表对应自定义覆盖物
  504. var _point = $(this).attr('data-id');
  505. var _pointx = _point.split(',')[0];
  506. var _pointy = _point.split(',')[1];
  507. var _points = new BMap.Point(_pointx, _pointy);
  508. var _i = $(this).index();
  509. // console.log(_i);
  510. var _newhou = json.data[_i];
  511. // console.log(_newhou)
  512. var ih = createInfoWindow(_newhou);
  513. mp.centerAndZoom(_points, 15); //对应的坐标及放大级别
  514. labal(json); //遍历所以有的点
  515. mp.openInfoWindow(ih, _points) //当前覆盖添加并展示
  516. });
  517. }else{
  518. $(".y_mapcenter_list ul").append('<li id="loading">未找到符合条件的楼盘...</li>');//显示加载动画
  519. $('.housenum em').html(0);
  520. total = 0; //总记录数
  521. }
  522. },
  523. complete:function(){ //生成分页条
  524. getPageBar();
  525. fun();
  526. },
  527. error:function(){
  528. // alert("数据加载失败");
  529. }
  530. });
  531. }
  532. //获取分页条
  533. function getPageBar(){
  534. //页码大于最大页数
  535. if(curPage>totalPage) curPage=totalPage;
  536. //页码小于1
  537. if(curPage<1) curPage=1;
  538. pageStr = '<div class="amount"><i>共'+total+'条</i><i>'+curPage+"/"+totalPage+'</i></div>';
  539. //如果是第一页
  540. if(curPage==1){
  541. pageStr += "<span>首页</span><span>上一页</span>";
  542. // alert("已经是首页!")
  543. }else{
  544. pageStr += "<span><a href='javascript:void(0)' rel='1'>首页</a></span><span><a href='javascript:void(0)' rel='"+(curPage-1)+"'>上一页</a></span>";
  545. }
  546. //如果是最后页
  547. if(curPage>=totalPage){
  548. pageStr += "<span>下一页</span><span>尾页</span>";
  549. // alert("已经最后一页!")
  550. }else{
  551. pageStr += "<span><a href='javascript:void(0)' rel='"+(parseInt(curPage)+1)+"'> 下一页</a></span><span><a href='javascript:void(0)' rel='"+totalPage+"'>尾页</a></span>";
  552. }
  553. $("#pagecount").html(pageStr);
  554. }
  555. $(function(){
  556. getData(1);
  557. });
  558. function fun(){
  559. $("#pagecount span a").on('click',function(){
  560. var rel = $(this).attr("rel");
  561. // alert(rel)
  562. if(rel){
  563. getData(rel,dataID);
  564. }
  565. });
  566. }
  567. /*-------------------------------------------------------------------------*/
  568. // 处理经纬坐标
  569. function newPoint(_point){
  570. var pointArr = [];
  571. if(_point.indexOf('|') != -1){
  572. var _pointx = _point.split('|')[0];
  573. var _pointy = _point.split('|')[1];
  574. }
  575. if(_point.indexOf(',') != -1){
  576. var _pointx = _point.split('|')[0];
  577. var _pointy = _point.split('|')[1];
  578. }
  579. pointArr.push(_pointx,_pointy);
  580. return pointArr;
  581. }
  582. /* 点击弹出对应信息 */
  583. function createInfoWindow(data){ //自定义覆盖物
  584. // console.log(data)
  585. var pri = '待定';
  586. if(data.sale_price != 0){
  587. pri = data.sale_price + data.price_unit;
  588. }
  589. var iw= new BMap.InfoWindow(
  590. '<div class="map_id" style="width:260px; height:auto; position:absolute; left:0px; top:0px;">'+
  591. '<p style="width:100%; height:155px; margin-top:10px;"><a target="_blank" href="/house/'+data.id+'/"><img src="'+data.thumb+'" alt="" width="100%" height="100%;"></a></p>'+
  592. '<p style="margin-top:8px;"><a style="font-size:16px; color:#333;" target="_blank" href="/house/'+data.id+'/">'+data.name+'</a><span style="font-size:12px; color:#888; padding-left:8px;">['+data.city_name+']</span></p>'+
  593. '<p style="margin-top:5px;"><span><em style="font-size:18px; color:#f00; font-style:normal;">'+pri+'</em></span></p>'+
  594. '</div>'
  595. );
  596. return iw
  597. }