Bing Maps AJAX Control SDK 7.0 PDF
Bing Maps AJAX Control SDK 7.0 PDF
In This Section
Getting Started with the 7.0 Map Control
What's New in the AJAX Map Control
Developing with the 7.0 Map Control
API Reference
Supported Browsers
Developer Resources
See Also
Terms and Conditions
6
When the Bing Maps AJAX Control 7.0 is loaded with a valid Bing Maps Key, Bing Maps
counts sessions. A session begins with the load of the Bing Maps AJAX Control 7.0 into a
user‟s browser and includes all Bing Maps AJAX Control 7.0 interactions until the
browser is closed or the user moves to a different page. Detailed information about Bing
Maps usage reports is found in Viewing Bing Maps Usage Reports.
New Features
This release of the map control includes the following new features:
Built-in info box functionality. Using the Infobox Class and the InfoboxOptions Object, you
can easily put info boxes on the map as well as create and customize your own pushpin
balloons.
Support for keyboard events. With the addition of the Map events keyup, keydown, and
keypress and the KeyEventArgs Object, you can customize keyboard event behavior in your
application.
New mouse event argument properties. The new wheelDelta, isPrimary, isSecondary, and
isTouchEvent properties of the MouseEventArgs Object allow you to more easily handle
mouse and touch events.
New map options. For increased flexibility, several new options have been added to the
MapOptions Object, including the showMapTypeSelector which allows you to hide the map
type selector in the map navigation control.
Additional mobile and desktop browser support. RIM BlackBerry 6.0 and Firefox 4.0 are
now supported browsers. See Bing Maps AJAX Control 7.0 Supported Browsers for more
information.
7
In This Section
Loading the AJAX Map Control
Changing the Map View
Adding Entities to the Map
Customizing Your Pushpins
Displaying Location Search Results Using the REST Services
Getting Route Directions Using the REST Services
Working with Tile Layers
Using Events in the AJAX Control
Returning a Localized Map
8
<script charset="UTF-8" type="text/javascript"
src="https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx
?v=7.0&s=1">
</script>
4. In the body of the page, add a DIV element to the page to contain the map. The size of the
map is defined by the height and width of the DIV element. The position of the map is set by
using the "position", "top", and "left" properties. You can set these values either inline or by
defining the values in a style class and then referencing that class, as follows.
<div id='mapDiv' style="position:absolute; width:400px;
height:400px;"></div>
or
.map {
position: absolute;
top: 20;
left: 10;
width: 400px;
height: 400px;
border:#555555 2px solid;
}
...
<div id="mapDiv" class="map"></div>
If you do not specify a width/height, the width/height of the div is used. For cross-
browser compatibility, you should always specify the position attribute (both
"absolute" and "relative" are valid values). If you use a percentage width and or
height in the map DIV, it is the percentage of the parent width or height, respectively.
5. Finally, create a new instance of the Map Class. You also need to include a map options
object to contain your credentials, which is your Bing Maps Key. See the Getting a Bing Maps
Key topic.
var map = new
Microsoft.Maps.Map(document.getElementById("mapDiv"),
{credentials:"Your Bing Maps Key"});
9
var mapOptions = {
mapTypeId: Microsoft.Maps.MapTypeId.aerial
Example
The following code shows a complete Web page that loads a map. Valid map types are found in
the MapTypeId Enumeration topic.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
mapTypeId: Microsoft.Maps.MapTypeId.road,
zoom: 7});
</script>
</head>
<body onload="GetMap();">
10
</body>
</html>
<html>
<head>
<title></title>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
var mapOptions = {
mapTypeId: Microsoft.Maps.MapTypeId.birdseye,
zoom: 17,
showScalebar: false
11
}
</script>
</head>
<body onload="GetMap();">
</body>
</html>
<html>
<head>
<title></title>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
function SetZoom()
12
var zoomLevel = parseInt(document.getElementById('txtZoom').value);
map.setView({zoom:zoomLevel});
</script>
</head>
<body onload="GetMap();">
Zoom Level:
</body>
</html>
To set the boundaries of the view instead of centering on a point, use the bounds option as shown
in the code below.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
13
map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), {credentials:
"Your Bing Maps Key"});
</script>
</head>
<body onload="GetMap();">
</body>
</html>
Adding a Pushpin
The following code adds a pushpin to the center of the map with the label “1”.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
14
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript"
src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
map.entities.push(pin);
</script>
</head>
<body onload="GetMap();">
</body>
</html>
To add a pushpin to a custom latitude and longitude coordinate, pass the Location object to the
Pushpin constructor, then set the view based on the location as shown below.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
15
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript"
src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
map.entities.push(pin);
</script>
</head>
<body onload="GetMap();">
</body>
16
</html>
Adding a Shape
To add a polyline or a polygon, use the same method used to add a pushpin. First, create your
shape then add it to the entities property of the map. The following code adds a purple polygon to
the map.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<script type="text/javascript"
src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
// Create a polygon
map.entities.push(polygon);
17
</script>
</head>
<body onload="GetMap();">
</body>
</html>
<html>
<head>
<title></title>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
18
// Create a polygon
// Create the entity collection with the polygon and pushpins at each corner
polygonWithPins.push(polygon);
polygonWithPins.push(new Microsoft.Maps.Pushpin(location1));
polygonWithPins.push(new Microsoft.Maps.Pushpin(location2));
polygonWithPins.push(new Microsoft.Maps.Pushpin(location3));
polygonWithPins.push(new Microsoft.Maps.Pushpin(location4));
map.entities.push(polygonWithPins)
</script>
</head>
<body onload="GetMap();">
</body>
</html>
<html>
19
<head>
<title></title>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
// Define colors
function GetMap()
map = new
Microsoft.Maps.Map(document.getElementById("mapDiv"),{credentials:"Your Bing Maps Key"});
20
var triangle = new Microsoft.Maps.Polygon(triangleVertices, { fillColor:
blue, strokeColor: blue });
map.entities.push(triangle);
map.entities.push(square);
function ChangePolygonColor()
// Get the map square entity. We know square was the last entity added,
if((currentColor.toString()) == (purple.toString()))
// Change it to green
else
mapSquare.setOptions({fillColor:purple, strokeColor:purple});
</script>
21
</head>
<body onload="GetMap();">
</body>
</html>
<html>
<head>
<title></title>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
22
var map = null;
function GetMap()
map.entities.push(pin);
</script>
</head>
<body onload="GetMap();">
</body>
</html>
23
<html>
<head>
<title></title>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
visible: false,
24
Microsoft.Maps.Events.addHandler(pin, 'click', displayInfobox);
map.entities.push(pin);
map.entities.push(pinInfobox);
function displayInfobox(e)
function hideInfobox(e)
</script>
</head>
<body onload="GetMap();">
</html>
25
Initialize the Map
Before you add geocoding functionality, initialize the map using the following code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
map = new
Microsoft.Maps.Map(document.getElementById("mapDiv"),{credentials:"Your Bing Maps Key",
mapTypeId:"r"});
</script>
</head>
<body onload="GetMap();">
</body>
</html>
26
Add Controls
For this sample, add a text box and a Geocode button. In your script, create a ClickGeocode
function that is called when the button is clicked.
<input id="txtQuery" type="text" value="Portland"/>
Since the Bing Maps REST Services also require a Bing Maps Key, you need to first retrieve the
key from the map object to ensure the session is valid. Use the getCredentials method of the
Map Class to do this. The getCredentials method takes a function to call when the credentials
are retrieved.
function ClickGeocode(credentials)
map.getCredentials(MakeGeocodeRequest);
CallRestService(geocodeRequest);
27
function CallRestService(request)
script.setAttribute("type", "text/javascript");
script.setAttribute("src", request);
document.body.appendChild(script);
function GeocodeCallback(result)
<html>
<head>
<title></title>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
28
map = new
Microsoft.Maps.Map(document.getElementById("mapDiv"),{credentials:"Your Bing Maps Key",
mapTypeId:"r"});
function ClickGeocode(credentials)
map.getCredentials(MakeGeocodeRequest);
function MakeGeocodeRequest(credentials)
CallRestService(geocodeRequest);
function GeocodeCallback(result)
if (result &&
result.resourceSets &&
result.resourceSets[0].resources &&
result.resourceSets[0].resources.length > 0)
29
var viewBoundaries = Microsoft.Maps.LocationRect.fromLocations(new
Microsoft.Maps.Location(bbox[0], bbox[1]), new Microsoft.Maps.Location(bbox[2],
bbox[3]));
map.entities.push(pushpin);
function CallRestService(request)
script.setAttribute("type", "text/javascript");
script.setAttribute("src", request);
document.body.appendChild(script);
</script>
</head>
<body onload="GetMap();">
</body>
</html>
30
Getting Route Directions Using the REST
Services
The Bing Maps AJAX Control, version 7.0 does not have built in route functionality, but you can
easily use the Bing Maps REST Services to calculate a route and display it on the map.
<html>
<head>
<title></title>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
map = new
Microsoft.Maps.Map(document.getElementById("mapDiv"),{credentials:"Your Bing Maps Key",
mapTypeId:"r"});
</script>
</head>
<body onload="GetMap();">
31
<div id='mapDiv' style="position:relative; width:400px; height:400px;"></div>
</body>
</html>
Then, construct the REST route request using the input values.
var routeRequest = "http://dev.virtualearth.net/REST/v1/Routes?wp.0=" +
document.getElementById('txtStart').value + "&wp.1=" +
document.getElementById('txtEnd').value +
"&routePathOutput=Points&output=json&jsonp=RouteCallback&key=" + credentials;
<html>
<head>
<title></title>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
32
function GetMap()
map = new
Microsoft.Maps.Map(document.getElementById("mapDiv"),{credentials:"Your Bing Maps Key",
mapTypeId:"r"});
function ClickRoute(credentials)
map.getCredentials(MakeRouteRequest);
function MakeRouteRequest(credentials)
CallRestService(routeRequest);
function RouteCallback(result) {
if (result &&
result.resourceSets &&
33
result.resourceSets.length > 0 &&
result.resourceSets[0].resources &&
result.resourceSets[0].resources.length > 0) {
routepoints[i]=new
Microsoft.Maps.Location(routeline.coordinates[i][0], routeline.coordinates[i][1]);
map.entities.push(routeshape);
function CallRestService(request)
34
var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
script.setAttribute("src", request);
document.body.appendChild(script);
</script>
</head>
<body onload="GetMap();">
</body>
</html>
<html>
<head>
<title></title>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
35
<script type="text/javascript">
function GetMap()
try
map.entities.push(tilelayer);
catch(err)
</script>
</head>
<body onload="GetMap();">
</body>
36
</html>
Example
The example below shows how to use the Map click event to display the coordinate values of
the clicked point in a text box.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
37
}
function displayLatLong(e) {
if (e.targetType == "map") {
</script>
</head>
<body onload="GetMap();">
Latitude, Longitude:
</body>
</html>
You can expand the example above and add a pushpin wherever the user clicks. The code below
also “greys out” the other pushpins in the entities collection when a new one is added.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
38
var map = null;
function GetMap()
function addPin(e) {
if (e.targetType == "map") {
map.entities.push(pin);
function shadePins(e) {
if (noPins) {
39
// If there aren't yet any pins on the map, do not grey the pin out.
noPins = false;
else
// Loop through the collection of pushpins on the map and grey out
// all but the last one added (which is at the end of the array).
var i = 0;
pin = e.collection.get(i);
</script>
</head>
<body onload="GetMap();">
</body>
</html>
40
Setting the Culture
By default the map labels and the navigation control text are provided in the culture English-
United States (en-US). However, the map control culture can be changed by adding the mkt
parameter to the map control reference, as in the following example, which sets the culture to
French-France (fr-FR).
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&mkt=fr-
fr"></script>
Supported Cultures
The following table lists supported cultures for the map control. The Culture column lists the valid
values for the mkt parameter.
Remarks
Error messages are always displayed in English - United States.
41
Bing Maps AJAX 7.0 Control API Reference
This section contains reference documentation for the Bing Maps AJAX Control 7.0.
In This Section
The Bing Maps AJAX Control 7.0 contains the following classes and enumerations.
Data Structures
AltitudeReference Enumeration
Location Class
LocationRect Class
Point Class
Mapping
Events Object
KeyEventArgs Object
LabelOverlay Enumeration
Map Class
MapOptions Object
MapTypeId Enumeration
MouseEventArgs Object
PixelReference Enumeration
ViewOptions Object
Entities
Color Class
EntityCollection Class
EntityCollectionOptions Object
Events Object
Infobox Class
InfoboxOptions Object
MouseEventArgs Object
Polyline Class
PolylineOptions Object
Polygon Class
PolygonOptions Object
Pushpin Class
42
PushpinOptions Object
TileLayer Class
TileLayerOptions Object
TileSource Class
TileSourceOptions Object
AltitudeReference Enumeration
Defines the reference point from which the altitude is measured.
Constants
Name Description
Methods
Name Definition Return Value Description
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>
43
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
center: groundLoc,
mapTypeId: Microsoft.Maps.MapTypeId.birdseye,
zoom:16};
// Add two pushpins to demonstrate the difference when using different altitude
references
</script>
</head>
<body onload="GetMap();">
</body>
</html>
44
Color Class
Represents a color.
Constructor
Name Definition Description
Properties
Name Type Description
Static Methods
Name Definition Return Value Description
45
Methods
Name Definition Return Value Description
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>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
46
function GetMap()
map = new
Microsoft.Maps.Map(document.getElementById("mapDiv"),{credentials:"Your Bing Maps Key"});
// Create a shape
map.entities.push(line);
function SetPolygonColor()
47
var bValue = document.getElementById('txtB').value;
else
</script>
</head>
<body onload="GetMap();">
</body>
48
</html>
EntityCollection Class
Contains a collection of entities. An Entity can be any one of the following types: Polygon,
Polyline, Pushpin, TileLayer, or EntityCollection.
Constructor
Name Definition Description
Methods
Name Definition Return Description
Value
49
Name Definition Return Description
Value
respect to other
items on the map.
50
* An Entity can be any one of the following types: Infobox, Polygon, Polyline, Pushpin, TileLayer,
and EntityCollection.
Events
Name Arguments Description
51
Name Arguments Description
collection (such as another
entity collection) fires the
entityremoved event.
For example, if collection #1
contains an entity, which is
another collection #2, then
when an entity of collection #2
is removed, two
entityremoved events are
fired.
* An Entity can be any one of the following types: Infobox, Polygon, Polyline, Pushpin, TileLayer,
and EntityCollection.
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>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
var pinTotal = 0;
function GetMap()
52
// Add handler for the map click event - add a pin to the click location.
function addPin(e) {
if (e.targetType == "map") {
// Return the location where the map was clicked and create the pin.
map.entities.push(pin);
function removePin(e)
map.entities.removeAt(indexOfPinToRemove);
53
</script>
</head>
<body onload="GetMap();">
</body>
</html>
EntityCollectionOptions Object
Contains options for an entity collection.
Properties
Name Type Description
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>
54
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
map = new
Microsoft.Maps.Map(document.getElementById("mapDiv"),{credentials:"Bing Maps Key"});
// Add handler for the map click event - add a pin to the click location.
function addPin(e) {
if (e.targetType == "map") {
// Return the location where the map was clicked and create the pin.
map.entities.push(pin);
function hideAllPins(){
55
// Hide all the entities on the map
map.entities.setOptions({visible:false});
function showAllPins(){
map.entities.setOptions({visible:true});
</script>
</head>
<body onload="GetMap();">
</body>
</html>
Events Object
Provides event handling functionality for map and entity events.
The Events object does not need to be initialized. Call the Events methods directly.
Methods
Name Definition Return Description
Value
56
Name Definition Return Description
Value
method.
Microsoft.Maps.Events.addHandle
r(map, 'viewchangedend’,
function(e){ //Handle the
event });
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>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
57
<script type="text/javascript">
function GetMap()
// Create a pin at the center of the map and its corresponding infobox
map.entities.push(pin);
map.entities.push(infobox);
function showInfobox()
infobox.setOptions({visible:true});
58
function hideInfobox()
infobox.setOptions({visible:false});
</script>
</head>
<body onload="GetMap();">
</body>
</html>
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
Methods
Name Definition Return Description
Value
59
Name Definition Return Description
Value
action that corresponds to that
action link.
60
Name Definition Return Description
Value
dler to call when the title of the
infobox is clicked.
61
Name Definition Return Description
Value
id="infoboxDescription"
style="position:absolute;
top:30px; left:10px;
width:220px;">lkjsl lkjdkl
lkajdlkj
klasdjfkl</a></div>');
Events
Name Arguments Description
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.
62
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>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
63
// Add a handler for the pushpin click event.
map.entities.push(pin);
map.entities.push(pinInfobox);
function displayInfobox(e)
function hideInfobox(e)
</script>
</head>
<body onload="GetMap();">
</html>
64
InfoboxOptions Object
Represents the options for an infobox.
Properties
Name Type Description
65
Name Type Description
it is the amount the info box bottom
left edge is shifted from the location
of the info box. The default value is
(0,0), which means there is no offset.
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>
66
<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">
function GetMap()
height: 100,
showPointer: false,
titleClickHandler: InfoboxHandler,
map.entities.push(myInfobox);
67
}
function InfoboxHandler()
</script>
</head>
<body onload="GetMap();">
</html>
See Also
Infobox Class
KeyEventArgs Object
Contains the arguments for keyboard events.
Properties
Name Type Description
68
Name Type Description
for the event is cancelled.
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>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
69
}
function addPin(e) {
if (e.keyCode == "112") {
map.entities.push(pin);
</script>
</head>
<body onload="GetMap();">
</body>
</html>
LabelOverlay Enumeration
Defines how map labels are displayed.
Constants
Name Description
70
Methods
Name Definition Return Value Description
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>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
var mapOptions =
mapTypeId: Microsoft.Maps.MapTypeId.birdseye,
zoom: 17,
labelOverlay: Microsoft.Maps.LabelOverlay.hidden
71
//Load the map
</script>
</head>
<body onload="GetMap();">
</body>
</html>
Constructor
Name Definition Description
Properties
Name Type Description
72
Name Type Description
Static Methods
Name Definition Return Description
Value
Methods
Name Definition Return Value Description
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>
73
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
function SetLocation()
// Retrieve the latitude and longitude values- normalize the longitude value
var longVal =
Microsoft.Maps.Location.normalizeLongitude(parseInt(latLongArray[1]));
</script>
</head>
<body onload="GetMap();">
74
Latitude, Longitude: <input id="txtlatlong" type="text" value="40, -120"/>
</body>
</html>
LocationRect Class
Represents a rectangle on the map.
Constructor
Name Definition Description
Properties
Name Type Description
Static Methods
Name Definition Return Description
Value
75
Name Definition Return Description
Value
s west:number, Rect specified northern and southern latitudes
south:number, and western and eastern longitudes for
east:number, the rectangle boundaries.
altitude:number,
altitudeReference:Altitude
Reference)
Microsoft.Maps.LocationRect.fromLocatio
ns(location1, location2, location3);
Methods
Name Definition Return Value Description
76
Name Definition Return Value Description
eastern edge of
the LocationRect.
77
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>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
map.setView({bounds: viewRect});
</script>
</head>
<body onload="GetMap();">
</body>
</html>
78
Map Class
Represents a map.
Constructor
Name Definition Description
Properties
Name Type Description
Methods
Name Definition Return Value Description
79
Name Definition Return Value Description
center of the current map
view.
80
Name Definition Return Value Description
have been set. Note that if an
option is not set, then the
default value for that option is
assumed and getOptions
returns undefined for that
option.
81
Name Definition Return Value Description
the map), relative to the page.
82
Name Definition Return Value Description
locations were converted. If
any of the conversions fail, null
is returned.
Events
Name Arguments Description
83
Name Arguments Description
key is pressed down.
84
Name Arguments Description
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>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
85
function GetMap()
</script>
</head>
<body onload="GetMap();">
</body>
</html>
MapOptions Object
Represents options to customize the map that is displayed.
Properties
Name Type Description
86
Name Type Description
87
Name Type Description
specified, then width must be
specified as well.
88
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>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
// Set the map and view options, setting the map style to Road and
height: 400,
width: 400,
mapTypeId: Microsoft.Maps.MapTypeId.road,
showMapTypeSelector: false};
</script>
</head>
<body onload="GetMap();">
89
</body>
</html>
MapTypeId Enumeration
Contains identifiers for the imagery displayed on the map.
Constants
Name Description
Example
This code sample sets the map imagery to Collin‟s Bart (collinsBart). Since this imagery is only
supported for the en-gb culture, the mkt parameter of the control is set to this culture.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
90
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&mkt=en-
gb"></script>
<script type="text/javascript">
function GetMap()
</script>
</head>
<body onload="GetMap();">
</body>
</html>
See Also
Changing the Map View
Returning a Localized Map
MouseEventArgs Object
Contains the arguments for mouse events.
Properties
Name Type Description
91
Name Type Description
for the event is cancelled.
Methods
Name Definition Return Value Description
92
Name Definition Return Value Description
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>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
function displayEventInfo(e) {
93
if (e.targetType == "map") {
</script>
</head>
<body onload="GetMap();">
Latitude, Longitude:
</body>
</html>
PixelReference Enumeration
Contains constants used to show how pixels are defined.
Constants
Name Description
94
Name Description
cause a page reflow which may negatively
impact performance.
Methods
Name Definition Return Value Description
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>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
95
{
function displayEventInfo(e) {
if (e.targetType == "map") {
if (loc!=null)
</script>
</head>
<body onload="GetMap();">
96
<b>Click the map to display the coordinate values at that point.</b><br>
</body>
</html>
Point Class
Represents a point on the map.
Constructor
Name Definition Description
Properties
Name Type Description
Static Methods
Name Definition Return Value Description
Methods
97
Name Definition Return Value Description
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>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
98
function displayEventInfo(e) {
if (e.targetType == "map") {
if (loc!=null)
</script>
</head>
<body onload="GetMap();">
</body>
</html>
Constructor
Name Definition Description
99
Methods
Name Definition Return Value Description
100
Name Definition Return Value Description
Events
Name Arguments Description
101
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>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
// Create a polygon
102
map.entities.push(polygon)
map.setView({bounds: Microsoft.Maps.LocationRect.fromLocations(vertices)});
</script>
</head>
<body onload="GetMap();">
</body>
</html>
PolygonOptions Object
Represents the options for a polygon.
Properties
Name Type Description
103
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>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
// Create a polygon
strokeThickness: 5});
104
// Add the shape to the map
map.entities.push(polygon)
map.setView({bounds: Microsoft.Maps.LocationRect.fromLocations(vertices)});
</script>
</head>
<body onload="GetMap();">
</body>
</html>
Polyline Class
Represents a polyline on the map.
Constructor
Name Definition Description
Methods
Name Definition Return Value Description
105
Name Definition Return Value Description
polyline.
Events
Name Arguments Description
106
Name Arguments Description
polyline.
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>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
107
var map = null;
function GetMap()
map = new
Microsoft.Maps.Map(document.getElementById("mapDiv"),{credentials:"Your Bing Maps Key"});
// Create a polyline
map.entities.push(line);
</script>
</head>
<body onload="GetMap();">
</body>
108
</html>
PolylineOptions Object
Represents the options for a polyline.
Properties
Name Type Description
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>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
109
function GetMap()
map = new
Microsoft.Maps.Map(document.getElementById("mapDiv"),{credentials:"Your Bing Maps Key"});
// Create a polyline
map.entities.push(line);
</script>
</head>
<body onload="GetMap();">
</body>
</html>
110
Pushpin Class (AJAX)
Defines a pushpin on the map.
Constructor
Name Definition Description
Methods
Name Definition Return Value Description
111
Name Definition Return Value Description
Events
112
Name Arguments Description
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>
113
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
map.entities.push(pin);
function DisplayLoc(e){
if (e.targetType == 'pushpin'){
114
</script>
</head>
<body onload="GetMap();">
</body>
</html>
PushpinOptions Object
Represents the options for a pushpin.
Properties
Name Type Description
115
Name Type Description
Example
This example uses the image below, named “BluePushpin.png”, as the pushpin icon.
<html>
<head>
<title></title>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
116
var map = null;
function GetMap()
map.entities.push(pin);
</script>
</head>
<body onload="GetMap();">
</body>
</html>
TileLayer Class
Represents a tile layer.
117
Constructor
Name Definition Description
Methods
Name Definition Return Description
Type
Example
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
118
<html>
<head>
<title></title>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
try
'http://www.microsoft.com/maps/isdk/ajax/layers/lidar/{quadkey}.png'});
map.entities.push(tilelayer);
catch(err)
119
}
</script>
</head>
<body onload="GetMap();">
</body>
</html>
See Also
Working with Tile Layers
TileLayerOptions Object
Defines the options for a tile layer.
Properties
Name Type Description
120
Name Type Description
the map.
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>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
try
'http://www.microsoft.com/maps/isdk/ajax/layers/lidar/{quadkey}.png'});
121
tilelayer= new Microsoft.Maps.TileLayer({ mercator: tileSource, opacity:
.7 });
map.entities.push(tilelayer);
catch(err)
function SetOpacity()
else
tilelayer.setOptions({opacity: opacityVal});
</script>
</head>
122
<body onload="GetMap();">
</body>
</html>
See Also
Working with Tile Layers
TileSource Class
Defines a tile source for a tile layer.
Constructor
Name Definition Description
Methods
Name Definition Return Type Description
123
Name Definition Return Type Description
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>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
try
124
// Push the tile layer to the map
map.entities.push(tilelayer);
catch(err)
</script>
</head>
<body onload="GetMap();">
</body>
</html>
See Also
Working with Tile Layers
TileSourceOptions Object
Defines options for a tile source.
Properties
Name Type Description
125
Name Type Description
The specified height needs to
be a multiplier of 2 of the
current projection‟s tile height
for the tiles to be shown. For
example, since Mercator tile
source tiles are 256x256, this
projection supports tiles that
are 64x64, 128x128, 256x256,
512x512, or any combination of
these.
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>
126
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
try
map.entities.push(tilelayer);
catch(err)
</script>
</head>
127
<body onload="GetMap();">
</body>
</html>
See Also
Working with Tile Layers
ViewOptions Object
Contains options for the map view.
Properties
Name Type Description
128
Name Type Description
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>
<script type="text/javascript"
src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap()
var options = {credentials:"Bing Maps Key", width: 500, height: 500, bounds:
initialViewBounds, mapTypeId:Microsoft.Maps.MapTypeId.aerial, animate: false};
129
// Initialize the map
function SetZoom()
options.zoom = zoomLevel;
map.setView(options);
</script>
</head>
<body onload="GetMap();">
</body>
</html>
130
Bing Maps AJAX Control 7.0 Supported
Browsers
This topic contains information about browser support for the Bing Maps AJAX Control 7.0.
The Bing Maps AJAX Control 7.0 uses features of HTML5 if it detects that the client
browser supports HTML5. If this is the case, map performance will be faster, and map
animations and transitions will be smoother.
Supported Browsers
The Bing Maps AJAX Control 7.0 is supported on the following Web browsers. If you are not
using a supported Web browser, certain features of the map control may not work.
Mobile Browser
131
Bing Maps AJAX Control 7.0 Developer
Resources
This topic contains support resources and contact information.
Developer Resources
The following resources are available for Bing Maps developers:
Connect with other Bing Maps developers on the Bing Maps AJAX Control Forum.
Visit the http://www.microsoft.com/maps website.
Read the Bing Maps Developer blog
Account Issues
If you are having issues creating a Bing Maps Developer Account, getting a Bing Maps Key, or
have an account access question, contact mpnet@microsoft.com.
Licensing Questions
If you are interested in finding out more about Bing Maps or have questions about licensing Bing
Maps, email maplic@microsoft.com or go to
http://www.microsoft.com/maps/resources/default.aspx. From North, Central, and South America,
you can also contact Bing Maps by calling (800) 426-9400, ext. 11315.
132