Virtual Earth Tile Server

Modified: 2008/03/30 15:08 by admin - Uncategorized
Edit

Get the Code

Subversion Repository. Get the HEAD revision using a Subversion client

Edit

Configuration

How to Configure Tile Server:

There are 2 main things you need to do to configure this for your site - add the layer to your Virtual Earth map control, setup a TileService in the web.config.

Adding a Tile Layer to the Virtual Earth Map Control:

Using version 6 of the Map control this is very easy (the Default.aspx file in the attached zip file has this code in it)

First Create a bounding box that will limit the area that Virtual Earth will make tile requests. This box is for Colorado.

var bounds = [new VELatLongRectangle(new VELatLong(40,-109),new VELatLong(37,-102))];

Next, create a Tile Source Specification. You will need to specify the full Url to the handler if your Virtual Earth page is not located in the same web application. What's important to note is that the name of the TileService must be in the url - in this case it's "colorado". You will need to change this to the name of the TileService you want this layer to pull from.
var tileSourceSpec = new VETileSourceSpecification("agssoap", "./colorado/%4.ashx");

From here, it's just setting some simple tile source properties...
tileSourceSpec.NumServers = 1;
tileSourceSpec.Bounds = bounds;
tileSourceSpec.MinZoomLevel = 10;
tileSourceSpec.MaxZoomLevel = 18;
tileSourceSpec.Opacity = 0.5;
tileSourceSpec.ZIndex = 100;

Finally you want to add the layer to your map
map.AddTileLayer(tileSourceSpec, true);

 

Setting up a Tile Service in Web.config

A Tile Service is a container for a Tile Provider and a Storage Provider, so we are going to set up these three things, and link them together. The web.config file in the download already has these sections in it - you will just need to change a few things.

Step 1: Configure the Tile Service

Change the service name to match what you put into the VETileSourceSpecification path, as this is the linkage between the Tile Service and the Url that the request is coming from. For now, leave the other elements alone.

<!-- Colorado Tile Service-->

      <component id="ColoradoVETileService"

                service="ArcDeveloper.TileServer.Interfaces.IVirtualEarthTileService, ArcDeveloper.TileServer.Interfaces"

                type="ArcDeveloper.TileServer.Core.VirtualEarthTileService, ArcDeveloper.TileServer.Core" >

        <parameters>

          <!-- Service Name - must be specified in the url parsed by the handler -->

          <servicename>colorado</servicename>

          <!-- The tile provider for this service is AGSColorado, with it's settings defined lower down -->

          <tileProvider>${AGSColorado}</tileProvider>

          <!-- The storage provide for the cache is the default FileStorage Provider, but this could be changed as needed -->

          <storageProvider>${FileStorageProvider}</storageProvider>

        </parameters>

      </component>

The other sections specify the TileProvider and StorageProvider that this Tile Service will use. If you want to use different or differently configurated providers, just copy/paste the sections and rename them. The configuration syntax here is based on the Castle Windsor project, and you can get more information about how this works by reading Simone Busoli's articles here: Part 1, Part 2, Part 3, and Part 4.

Step 2: Specify the Map Service URL

Locate the following section in the web.config

<component id="AGSColorado"

                service="ArcDeveloper.TileServer.Interfaces.ITileProvider, ArcDeveloper.TileServer.Interfaces"

                type="ArcDeveloper.TileServer.ArcGIS.ArcSoapTileProvider, ArcDeveloper.TileServer.ArcGIS">

        <parameters>

          <!-- Make sure this Url is accessible from this web server or you'll get an exception -->

          <webServiceUrl>http://YOURSERVER/arcgis/services/YOURSERVICENAME/MapServer</webServiceUrl>

        </parameters>

      </component

 

Step 3: Change the StorageProvider location

The Storage Provider is used to cache the tiles as they are created. Thus the location you specify must have write privileges granted to the identity that the ASP.NET application runs as (ASPNET on Windows XP and NETWORK SERVICE on Windows Server 2003)

<component id="FileStorageProvider"

                service="ArcDeveloper.TileServer.Interfaces.IStorageProvider, ArcDeveloper.TileServer.Interfaces"

                type="ArcDeveloper.TileServer.Core.FileStorageProvider, ArcDeveloper.TileServer.Core">

        <parameters>

          <!-- Make sure this path exists, or you'll get an Exception instantiating the FileStorageProvider -->

          <cacheFilePath>c:\tiles\</cacheFilePath>

        </parameters>

      </component>

That's it.



Edit

Known Issues

Edit

Labeling

Since the tiles are created one at a time, you do not want to use any labeling. This is because ArcGIS Server will try to place labels on all features within the 256 by 256 tile, and since you see 9 or more tiles on the screen at any time, the result looks really bad.
The API is designed to support using "super tiles" but this functionality was not implemented because of issues that occur when you are building the cache on the fly - should you overwrite any existing tiles with new tiles? What if a label crosses into an exsting tile, but that tile also had a label that extended into an adjacent one. Anyhow it gets complex, and as far as I can tell, a "super tile" strategy will only work if you are creating the tiles in an orderly fashion (see Future Extensions).

Edit

Empty Tiles

I'm not sure why this is occurring, but occasionally ArcGIS Server sends back an image that is just simply empty. No exception occurs, and there is nothing out of the ordinary in the image so it's very hard to trap.

Edit

Future Extensions

The Tile Server is based on a provider model, so we can easily extend it to create tiles from pretty much any mapping engine. The obvious ones which occur to me are:
  • ArcIMS Tile Provider
  • WMS Tile Provider
  • SharpMap Tile Provider

Addionally, I have thought about building a managment console type of Windows form application that would let you define areas to pre-cache.