goog.provide('ol.source.ImageTileSource'); goog.provide('ol.source.ImageTileSourceOptions'); goog.require('ol.Attribution'); goog.require('ol.Extent'); goog.require('ol.ImageTile'); goog.require('ol.Projection'); goog.require('ol.TileCoord'); goog.require('ol.TileUrlFunction'); goog.require('ol.TileUrlFunctionType'); goog.require('ol.source.TileSource'); goog.require('ol.tilegrid.TileGrid'); /** * @typedef {{attributions: (Array.|undefined), * crossOrigin: (null|string|undefined), * extent: (ol.Extent|undefined), * projection: (ol.Projection|undefined), * tileGrid: (ol.tilegrid.TileGrid|undefined), * tileUrlFunction: (ol.TileUrlFunctionType|undefined)}} */ ol.source.ImageTileSourceOptions; /** * @constructor * @extends {ol.source.TileSource} * @param {ol.source.ImageTileSourceOptions} options Options. */ ol.source.ImageTileSource = function(options) { goog.base(this, { attributions: options.attributions, extent: options.extent, projection: options.projection, tileGrid: options.tileGrid }); /** * @protected * @type {ol.TileUrlFunctionType} */ this.tileUrlFunction = goog.isDef(options.tileUrlFunction) ? options.tileUrlFunction : ol.TileUrlFunction.nullTileUrlFunction; /** * @private * @type {?string} */ this.crossOrigin_ = goog.isDef(options.crossOrigin) ? options.crossOrigin : 'anonymous'; /** * @private * @type {Object.} * FIXME will need to expire elements from this cache * FIXME see elemoine's work with goog.structs.LinkedMap */ this.tileCache_ = {}; }; goog.inherits(ol.source.ImageTileSource, ol.source.TileSource); /** * @inheritDoc */ ol.source.ImageTileSource.prototype.getTile = function(tileCoord) { var key = tileCoord.toString(); if (goog.object.containsKey(this.tileCache_, key)) { return this.tileCache_[key]; } else { var tileUrl = this.getTileCoordUrl(tileCoord); var tile; if (goog.isDef(tileUrl)) { tile = new ol.ImageTile(tileCoord, tileUrl, this.crossOrigin_); } else { tile = null; } this.tileCache_[key] = tile; return tile; } }; /** * @param {ol.TileCoord} tileCoord Tile coordinate. * @return {string|undefined} Tile URL. */ ol.source.ImageTileSource.prototype.getTileCoordUrl = function(tileCoord) { return this.tileUrlFunction(tileCoord); };