Export (0) Print
Expand All

DirectionsStepWarning Class

Bing

Represents a route direction warning, such as a traffic congestion warning.

Properties

Name Type Description

style

StepWarningStyle

The type of the route warning.

text

string

The warning text.

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 directionsManager = null;

         function GetMap()
         {
            // Initialize the map
            map = new Microsoft.Maps.Map(document.getElementById("mapDiv"),{credentials:"Bing Maps Key"});
            Microsoft.Maps.loadModule('Microsoft.Maps.Directions', { callback: directionsModuleLoaded });

         }



         function directionsModuleLoaded()
         {
            // Initialize the DirectionsManager
            directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);

            // Create start and end waypoints and add them to the route
            var startWaypoint = new Microsoft.Maps.Directions.Waypoint({address:"Seattle, WA"});
            var endWaypoint = new Microsoft.Maps.Directions.Waypoint({address:"Bellevue, WA"});

            directionsManager.addWaypoint(startWaypoint);
            directionsManager.addWaypoint(endWaypoint);

            // Set directions options
            directionsManager.setRequestOptions({ avoidTraffic: true });
            directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('itineraryDiv') });

            // Specify a handler for when the directions are calculated
            Microsoft.Maps.Events.addHandler(directionsManager, 'directionsUpdated', displayMessage );
            Microsoft.Maps.Events.addHandler(directionsManager, 'directionsError', displayError);

            // Calculate directions, which displays a route on the map
            directionsManager.calculateDirections();


         } 



         function displayMessage(e)
         {
            // Variable for counting warnings
            var warningCount = 0;

            for( j=0; j< e.route[0].routeLegs.length; j++)
            {

               var i = 0;
               for (i=0; i < e.route[0].routeLegs[j].itineraryItems.length; i++)
               {
                  if (e.route[0].routeLegs[j].itineraryItems[i].warnings.length != 0 )
                  {
                     warningCount = warningCount + e.route[0].routeLegs[j].itineraryItems[i].warnings.length;
                  }
               }
            }

            alert("There are " + warningCount + " warning(s) in this route.");             
         }


         function displayError(e)
         {
            alert(e.message);
         }




      </script>
   </head>
   <body onload="GetMap();">
      <div id='mapDiv' style="position:relative; width:400px; height:400px;"></div>       
      <div id='itineraryDiv' style="position:relative; width:400px;"></div>
   </body>
</html>
Show:
© 2014 Microsoft