Export (0) Print
Expand All
4 out of 42 rated this helpful - Rate this topic

Events Object

Bing

Provides event handling functionality for map and entity events.

Gg427623.note(en-us,MSDN.10).gifNote:
The Events object does not need to be initialized. Call the Events methods directly.

Methods

Name Definition Return Value Description

addHandler

addHandler(target:object, eventName:string, handler:function)

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.

Microsoft.Maps.Events.addHandler(map, 'viewchangeend’, function(e){ //Handle the event });

addThrottledHandler

addThrottledHandler(target:object, eventName:string, handler:function, throttleInterval:number)

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 throttleInterval parameter. The last occurrence of the event is called after the specified throttleInterval.

hasHandler

hasHandler(target:object, eventName:string)

boolean

Checks if the target has any attached event handler.

invoke

invoke(target:object, eventName:string, args:object)

None

Invokes an event on the target. This causes all handlers for the specified eventName to be called.

removeHandler

removeHandler(handlerId: object)

None

Detaches the specified handler from the event. The handlerId is returned by the addHandler and addThrottledHandler methods.

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>
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.