yzt
2023-05-26 de4278af2fd46705a40bac58ec01122db6b7f3d7
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
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;