Dear list,<br>here is a simple <a href="http://ASP.NET">ASP.NET</a> ashx to server MapGuide Tiles Directly.<br><br>It&#39; different from the one found on &quot;<a href="http://trac.osgeo.org/mapguide/wiki/CodeSamples/Tiles/ServingTilesViaHttp">http://trac.osgeo.org/mapguide/wiki/CodeSamples/Tiles/ServingTilesViaHttp</a>&quot; because it doesn&#39;t require any web server configuration.<br>

The only point is to use my ashx as a proxy to MapGuide.<br>Testing would be nice. If it&#39;s all OK, and someone wants to post it on wiki... or translate in PHP...<br>BUT don&#39;t test it with a non server OS. For example in WindowsXP I get lot of empty tiles. This is not the case with Windows Server 2003.<br>

REMINDER FOR ME: don&#39;t loose time! Test on real server OSs!<br>NOTE: <b>call somewhere &quot;<span style="font-family: courier new,monospace;">MapGuideApi.MgInitializeWebTier(MgMapHelper.WebconfigIniPhysicalPath);</span>&quot; before using this handler!</b><br>

           [<b>App_Start is a good choise</b>]<br><br><br>Code:<br><br><span style="font-family: courier new,monospace;">&lt;%@ WebHandler Language=&quot;C#&quot; Class=&quot;GetMGTiles&quot; %&gt;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">//#define LOG_WITH_LOG4NET</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">using System;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">using System.Web;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">using System.Text;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">using System.Net;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">using System.Collections.Specialized;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">using MapGuideHelper;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">using OSGeo.MapGuide;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">using System.IO;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">//This is different from [<a href="http://trac.osgeo.org/mapguide/wiki/CodeSamples/Tiles/ServingTilesViaHttp">http://trac.osgeo.org/mapguide/wiki/CodeSamples/Tiles/ServingTilesViaHttp</a> ]</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">//where the web server must be configured.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">//Here you use GetMGTiles.ashx as OpenLayers mapguide tiled layer address [not HttpTile!].</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">//NOTE: if you try this with a non server OS [such as WindowsXP] you will certainly get missed tiles</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">public class GetMGTiles : IHttpHandler</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    #region Compile Time Configuration</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    private readonly int BUFF_SIZE = 20480;//4096</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    #endregion</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    #region Properties to be configured [if needed] on application start</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    private static string _tileDirectory = &quot;C:/OSGeo/MapGuide/Server/Repositories/TileCache/&quot;;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    public static string TileDirectory</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        get { return _tileDirectory; }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        set { _tileDirectory = value; }</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    private static string _imageFileFormat = &quot;.png&quot;; //depends on &quot;serverconfig.ini&quot;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    private static string _contentType = &quot;image/png&quot;; //depends on &quot;serverconfig.ini&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    public static string ImageFileFormat</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        get { return _imageFileFormat; }</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        set</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            _contentType = String.Concat(&quot;image/&quot;, value);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            _imageFileFormat = String.Concat(&quot;.&quot;, value);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    }</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    private static double _tileRowsPerFolder = 30.0; //depends on &quot;serverconfig.ini&quot;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    private static int _tileRowsPerFolderInt = 30; //depends on &quot;serverconfig.ini&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    public static int TileRowsPerFolder</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        get { return _tileRowsPerFolderInt; }</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        set { _tileRowsPerFolder = _tileRowsPerFolderInt = value; }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    }</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    private static double _tileColumnsPerFolder = 30.0; //depends on &quot;serverconfig.ini&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    private static int _tileColumnsPerFolderInt = 30; //depends on &quot;serverconfig.ini&quot;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    public static int TileColumnsPerFolder</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        get { return _tileColumnsPerFolderInt; }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        set { _tileColumnsPerFolder = _tileColumnsPerFolderInt = value; }</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    #endregion</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    #region input request params</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    int _tileRow, _tileCol, _scaleIndex;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    string _baseLayerGroupname;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    string _mapDefinition;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    #endregion</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    protected void ServeMgTile(HttpResponse response)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        MgUserInformation userInfo = null;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        MgSiteConnection siteConnection = null;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        MgTileService tileService = null;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        MgResourceIdentifier resIdent = null;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        MgByteReader mgReader = null;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        try</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            ///////MapGuideApi.MgInitializeWebTier(MgMapHelper.WebconfigIniPhysicalPath);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            userInfo = new MgUserInformation(&quot;Anonymous&quot;, &quot;&quot;);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            siteConnection = new MgSiteConnection();</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            siteConnection.Open(userInfo);</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            tileService = siteConnection.CreateService(MgServiceType.TileService) as MgTileService;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            resIdent = new MgResourceIdentifier(_mapDefinition);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            mgReader = tileService.GetTile(resIdent, _baseLayerGroupname, _tileCol, _tileRow, _scaleIndex);</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            //--------------------------------------------------------------</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            //Debugging helper:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            //  context.Response.Cache.SetNoStore();</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            //  context.Response.AppendHeader(&quot;Pragma&quot;, &quot;no-cache&quot;);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            //--------------------------------------------------------------</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            int readBytes;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            byte[] buffer = new byte[BUFF_SIZE];</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            while ((readBytes = mgReader.Read(buffer, BUFF_SIZE)) &gt; 0)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                response.OutputStream.Write(buffer, 0, readBytes);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            }</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        finally</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            if (null != mgReader) mgReader.Dispose();</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            if (null != resIdent) resIdent.Dispose();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            if (null != tileService) tileService.Dispose();</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            if (null != siteConnection) siteConnection.Dispose();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            if (null != userInfo) userInfo.Dispose();</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    }</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    protected void StreamFile(string filePath, HttpResponse response)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        //response.AddHeader(&quot;content-disposition&quot;, String.Concat(&quot;attachment; filename=&quot;,Path.GetFileName(filePath)));</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            long fileSize = fileStream.Length;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#if false</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            //all at once:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            byte[] buffer = new byte[(int)fileSize]; </span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            fileStream.Read(buffer, 0, (int)fileStream.Length);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            fileStream.Close();</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            response.BinaryWrite(buffer);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#else</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            int readBytes;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            byte[] buffer = new byte[BUFF_SIZE];</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            while ((readBytes = fileStream.Read(buffer, 0, BUFF_SIZE)) &gt; 0)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                response.OutputStream.Write(buffer, 0, readBytes);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            }</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            fileStream.Close();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#endif</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    }</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    public void ProcessRequest(HttpContext context)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        try</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            //---------------------------------------------------------------------------------------------------------------------</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            //Startup</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            //---------------------------------------------------------------------------------------------------------------------</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            //It&#39;s always GET, but this costs nothing:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            NameValueCollection nvInput = context.Request.HttpMethod == &quot;POST&quot; ? <br>

                                                      context.Request.Form : nvInput = context.Request.QueryString;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#if false</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            //string requestedUrl = context.Request.Path.ToLower();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            if (nvInput == null) //it&#39;s never null</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                context.Response.Clear();</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                context.Response.ContentType = &quot;text/plain&quot;;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                context.Response.Write(&quot;Hello World&quot;);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                return;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            }</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            if (nvInput.Count == 0)//don&#39;t mind if is 0 =&gt; we will just get null strings when trying to read them</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                context.Response.Clear();</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                context.Response.ContentType = &quot;text/plain&quot;;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                context.Response.Write(&quot;Hello World&quot;);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                return;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            }</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">#endif</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            //---------------------------------------------------------------------------------------------------------------------</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            //---------------------------------------------------------------------------------------------------------------------</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            //Input params reading</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            //---------------------------------------------------------------------------------------------------------------------</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            _mapDefinition = HttpUtility.UrlDecode(nvInput[&quot;mapdefinition&quot;]);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            if (String.IsNullOrEmpty(_mapDefinition))</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                context.Response.StatusCode = (int)HttpStatusCode.BadRequest;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                return;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            }</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            if (nvInput[&quot;operation&quot;].ToUpper() != &quot;GETTILEIMAGE&quot;)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                context.Response.StatusCode = (int)HttpStatusCode.BadRequest;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                return;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            //---------------------------------</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            //we don&#39;t read nvInput[&quot;version&quot;]</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            //---------------------------------</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            _baseLayerGroupname = HttpUtility.UrlDecode(nvInput[&quot;basemaplayergroupname&quot;]);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            if (String.IsNullOrEmpty(_baseLayerGroupname))</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                context.Response.StatusCode = (int)HttpStatusCode.BadRequest;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                return;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            }</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            if (!Int32.TryParse(nvInput[&quot;tilecol&quot;], out _tileCol))<br>            {<br>                context.Response.StatusCode = (int)HttpStatusCode.BadRequest;<br>

                return;<br>            }<br>            if (!Int32.TryParse(nvInput[&quot;tilerow&quot;], out _tileRow))<br>            {<br>                context.Response.StatusCode = (int)HttpStatusCode.BadRequest;<br>

                return;<br>            }<br>            if (!Int32.TryParse(nvInput[&quot;scaleindex&quot;], out _scaleIndex))<br>            {<br>                context.Response.StatusCode = (int)HttpStatusCode.BadRequest;<br>

                return;<br>            }<br></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            //---------------------------------------------------------------------------------------------------------------------</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            //Tile file name</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            //---------------------------------------------------------------------------------------------------------------------</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            //The tiles base dir, if for example we want</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            //          &quot;Library://Samples/Sheboygan/MapsTiled/Sheboygan.MapDefinition&quot; </span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            // , is</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            //          &quot;Samples_Sheboygan_MapsTiled_Sheboygan/&quot;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            string mapDefDir = _mapDefinition.Replace(&quot;Library://&quot;, &quot;&quot;).Replace(&quot;/&quot;, &quot;_&quot;).Replace(&quot;.MapDefinition&quot;, &quot;/&quot;);</span><br style="font-family: courier new,monospace;">

