Friday, September 12, 2008

ArcGIS Tiles on Amazon S3

Once you have generated your tiles from a map services, you can move these tiles to Amazon S3. I used the S3Fox Firefox extension to move the files from my local system to S3. In addition, make sure to copy the JSON map service metadata to a file named "MapServer" (without quotes of course :-). You can access these tiles using the Flex API for ArcGIS server as follows:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:esri="http://www.esri.com/2008/ags"
xmlns:s3="com.esri.s3.*"
layout="absolute"
>
<esri:Map>
<s3:S3ArcGISTiledMapServiceLayer
url="http://s3.amazonaws.com/your_map_service/MapServer"/>
</esri:Map>
</mx:Application>

And here is the implements of S3ArcGISTiledMapServiceLayer class:

package com.esri.s3
{
import com.esri.ags.layers.ArcGISTiledMapServiceLayer;

import flash.net.URLRequest;

public class S3ArcGISTiledMapServiceLayer extends ArcGISTiledMapServiceLayer
{
private var m_baseURL : String;

public function S3ArcGISTiledMapServiceLayer(url:String=null)
{
super(url);
}

override public function set url(value:String):void
{
super.url = value;
if( value )
{
var index : int = value.lastIndexOf( "/" );
m_baseURL = value.substr( 0, index );
}
else
{
m_baseURL = "";
}
}

override protected function getTileURL(
level:Number,
row:Number,
col:Number
):URLRequest
{
return new URLRequest( m_baseURL + "/l" + level + "r" + row + "c" + col + ".jpg" );
}
}
}

Note that I simplified the storage retrieval in the getTileURL function. ArcGIS places the tiles on the file system as a set of sub-directories of the form level/row/column.jpg. I decided (out of laziness :-) to keep it flat and have a set of files in the form lXrXcX.jpg.

9 comments:

Stuart said...

Great example. Have you tried using Akamai for storage of tile cache?

ThunderHead said...

Interesting idea - will connect with some folks here at ESRI that have Akamai knowledge and see what we can come up with :-)

Daniel said...

I must say that this blog is great!! I am a new-b to flex and the discussions, code, and examples here open my eyes to all the great possibilities. Thanks and keep blogging

ThunderHead said...

Glad you like it :-)

Greg said...

You are a madman Mr. Raad! Great stuff!

Jesse Andrews said...

https://addons.mozilla.org/en-US/firefox/addon/6955 is another option for interacting with S3 in firefox.

西域蝈蝈 said...

hello,i want to known "JSON map service metadata" how to create,give me a simple sample for "MapServer".thank

ThunderHead said...

Check out http://s3.amazonaws.com/ESRI_StreetMap_World_2D/MapServer

西域蝈蝈 said...

thanks.you help me more,I get my map metadata from my_map_service/MapServer?f=json. I'm intresting your blog.