forked from CesiumGS/cesium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMockImageryProvider.js
82 lines (73 loc) · 1.94 KB
/
MockImageryProvider.js
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
import createTileKey from "./createTileKey.js";
import runLater from "./runLater.js";
import {
Event,
GeographicTilingScheme,
Resource,
RuntimeError,
} 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.errorEvent = new Event();
this._requestImageWillSucceed = {};
const 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) {
const willSucceed = this._requestImageWillSucceed[createTileKey(x, y, level)];
if (willSucceed === undefined) {
return undefined; // defer by default
}
const that = this;
return runLater(function () {
if (willSucceed === true) {
return that._image;
} else if (willSucceed === false) {
throw new RuntimeError("requestImage failed as request.");
}
return Promise.resolve(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;