Server : nginx/1.20.1 System : Linux iZ2ze9ojcl78uluczwag69Z 4.18.0-240.22.1.el8_3.x86_64 #1 SMP Thu Apr 8 19:01:30 UTC 2021 x86_64 User : www ( 1000) PHP Version : 7.3.28 Disable Function : passthru,exec,system,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv Directory : /www/wwwroot/0531yanglao.com/public/js/ |
$(function(){ var url=window.location.host; // 创建地图实例 var map = new BMap.Map("container",{enableMapClick:false,minZoom:7,maxZoom:19}); var point = new BMap.Point(116.679582,36.497779); // 创建点坐标 map.centerAndZoom(point,10); // 初始化地图,设置中心点坐标和地图级别 map.enableScrollWheelZoom(); //启用地图滚轮放大缩小 map.addControl(new BMap.ScaleControl({anchor:BMAP_ANCHOR_BOTTOM_RIGHT,offset: new BMap.Size(20, 20)})); map.addControl(new BMap.NavigationControl({type:BMAP_NAVIGATION_CONTROL_ZOOM})); //地图街道控件, // 页面添加覆盖层 console.log(map); function zidingyi(point,p_ming,p_tao,id){ // console.log(point,longitude,latitude,id,clas1,p_ming,p_tao,p_qian,zhangtai); function SquareOverlay(point,p_ming,p_tao,id){ // 定义自定义覆盖物的构造函数 this._point = point; p_ming=p_ming; p_tao=p_tao; this._length=1; } // 继承API的BMap.Overlay SquareOverlay.prototype = new BMap.Overlay(); SquareOverlay.prototype.initialize = function(map){ // 保存map对象实例 console.log(map); this._map = map; var point = new BMap.Point(this._point); // 创建div元素,作为自定义覆盖物的容器 var label = document.createElement("label"); label.style.position = "absolute"; label.style.whiteSpace = "nowrap"; label.style.zIndex = "2"; label.style.cursor = "pointer"; var div = document.createElement("a"); label.appendChild(div); div.setAttribute("href",'/lingyuan/view/id/'+id+'.html'); // div.setAttribute("class",clas2); div.setAttribute("data-id",id); var title = document.createElement("p"); title.setAttribute("class",'title'); var titles=document.createTextNode(p_ming); title.appendChild(titles); div.appendChild(title); // if (p_tao!="") { // var tao = document.createElement("p"); // var taos=document.createTextNode(p_tao); // tao.appendChild(taos); // div.appendChild(tao); // }; label.addEventListener("touchend", function() { var src=$(this).find('a').attr('href'); location.href=src; }) // 将div添加到覆盖物容器中 label.mouseover = function(){ this.style.borderColor = "#000000"; } map.getPanes().markerPane.appendChild(label); // 保存div实例 this._label = label; // 需要将div元素作为方法的返回值,当调用该覆盖物的show、 // hide方法,或者对覆盖物进行移除时,API都将操作此元素。 return label; } // 实现初始化方法 SquareOverlay.prototype.draw = function(){ // 根据地理坐标转换为像素坐标,并设置给容器 var position = this._map.pointToOverlayPixel(this._point); this._label.style.left = position.x - this._length / 2 + "px"; this._label.style.top = position.y - this._length / 2 + "px"; } SquareOverlay.prototype.addEventListener = function(event,fun){ this._div[event] = fun; mySquare.addEventListener("mouseover", function(e){}); mySquare.addEventListener("mouseout", function(e){}); } var mySquare = new SquareOverlay(point,length); map.addOverlay(mySquare); }; // var point = new BMap.Point(121.636953,38.928878); // var p_ming="测试标题"; // var p_tao="测试价格"; // var id="1"; // zidingyi(point,p_ming,p_tao,id) // 获取地图坐标和房源总数 function init(){ $.ajax({ url:'/map/get_data', type: 'post', dataType: 'json', data:{ }, success: function(result) { if (result.status=="1") { var html=""; var data=result.data; var nlng=data[0].lng; var nlat=data[0].lat; var npoint=new BMap.Point(nlng,nlat); map.panTo(npoint); $.each(result.data,function(i,n){ var point = new BMap.Point(n.lng,n.lat); var p_ming=n.title; var p_tao=n.price+"万起"; var id=n.id; zidingyi(point,p_ming,p_tao,id) html+='<li><a href="/lingyuan/view/id/'+id+'.html" class="cle"><img src="'+n.filename+'" alt=""><div class="neirong"><h1>'+p_ming+'</h1><h3>'+n.address+'</h3>';//<h2>¥<span>'+p_tao+'</span></h2><h4> if (n.tag_array) { $.each(n.tag_array,function(j,k){ html+='<span>'+k+'</span>' }) }; html+='</h4></div></a></li>' }); $('.leibiao').html(html); }; } }) } init(); // $('body').on('click','label a',function(){ // alert(1); // }); });