index.js 17 KB

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