itis01

Custom TiledMapServiceLayer not working in 2.2 API.

Discussion created by itis01 on Aug 1, 2011
Latest reply on Aug 2, 2011 by itis01
I used the following custom TiledMapServiceLayer in the 2.2 beta API for loading and viewing map tiles from my local disk. This does no longer works in the 2.2 released API. "GetTileUrl" is called as expected and a valid url is returned but the tiles are not displayed. Does anyone have any ideas about what might have changed between the 2.2 beta and the 2.2 release that may cause this behavior?

   public class LocalTileDataLayer : TiledMapServiceLayer
   {
      /// <summary>Simple constant used for full extent and tile origin specific to this projection.</summary>
      private const double cornerCoordinate = 20037508.342789002;

      /// <summary>ESRI Spatial Reference ID for Web Mercator.</summary>
      private const int WKID = 102113; // WGS_1984_Web_Mercator

      private string mBaseURL;

      public LocalTileDataLayer(string aId, double aOpacity, string aBaseURL)
      {
         this.ID = aId;
         this.Opacity = aOpacity;
         mBaseURL = aBaseURL;
      }

      /// <summary>
      /// Initializes the layer.
      /// </summary>
      /// <seealso cref="ESRI.ArcGIS.Client.Layer.Initialized"/>
      /// <seealso cref="ESRI.ArcGIS.Client.Layer.InitializationFailure"/>
      public override void Initialize()
      {
         //Full extent fo the layer
         this.FullExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(-cornerCoordinate, -cornerCoordinate, cornerCoordinate, cornerCoordinate)
         {
            SpatialReference = new SpatialReference(WKID)
         };

         //This layer's spatial reference
         this.SpatialReference = new SpatialReference(WKID);

         //Set up tile information. Each tile is 256x256px, 18 levels.
         this.TileInfo = new TileInfo()
         {
            Height = 256,
            Width = 256,
            Origin = new MapPoint(-cornerCoordinate, cornerCoordinate)
            {
               SpatialReference = new SpatialReference(WKID)
            },
            SpatialReference = new SpatialReference(WKID),
            Lods = new Lod[20]            
         };

         double resolution = cornerCoordinate * 2 / 256;
         for (int i = 0; i < TileInfo.Lods.Length; i++)
         {
            TileInfo.Lods[i] = new Lod() { Resolution = resolution };
            resolution /= 2;
         }

         //Call base initialize to raise the initialization event
         base.Initialize();
      }

      public override string GetTileUrl(int level, int row, int col)
      {
         string url = mBaseURL
                      + "\\L" + ("00" + level.ToString()).Substring(("00" + level.ToString()).Length - 2)
                      + "\\R" + ("00000000" + row.ToString("X")).Substring(("00000000" + row.ToString("X")).Length - 8)
                      + "\\C" + ("00000000" + col.ToString("X")).Substring(("00000000" + col.ToString("X")).Length - 8)
                      + ".png";

         if (System.IO.File.Exists(url))
            return url;

         return "";
      }
   }

Outcomes