You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.0 KiB
JavaScript
80 lines
2.0 KiB
JavaScript
import createTileKey from "./createTileKey.js";
|
|
import runLater from "./runLater.js";
|
|
import { GeographicTilingScheme } from "../Source/Cesium.js";
|
|
import { Resource } from "../Source/Cesium.js";
|
|
import { RuntimeError } from "../Source/Cesium.js";
|
|
import { when } from "../Source/Cesium.js";
|
|
|
|
function MockImageryProvider() {
|
|
this.tilingScheme = new GeographicTilingScheme();
|
|
this.ready = false;
|
|
this.rectangle = this.tilingScheme.rectangle;
|
|
this.tileWidth = 256;
|
|
this.tileHeight = 256;
|
|
this._requestImageWillSucceed = {};
|
|
|
|
var that = this;
|
|
Resource.fetchImage("./Data/Images/Green.png").then(function (image) {
|
|
that.ready = true;
|
|
that._image = image;
|
|
});
|
|
}
|
|
|
|
MockImageryProvider.prototype.requestImage = function (x, y, level, request) {
|
|
var willSucceed = this._requestImageWillSucceed[createTileKey(x, y, level)];
|
|
if (willSucceed === undefined) {
|
|
return undefined; // defer by default
|
|
}
|
|
|
|
var that = this;
|
|
return runLater(function () {
|
|
if (willSucceed === true) {
|
|
return that._image;
|
|
} else if (willSucceed === false) {
|
|
throw new RuntimeError("requestImage failed as request.");
|
|
}
|
|
|
|
return when(willSucceed).then(function () {
|
|
return that._image;
|
|
});
|
|
});
|
|
};
|
|
|
|
MockImageryProvider.prototype.requestImageWillSucceed = function (
|
|
xOrTile,
|
|
y,
|
|
level
|
|
) {
|
|
this._requestImageWillSucceed[createTileKey(xOrTile, y, level)] = true;
|
|
return this;
|
|
};
|
|
|
|
MockImageryProvider.prototype.requestImageWillFail = function (
|
|
xOrTile,
|
|
y,
|
|
level
|
|
) {
|
|
this._requestImageWillSucceed[createTileKey(xOrTile, y, level)] = false;
|
|
return this;
|
|
};
|
|
|
|
MockImageryProvider.prototype.requestImageWillDefer = function (
|
|
xOrTile,
|
|
y,
|
|
level
|
|
) {
|
|
this._requestImageWillSucceed[createTileKey(xOrTile, y, level)] = undefined;
|
|
return this;
|
|
};
|
|
|
|
MockImageryProvider.prototype.requestImageWillWaitOn = function (
|
|
promise,
|
|
xOrTile,
|
|
y,
|
|
level
|
|
) {
|
|
this._requestImageWillSucceed[createTileKey(xOrTile, y, level)] = promise;
|
|
return this;
|
|
};
|
|
export default MockImageryProvider;
|