Share via


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

Adds a tile layer to the map, and if the visibleOnLoad parameter is true, it also shows it on the map.

VEMap.AddTileLayer(layerSource, visibleOnLoad);

Parameters

Parameter Description

layerSource

The VETileSourceSpecification Class object representing the source of the tile layer. Required.

visibleOnLoad

If true, the layer is immediately shown when added to the map. Optional.

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 tileLayer;
         
         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 opacity = 0.9;

            var tileSourceSpec = new VETileSourceSpecification("lidar", 
            "https://www.microsoft.com/maps/isdk/ajax/layers/lidar/%4.png");
            tileSourceSpec.NumServers = 1;
            tileSourceSpec.Bounds = bounds;
            tileSourceSpec.MinZoomLevel = 10;
            tileSourceSpec.MaxZoomLevel = 18;
            tileSourceSpec.Opacity = opacity;
            tileSourceSpec.ZIndex = 100;

            map.AddTileLayer(tileSourceSpec, true);
            btnAdd.disabled="disabled";
            btnDelete.disabled=null;
            btnHide.disabled=null;
            btnShow.disabled="disabled";
         }  
         
         function DeleteTileLayer()
         {
            map.DeleteTileLayer("lidar");
            btnAdd.disabled=null;
            btnDelete.disabled="disabled";
            btnHide.disabled="disabled";
            btnShow.disabled="disabled";
         }  
                 
         function ShowTileLayer()
         {
            map.ShowTileLayer("lidar");
            btnAdd.disabled="disabled";
            btnDelete.disabled=null;
            btnHide.disabled=null;
            btnShow.disabled="disabled";
         }
                  
         function HideTileLayer()
         {
            map.HideTileLayer("lidar");
            btnAdd.disabled="disabled";
            btnDelete.disabled=null;
            btnHide.disabled="disabled";
            btnShow.disabled=null;
         }
      </script>
   </head>
   <body onload="GetMap();">
      <div id='myMap' style="position:relative; width:400px; height:400px;"></div>
      <input id="btnAdd" type="button" onclick="GetTiles()" value="Add Tile Layer"/>
      <input id="btnDelete" type="button" onclick="DeleteTileLayer()" value="Delete Tile Layer"/><br />
      <input id="btnHide" type="button" onclick="HideTileLayer()" value="Hide Tile Layer"/>
      <input id="btnShow" type="button" onclick="ShowTileLayer()" value="Show Tile Layer"/>
   </body>
</html>

See Also

Reference

VEMap.DeleteTileLayer Method
VEMap.HideTileLayer Method