GoogleEarthEnterpriseTileInformation.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import defined from './defined.js';
  2. import isBitSet from './isBitSet.js';
  3. // Bitmask for checking tile properties
  4. var childrenBitmasks = [0x01, 0x02, 0x04, 0x08];
  5. var anyChildBitmask = 0x0F;
  6. var cacheFlagBitmask = 0x10; // True if there is a child subtree
  7. var imageBitmask = 0x40;
  8. var 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(bits, cnodeVersion, imageryVersion, terrainVersion, imageryProvider, terrainProvider) {
  22. this._bits = bits;
  23. this.cnodeVersion = cnodeVersion;
  24. this.imageryVersion = imageryVersion;
  25. this.terrainVersion = terrainVersion;
  26. this.imageryProvider = imageryProvider;
  27. this.terrainProvider = terrainProvider;
  28. this.ancestorHasTerrain = false; // Set it later once we find its parent
  29. this.terrainState = undefined;
  30. }
  31. /**
  32. * Creates GoogleEarthEnterpriseTileInformation from an object
  33. *
  34. * @param {Object} info Object to be cloned
  35. * @param {GoogleEarthEnterpriseTileInformation} [result] The object onto which to store the result.
  36. * @returns {GoogleEarthEnterpriseTileInformation} The modified result parameter or a new GoogleEarthEnterpriseTileInformation instance if none was provided.
  37. */
  38. GoogleEarthEnterpriseTileInformation.clone = function(info, result) {
  39. if (!defined(result)) {
  40. result = new GoogleEarthEnterpriseTileInformation(info._bits, info.cnodeVersion, info.imageryVersion, info.terrainVersion,
  41. info.imageryProvider, info.terrainProvider);
  42. } else {
  43. result._bits = info._bits;
  44. result.cnodeVersion = info.cnodeVersion;
  45. result.imageryVersion = info.imageryVersion;
  46. result.terrainVersion = info.terrainVersion;
  47. result.imageryProvider = info.imageryProvider;
  48. result.terrainProvider = info.terrainProvider;
  49. }
  50. result.ancestorHasTerrain = info.ancestorHasTerrain;
  51. result.terrainState = info.terrainState;
  52. return result;
  53. };
  54. /**
  55. * Sets the parent for the tile
  56. *
  57. * @param {GoogleEarthEnterpriseTileInformation} parent Parent tile
  58. */
  59. GoogleEarthEnterpriseTileInformation.prototype.setParent = function(parent) {
  60. this.ancestorHasTerrain = parent.ancestorHasTerrain || this.hasTerrain();
  61. };
  62. /**
  63. * Gets whether a subtree is available
  64. *
  65. * @returns {Boolean} true if subtree is available, false otherwise.
  66. */
  67. GoogleEarthEnterpriseTileInformation.prototype.hasSubtree = function() {
  68. return isBitSet(this._bits, cacheFlagBitmask);
  69. };
  70. /**
  71. * Gets whether imagery is available
  72. *
  73. * @returns {Boolean} true if imagery is available, false otherwise.
  74. */
  75. GoogleEarthEnterpriseTileInformation.prototype.hasImagery = function() {
  76. return isBitSet(this._bits, imageBitmask);
  77. };
  78. /**
  79. * Gets whether terrain is available
  80. *
  81. * @returns {Boolean} true if terrain is available, false otherwise.
  82. */
  83. GoogleEarthEnterpriseTileInformation.prototype.hasTerrain = function() {
  84. return isBitSet(this._bits, terrainBitmask);
  85. };
  86. /**
  87. * Gets whether any children are present
  88. *
  89. * @returns {Boolean} true if any children are available, false otherwise.
  90. */
  91. GoogleEarthEnterpriseTileInformation.prototype.hasChildren = function() {
  92. return isBitSet(this._bits, anyChildBitmask);
  93. };
  94. /**
  95. * Gets whether a specified child is available
  96. *
  97. * @param {Number} index Index of child tile
  98. *
  99. * @returns {Boolean} true if child is available, false otherwise
  100. */
  101. GoogleEarthEnterpriseTileInformation.prototype.hasChild = function(index) {
  102. return isBitSet(this._bits, childrenBitmasks[index]);
  103. };
  104. /**
  105. * Gets bitmask containing children
  106. *
  107. * @returns {Number} Children bitmask
  108. */
  109. GoogleEarthEnterpriseTileInformation.prototype.getChildBitmask = function() {
  110. return this._bits & anyChildBitmask;
  111. };
  112. export default GoogleEarthEnterpriseTileInformation;