Imagery.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. var parentX = x / 2 | 0;
  18. var parentY = y / 2 | 0;
  19. var parentLevel = level - 1;
  20. this.parent = imageryLayer.getImageryFromCache(parentX, parentY, parentLevel);
  21. }
  22. this.state = ImageryState.UNLOADED;
  23. this.imageUrl = undefined;
  24. this.image = undefined;
  25. this.texture = undefined;
  26. this.textureWebMercator = undefined;
  27. this.credits = undefined;
  28. this.referenceCount = 0;
  29. if (!defined(rectangle) && imageryLayer.imageryProvider.ready) {
  30. var tilingScheme = imageryLayer.imageryProvider.tilingScheme;
  31. rectangle = tilingScheme.tileXYToRectangle(x, y, level);
  32. }
  33. this.rectangle = rectangle;
  34. }
  35. Imagery.createPlaceholder = function(imageryLayer) {
  36. var result = new Imagery(imageryLayer, 0, 0, 0);
  37. result.addReference();
  38. result.state = ImageryState.PLACEHOLDER;
  39. return result;
  40. };
  41. Imagery.prototype.addReference = function() {
  42. ++this.referenceCount;
  43. };
  44. Imagery.prototype.releaseReference = function() {
  45. --this.referenceCount;
  46. if (this.referenceCount === 0) {
  47. this.imageryLayer.removeImageryFromCache(this);
  48. if (defined(this.parent)) {
  49. this.parent.releaseReference();
  50. }
  51. if (defined(this.image) && defined(this.image.destroy)) {
  52. this.image.destroy();
  53. }
  54. if (defined(this.texture)) {
  55. this.texture.destroy();
  56. }
  57. if (defined(this.textureWebMercator) && this.texture !== this.textureWebMercator) {
  58. this.textureWebMercator.destroy();
  59. }
  60. destroyObject(this);
  61. return 0;
  62. }
  63. return this.referenceCount;
  64. };
  65. Imagery.prototype.processStateMachine = function(frameState, needGeographicProjection, skipLoading) {
  66. if (this.state === ImageryState.UNLOADED && !skipLoading) {
  67. this.state = ImageryState.TRANSITIONING;
  68. this.imageryLayer._requestImagery(this);
  69. }
  70. if (this.state === ImageryState.RECEIVED) {
  71. this.state = ImageryState.TRANSITIONING;
  72. this.imageryLayer._createTexture(frameState.context, this);
  73. }
  74. // If the imagery is already ready, but we need a geographic version and don't have it yet,
  75. // we still need to do the reprojection step. This can happen if the Web Mercator version
  76. // is fine initially, but the geographic one is needed later.
  77. var needsReprojection = this.state === ImageryState.READY && needGeographicProjection && !this.texture;
  78. if (this.state === ImageryState.TEXTURE_LOADED || needsReprojection) {
  79. this.state = ImageryState.TRANSITIONING;
  80. this.imageryLayer._reprojectTexture(frameState, this, needGeographicProjection);
  81. }
  82. };
  83. export default Imagery;