百度地图InfoWindow事件绑定

最近用百度地图开发了一个功能,需要绑定marker的提示框InfoWindow的事件,用百度原先提供的API :addEventListener方法绑定事件没有任何反应。

  处理方案:

     1.引入

<script src="https://raw.github.com/jiazheng/EventWrapper/master/release/eventwrapper.min.js" type="text/javascript"></script>
    
    2.在InfoWindow的HTML绑定id
      	var sContent ="<div id='markerInfo'><h4 style='margin:0 0 5px 0;padding:0.2em 0;color:"+colors+"'>"+title+"</h4>" + "<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>"+showInfo+"</p>" +"</div>";
   
    3.绑定marker单击事件
  	    	var clickListener = EventWrapper.addListener(marker, 'click', function(e){
  	    		 map.openInfoWindow(infoWindow,point); //单击marker显示InfoWindow
	    	});
  	    	//自动调用单击事件
  	    	EventWrapper.trigger(marker,"click");

  4.监听InfoWindow的打开事件open
	EventWrapper.addListener(infoWindow, 'open', function(e){
	  		//绑定信息框的单击事件
	  		$("#markerInfo").bind("click",function(){
                                console.log("点击了InfoWindow");
	  	        });
	 });
 注意:一定要监听 InfoWindow的open事件,通过sContent HTML绑定的id 我们可以注册各种事件!

猜你喜欢

转载自blog.csdn.net/qq_23039185/article/details/53536705