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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. import Check from "../Core/Check.js";
  2. import clone from "../Core/clone.js";
  3. import defined from "../Core/defined.js";
  4. import Resource from "../Core/Resource.js";
  5. import RuntimeError from "../Core/RuntimeError.js";
  6. import hasExtension from "./hasExtension.js";
  7. import ImplicitSubdivisionScheme from "./ImplicitSubdivisionScheme.js";
  8. /**
  9. * An ImplicitTileset is a simple struct that stores information about the
  10. * structure of a single implicit tileset. This includes template URIs for
  11. * locating resources, details from the implicit root tile (bounding volume,
  12. * geometricError, etc.), and details about the subtrees (e.g. subtreeLevels,
  13. * subdivisionScheme).
  14. *
  15. * @alias ImplicitTileset
  16. * @constructor
  17. *
  18. * @param {Resource} baseResource The base resource for the tileset
  19. * @param {object} tileJson The JSON header of the tile with either implicit tiling (3D Tiles 1.1) or the 3DTILES_implicit_tiling extension.
  20. * @param {MetadataSchema} [metadataSchema] The metadata schema containing the implicit tile metadata class.
  21. * @private
  22. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  23. */
  24. function ImplicitTileset(baseResource, tileJson, metadataSchema) {
  25. const implicitTiling = hasExtension(tileJson, "3DTILES_implicit_tiling")
  26. ? tileJson.extensions["3DTILES_implicit_tiling"]
  27. : tileJson.implicitTiling;
  28. //>>includeStart('debug', pragmas.debug);
  29. Check.typeOf.object("implicitTiling", implicitTiling);
  30. //>>includeEnd('debug');
  31. /**
  32. * The base resource for the tileset. This is stored here as it is needed
  33. * later when expanding Implicit3DTileContents so tile URLs are relative
  34. * to the tileset, not the subtree file.
  35. *
  36. * @type {Resource}
  37. * @readonly
  38. * @private
  39. */
  40. this.baseResource = baseResource;
  41. /**
  42. * The geometric error of the root tile
  43. *
  44. * @type {number}
  45. * @readonly
  46. * @private
  47. */
  48. this.geometricError = tileJson.geometricError;
  49. /**
  50. * The metadata schema containing the implicit tile metadata class.
  51. *
  52. * @type {MetadataSchema|undefined}
  53. * @readonly
  54. * @private
  55. */
  56. this.metadataSchema = metadataSchema;
  57. // Due to using explicit tile metadata to store a tight bounding box
  58. // in some cases (see https://github.com/CesiumGS/cesium/pull/11365)
  59. // it's important that this bounding volume is computed from the tile JSON
  60. // (which is the original, possibly loose bounding volume) rather than
  61. // tile.boundingVolume which is the tighter one.
  62. const boundingVolume = tileJson.boundingVolume;
  63. if (
  64. !defined(boundingVolume.box) &&
  65. !defined(boundingVolume.region) &&
  66. !hasExtension(boundingVolume, "3DTILES_bounding_volume_S2") &&
  67. !hasExtension(boundingVolume, "3DTILES_bounding_volume_cylinder")
  68. ) {
  69. throw new RuntimeError(
  70. "Only box, region, 3DTILES_bounding_volume_S2, and 3DTILES_bounding_volume_cylinder are supported for implicit tiling",
  71. );
  72. }
  73. /**
  74. * The JSON representation of a bounding volume. This is either a box or a
  75. * region.
  76. *
  77. * @type {object}
  78. * @readonly
  79. * @private
  80. */
  81. this.boundingVolume = boundingVolume;
  82. /**
  83. * The refine strategy as a string, either 'ADD' or 'REPLACE'
  84. *
  85. * @type {string}
  86. * @readonly
  87. * @private
  88. */
  89. this.refine = tileJson.refine;
  90. /**
  91. * Template URI for the subtree resources, e.g.
  92. * <code>https://example.com/{level}/{x}/{y}.subtree</code>
  93. *
  94. * @type {Resource}
  95. * @readonly
  96. * @private
  97. */
  98. this.subtreeUriTemplate = new Resource({ url: implicitTiling.subtrees.uri });
  99. /**
  100. * Template URIs for locating content resources, e.g.
  101. * <code>https://example.com/{level}/{x}/{y}.b3dm</code>.
  102. * <p>
  103. * This is an array to support multiple contents.
  104. * </p>
  105. *
  106. * @type {Resource[]}
  107. * @readonly
  108. * @private
  109. */
  110. this.contentUriTemplates = [];
  111. /**
  112. * Store a copy of the content headers, so properties such as
  113. * <code>extras</code> or <code>extensions</code> are preserved when
  114. * {@link Cesium3DTile}s are created for each tile.
  115. * <p>
  116. * This is an array to support multiple contents.
  117. * </p>
  118. *
  119. * @type {object[]}
  120. * @readonly
  121. * @private
  122. */
  123. this.contentHeaders = [];
  124. const contentHeaders = gatherContentHeaders(tileJson);
  125. for (let i = 0; i < contentHeaders.length; i++) {
  126. const contentHeader = contentHeaders[i];
  127. this.contentHeaders.push(clone(contentHeader, true));
  128. const contentResource = new Resource({ url: contentHeader.uri });
  129. this.contentUriTemplates.push(contentResource);
  130. }
  131. /**
  132. * The maximum number of contents as well as content availability bitstreams.
  133. * This is used for loop bounds when checking content availability.
  134. *
  135. * @type {number}
  136. * @readonly
  137. * @private
  138. */
  139. this.contentCount = this.contentHeaders.length;
  140. /**
  141. * Stores a copy of the root implicit tile's JSON header. This is used
  142. * as a template for creating {@link Cesium3DTile}s. The following properties
  143. * are removed:
  144. *
  145. * <ul>
  146. * <li><code>tile.implicitTiling</code> to prevent infinite loops of implicit tiling</li>
  147. * <li><code>tile.extensions["3DTILES_implicit_tiling"]</code>, if used instead of tile.implicitTiling</li>
  148. * <li><code>tile.contents</code>, since contents are handled separately</li>
  149. * <li><code>tile.content</code>, if used instead of tile.contents</li>
  150. * <li><code>tile.extensions["3DTILES_multiple_contents"]</code>, if used instead of tile.contents or tile.content</li>
  151. * </ul>
  152. *
  153. * @type {object}
  154. * @readonly
  155. * @private
  156. */
  157. this.tileHeader = makeTileHeaderTemplate(tileJson);
  158. /**
  159. * The subdivision scheme for this implicit tileset; either OCTREE or QUADTREE
  160. *
  161. * @type {ImplicitSubdivisionScheme}
  162. * @readonly
  163. * @private
  164. */
  165. this.subdivisionScheme =
  166. ImplicitSubdivisionScheme[implicitTiling.subdivisionScheme];
  167. /**
  168. * The branching factor for this tileset. Either 4 for quadtrees or 8 for
  169. * octrees.
  170. *
  171. * @type {number}
  172. * @readonly
  173. * @private
  174. */
  175. this.branchingFactor = ImplicitSubdivisionScheme.getBranchingFactor(
  176. this.subdivisionScheme,
  177. );
  178. /**
  179. * How many distinct levels within each subtree. For example, a quadtree
  180. * with subtreeLevels = 2 will have 5 nodes per quadtree (1 root + 4 children)
  181. *
  182. * @type {number}
  183. * @readonly
  184. * @private
  185. */
  186. this.subtreeLevels = implicitTiling.subtreeLevels;
  187. /**
  188. * The number of levels containing available tiles in the tileset.
  189. *
  190. * @type {number}
  191. * @readonly
  192. * @private
  193. */
  194. if (defined(implicitTiling.availableLevels)) {
  195. this.availableLevels = implicitTiling.availableLevels;
  196. } else {
  197. this.availableLevels = implicitTiling.maximumLevel + 1;
  198. }
  199. }
  200. /**
  201. * Gather JSON headers for all contents in the tile.
  202. * This handles both regular tiles and tiles with multiple contents, either
  203. * in the contents array (3D Tiles 1.1) or the `3DTILES_multiple_contents` extension
  204. *
  205. * @param {object} tileJson The JSON header of the tile with either implicit tiling (3D Tiles 1.1) or the 3DTILES_implicit_tiling extension.
  206. * @return {object[]} An array of JSON headers for the contents of each tile
  207. * @private
  208. */
  209. function gatherContentHeaders(tileJson) {
  210. if (hasExtension(tileJson, "3DTILES_multiple_contents")) {
  211. const extension = tileJson.extensions["3DTILES_multiple_contents"];
  212. return defined(extension.contents) ? extension.contents : extension.content;
  213. }
  214. if (defined(tileJson.contents)) {
  215. return tileJson.contents;
  216. }
  217. if (defined(tileJson.content)) {
  218. return [tileJson.content];
  219. }
  220. return [];
  221. }
  222. function makeTileHeaderTemplate(tileJson) {
  223. const template = clone(tileJson, true);
  224. // Remove the implicit tiling extension to prevent infinite loops,
  225. // as well as content-related properties since content is handled separately
  226. if (defined(template.extensions)) {
  227. delete template.extensions["3DTILES_implicit_tiling"];
  228. delete template.extensions["3DTILES_multiple_contents"];
  229. // if there are no other extensions, remove the extensions property to
  230. // keep each tile simple
  231. if (Object.keys(template.extensions).length === 0) {
  232. delete template.extensions;
  233. }
  234. }
  235. delete template.implicitTiling;
  236. delete template.contents;
  237. delete template.content;
  238. return template;
  239. }
  240. export default ImplicitTileset;