Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stoolrossa/4276447 to your computer and use it in GitHub Desktop.
Save stoolrossa/4276447 to your computer and use it in GitHub Desktop.
Example of S3TileMapServiceLayer class using the ArcGIS Javascript API, with a configurable definition for the map service details.
dojo.require("esri.map");
dojo.require("esri.layers.tiled");
dojo.require("dojo/string");
var map;
function init() {
dojo.declare("S3TiledMapServiceLayer", esri.layers.TiledMapServiceLayer, {
constructor: function(externalS3TileCacheUrl, serviceDetails) {
this._s3TileUrl = externalS3TileCacheUrl;
this.spatialReference = serviceDetails.spatialReference;
this.initialExtent = serviceDetails.initialExtent;
this.fullExtent = serviceDetails.fullExtent;
this.tileInfo = new esri.layers.TileInfo(serviceDetails.tileInfo);
this.loaded = true;
this.onLoad(this);
}, // 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 serviceDetails = {
"spatialReference" : {
"wkid" : 4283
},
"tileInfo" : {
"rows" : 256,
"cols" : 256,
"dpi" : 96,
"format" : "PNG32",
"compressionQuality" : 0,
"origin" : {
"x" : -400,
"y" : 9006799.25474099
},
"spatialReference" : {
"wkid" : 4283
},
"lods" : [
{"level" : 0, "resolution" : 4.75892201166056E-05, "scale" : 20000},
{"level" : 1, "resolution" : 3.56919150874542E-05, "scale" : 15000},
{"level" : 2, "resolution" : 2.37946100583028E-05, "scale" : 10000}
]
},
"initialExtent" : {
"xmin" : 152.260192894019,
"ymin" : -27.6147957518947,
"xmax" : 153.686679767014,
"ymax" : -26.9985153513847,
"spatialReference" : {
"wkid" : 4283
}
},
"fullExtent" : {
"xmin" : 137.994646199563,
"ymin" : -29.178663414,
"xmax" : 153.551849592,
"ymax" : -9.08799055699995,
"spatialReference" : {
"wkid" : 4283
}
}
};
var tiledLayer = new S3TiledMapServiceLayer("https://<S3_BUCKET>.s3.amazonaws.com/_alllayers", serviceDetails);
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