We’ve learned how to add markers on map using baidu map api. An often encountered use case is when user clicks on a marker, an information window pops up showing some information about this marker. Note that by default, there are many clickable objects on the map. Clicking on these objects will bring up a dialog showing the address information and traffic information. But if you want to display your own information, how to do that? To make a popup window on click, you should know how to listen to the click event and do something in the event handler. Many objects such as the marker, have addEventListener function, which can be used to bind an event handling function to a specific function.
var marker = new BMap.Marker(point,{icon: myIcon}); marker.addEventListener("click", function(){ var opts={width:250,height:150,title:"Hello"}; var infoWindow = new BMap.InfoWindow("World", opts); map.openInfoWindow(infoWindow, this.getPosition()); }); map.addOverlay(marker);
In the above example, after creating the marker, we bind an event handler to its “click” event. In the event handling function, we create a BMap.InfoWindow object, then use map.openInfoWindow to show the information window at the location of the marker. The effects are as follows:

Comments are closed, but trackbacks and pingbacks are open.