ViewOptions Object
Contains options for the map view.
Properties
| Name | Type | Description |
|---|---|---|
|
animate |
boolean |
A boolean that specifies whether to animate map navigation. Note that this option is associated with each setView call and defaults to true if not specified. |
|
bounds |
The bounding rectangle of the map view. If both are specified, bounds takes precedence over center. |
|
|
center |
The location of the center of the map view. If both are specified, bounds takes precedence over center. |
|
|
centerOffset |
The amount the center is shifted. This property is ignored if center is not specified. |
|
|
heading |
number |
The directional heading of the map. The heading is represented in geometric degrees with 0 or 360 = North, 90 = East, 180 = South, and 270 = West. |
|
labelOverlay |
A constant indicating how map labels are displayed. |
|
|
mapTypeId |
string |
The map type of the view. Valid map types are found in the MapTypeId Enumeration topic. |
|
padding |
number |
The amount of padding to be added to each side of the bounds of the map view. |
|
zoom |
number |
The zoom level of the map view. For information about map scale and resolution with respect to zoom level, see Understanding Scale and Resolution. |
Remarks
To 'lock' the map in a certain position, disable mouse and keyboard events during the application session. The following code disables mouse events.
// Attach an event handler for a mousemove event.
Microsoft.Maps.Events.addHandler(map, "mousemove", cancelEvent);
// When the mouse is used, the cancelEvent function will
// get called. Setting the handled property to true will
// disable the mousemove event, which disables panning.
function cancelEvent(e)
{
e.handled = true;
}
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;
function GetMap()
{
// Set the initial map and view settings
var initialViewBounds = Microsoft.Maps.LocationRect.fromCorners(new Microsoft.Maps.Location(43,-123), new Microsoft.Maps.Location(33,-113));
var options = {credentials:"Bing Maps Key", width: 500, height: 500, bounds: initialViewBounds, mapTypeId:Microsoft.Maps.MapTypeId.aerial, animate: false};
// Initialize the map
map = new Microsoft.Maps.Map(document.getElementById("mapDiv"),options);
}
function SetZoom()
{
// Retrieve the zoom level set by the user - converting it to a number.
var zoomLevel = parseInt(document.getElementById("txtZoom").value);
// Get the existing options.
var options = map.getOptions();
// Set the zoom level of the map
options.zoom = zoomLevel;
map.setView(options);
}
</script>
</head>
<body onload="GetMap();">
<div id='mapDiv' style="position:relative;"></div>
<input id="txtZoom" type="text" value="1"/>
<input type="button" value="Set Zoom" onclick="SetZoom();"/>
</body>
</html>