百度地图生成标注事件触发弹出SearchInfoWindow


 

 var mapArr=[
    {
    id:1,
    longitude:${hospital.longitude},   
    latitude:${hospital.latitude},
    title:'${hospital.hospitalName}',
    content:'地址: ${hospital.addr}',
    imgUrl:'${base}/upload/${hospital.logoUrl}'
  }
]
function A()  //地图外面点击事件触发地图标注点击事件
{

callback(mapArr[0]);
marker.getLabel().hide();
}
  var map = new BMap.Map("map"); // 创建地图实例  
  var point = new BMap.Point(${hospital.longitude}, ${hospital.latitude});
  map.centerAndZoom(point, 16);//地图中心(北京),地图级别
  //map.centerAndZoom("北京",13);这种方式也可以
  map.enableScrollWheelZoom();//启用滚轮放大缩小,默认禁用
  function callback(obj)//单击热点图层
{
var _point=point;

var content = '
' +'' +obj.content+'
';
var searchInfoWindow = new BMapLib.SearchInfoWindow(map, content, {
title: obj.title, //标题
width: 290, //宽度
height: 110, //高度
panel : "panel", //检索结果面板
enableAutoPan : true,     //自动平移
searchTypes :[

]
});
searchInfoWindow.addEventListener("close",function(){ 
marker.getLabel().show();
});
searchInfoWindow.open(_point);
}
  //IP定位
  
    
      point = new BMap.Point(${hospital.longitude},${hospital.latitude});
      
      var marker = new BMap.Marker(point); // 初始化地图和地图级别
      map.addOverlay(marker);
      var label = new BMap.Label('
'+mapArr[0].id+''+mapArr[0].title+'
',{offset:new BMap.Size(-5,-5)});
      label.addEventListener("click",function(){
  callback(mapArr[0]);
  marker.getLabel().hide();
   })
      marker.setLabel(label);
       marker.addEventListener("click",function(){
   callback(mapArr[0]);
    marker.getLabel().hide();
   }); 
 
    
    
    //鼠标经过事件


    $(document).on({
      'mouseenter':function(e) {
        $(this).find('span').css({
          'background-image':'url(${base}/Images/map2.png)',
          'color':'#dd772b'
        })
      },
      'mouseleave':function(e) {
    
        $(this).find('span').css({
          'background-image':'url(${base}/Images/map.png)',
          'color':''
        })
      }
    },'.map_tip_Box');
    //公交查询
    var transit = new BMap.TransitRoute(map, {
      renderOptions: {map: map, panel: "result_map"}
    });
    //驾车查询
    var driving = new BMap.DrivingRoute(map, {renderOptions: {
      map: map, 
      panel: "result_map", 
      autoViewport: true}
    });
    //点击查询公交信息
    $('.result_end a').get(0).onclick = function(){
      
      transit.search($(this).siblings('input').val(),point);
    }
    
    $('.result_start a').get(0).onclick = function(){
      
      transit.search(point,$(this).siblings('input').val());
    }
    //点击查询自驾信息
    $('.result_end a').get(1).onclick = function(){
    
      driving.search($(this).siblings('input').val(),point);
    }
    $('.result_start a').get(1).onclick = function(){
      
      driving.search(point,$(this).siblings('input').val());
    }

你可能感兴趣的:(百度地图生成标注事件触发弹出SearchInfoWindow)