map.js 30 KB

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