Events Object
Provides event handling functionality for map and entity events.
Note: |
|---|
| The Events object does not need to be initialized. Call the Events methods directly. |
Methods
| Name | Definition | Return Value | Description |
|---|---|---|---|
|
addHandler |
|
object |
Attaches the handler for the event that is thrown by the target. Use the return object to remove the handler using the removeHandler method.
|
|
addThrottledHandler |
|
object |
Attaches the handler for the event that is thrown by the target, where the minimum interval between events (in milliseconds) is specified in the |
|
hasHandler |
|
boolean |
Checks if the target has any attached event handler. |
|
invoke |
|
None |
Invokes an event on the target. This causes all handlers for the specified |
|
removeHandler |
|
None |
Detaches the specified handler from the event. The |
Example
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
var map = null;
var infobox = null;
function GetMap()
{
// Initialize the map
map = new Microsoft.Maps.Map(document.getElementById("myMap"),
{credentials:"Bing Maps Key"});
// Retrieve the location of the map center
var center = map.getCenter();
// Create a pin at the center of the map and its corresponding infobox
var pin = new Microsoft.Maps.Pushpin(center);
infobox = new Microsoft.Maps.Infobox(center, {title: 'Pushpin infobox', visible:false, offset:new Microsoft.Maps.Point(0,35)});
// Add event handlers for hovering over the pushpin
Microsoft.Maps.Events.addHandler(pin, 'mouseover', showInfobox);
Microsoft.Maps.Events.addHandler(pin, 'mouseout', hideInfobox);
// Add the pushpin and hidden infobox to the map
map.entities.push(pin);
map.entities.push(infobox);
}
function showInfobox()
{
infobox.setOptions({visible:true});
}
function hideInfobox()
{
infobox.setOptions({visible:false});
}
</script>
</head>
<body onload="GetMap();">
<div id='myMap' style="position:relative; width:500px; height:500px;"></div>
</body>
</html>
Note: