1
|
/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for
|
2
|
* full list of contributors). Published under the 2-clause BSD license.
|
3
|
* See license.txt in the OpenLayers distribution or repository for the
|
4
|
* full text of the license. */
|
5
|
|
6
|
|
7
|
/**
|
8
|
* @requires OpenLayers/Layer/Grid.js
|
9
|
*/
|
10
|
|
11
|
/**
|
12
|
* Class: OpenLayers.Layer.TMS
|
13
|
* Create a layer for accessing tiles from services that conform with the
|
14
|
* Tile Map Service Specification
|
15
|
* (http://wiki.osgeo.org/wiki/Tile_Map_Service_Specification).
|
16
|
*
|
17
|
* Example:
|
18
|
* (code)
|
19
|
* var layer = new OpenLayers.Layer.TMS(
|
20
|
* "My Layer", // name for display in LayerSwitcher
|
21
|
* "http://tilecache.osgeo.org/wms-c/Basic.py/", // service endpoint
|
22
|
* {layername: "basic", type: "png"} // required properties
|
23
|
* );
|
24
|
* (end)
|
25
|
*
|
26
|
* Inherits from:
|
27
|
* - <OpenLayers.Layer.Grid>
|
28
|
*/
|
29
|
OpenLayers.Layer.TMS = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
30
|
|
31
|
/**
|
32
|
* APIProperty: serviceVersion
|
33
|
* {String} Service version for tile requests. Default is "1.0.0".
|
34
|
*/
|
35
|
serviceVersion: "1.0.0",
|
36
|
|
37
|
/**
|
38
|
* APIProperty: layername
|
39
|
* {String} The identifier for the <TileMap> as advertised by the service.
|
40
|
* For example, if the service advertises a <TileMap> with
|
41
|
* 'href="http://tms.osgeo.org/1.0.0/vmap0"', the <layername> property
|
42
|
* would be set to "vmap0".
|
43
|
*/
|
44
|
layername: null,
|
45
|
|
46
|
/**
|
47
|
* APIProperty: type
|
48
|
* {String} The format extension corresponding to the requested tile image
|
49
|
* type. This is advertised in a <TileFormat> element as the
|
50
|
* "extension" attribute. For example, if the service advertises a
|
51
|
* <TileMap> with <TileFormat width="256" height="256" mime-type="image/jpeg" extension="jpg" />,
|
52
|
* the <type> property would be set to "jpg".
|
53
|
*/
|
54
|
type: null,
|
55
|
|
56
|
/**
|
57
|
* APIProperty: isBaseLayer
|
58
|
* {Boolean} Make this layer a base layer. Default is true. Set false to
|
59
|
* use the layer as an overlay.
|
60
|
*/
|
61
|
isBaseLayer: true,
|
62
|
|
63
|
/**
|
64
|
* APIProperty: tileOrigin
|
65
|
* {<OpenLayers.LonLat>} Optional origin for aligning the grid of tiles.
|
66
|
* If provided, requests for tiles at all resolutions will be aligned
|
67
|
* with this location (no tiles shall overlap this location). If
|
68
|
* not provided, the grid of tiles will be aligned with the bottom-left
|
69
|
* corner of the map's <maxExtent>. Default is ``null``.
|
70
|
*
|
71
|
* Example:
|
72
|
* (code)
|
73
|
* var layer = new OpenLayers.Layer.TMS(
|
74
|
* "My Layer",
|
75
|
* "http://tilecache.osgeo.org/wms-c/Basic.py/",
|
76
|
* {
|
77
|
* layername: "basic",
|
78
|
* type: "png",
|
79
|
* // set if different than the bottom left of map.maxExtent
|
80
|
* tileOrigin: new OpenLayers.LonLat(-180, -90)
|
81
|
* }
|
82
|
* );
|
83
|
* (end)
|
84
|
*/
|
85
|
tileOrigin: null,
|
86
|
|
87
|
/**
|
88
|
* APIProperty: serverResolutions
|
89
|
* {Array} A list of all resolutions available on the server. Only set this
|
90
|
* property if the map resolutions differ from the server. This
|
91
|
* property serves two purposes. (a) <serverResolutions> can include
|
92
|
* resolutions that the server supports and that you don't want to
|
93
|
* provide with this layer; you can also look at <zoomOffset>, which is
|
94
|
* an alternative to <serverResolutions> for that specific purpose.
|
95
|
* (b) The map can work with resolutions that aren't supported by
|
96
|
* the server, i.e. that aren't in <serverResolutions>. When the
|
97
|
* map is displayed in such a resolution data for the closest
|
98
|
* server-supported resolution is loaded and the layer div is
|
99
|
* stretched as necessary.
|
100
|
*/
|
101
|
serverResolutions: null,
|
102
|
|
103
|
/**
|
104
|
* APIProperty: zoomOffset
|
105
|
* {Number} If your cache has more zoom levels than you want to provide
|
106
|
* access to with this layer, supply a zoomOffset. This zoom offset
|
107
|
* is added to the current map zoom level to determine the level
|
108
|
* for a requested tile. For example, if you supply a zoomOffset
|
109
|
* of 3, when the map is at the zoom 0, tiles will be requested from
|
110
|
* level 3 of your cache. Default is 0 (assumes cache level and map
|
111
|
* zoom are equivalent). Using <zoomOffset> is an alternative to
|
112
|
* setting <serverResolutions> if you only want to expose a subset
|
113
|
* of the server resolutions.
|
114
|
*/
|
115
|
zoomOffset: 0,
|
116
|
|
117
|
/**
|
118
|
* Constructor: OpenLayers.Layer.TMS
|
119
|
*
|
120
|
* Parameters:
|
121
|
* name - {String} Title to be displayed in a <OpenLayers.Control.LayerSwitcher>
|
122
|
* url - {String} Service endpoint (without the version number). E.g.
|
123
|
* "http://tms.osgeo.org/".
|
124
|
* options - {Object} Additional properties to be set on the layer. The
|
125
|
* <layername> and <type> properties must be set here.
|
126
|
*/
|
127
|
initialize: function(name, url, options) {
|
128
|
var newArguments = [];
|
129
|
newArguments.push(name, url, {}, options);
|
130
|
OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
|
131
|
},
|
132
|
|
133
|
/**
|
134
|
* APIMethod: clone
|
135
|
* Create a complete copy of this layer.
|
136
|
*
|
137
|
* Parameters:
|
138
|
* obj - {Object} Should only be provided by subclasses that call this
|
139
|
* method.
|
140
|
*
|
141
|
* Returns:
|
142
|
* {<OpenLayers.Layer.TMS>} An exact clone of this <OpenLayers.Layer.TMS>
|
143
|
*/
|
144
|
clone: function (obj) {
|
145
|
|
146
|
if (obj == null) {
|
147
|
obj = new OpenLayers.Layer.TMS(this.name,
|
148
|
this.url,
|
149
|
this.getOptions());
|
150
|
}
|
151
|
|
152
|
//get all additions from superclasses
|
153
|
obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
|
154
|
|
155
|
// copy/set any non-init, non-simple values here
|
156
|
|
157
|
return obj;
|
158
|
},
|
159
|
|
160
|
/**
|
161
|
* Method: getURL
|
162
|
*
|
163
|
* Parameters:
|
164
|
* bounds - {<OpenLayers.Bounds>}
|
165
|
*
|
166
|
* Returns:
|
167
|
* {String} A string with the layer's url and parameters and also the
|
168
|
* passed-in bounds and appropriate tile size specified as
|
169
|
* parameters
|
170
|
*/
|
171
|
getURL: function (bounds) {
|
172
|
bounds = this.adjustBounds(bounds);
|
173
|
var res = this.getServerResolution();
|
174
|
var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w));
|
175
|
var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h));
|
176
|
var z = this.getServerZoom();
|
177
|
var path = this.serviceVersion + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type;
|
178
|
var url = this.url;
|
179
|
if (OpenLayers.Util.isArray(url)) {
|
180
|
url = this.selectUrl(path, url);
|
181
|
}
|
182
|
return url + path;
|
183
|
},
|
184
|
|
185
|
/**
|
186
|
* Method: setMap
|
187
|
* When the layer is added to a map, then we can fetch our origin
|
188
|
* (if we don't have one.)
|
189
|
*
|
190
|
* Parameters:
|
191
|
* map - {<OpenLayers.Map>}
|
192
|
*/
|
193
|
setMap: function(map) {
|
194
|
OpenLayers.Layer.Grid.prototype.setMap.apply(this, arguments);
|
195
|
if (!this.tileOrigin) {
|
196
|
this.tileOrigin = new OpenLayers.LonLat(this.map.maxExtent.left,
|
197
|
this.map.maxExtent.bottom);
|
198
|
}
|
199
|
},
|
200
|
|
201
|
CLASS_NAME: "OpenLayers.Layer.TMS"
|
202
|
});
|