<br>  <br><span style="font-family: courier new,monospace;">            //---------------------------------<br>            //Taken from Openlayers:<br>            int tileRowGroup = (int)(Math.Floor(Math.Abs(_tileRow / _tileRowsPerFolder))) * TileRowsPerFolder;<br>

            int tileColGroup = (int)(Math.Floor(Math.Abs(_tileCol / _tileColumnsPerFolder))) * TileColumnsPerFolder;<br>            int imgPartA = _tileRow % TileRowsPerFolder;<br>            int imgPartB = _tileCol % TileColumnsPerFolder;<br>

            //---------------------------------<br></span><span style="font-family: courier new,monospace;">            StringBuilder sb = new StringBuilder(256);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            sb.Append(_tileDirectory);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            sb.Append(mapDefDir);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            sb.Append(&quot;S&quot;);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            sb.Append(this._scaleIndex);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            sb.Append(&quot;/&quot;);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            sb.Append(this._baseLayerGroupname);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            sb.Append(&quot;/R&quot;);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            sb.Append(tileRowGroup);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            sb.Append(&quot;/C&quot;);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            sb.Append(tileColGroup);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            sb.Append(&quot;/&quot;);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            sb.Append(imgPartA);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            sb.Append(&quot;_&quot;);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            sb.Append(imgPartB);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            sb.Append(_imageFileFormat);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            //---------------------------------------------------------------------------------------------------------------------</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            //---------------------------------------------------------------------------------------------------------------------</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            //We give file if possible, let mapGuide build the tile otherwise</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            //---------------------------------------------------------------------------------------------------------------------</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            context.Response.ContentType = _contentType;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            string file = sb.ToString();</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            if (System.IO.File.Exists(file))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                try</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">#if false</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                    context.Response.WriteFile(file);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">#else</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                    StreamFile(file, context.Response);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">#endif</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                }</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                catch (System.IO.IOException ex)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                    //FileExists is not enough:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                    //MapGuide could possibly be writing the file while we where trying to get access!!!!</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">#if LOG_WITH_LOG4NET</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                    log4net.ILog logger = log4net.LogManager.GetLogger(&quot;exceptions&quot;);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                    logger.Error(&quot;GetMGTiles.ashx::ProcessRequest - Tried StreamFile [System.IO.IOException] - serve file via MapGuide&quot;, ex);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">#endif</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                    ServeMgTile(context.Response);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                </span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                context.Response.Flush();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                context.Response.Close();</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            else</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                context.Response.ContentType = _contentType;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                ServeMgTile(context.Response);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">                context.Response.Flush();</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">                context.Response.Close();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            }</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        catch (ArgumentNullException ex)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            log4net.ILog logger = log4net.LogManager.GetLogger(&quot;exceptions&quot;);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            logger.Error(&quot;GetMGTiles.ashx::ProcessRequest [ArgumentNullException]&quot;, ex);</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            context.Response.StatusCode = (int)HttpStatusCode.NotFound;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            System.Diagnostics.Trace.WriteLine(ex.ToString());</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        catch (System.Security.SecurityException ex)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#if LOG_WITH_LOG4NET</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            log4net.ILog logger = log4net.LogManager.GetLogger(&quot;exceptions&quot;);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            logger.Error(&quot;GetMGTiles.ashx::ProcessRequest [SecurityException]&quot;, ex);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">#endif</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            context.Response.StatusCode = (int)HttpStatusCode.Forbidden;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            System.Diagnostics.Trace.WriteLine(ex.ToString());</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        }</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        catch (UriFormatException ex)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">#if LOG_WITH_LOG4NET</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            log4net.ILog logger = log4net.LogManager.GetLogger(&quot;exceptions&quot;);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            logger.Error(&quot;GetMGTiles.ashx::ProcessRequest [UriFormatException]&quot;, ex);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#endif</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            context.Response.StatusCode = (int)HttpStatusCode.BadRequest;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            System.Diagnostics.Trace.WriteLine(ex.ToString());</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        catch (TimeoutException ex)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#if LOG_WITH_LOG4NET</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            log4net.ILog logger = log4net.LogManager.GetLogger(&quot;exceptions&quot;);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            logger.Error(&quot;GetMGTiles.ashx::ProcessRequest [TimeoutException]&quot;, ex);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">#endif</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            context.Response.StatusCode = (int)HttpStatusCode.RequestTimeout;</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            System.Diagnostics.Trace.WriteLine(ex.ToString());</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        }</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        catch (Exception ex)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">#if LOG_WITH_LOG4NET</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            log4net.ILog logger = log4net.LogManager.GetLogger(&quot;exceptions&quot;);</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            logger.Error(&quot;GetMGTiles.ashx::ProcessRequest [Exception]&quot;, ex);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#endif</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">            System.Diagnostics.Trace.WriteLine(ex.ToString());</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    }</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    public bool IsReusable</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        get</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        {</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">            return false;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        }</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">}</span><br>
