VEMap.GetTileLayerByIndex 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.

Gets a tile layer based upon an index value.


VEMap.GetTileLayerByIndex(index);

Parameters

Parameter Description

index

The index into the list of tile layers. The value ranges from 0 to GetTileLayerCount.

<!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=6.3"></script>

      <script type="text/javascript">
         var map = null;
         
         function GetMap()
         {
            map = new VEMap('myMap');
            map.LoadMap(new VELatLong(48.03,-122.4),12,'r' ,false);

            GetTiles();
         }   
         
         function GetTiles()
         {
            var bounds = [new VELatLongRectangle(new VELatLong(49,-123),new VELatLong(47,-121))];
            
            var tileSourceSpec = 
              new VETileSourceSpecification(
                "lidar", 
                "http://www.microsoft.com/maps/isdk/ajax/layers/lidar/%4.png",
                1,
                bounds,
                10,
                18,
                null,
                1.0,
                100);                              

            map.AddTileLayer(tileSourceSpec, true);
         }  
         
         function ListTileLayers()
         {
           var numLayers = map.GetTileLayerCount();

           if(numLayers < 1)
           {
             setDivText("tilelayers", "There are no tile layers to list!");
             return;
           }

           var layers = "There are " + numLayers + " tile layers:<br/>";

           for(var i = 0; i < numLayers; i++)
           {
             layers += "&nbsp;&nbsp;" + map.GetTileLayerByIndex(i).ID + "<br/>";
           }

           setDivText("tilelayers", layers);
         }
         
         function DeleteTileLayer()
         {
           var zindex = 0;
           
           var numLayers = map.GetTileLayerCount();

           if(numLayers < 1)
           {
             setDivText("tilelayers", "There are no tile layers to delete!");
             return;
           }

           var theLayerId;

           for(var i = 0; i < numLayers; i++)
           {
             if(map.GetTileLayerByIndex(i).ZIndex > zindex)
             {
               zindex = map.GetTileLayerByIndex(i).ZIndex;
               theLayerId = map.GetTileLayerByIndex(i).ID;
             }
           }
           
           map.DeleteTileLayer(theLayerId);

           setDivText("tilelayers", "Deleted layer " + theLayerId);
         }


        function setDivText(dId, s)
        {
          var d = document.getElementById(dId);
          d.innerHTML = s;
        }
      </script>
   </head>
   <body onload="GetMap();">
      <div id='myMap' style="position:relative; width:600px; height:400px;"></div>
      <input id="btnshow" type="button" onclick="ListTileLayers()" value="List Tile Layers"/>
      <input id="btndelete" type="button" onclick="DeleteTileLayer()" value="Delete Top Tile Layer"/>
      <div id='tilelayers'></div>
   </body>
</html>

Show: