How to pop up an information window when clicking a marker on map?

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:

infowindow
infowindow
Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:

Comments are closed, but trackbacks and pingbacks are open.