yzt
2023-05-05 4c558c77a6a9d23f057f094c4dc3e315eabef497
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import defined from "../Core/defined.js";
import destroyObject from "../Core/destroyObject.js";
import ImageryState from "./ImageryState.js";
 
/**
 * Stores details about a tile of imagery.
 *
 * @alias Imagery
 * @private
 */
function Imagery(imageryLayer, x, y, level, rectangle) {
  this.imageryLayer = imageryLayer;
  this.x = x;
  this.y = y;
  this.level = level;
  this.request = undefined;
 
  if (level !== 0) {
    var parentX = (x / 2) | 0;
    var parentY = (y / 2) | 0;
    var parentLevel = level - 1;
    this.parent = imageryLayer.getImageryFromCache(
      parentX,
      parentY,
      parentLevel
    );
  }
 
  this.state = ImageryState.UNLOADED;
  this.imageUrl = undefined;
  this.image = undefined;
  this.texture = undefined;
  this.textureWebMercator = undefined;
  this.credits = undefined;
  this.referenceCount = 0;
 
  if (!defined(rectangle) && imageryLayer.imageryProvider.ready) {
    var tilingScheme = imageryLayer.imageryProvider.tilingScheme;
    rectangle = tilingScheme.tileXYToRectangle(x, y, level);
  }
 
  this.rectangle = rectangle;
}
Imagery.createPlaceholder = function (imageryLayer) {
  var result = new Imagery(imageryLayer, 0, 0, 0);
  result.addReference();
  result.state = ImageryState.PLACEHOLDER;
  return result;
};
 
Imagery.prototype.addReference = function () {
  ++this.referenceCount;
};
 
Imagery.prototype.releaseReference = function () {
  --this.referenceCount;
 
  if (this.referenceCount === 0) {
    this.imageryLayer.removeImageryFromCache(this);
 
    if (defined(this.parent)) {
      this.parent.releaseReference();
    }
 
    if (defined(this.image) && defined(this.image.destroy)) {
      this.image.destroy();
    }
 
    if (defined(this.texture)) {
      this.texture.destroy();
    }
 
    if (
      defined(this.textureWebMercator) &&
      this.texture !== this.textureWebMercator
    ) {
      this.textureWebMercator.destroy();
    }
 
    destroyObject(this);
 
    return 0;
  }
 
  return this.referenceCount;
};
 
Imagery.prototype.processStateMachine = function (
  frameState,
  needGeographicProjection,
  skipLoading
) {
  if (this.state === ImageryState.UNLOADED && !skipLoading) {
    this.state = ImageryState.TRANSITIONING;
    this.imageryLayer._requestImagery(this);
  }
 
  if (this.state === ImageryState.RECEIVED) {
    this.state = ImageryState.TRANSITIONING;
    this.imageryLayer._createTexture(frameState.context, this);
  }
 
  // If the imagery is already ready, but we need a geographic version and don't have it yet,
  // we still need to do the reprojection step. This can happen if the Web Mercator version
  // is fine initially, but the geographic one is needed later.
  var needsReprojection =
    this.state === ImageryState.READY &&
    needGeographicProjection &&
    !this.texture;
 
  if (this.state === ImageryState.TEXTURE_LOADED || needsReprojection) {
    this.state = ImageryState.TRANSITIONING;
    this.imageryLayer._reprojectTexture(
      frameState,
      this,
      needGeographicProjection
    );
  }
};
export default Imagery;