<br>
------------<br>Test page [slightly modified from the wiki]<br>Assumes <span style="font-family: courier new,monospace;">GetMGTiles.ashx is accessible in <a href="http://localhost/">http://localhost/</a></span>ash/<span style="font-family: courier new,monospace;">GetMGTiles.ashx</span><br>

-----------<br><br><span style="font-family: courier new,monospace;">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Mapguide Http Tile Cache Demo&lt;/title&gt;<br>

<br>    &lt;script type=&quot;text/javascript&quot; src=&quot;<a href="http://www.openlayers.org/api/OpenLayers.js">http://www.openlayers.org/api/OpenLayers.js</a>&quot;&gt;&lt;/script&gt;<br><br>&lt;/head&gt;<br>&lt;body onload=&quot;initTiled()&quot;&gt;<br>

<br>    &lt;script type=&quot;text/javascript&quot;&gt;<br>        var windowSize = 550; //200;//<br>        var extent;<br><br>        var addrs = &quot;<a href="http://localhost/">http://localhost/</a>&quot;;<br>        //var addrs = &quot;<a href="http://192.168.1.247/">http://192.168.1.247/</a>&quot;;<br>

<br>        var mg_url = addrs + &quot;mapguide/mapagent/mapagent.fcgi?USERNAME=Anonymous&amp;&quot;;<br>        var http_url = addrs + &quot;sheboyganTiles&quot;;<br>        var my_proxy_url = addrs + &quot;ash/GetMGTiles.ashx&quot;;<br>

        var mg_map, http_or_tileproxy_map;<br>        var eventsLog = &quot;&quot;;<br>        var c = 0;<br>        //var bUseHttpUrl = false; //http_url || my_proxy_url <br><br>        function initTiled() {<br><br>            document.getElementById(&#39;map_mg&#39;).style.width = windowSize;<br>

            document.getElementById(&#39;map_http&#39;).style.width = windowSize;<br><br>            document.getElementById(&#39;map_mg&#39;).style.height = windowSize;<br>            document.getElementById(&#39;map_http&#39;).style.height = windowSize;<br>

<br>            OpenLayers.DOTS_PER_INCH = 96;<br><br>            //extent = new OpenLayers.Bounds(-87.865114442365922,43.665065564837931,-87.595394059497067,43.823852564430069);          <br>            var extent = new OpenLayers.Bounds(-87.764986990963, 43.691398128788, -87.6955215109, 43.79752000048);<br>

            var tempScales = [1000, 1930.6977300000001, 3727.5937199999998, 7196.8567300000004, 13894.95494, 26826.95795, 51794.746789999997, 100000];<br><br>            var mapOptions = {<br>                maxExtent: extent,<br>

                restrictedExtent: extent,<br>                scales: tempScales<br>            };<br><br>            var params = {<br>                mapdefinition: &#39;Library://Samples/Sheboygan/MapsTiled/Sheboygan.MapDefinition&#39;,<br>

                basemaplayergroupname: &quot;Base Layer Group&quot;<br>            }<br><br>            mg_map = new OpenLayers.Map(&#39;map_mg&#39;, mapOptions);<br>            http_or_tileproxy_map = new OpenLayers.Map(&#39;map_http&#39;, mapOptions);<br>

<br>            var mgOptions = {<br>                singleTile: false,<br>                useHttpTile: false,<br>                buffer: 1<br>            }<br><br>            /*var httpOptions = {<br>                singleTile: false,<br>

                useHttpTile: true,<br>                buffer: 1<br>            }*/<br><br>            var myProxyOptions = {<br>                singleTile: false,<br>                useHttpTile: false,<br>                buffer: 1<br>

            }<br><br>            mg_layer = new OpenLayers.Layer.MapGuide(&quot;MapGuide OS tiled layer&quot;, mg_url, params, mgOptions);<br>            //if (bUseHttpUrl) http_layer = new OpenLayers.Layer.MapGuide(&quot;MapGuide OS tiled layer&quot;, http_url, params, httpOptions);<br>

            //else<br>            http_layer = new OpenLayers.Layer.MapGuide(&quot;MG OS proxy - tiled layer&quot;, my_proxy_url, params, myProxyOptions);<br><br>            mg_map.addLayer(mg_layer);<br><br>            mg_map.addControl(new OpenLayers.Control.MousePosition());<br>

            http_or_tileproxy_map.addControl(new OpenLayers.Control.MousePosition());<br><br>            http_or_tileproxy_map.addLayer(http_layer);<br><br>            mg_map.setCenter(extent.getCenterLonLat());<br>            http_or_tileproxy_map.setCenter(extent.getCenterLonLat());<br>

<br>            mg_map.events.register(&quot;zoomend&quot;, mg_map, setZoomHttp);<br>            //http_or_tileproxy_map.events.register(&quot;zoomend&quot;, http_or_tileproxy_map, setZoomMg);<br><br>            mg_map.events.register(&quot;moveend&quot;, mg_map, moveHttp);<br>

            //http_or_tileproxy_map.events.register(&quot;moveend&quot;, http_or_tileproxy_map, moveMg);<br><br>        }<br><br>        function moveHttp() {<br>            if (mg_map.getCenter() != http_or_tileproxy_map.getCenter())<br>

                http_or_tileproxy_map.setCenter(mg_map.getCenter());<br>        }<br><br>        function moveMg() {<br>            if (mg_map.getCenter() != http_or_tileproxy_map.getCenter())<br>                mg_map.setCenter(http_or_tileproxy_map.getCenter());<br>

        }<br><br><br><br>        function setZoomMg() {<br>            if (mg_map.getZoom() != http_or_tileproxy_map.getZoom())<br>                mg_map.zoomTo(http_or_tileproxy_map.getZoom());<br>        }<br>        function setZoomHttp() {<br>

            if (mg_map.getZoom() != http_or_tileproxy_map.getZoom())<br>                http_or_tileproxy_map.zoomTo(mg_map.getZoom());<br><br>        }<br>    <br>    &lt;/script&gt;<br><br>    &lt;div style=&quot;float: left&quot;&gt;<br>

        &lt;h1&gt;Served by Mapguide&lt;/h1&gt;<br>        &lt;div id=&quot;map_mg&quot; style=&quot;border: medium inset Maroon; float: left; background-color: #F5DEB3;&quot;&gt;<br>        &lt;/div&gt;<br>        &lt;br /&gt;This cannot be proxied, it lacks cache headers<br>

    &lt;/div&gt;<br>    &lt;div style=&quot;float: left&quot;&gt;<br>        &lt;h1&gt;Served by Http&lt;/h1&gt;<br>        &lt;div id=&quot;map_http&quot; style=&quot;border: medium inset Maroon; float: left; background-color: #F5DEB3;&quot;&gt;<br>

        &lt;/div&gt;<br>        &lt;br /&gt;This is can be proxied by proxy servers<br>    &lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br></span><br style="font-family: courier new,monospace;"><br><br><br>------------<br>

[OFFTOPIC] A suggestion about MapGuide Installer -<br><br>it would be nice that besides the installer, there was a zipped archive with the installed files, to give the possibility of manually installing MapGuide without running an installer. This could be clearly set to UNSUPPORTED, and that no help would be given in the list to who desires to use the zipped archive.<br>


<br>This is because, in my opinion, one cannot understand the system, if not by using a manual install. It&#39;s the path I followed when I for the first time used MapGuide. <br><br>To provide such a thing is very simple: install in C:\OsGeo, zip folder and publish in &quot;<a href="http://mapguide.osgeo.org/download" target="_blank">http://mapguide.osgeo.org/download</a>&quot;. Only for windows, linux always needs compilation because of different shared objects between distributions.<br>


<br>At this point one can extract the zip wherever she wants, change ini files, set virtual directories, enable PHP, change folder permissions, and the game is done!<br>------------<br><br>Pietro Ianniello<br><br>