1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337 | 1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
210×
210×
210×
210×
210×
210×
210×
1×
1×
26×
1×
1×
484×
484×
484×
484×
484×
566×
808×
808×
808×
18×
18×
18×
14×
808×
798×
484×
1×
25×
1×
545×
1×
161×
157×
157×
1×
1×
59×
1×
1×
1×
106×
1×
28×
7×
21×
1×
238×
238×
238×
1×
145×
1×
112×
112×
112×
112×
112×
1×
299×
299×
299×
271×
299×
1×
1×
1×
1×
1×
144×
144×
1×
| goog.provide('ol.source.Tile');
goog.require('ol');
goog.require('ol.TileCache');
goog.require('ol.TileState');
goog.require('ol.events.Event');
goog.require('ol.proj');
goog.require('ol.size');
goog.require('ol.source.Source');
goog.require('ol.tilecoord');
goog.require('ol.tilegrid');
/**
* @classdesc
* Abstract base class; normally only used for creating subclasses and not
* instantiated in apps.
* Base class for sources providing images divided into a tile grid.
*
* @constructor
* @abstract
* @extends {ol.source.Source}
* @param {ol.SourceTileOptions} options Tile source options.
* @api
*/
ol.source.Tile = function(options) {
ol.source.Source.call(this, {
attributions: options.attributions,
extent: options.extent,
logo: options.logo,
projection: options.projection,
state: options.state,
wrapX: options.wrapX
});
/**
* @private
* @type {boolean}
*/
this.opaque_ = options.opaque !== undefined ? options.opaque : false;
/**
* @private
* @type {number}
*/
this.tilePixelRatio_ = options.tilePixelRatio !== undefined ?
options.tilePixelRatio : 1;
/**
* @protected
* @type {ol.tilegrid.TileGrid}
*/
this.tileGrid = options.tileGrid !== undefined ? options.tileGrid : null;
/**
* @protected
* @type {ol.TileCache}
*/
this.tileCache = new ol.TileCache(options.cacheSize);
/**
* @protected
* @type {ol.Size}
*/
this.tmpSize = [0, 0];
/**
* @private
* @type {string}
*/
this.key_ = '';
};
ol.inherits(ol.source.Tile, ol.source.Source);
/**
* @return {boolean} Can expire cache.
*/
ol.source.Tile.prototype.canExpireCache = function() {
return this.tileCache.canExpireCache();
};
/**
* @param {ol.proj.Projection} projection Projection.
* @param {Object.<string, ol.TileRange>} usedTiles Used tiles.
*/
ol.source.Tile.prototype.expireCache = function(projection, usedTiles) {
var tileCache = this.getTileCacheForProjection(projection);
if (tileCache) {
tileCache.expireCache(usedTiles);
}
};
/**
* @param {ol.proj.Projection} projection Projection.
* @param {number} z Zoom level.
* @param {ol.TileRange} tileRange Tile range.
* @param {function(ol.Tile):(boolean|undefined)} callback Called with each
* loaded tile. If the callback returns `false`, the tile will not be
* considered loaded.
* @return {boolean} The tile range is fully covered with loaded tiles.
*/
ol.source.Tile.prototype.forEachLoadedTile = function(projection, z, tileRange, callback) {
var tileCache = this.getTileCacheForProjection(projection);
Iif (!tileCache) {
return false;
}
var covered = true;
var tile, tileCoordKey, loaded;
for (var x = tileRange.minX; x <= tileRange.maxX; ++x) {
for (var y = tileRange.minY; y <= tileRange.maxY; ++y) {
tileCoordKey = this.getKeyZXY(z, x, y);
loaded = false;
if (tileCache.containsKey(tileCoordKey)) {
tile = /** @type {!ol.Tile} */ (tileCache.get(tileCoordKey));
loaded = tile.getState() === ol.TileState.LOADED;
if (loaded) {
loaded = (callback(tile) !== false);
}
}
if (!loaded) {
covered = false;
}
}
}
return covered;
};
/**
* @param {ol.proj.Projection} projection Projection.
* @return {number} Gutter.
*/
ol.source.Tile.prototype.getGutter = function(projection) {
return 0;
};
/**
* Return the key to be used for all tiles in the source.
* @return {string} The key for all tiles.
* @protected
*/
ol.source.Tile.prototype.getKey = function() {
return this.key_;
};
/**
* Set the value to be used as the key for all tiles in the source.
* @param {string} key The key for tiles.
* @protected
*/
ol.source.Tile.prototype.setKey = function(key) {
if (this.key_ !== key) {
this.key_ = key;
this.changed();
}
};
/**
* @param {number} z Z.
* @param {number} x X.
* @param {number} y Y.
* @return {string} Key.
* @protected
*/
ol.source.Tile.prototype.getKeyZXY = ol.tilecoord.getKeyZXY;
/**
* @param {ol.proj.Projection} projection Projection.
* @return {boolean} Opaque.
*/
ol.source.Tile.prototype.getOpaque = function(projection) {
return this.opaque_;
};
/**
* @inheritDoc
*/
ol.source.Tile.prototype.getResolutions = function() {
return this.tileGrid.getResolutions();
};
/**
* @abstract
* @param {number} z Tile coordinate z.
* @param {number} x Tile coordinate x.
* @param {number} y Tile coordinate y.
* @param {number} pixelRatio Pixel ratio.
* @param {ol.proj.Projection} projection Projection.
* @return {!ol.Tile} Tile.
*/
ol.source.Tile.prototype.getTile = function(z, x, y, pixelRatio, projection) {};
/**
* Return the tile grid of the tile source.
* @return {ol.tilegrid.TileGrid} Tile grid.
* @api
*/
ol.source.Tile.prototype.getTileGrid = function() {
return this.tileGrid;
};
/**
* @param {ol.proj.Projection} projection Projection.
* @return {!ol.tilegrid.TileGrid} Tile grid.
*/
ol.source.Tile.prototype.getTileGridForProjection = function(projection) {
if (!this.tileGrid) {
return ol.tilegrid.getForProjection(projection);
} else {
return this.tileGrid;
}
};
/**
* @param {ol.proj.Projection} projection Projection.
* @return {ol.TileCache} Tile cache.
* @protected
*/
ol.source.Tile.prototype.getTileCacheForProjection = function(projection) {
var thisProj = this.getProjection();
Iif (thisProj && !ol.proj.equivalent(thisProj, projection)) {
return null;
} else {
return this.tileCache;
}
};
/**
* Get the tile pixel ratio for this source. Subclasses may override this
* method, which is meant to return a supported pixel ratio that matches the
* provided `pixelRatio` as close as possible.
* @param {number} pixelRatio Pixel ratio.
* @return {number} Tile pixel ratio.
*/
ol.source.Tile.prototype.getTilePixelRatio = function(pixelRatio) {
return this.tilePixelRatio_;
};
/**
* @param {number} z Z.
* @param {number} pixelRatio Pixel ratio.
* @param {ol.proj.Projection} projection Projection.
* @return {ol.Size} Tile size.
*/
ol.source.Tile.prototype.getTilePixelSize = function(z, pixelRatio, projection) {
var tileGrid = this.getTileGridForProjection(projection);
var tilePixelRatio = this.getTilePixelRatio(pixelRatio);
var tileSize = ol.size.toSize(tileGrid.getTileSize(z), this.tmpSize);
Eif (tilePixelRatio == 1) {
return tileSize;
} else {
return ol.size.scale(tileSize, tilePixelRatio, this.tmpSize);
}
};
/**
* Returns a tile coordinate wrapped around the x-axis. When the tile coordinate
* is outside the resolution and extent range of the tile grid, `null` will be
* returned.
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {ol.proj.Projection=} opt_projection Projection.
* @return {ol.TileCoord} Tile coordinate to be passed to the tileUrlFunction or
* null if no tile URL should be created for the passed `tileCoord`.
*/
ol.source.Tile.prototype.getTileCoordForTileUrlFunction = function(tileCoord, opt_projection) {
var projection = opt_projection !== undefined ?
opt_projection : this.getProjection();
var tileGrid = this.getTileGridForProjection(projection);
if (this.getWrapX() && projection.isGlobal()) {
tileCoord = ol.tilegrid.wrapX(tileGrid, tileCoord, projection);
}
return ol.tilecoord.withinExtentAndZ(tileCoord, tileGrid) ? tileCoord : null;
};
/**
* @inheritDoc
*/
ol.source.Tile.prototype.refresh = function() {
this.tileCache.clear();
this.changed();
};
/**
* Marks a tile coord as being used, without triggering a load.
* @param {number} z Tile coordinate z.
* @param {number} x Tile coordinate x.
* @param {number} y Tile coordinate y.
* @param {ol.proj.Projection} projection Projection.
*/
ol.source.Tile.prototype.useTile = ol.nullFunction;
/**
* @classdesc
* Events emitted by {@link ol.source.Tile} instances are instances of this
* type.
*
* @constructor
* @extends {ol.events.Event}
* @implements {oli.source.Tile.Event}
* @param {string} type Type.
* @param {ol.Tile} tile The tile.
*/
ol.source.Tile.Event = function(type, tile) {
ol.events.Event.call(this, type);
/**
* The tile related to the event.
* @type {ol.Tile}
* @api
*/
this.tile = tile;
};
ol.inherits(ol.source.Tile.Event, ol.events.Event);
|