1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2 * licence. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3 * full text of the license. */
7 * @requires OpenLayers/Layer/Grid.js
8 * @requires OpenLayers/Tile/Image.js
12 * Class: OpenLayers.Layer.TMS
15 * - <OpenLayers.Layer.Grid>
17 OpenLayers.Layer.TMS = OpenLayers.Class(OpenLayers.Layer.Grid, {
20 * APIProperty: serviceVersion
23 serviceVersion: "1.0.0",
26 * APIProperty: isBaseLayer
32 * APIProperty: tileOrigin
33 * {<OpenLayers.Pixel>}
38 * APIProperty: serverResolutions
39 * {Array} A list of all resolutions available on the server. Only set this
40 * property if the map resolutions differs from the server.
42 serverResolutions: null,
45 * Constructor: OpenLayers.Layer.TMS
50 * options - {Object} Hashtable of extra options to tag onto the layer
52 initialize: function(name, url, options) {
53 var newArguments = [];
54 newArguments.push(name, url, {}, options);
55 OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
62 // for now, nothing special to do here.
63 OpenLayers.Layer.Grid.prototype.destroy.apply(this, arguments);
74 * {<OpenLayers.Layer.TMS>} An exact clone of this <OpenLayers.Layer.TMS>
76 clone: function (obj) {
79 obj = new OpenLayers.Layer.TMS(this.name,
84 //get all additions from superclasses
85 obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
87 // copy/set any non-init, non-simple values here
96 * bounds - {<OpenLayers.Bounds>}
99 * {String} A string with the layer's url and parameters and also the
100 * passed-in bounds and appropriate tile size specified as
103 getURL: function (bounds) {
104 bounds = this.adjustBounds(bounds);
105 var res = this.map.getResolution();
106 var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w));
107 var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h));
108 var z = this.serverResolutions != null ?
109 OpenLayers.Util.indexOf(this.serverResolutions, res) :
111 var path = this.serviceVersion + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type;
113 if (url instanceof Array) {
114 url = this.selectUrl(path, url);
121 * addTile creates a tile, initializes it, and adds it to the layer div.
124 * bounds - {<OpenLayers.Bounds>}
125 * position - {<OpenLayers.Pixel>}
128 * {<OpenLayers.Tile.Image>} The added OpenLayers.Tile.Image
130 addTile:function(bounds,position) {
131 return new OpenLayers.Tile.Image(this, position, bounds,
132 null, this.tileSize);
137 * When the layer is added to a map, then we can fetch our origin
138 * (if we don't have one.)
141 * map - {<OpenLayers.Map>}
143 setMap: function(map) {
144 OpenLayers.Layer.Grid.prototype.setMap.apply(this, arguments);
145 if (!this.tileOrigin) {
146 this.tileOrigin = new OpenLayers.LonLat(this.map.maxExtent.left,
147 this.map.maxExtent.bottom);
151 CLASS_NAME: "OpenLayers.Layer.TMS"