CesiumInspector.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. import defined from '../../Core/defined.js';
  2. import defineProperties from '../../Core/defineProperties.js';
  3. import destroyObject from '../../Core/destroyObject.js';
  4. import DeveloperError from '../../Core/DeveloperError.js';
  5. import knockout from '../../ThirdParty/knockout.js';
  6. import getElement from '../getElement.js';
  7. import InspectorShared from '../InspectorShared.js';
  8. import CesiumInspectorViewModel from './CesiumInspectorViewModel.js';
  9. /**
  10. * Inspector widget to aid in debugging
  11. *
  12. * @alias CesiumInspector
  13. * @constructor
  14. *
  15. * @param {Element|String} container The DOM element or ID that will contain the widget.
  16. * @param {Scene} scene The Scene instance to use.
  17. *
  18. * @demo {@link https://sandcastle.cesium.com/index.html?src=Cesium%20Inspector.html|Cesium Sandcastle Cesium Inspector Demo}
  19. */
  20. function CesiumInspector(container, scene) {
  21. //>>includeStart('debug', pragmas.debug);
  22. if (!defined(container)) {
  23. throw new DeveloperError('container is required.');
  24. }
  25. if (!defined(scene)) {
  26. throw new DeveloperError('scene is required.');
  27. }
  28. //>>includeEnd('debug');
  29. container = getElement(container);
  30. var performanceContainer = document.createElement('div');
  31. var viewModel = new CesiumInspectorViewModel(scene, performanceContainer);
  32. this._viewModel = viewModel;
  33. this._container = container;
  34. var element = document.createElement('div');
  35. this._element = element;
  36. var text = document.createElement('div');
  37. text.textContent = 'Cesium Inspector';
  38. text.className = 'cesium-cesiumInspector-button';
  39. text.setAttribute('data-bind', 'click: toggleDropDown');
  40. element.appendChild(text);
  41. element.className = 'cesium-cesiumInspector';
  42. element.setAttribute('data-bind', 'css: { "cesium-cesiumInspector-visible" : dropDownVisible, "cesium-cesiumInspector-hidden" : !dropDownVisible }');
  43. container.appendChild(this._element);
  44. var panel = document.createElement('div');
  45. this._panel = panel;
  46. panel.className = 'cesium-cesiumInspector-dropDown';
  47. element.appendChild(panel);
  48. var createSection = InspectorShared.createSection;
  49. var createCheckbox = InspectorShared.createCheckbox;
  50. // General
  51. var generalSection = createSection(panel, 'General', 'generalVisible', 'toggleGeneral');
  52. var debugShowFrustums = createCheckbox('Show Frustums', 'frustums');
  53. var frustumStatistics = document.createElement('div');
  54. frustumStatistics.className = 'cesium-cesiumInspector-frustumStatistics';
  55. frustumStatistics.setAttribute('data-bind', 'visible: frustums, html: frustumStatisticText');
  56. debugShowFrustums.appendChild(frustumStatistics);
  57. generalSection.appendChild(debugShowFrustums);
  58. generalSection.appendChild(createCheckbox('Show Frustum Planes', 'frustumPlanes'));
  59. generalSection.appendChild(createCheckbox('Performance Display', 'performance'));
  60. performanceContainer.className = 'cesium-cesiumInspector-performanceDisplay';
  61. generalSection.appendChild(performanceContainer);
  62. var shaderCacheDisplay = document.createElement('div');
  63. shaderCacheDisplay.className = 'cesium-cesiumInspector-shaderCache';
  64. shaderCacheDisplay.setAttribute('data-bind', 'html: shaderCacheText');
  65. generalSection.appendChild(shaderCacheDisplay);
  66. // https://github.com/AnalyticalGraphicsInc/cesium/issues/6763
  67. // var globeDepth = createCheckbox('Show globe depth', 'globeDepth');
  68. // generalSection.appendChild(globeDepth);
  69. //
  70. // var globeDepthFrustum = document.createElement('div');
  71. // globeDepth.appendChild(globeDepthFrustum);
  72. //
  73. // generalSection.appendChild(createCheckbox('Show pick depth', 'pickDepth'));
  74. var depthFrustum = document.createElement('div');
  75. generalSection.appendChild(depthFrustum);
  76. // Use a span with HTML binding so that we can indent with non-breaking spaces.
  77. var gLabel = document.createElement('span');
  78. gLabel.setAttribute('data-bind', 'html: "     Frustum:"');
  79. depthFrustum.appendChild(gLabel);
  80. var gText = document.createElement('span');
  81. gText.setAttribute('data-bind', 'text: depthFrustumText');
  82. depthFrustum.appendChild(gText);
  83. var gMinusButton = document.createElement('input');
  84. gMinusButton.type = 'button';
  85. gMinusButton.value = '-';
  86. gMinusButton.className = 'cesium-cesiumInspector-pickButton';
  87. gMinusButton.setAttribute('data-bind', 'click: decrementDepthFrustum');
  88. depthFrustum.appendChild(gMinusButton);
  89. var gPlusButton = document.createElement('input');
  90. gPlusButton.type = 'button';
  91. gPlusButton.value = '+';
  92. gPlusButton.className = 'cesium-cesiumInspector-pickButton';
  93. gPlusButton.setAttribute('data-bind', 'click: incrementDepthFrustum');
  94. depthFrustum.appendChild(gPlusButton);
  95. // Primitives
  96. var primSection = createSection(panel, 'Primitives', 'primitivesVisible', 'togglePrimitives');
  97. var pickPrimRequired = document.createElement('div');
  98. pickPrimRequired.className = 'cesium-cesiumInspector-pickSection';
  99. primSection.appendChild(pickPrimRequired);
  100. var pickPrimitiveButton = document.createElement('input');
  101. pickPrimitiveButton.type = 'button';
  102. pickPrimitiveButton.value = 'Pick a primitive';
  103. pickPrimitiveButton.className = 'cesium-cesiumInspector-pickButton';
  104. pickPrimitiveButton.setAttribute('data-bind', 'css: {"cesium-cesiumInspector-pickButtonHighlight" : pickPrimitiveActive}, click: pickPrimitive');
  105. var buttonWrap = document.createElement('div');
  106. buttonWrap.className = 'cesium-cesiumInspector-center';
  107. buttonWrap.appendChild(pickPrimitiveButton);
  108. pickPrimRequired.appendChild(buttonWrap);
  109. pickPrimRequired.appendChild(createCheckbox('Show bounding sphere', 'primitiveBoundingSphere', 'hasPickedPrimitive'));
  110. pickPrimRequired.appendChild(createCheckbox('Show reference frame', 'primitiveReferenceFrame', 'hasPickedPrimitive'));
  111. this._primitiveOnly = createCheckbox('Show only selected', 'filterPrimitive', 'hasPickedPrimitive');
  112. pickPrimRequired.appendChild(this._primitiveOnly);
  113. // Terrain
  114. var terrainSection = createSection(panel, 'Terrain', 'terrainVisible', 'toggleTerrain');
  115. var pickTileRequired = document.createElement('div');
  116. pickTileRequired.className = 'cesium-cesiumInspector-pickSection';
  117. terrainSection.appendChild(pickTileRequired);
  118. var pickTileButton = document.createElement('input');
  119. pickTileButton.type = 'button';
  120. pickTileButton.value = 'Pick a tile';
  121. pickTileButton.className = 'cesium-cesiumInspector-pickButton';
  122. pickTileButton.setAttribute('data-bind', 'css: {"cesium-cesiumInspector-pickButtonHighlight" : pickTileActive}, click: pickTile');
  123. buttonWrap = document.createElement('div');
  124. buttonWrap.appendChild(pickTileButton);
  125. buttonWrap.className = 'cesium-cesiumInspector-center';
  126. pickTileRequired.appendChild(buttonWrap);
  127. var tileInfo = document.createElement('div');
  128. pickTileRequired.appendChild(tileInfo);
  129. var parentTile = document.createElement('input');
  130. parentTile.type = 'button';
  131. parentTile.value = 'Parent';
  132. parentTile.className = 'cesium-cesiumInspector-pickButton';
  133. parentTile.setAttribute('data-bind', 'click: selectParent');
  134. var nwTile = document.createElement('input');
  135. nwTile.type = 'button';
  136. nwTile.value = 'NW';
  137. nwTile.className = 'cesium-cesiumInspector-pickButton';
  138. nwTile.setAttribute('data-bind', 'click: selectNW');
  139. var neTile = document.createElement('input');
  140. neTile.type = 'button';
  141. neTile.value = 'NE';
  142. neTile.className = 'cesium-cesiumInspector-pickButton';
  143. neTile.setAttribute('data-bind', 'click: selectNE');
  144. var swTile = document.createElement('input');
  145. swTile.type = 'button';
  146. swTile.value = 'SW';
  147. swTile.className = 'cesium-cesiumInspector-pickButton';
  148. swTile.setAttribute('data-bind', 'click: selectSW');
  149. var seTile = document.createElement('input');
  150. seTile.type = 'button';
  151. seTile.value = 'SE';
  152. seTile.className = 'cesium-cesiumInspector-pickButton';
  153. seTile.setAttribute('data-bind', 'click: selectSE');
  154. var tileText = document.createElement('div');
  155. tileText.className = 'cesium-cesiumInspector-tileText';
  156. tileInfo.className = 'cesium-cesiumInspector-frustumStatistics';
  157. tileInfo.appendChild(tileText);
  158. tileInfo.setAttribute('data-bind', 'visible: hasPickedTile');
  159. tileText.setAttribute('data-bind', 'html: tileText');
  160. var relativeText = document.createElement('div');
  161. relativeText.className = 'cesium-cesiumInspector-relativeText';
  162. relativeText.textContent = 'Select relative:';
  163. tileInfo.appendChild(relativeText);
  164. var table = document.createElement('table');
  165. var tr1 = document.createElement('tr');
  166. var tr2 = document.createElement('tr');
  167. var td1 = document.createElement('td');
  168. td1.appendChild(parentTile);
  169. var td2 = document.createElement('td');
  170. td2.appendChild(nwTile);
  171. var td3 = document.createElement('td');
  172. td3.appendChild(neTile);
  173. tr1.appendChild(td1);
  174. tr1.appendChild(td2);
  175. tr1.appendChild(td3);
  176. var td4 = document.createElement('td');
  177. var td5 = document.createElement('td');
  178. td5.appendChild(swTile);
  179. var td6 = document.createElement('td');
  180. td6.appendChild(seTile);
  181. tr2.appendChild(td4);
  182. tr2.appendChild(td5);
  183. tr2.appendChild(td6);
  184. table.appendChild(tr1);
  185. table.appendChild(tr2);
  186. tileInfo.appendChild(table);
  187. pickTileRequired.appendChild(createCheckbox('Show bounding volume', 'tileBoundingSphere', 'hasPickedTile'));
  188. pickTileRequired.appendChild(createCheckbox('Show only selected', 'filterTile', 'hasPickedTile'));
  189. terrainSection.appendChild(createCheckbox('Wireframe', 'wireframe'));
  190. terrainSection.appendChild(createCheckbox('Suspend LOD update', 'suspendUpdates'));
  191. terrainSection.appendChild(createCheckbox('Show tile coordinates', 'tileCoordinates'));
  192. knockout.applyBindings(viewModel, this._element);
  193. }
  194. defineProperties(CesiumInspector.prototype, {
  195. /**
  196. * Gets the parent container.
  197. * @memberof CesiumInspector.prototype
  198. *
  199. * @type {Element}
  200. */
  201. container : {
  202. get : function() {
  203. return this._container;
  204. }
  205. },
  206. /**
  207. * Gets the view model.
  208. * @memberof CesiumInspector.prototype
  209. *
  210. * @type {CesiumInspectorViewModel}
  211. */
  212. viewModel : {
  213. get : function() {
  214. return this._viewModel;
  215. }
  216. }
  217. });
  218. /**
  219. * @returns {Boolean} true if the object has been destroyed, false otherwise.
  220. */
  221. CesiumInspector.prototype.isDestroyed = function() {
  222. return false;
  223. };
  224. /**
  225. * Destroys the widget. Should be called if permanently
  226. * removing the widget from layout.
  227. */
  228. CesiumInspector.prototype.destroy = function() {
  229. knockout.cleanNode(this._element);
  230. this._container.removeChild(this._element);
  231. this.viewModel.destroy();
  232. return destroyObject(this);
  233. };
  234. export default CesiumInspector;