UNPKG

3.77 kBTypeScriptView Raw
1import Target from './events/Target';
2import Projection from './proj/Projection';
3import { TileCoord } from './tilecoord';
4import TileState from './TileState';
5
6/**
7 * A function that takes an {@link module:ol/Tile} for the tile and a
8 * {string} for the url as arguments. The default is
9 * <code>source.setTileLoadFunction(function(tile, src) {
10 * tile.getImage().src = src;
11 * });</code>For more fine grained control, the load function can use fetch or XMLHttpRequest and involve
12 * error handling:
13 * <code>import TileState from 'ol/TileState';
14 *
15 * source.setTileLoadFunction(function(tile, src) {
16 * var xhr = new XMLHttpRequest();
17 * xhr.responseType = 'blob';
18 * xhr.addEventListener('loadend', function (evt) {
19 * var data = this.response;
20 * if (data !== undefined) {
21 * tile.getImage().src = URL.createObjectURL(data);
22 * } else {
23 * tile.setState(TileState.ERROR);
24 * }
25 * });
26 * xhr.addEventListener('error', function () {
27 * tile.setState(TileState.ERROR);
28 * });
29 * xhr.open('GET', src);
30 * xhr.send();
31 * });</code>
32 */
33export type LoadFunction = (p0: Tile, p1: string) => void;
34export interface Options {
35 transition?: number | undefined;
36}
37/**
38 * {@link module:ol/source/Tile~Tile} sources use a function of this type to get
39 * the url that provides a tile for a given tile coordinate.
40 * This function takes an {@link module:ol/tilecoord~TileCoord} for the tile
41 * coordinate, a {number} representing the pixel ratio and a
42 * {@link module:ol/proj/Projection} for the projection as arguments
43 * and returns a {string} representing the tile URL, or undefined if no tile
44 * should be requested for the passed tile coordinate.
45 */
46export type UrlFunction = (p0: TileCoord, p1: number, p2: Projection) => string | undefined;
47export default abstract class Tile extends Target {
48 constructor(tileCoord: TileCoord, state: TileState, opt_options?: Options);
49 protected state: TileState;
50 protected changed(): void;
51 /**
52 * Mark a transition as complete.
53 */
54 endTransition(id: string): void;
55 /**
56 * Get the alpha value for rendering.
57 */
58 getAlpha(id: string, time: number): number;
59 /**
60 * Get the interim tile most suitable for rendering using the chain of interim
61 * tiles. This corresponds to the most recent tile that has been loaded, if no
62 * such tile exists, the original tile is returned.
63 */
64 getInterimTile(): Tile;
65 getKey(): string;
66 getState(): TileState;
67 /**
68 * Get the tile coordinate for this tile.
69 */
70 getTileCoord(): TileCoord;
71 /**
72 * Determine if a tile is in an alpha transition. A tile is considered in
73 * transition if tile.getAlpha() has not yet been called or has been called
74 * and returned 1.
75 */
76 inTransition(id: string): boolean;
77 /**
78 * Load the image or retry if loading previously failed.
79 * Loading is taken care of by the tile queue, and calling this method is
80 * only needed for preloading or for reloading in case of an error.
81 */
82 abstract load(): void;
83 /**
84 * Goes through the chain of interim tiles and discards sections of the chain
85 * that are no longer relevant.
86 */
87 refreshInterimChain(): void;
88 /**
89 * Called by the tile cache when the tile is removed from the cache due to expiry
90 */
91 release(): void;
92 /**
93 * Sets the state of this tile. If you write your own {@link module:ol/Tile~LoadFunction tileLoadFunction} ,
94 * it is important to set the state correctly to {@link module:ol/TileState~ERROR}
95 * when the tile cannot be loaded. Otherwise the tile cannot be removed from
96 * the tile queue and will block other requests.
97 */
98 setState(state: TileState): void;
99}