1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- // 设置屏幕的高度
- _heith = $(window).height()-134;
- $('#y_lpmap').css('height',_heith);
- var jwb = $('#y_lpmap').attr('data-jwd'); //获取经纬度
- x = jwb.split(',')[0];
- y = jwb.split(',')[1];
- // 添加百度地图
- var mp = new BMap.Map("y_lpmap",{minZoom:9,maxZoom:16});
- var point=new BMap.Point(x,y);
- mp.addControl(new BMap.OverviewMapControl()); //添加默认缩略地图控件
- mp.addControl(new BMap.NavigationControl()); //添加默认缩放平移控件
- mp.centerAndZoom(point, 9);
- mp.enableScrollWheelZoom();
- //创建标签
- var myIcon = new BMap.Icon("/image/label.png", new BMap.Size(17,34));
- var marker2 = new BMap.Marker(point,{icon:myIcon}); // 创建标注
- mp.addOverlay(marker2); // 将标注添加到地图中
- $('.y_lpdt_list li').on('click',function(){
- var txt = $(this).find('.y_text').html();
- var imgUrl = $(this).find('.y_tu').children('img').attr('src');
- // console.log(imgUrl)
- // alert(txt)
- doSearch(txt,point,imgUrl); //调用周围检索方法
- })
- //map展现结果的地图实例
- //autoViewport检索结束后是否自动调整地图视野,false 不调整地图视野
- // var local = new BMap.LocalSearch(map,{renderOptions:{map:map,autoViewport:true}});
- var local = new BMap.LocalSearch(mp,{renderOptions:{map:mp,autoViewport:true}});
- //地址检索
- function doSearch(Odata,Opoint,URL){
- var address = Odata;
- /*
- * 智能搜索有三种方法,分别是:search、searchInBounds和searchNearby。
- * search :在指定城市或全国内搜索关键字
- * searchInBound :在可视范围内搜索关键字内容
- * searchNearby :中心点为字符串时,将自动忽略半径
- * 比如: searchNearby("公交"); searchNearby("公交",new BMap.Point(pointx,pointy),500);
- */
- local.searchNearby(address,Opoint)
- mp.clearOverlays(); //删除地图上的覆盖物
- //创建标签
- var myIcon = new BMap.Icon("/image/label.png", new BMap.Size(17,34));
- var marker2 = new BMap.Marker(Opoint,{icon:myIcon}); // 创建标注
- mp.addOverlay(marker2); // 将标注添加到地图中
- //检索结束后的回调方法
- local.setSearchCompleteCallback(function(results){
- // console.log(results)
- if(results.Br.length != 0){
- // BMAP_STATUS_SUCCESS 检索成功。对应数值“0”。
- if (local.getStatus() == BMAP_STATUS_SUCCESS){
- for (var i = 0; i < results.getCurrentNumPois(); i ++){
- var poi = results.getPoi(i).point;
- // console.log(poi)
- //创建标签
- var myIcon = new BMap.Icon(URL, new BMap.Size(25,40));
- var marker2 = new BMap.Marker(poi,{icon:myIcon}); // 创建标注
- mp.addOverlay(marker2); // 将标注添加到地图中
- }
- }
- }else{
- }
- });
- }
|