Skip to content

Instantly share code, notes, and snippets.

@stoolrossa
Created December 13, 2012 13:34
Show Gist options
  • Save stoolrossa/4276415 to your computer and use it in GitHub Desktop.
Save stoolrossa/4276415 to your computer and use it in GitHub Desktop.
Example of S3TileMapServiceLayer class using the ArcGIS Javascript API, which gets the map service definition from an ArcGIS Server endpoint, and accesses the tiles from S3
dojo.require("esri.map");
dojo.require("esri.layers.agstiled");
dojo.require("dojo/string");
var map;
function init() {
dojo.declare("S3TiledMapServiceLayer", esri.layers.ArcGISTiledMapServiceLayer, {
constructor: function(mapServiceUrl, externalS3TileCacheUrl) {
this._s3TileUrl = externalS3TileCacheUrl;
dojo.safeMixin(this, mapServiceUrl);
}, // constructor
getTileUrl: function(level, row, col) {
return this._s3TileUrl
+ "/L" + dojo.string.pad(level.toString(), 2, '0')
+ "/R" + dojo.string.pad(row.toString(16), 8, '0')
+ "/C" + dojo.string.pad(col.toString(16), 8, '0')
+ ".png";
} // getTileUrl
});
var initExtent = new esri.geometry.Extent({ "xmin": 152.260192894019, "ymin": -27.6147957518947, "xmax": 153.686679767014, "ymax": -26.9985153513847, "spatialReference": { "wkid": 4283} });
map = new esri.Map("map",{extent:initExtent});
var tiledLayer = new S3TiledMapServiceLayer("http://<SERVER_NAME>/ArcGIS/rest/services/<MAP_SERVICE_NAME>/MapServer", "https://<S3_BUCKET.s3.amazonaws.com/_alllayers");
map.addLayer(tiledLayer);
dojo.connect(map, 'onLoad', function(theMap) {
//resize the map when the browser resizes
dojo.connect(window, 'resize', map,map.resize);
});
}
dojo.addOnLoad(init);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment