Imagery.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import defined from "../Core/defined.js";
  2. import destroyObject from "../Core/destroyObject.js";
  3. import ImageryState from "./ImageryState.js";
  4. /**
  5. * Stores details about a tile of imagery.
  6. *
  7. * @alias Imagery
  8. * @private
  9. */
  10. function Imagery(imageryLayer, x, y, level, rectangle) {
  11. this.imageryLayer = imageryLayer;
  12. this.x = x;
  13. this.y = y;
  14. this.level = level;
  15. this.request = undefined;
  16. if (level !== 0) {
  17. const parentX = (x / 2) | 0;
  18. const parentY = (y / 2) | 0;
  19. const parentLevel = level - 1;
  20. this.parent = imageryLayer.getImageryFromCache(
  21. parentX,
  22. parentY,
  23. parentLevel
  24. );
  25. }
  26. this.state = ImageryState.UNLOADED;
  27. this.imageUrl = undefined;
  28. this.image = undefined;
  29. this.texture = undefined;
  30. this.textureWebMercator = undefined;
  31. this.credits = undefined;
  32. this.referenceCount = 0;
  33. // imageryProvider._ready is deprecated; This is here for backward compatibility
  34. if (
  35. !defined(rectangle) &&
  36. imageryLayer.ready &&
  37. imageryLayer.imageryProvider._ready
  38. ) {
  39. const tilingScheme = imageryLayer.imageryProvider.tilingScheme;
  40. rectangle = tilingScheme.tileXYToRectangle(x, y, level);
  41. }
  42. this.rectangle = rectangle;
  43. }
  44. Imagery.createPlaceholder = function (imageryLayer) {
  45. const result = new Imagery(imageryLayer, 0, 0, 0);
  46. result.addReference();
  47. result.state = ImageryState.PLACEHOLDER;
  48. return result;
  49. };
  50. Imagery.prototype.addReference = function () {
  51. ++this.referenceCount;
  52. };
  53. Imagery.prototype.releaseReference = function () {
  54. --this.referenceCount;
  55. if (this.referenceCount === 0) {
  56. this.imageryLayer.removeImageryFromCache(this);
  57. if (defined(this.parent)) {
  58. this.parent.releaseReference();
  59. }
  60. if (defined(this.image) && defined(this.image.destroy)) {
  61. this.image.destroy();
  62. }
  63. if (defined(this.texture)) {
  64. this.texture.destroy();
  65. }
  66. if (
  67. defined(this.textureWebMercator) &&
  68. this.texture !== this.textureWebMercator
  69. ) {
  70. this.textureWebMercator.destroy();
  71. }
  72. destroyObject(this);
  73. return 0;
  74. }
  75. return this.referenceCount;
  76. };
  77. Imagery.prototype.processStateMachine = function (
  78. frameState,
  79. needGeographicProjection,
  80. skipLoading
  81. ) {
  82. if (this.state === ImageryState.UNLOADED && !skipLoading) {
  83. this.state = ImageryState.TRANSITIONING;
  84. this.imageryLayer._requestImagery(this);
  85. }
  86. if (this.state === ImageryState.RECEIVED) {
  87. this.state = ImageryState.TRANSITIONING;
  88. this.imageryLayer._createTexture(frameState.context, this);
  89. }
  90. // If the imagery is already ready, but we need a geographic version and don't have it yet,
  91. // we still need to do the reprojection step. This can happen if the Web Mercator version
  92. // is fine initially, but the geographic one is needed later.
  93. const needsReprojection =
  94. this.state === ImageryState.READY &&
  95. needGeographicProjection &&
  96. !this.texture;
  97. if (this.state === ImageryState.TEXTURE_LOADED || needsReprojection) {
  98. this.state = ImageryState.TRANSITIONING;
  99. this.imageryLayer._reprojectTexture(
  100. frameState,
  101. this,
  102. needGeographicProjection
  103. );
  104. }
  105. };
  106. export default Imagery;