VEMap.SetMapStyle Method

You are not viewing the latest version of the AJAX control. Bing Maps AJAX V7 is the recommended JavaScript control for Bing Maps. If you need this documentation, it is available in as a CHM or PDF download.

Sets the style of the map.

Note

On July 6, 2011, the new enhanced road map style in use on https://www.bing.com/maps became the default and only road style available for all Bing Maps APIs.

VEMap.SetMapStyle(mapStyle);

Parameters

Parameter Description

mapStyle

A VEMapStyle Enumeration value specifying the map style.

Remarks

The map style can also be set when the map is loaded with the VEMap.LoadMap Method.

Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://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="https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3"></script>

      <script type="text/javascript">
         var map = null;
         var center = new VELatLong(38.62504326121764, -90.18497586250308);
         var initView = new VEMapViewSpecification(center, 16, 1000, -90, 0);
         
         function GetMap()
         {
            map = new VEMap('myMap');
            map.LoadMap();

            map.SetMapMode(VEMapMode.Mode2D);
            map.SetMapStyle(VEMapStyle.Aerial);
            map.SetMapView(initView);
         }   
         
         function ToggleMode()
         {
            var mode = map.GetMapMode();

            if (mode == VEMapMode.Mode2D)
            {
               map.SetMapMode(VEMapMode.Mode3D);
            }
            else if (mode == VEMapMode.Mode3D)
            {
               map.SetMapMode(VEMapMode.Mode2D);
            }
         }
         
         function SetMapStyle()
         {
            if (styleForm.styleType[0].checked)
            {
               var style = map.GetMapStyle();

               if (style == VEMapStyle.Aerial)
               {
                  alert("The Aerial style is already set.");
               }
               else
               {
                  map.SetMapStyle(VEMapStyle.Aerial);
                  alert("Map style has been set to Aerial.");
               }
            }
            else if (styleForm.styleType[1].checked)
            {
               var style = map.GetMapStyle();

               if (style == VEMapStyle.Birdseye)
               {
                  alert("The Birdseye style is already set.");
               }
               else
               {
                  map.SetMapStyle(VEMapStyle.Birdseye);
                  alert("Map style has been set to Birdseye.");
               }
            }
            else if (styleForm.styleType[2].checked)
            {
               var style = map.GetMapStyle();

               if (style == VEMapStyle.Road)
               {
                  alert("The Road style is already set.");
               }
               else
               {
                  map.SetMapStyle(VEMapStyle.Road);
                  alert("Map style has been set to Road.");
               }
            }
            else if (styleForm.styleType[3].checked)
            {
               var style = map.GetMapStyle();

               if (style == VEMapStyle.Hybrid)
               {
                  alert("The Hybrid style is already set.");
               }
               else
               {
                  map.SetMapStyle(VEMapStyle.Hybrid);
                  alert("Map style has been set to Hybrid.");
               }
            }
         }
      </script>
   </head>
   <body onload="GetMap();">
      <div id='myMap' style="position:relative; width:400px; height:400px;"></div>
      <INPUT id="btnToggle" type="button" value="Toggle Map Mode" name="btnToggle" 
         onclick="ToggleMode();">
      <form name="styleForm">
            <input id="aerial" type="radio" name="styleType" checked="checked" /> Aerial<br />
            <input id="birdseye" type="radio" name="styleType" /> Birdseye<br /> 
            <input id="road" type="radio" name="styleType" /> Road<br />
            <input id="hybrid" type="radio" name="styleType" /> Hybrid
      </form>
      <INPUT id="btnStyle" type="button" value="Set Selected Map Style" name="btnStyle" 
         onclick="SetMapStyle();">
      <div id="latlon"></div>
   </body>
</html>

See Also

Reference

VEMap.GetMapStyle Method