GoogleEarthEnterpriseTileInformation.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import defined from "./defined.js";
  2. import isBitSet from "./isBitSet.js";
  3. // Bitmask for checking tile properties
  4. const childrenBitmasks = [0x01, 0x02, 0x04, 0x08];
  5. const anyChildBitmask = 0x0f;
  6. const cacheFlagBitmask = 0x10; // True if there is a child subtree
  7. const imageBitmask = 0x40;
  8. const terrainBitmask = 0x80;
  9. /**
  10. * Contains information about each tile from a Google Earth Enterprise server
  11. *
  12. * @param {Number} bits Bitmask that contains the type of data and available children for each tile.
  13. * @param {Number} cnodeVersion Version of the request for subtree metadata.
  14. * @param {Number} imageryVersion Version of the request for imagery tile.
  15. * @param {Number} terrainVersion Version of the request for terrain tile.
  16. * @param {Number} imageryProvider Id of imagery provider.
  17. * @param {Number} terrainProvider Id of terrain provider.
  18. *
  19. * @private
  20. */
  21. function GoogleEarthEnterpriseTileInformation(
  22. bits,
  23. cnodeVersion,
  24. imageryVersion,
  25. terrainVersion,
  26. imageryProvider,
  27. terrainProvider
  28. ) {
  29. this._bits = bits;
  30. this.cnodeVersion = cnodeVersion;
  31. this.imageryVersion = imageryVersion;
  32. this.terrainVersion = terrainVersion;
  33. this.imageryProvider = imageryProvider;
  34. this.terrainProvider = terrainProvider;
  35. this.ancestorHasTerrain = false; // Set it later once we find its parent
  36. this.terrainState = undefined;
  37. }
  38. /**
  39. * Creates GoogleEarthEnterpriseTileInformation from an object
  40. *
  41. * @param {Object} info Object to be cloned
  42. * @param {GoogleEarthEnterpriseTileInformation} [result] The object onto which to store the result.
  43. * @returns {GoogleEarthEnterpriseTileInformation} The modified result parameter or a new GoogleEarthEnterpriseTileInformation instance if none was provided.
  44. */
  45. GoogleEarthEnterpriseTileInformation.clone = function (info, result) {
  46. if (!defined(result)) {
  47. result = new GoogleEarthEnterpriseTileInformation(
  48. info._bits,
  49. info.cnodeVersion,
  50. info.imageryVersion,
  51. info.terrainVersion,
  52. info.imageryProvider,
  53. info.terrainProvider
  54. );
  55. } else {
  56. result._bits = info._bits;
  57. result.cnodeVersion = info.cnodeVersion;
  58. result.imageryVersion = info.imageryVersion;
  59. result.terrainVersion = info.terrainVersion;
  60. result.imageryProvider = info.imageryProvider;
  61. result.terrainProvider = info.terrainProvider;
  62. }
  63. result.ancestorHasTerrain = info.ancestorHasTerrain;
  64. result.terrainState = info.terrainState;
  65. return result;
  66. };
  67. /**
  68. * Sets the parent for the tile
  69. *
  70. * @param {GoogleEarthEnterpriseTileInformation} parent Parent tile
  71. */
  72. GoogleEarthEnterpriseTileInformation.prototype.setParent = function (parent) {
  73. this.ancestorHasTerrain = parent.ancestorHasTerrain || this.hasTerrain();
  74. };
  75. /**
  76. * Gets whether a subtree is available
  77. *
  78. * @returns {Boolean} true if subtree is available, false otherwise.
  79. */
  80. GoogleEarthEnterpriseTileInformation.prototype.hasSubtree = function () {
  81. return isBitSet(this._bits, cacheFlagBitmask);
  82. };
  83. /**
  84. * Gets whether imagery is available
  85. *
  86. * @returns {Boolean} true if imagery is available, false otherwise.
  87. */
  88. GoogleEarthEnterpriseTileInformation.prototype.hasImagery = function () {
  89. return isBitSet(this._bits, imageBitmask);
  90. };
  91. /**
  92. * Gets whether terrain is available
  93. *
  94. * @returns {Boolean} true if terrain is available, false otherwise.
  95. */
  96. GoogleEarthEnterpriseTileInformation.prototype.hasTerrain = function () {
  97. return isBitSet(this._bits, terrainBitmask);
  98. };
  99. /**
  100. * Gets whether any children are present
  101. *
  102. * @returns {Boolean} true if any children are available, false otherwise.
  103. */
  104. GoogleEarthEnterpriseTileInformation.prototype.hasChildren = function () {
  105. return isBitSet(this._bits, anyChildBitmask);
  106. };
  107. /**
  108. * Gets whether a specified child is available
  109. *
  110. * @param {Number} index Index of child tile
  111. *
  112. * @returns {Boolean} true if child is available, false otherwise
  113. */
  114. GoogleEarthEnterpriseTileInformation.prototype.hasChild = function (index) {
  115. return isBitSet(this._bits, childrenBitmasks[index]);
  116. };
  117. /**
  118. * Gets bitmask containing children
  119. *
  120. * @returns {Number} Children bitmask
  121. */
  122. GoogleEarthEnterpriseTileInformation.prototype.getChildBitmask = function () {
  123. return this._bits & anyChildBitmask;
  124. };
  125. export default GoogleEarthEnterpriseTileInformation;