Updated Tile loading API docs

This commit is contained in:
scroach
2018-08-01 10:39:30 +02:00
committed by ahocevar
parent 93b92d3990
commit 68ce6de0ca
2 changed files with 26 additions and 2 deletions

View File

@@ -11,6 +11,26 @@ import EventType from './events/EventType.js';
* A function that takes an {@link module:ol/Tile} for the tile and a * A function that takes an {@link module:ol/Tile} for the tile and a
* `{string}` for the url as arguments. * `{string}` for the url as arguments.
* *
*
* ```
* function (imageTile, src) {
* var xhr = new XMLHttpRequest();
* xhr.responseType = "blob";
* xhr.addEventListener("loadend", function (evt) {
* var data = this.response;
* if (typeof data !== "undefined") {
* imageTile.getImage().src = window.URL.createObjectURL(data);
* }
* });
* xhr.addEventListener('error', function () {
* // be sure to set the tile state to ERROR her or the tile will remain in the queue
* imageTile.setState(3);
* });
* xhr.open("GET", src);
* xhr.send();
* }
* ```
*
* @typedef {function(module:ol/Tile, string)} LoadFunction * @typedef {function(module:ol/Tile, string)} LoadFunction
* @api * @api
*/ */
@@ -44,7 +64,7 @@ import EventType from './events/EventType.js';
* Base class for tiles. * Base class for tiles.
* *
* @abstract * @abstract
*/ */
class Tile extends EventTarget { class Tile extends EventTarget {
/** /**
@@ -192,7 +212,10 @@ class Tile extends EventTarget {
} }
/** /**
* Sets the state of this tile. If you write your own tileLoadFunction,
* it is important to set the state correctly to {@link module:ol/TileState.ERROR} in order for the tile to be removed from the queue.
* @param {module:ol/TileState} state State. * @param {module:ol/TileState} state State.
* @api
*/ */
setState(state) { setState(state) {
this.state = state; this.state = state;

View File

@@ -5,7 +5,7 @@
/** /**
* @enum {number} * @enum {number}
*/ */
export default { const states = {
IDLE: 0, IDLE: 0,
LOADING: 1, LOADING: 1,
LOADED: 2, LOADED: 2,
@@ -13,3 +13,4 @@ export default {
EMPTY: 4, EMPTY: 4,
ABORT: 5 ABORT: 5
}; };
export default states;