智慧水务管理系统 - 精河县供水工程综合管理平台

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import defined from "../Core/defined.js";
  2. import ImageryState from "./ImageryState.js";
  3. /**
  4. * The assocation between a terrain tile and an imagery tile.
  5. *
  6. * @alias TileImagery
  7. * @private
  8. *
  9. * @param {Imagery} imagery The imagery tile.
  10. * @param {Cartesian4} textureCoordinateRectangle The texture rectangle of the tile that is covered
  11. * by the imagery, where X=west, Y=south, Z=east, W=north.
  12. * @param {boolean} useWebMercatorT true to use the Web Mercator texture coordinates for this imagery tile.
  13. */
  14. function TileImagery(imagery, textureCoordinateRectangle, useWebMercatorT) {
  15. this.readyImagery = undefined;
  16. this.loadingImagery = imagery;
  17. this.textureCoordinateRectangle = textureCoordinateRectangle;
  18. this.textureTranslationAndScale = undefined;
  19. this.useWebMercatorT = useWebMercatorT;
  20. }
  21. /**
  22. * Frees the resources held by this instance.
  23. */
  24. TileImagery.prototype.freeResources = function () {
  25. if (defined(this.readyImagery)) {
  26. this.readyImagery.releaseReference();
  27. }
  28. if (defined(this.loadingImagery)) {
  29. this.loadingImagery.releaseReference();
  30. }
  31. };
  32. /**
  33. * Processes the load state machine for this instance.
  34. *
  35. * @param {Tile} tile The tile to which this instance belongs.
  36. * @param {FrameState} frameState The frameState.
  37. * @param {boolean} skipLoading True to skip loading, e.g. new requests, creating textures. This function will
  38. * still synchronously process imagery that's already mostly ready to go, e.g. use textures
  39. * already loaded on ancestor tiles.
  40. * @returns {boolean} True if this instance is done loading; otherwise, false.
  41. */
  42. TileImagery.prototype.processStateMachine = function (
  43. tile,
  44. frameState,
  45. skipLoading,
  46. ) {
  47. const loadingImagery = this.loadingImagery;
  48. const imageryLayer = loadingImagery.imageryLayer;
  49. loadingImagery.processStateMachine(
  50. frameState,
  51. !this.useWebMercatorT,
  52. skipLoading,
  53. );
  54. if (loadingImagery.state === ImageryState.READY) {
  55. if (defined(this.readyImagery)) {
  56. this.readyImagery.releaseReference();
  57. }
  58. this.readyImagery = this.loadingImagery;
  59. this.loadingImagery = undefined;
  60. this.textureTranslationAndScale =
  61. imageryLayer._calculateTextureTranslationAndScale(tile, this);
  62. return true; // done loading
  63. }
  64. // Find some ancestor imagery we can use while this imagery is still loading.
  65. let ancestor = loadingImagery.parent;
  66. let closestAncestorThatNeedsLoading;
  67. while (
  68. defined(ancestor) &&
  69. (ancestor.state !== ImageryState.READY ||
  70. (!this.useWebMercatorT && !defined(ancestor.texture)))
  71. ) {
  72. if (
  73. ancestor.state !== ImageryState.FAILED &&
  74. ancestor.state !== ImageryState.INVALID
  75. ) {
  76. // ancestor is still loading
  77. closestAncestorThatNeedsLoading =
  78. closestAncestorThatNeedsLoading || ancestor;
  79. }
  80. ancestor = ancestor.parent;
  81. }
  82. if (this.readyImagery !== ancestor) {
  83. if (defined(this.readyImagery)) {
  84. this.readyImagery.releaseReference();
  85. }
  86. this.readyImagery = ancestor;
  87. if (defined(ancestor)) {
  88. ancestor.addReference();
  89. this.textureTranslationAndScale =
  90. imageryLayer._calculateTextureTranslationAndScale(tile, this);
  91. }
  92. }
  93. if (
  94. loadingImagery.state === ImageryState.FAILED ||
  95. loadingImagery.state === ImageryState.INVALID
  96. ) {
  97. // The imagery tile is failed or invalid, so we'd like to use an ancestor instead.
  98. if (defined(closestAncestorThatNeedsLoading)) {
  99. // Push the ancestor's load process along a bit. This is necessary because some ancestor imagery
  100. // tiles may not be attached directly to a terrain tile. Such tiles will never load if
  101. // we don't do it here.
  102. closestAncestorThatNeedsLoading.processStateMachine(
  103. frameState,
  104. !this.useWebMercatorT,
  105. skipLoading,
  106. );
  107. return false; // not done loading
  108. }
  109. // This imagery tile is failed or invalid, and we have the "best available" substitute.
  110. return true; // done loading
  111. }
  112. return false; // not done loading
  113. };
  114. export default TileImagery;