Infobox Class
Represents an info box on the map. You can use this class to create pop-up balloons for pushpins.
Constructor
| Name | Definition | Description |
|---|---|---|
|
Infobox |
|
Initializes a new instance of the Infobox class. |
Methods
| Name | Definition | Return Value | Description |
|---|---|---|---|
|
getActions |
|
Object |
Returns a list of actions, where each item is a name-value pair indicating an action link name and the event name for the action that corresponds to that action link. |
|
getAnchor |
|
Returns the point on the infobox which is anchored to the map. An anchor of (0,0) is the top left corner of the infobox. |
|
|
getDescription |
|
string |
Returns the string that is printed inside the infobox. |
|
getHeight |
|
number |
Returns the height of the info box. |
|
getHtmlContent |
|
string |
Returns the info box as HTML. |
|
getId |
|
string |
Returns the ID of the info box. |
|
getLocation |
|
Returns the location on the map where the infobox’s anchor is attached. |
|
|
getOffset |
|
number |
Returns the amount the infobox pointer is shifted from the location of the infobox, or if showPointer is false, then it is the amount the infobox bottom left edge is shifted from the location of the infobox. The default value is (0,0), which means there is no offset. |
|
getOptions |
|
Returns the info box options. |
|
|
getShowCloseButton |
|
boolean |
Returns a boolean indicating whether the infobox close button is shown. |
|
getShowPointer |
|
boolean |
Returns a boolean indicating whether the infobox is drawn with a pointer. |
|
getTitle |
|
string |
Returns a string that is the title of the info box. |
|
getTitleAction |
|
Object |
Returns an object containing a name-value pair indicating the link text to the right of an info box title and the event name for the action that corresponds to that link. |
|
getTitleClickHandler |
|
string |
Returns the name of the function to call when the title of the info box is clicked. |
|
getVisible |
|
boolean |
Returns whether the infobox is visible. A value of false indicates that the infobox is hidden, although it is still an entity on the map. |
|
getWidth |
|
number |
Returns the width of the infobox. |
|
getZIndex |
|
number |
Returns the z-index of the infobox with respect to other items on the map. |
|
setHtmlContent |
|
None |
Sets the HTML content of the infobox. You can use this method to change the look of the infobox. Note that info box options are ignored if custom HTML is set. Also, when custom HTML is used to represent the info box, the info box is anchored at the top-left corner.
|
|
setLocation |
|
None |
Sets the location on the map where the anchor of the infobox is attached. |
|
setOptions |
|
None |
Sets options for the infobox. |
|
toString |
|
string |
Converts the Infobox object to a string. |
Events
| Name | Arguments | Description |
|---|---|---|
|
click |
eventArgs:MouseEventArgs |
Occurs when the mouse is used to click the infobox. |
|
entitychanged |
object: {entity:Entity} |
Occurs when the location of the infobox or any of the infobox options change. |
|
mouseenter |
eventArgs:MouseEventArgs |
Occurs when the mouse cursor enters the area covered by the infobox. |
|
mouseleave |
eventArgs:MouseEventArgs |
Occurs when the mouse cursor leaves the area covered by the infobox. |
Remarks
-
The Bing Maps AJAX Control default info box is designed for desktop browsers and may not function properly on all mobile browsers.
-
For the best performance, it is recommended that you have only one info box on the map at a time.
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 pinInfobox = 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();
// Add a pin to the center of the map
var pin = new Microsoft.Maps.Pushpin(center, {text: '1'});
// Create the info box for the pushpin
pinInfobox = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(0,0), {title: 'My Pushpin', visible: true});
// Add a handler for the pushpin click event.
Microsoft.Maps.Events.addHandler(pin, 'click', displayInfobox);
// Hide the info box when the map is moved.
Microsoft.Maps.Events.addHandler(map, 'viewchange', hideInfobox);
// Add the pushpin and info box to the map
map.entities.push(pin);
map.entities.push(pinInfobox);
}
function displayInfobox(e)
{
pinInfobox.setOptions({ visible:true });
}
function hideInfobox(e)
{
pinInfobox.setOptions({ visible: false });
}
</script>
</head>
<body onload="GetMap();">
<div id='myMap' style="position:relative; width:500px; height:500px;"></div>
</html>