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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import {
  2. defined,
  3. destroyObject,
  4. DeveloperError,
  5. EventHelper,
  6. OrthographicFrustum,
  7. SceneMode,
  8. } from "@cesium/engine";
  9. import knockout from "../ThirdParty/knockout.js";
  10. import createCommand from "../createCommand.js";
  11. /**
  12. * The view model for {@link ProjectionPicker}.
  13. * @alias ProjectionPickerViewModel
  14. * @constructor
  15. *
  16. * @param {Scene} scene The Scene to switch projections.
  17. */
  18. function ProjectionPickerViewModel(scene) {
  19. //>>includeStart('debug', pragmas.debug);
  20. if (!defined(scene)) {
  21. throw new DeveloperError("scene is required.");
  22. }
  23. //>>includeEnd('debug');
  24. this._scene = scene;
  25. this._orthographic = scene.camera.frustum instanceof OrthographicFrustum;
  26. this._flightInProgress = false;
  27. /**
  28. * Gets or sets whether the button drop-down is currently visible. This property is observable.
  29. * @type {boolean}
  30. * @default false
  31. */
  32. this.dropDownVisible = false;
  33. /**
  34. * Gets or sets the perspective projection tooltip. This property is observable.
  35. * @type {string}
  36. * @default 'Perspective Projection'
  37. */
  38. this.tooltipPerspective = "Perspective Projection";
  39. /**
  40. * Gets or sets the orthographic projection tooltip. This property is observable.
  41. * @type {string}
  42. * @default 'Orthographic Projection'
  43. */
  44. this.tooltipOrthographic = "Orthographic Projection";
  45. /**
  46. * Gets the currently active tooltip. This property is observable.
  47. * @type {string}
  48. */
  49. this.selectedTooltip = undefined;
  50. /**
  51. * Gets or sets the current SceneMode. This property is observable.
  52. * @type {SceneMode}
  53. */
  54. this.sceneMode = scene.mode;
  55. knockout.track(this, [
  56. "_orthographic",
  57. "_flightInProgress",
  58. "sceneMode",
  59. "dropDownVisible",
  60. "tooltipPerspective",
  61. "tooltipOrthographic",
  62. ]);
  63. const that = this;
  64. knockout.defineProperty(this, "selectedTooltip", function () {
  65. if (that._orthographic) {
  66. return that.tooltipOrthographic;
  67. }
  68. return that.tooltipPerspective;
  69. });
  70. this._toggleDropDown = createCommand(function () {
  71. if (that.sceneMode === SceneMode.SCENE2D || that._flightInProgress) {
  72. return;
  73. }
  74. that.dropDownVisible = !that.dropDownVisible;
  75. });
  76. this._eventHelper = new EventHelper();
  77. this._eventHelper.add(
  78. scene.morphComplete,
  79. function (transitioner, oldMode, newMode, isMorphing) {
  80. that.sceneMode = newMode;
  81. that._orthographic =
  82. newMode === SceneMode.SCENE2D ||
  83. that._scene.camera.frustum instanceof OrthographicFrustum;
  84. },
  85. );
  86. this._eventHelper.add(scene.preRender, function () {
  87. that._flightInProgress = defined(scene.camera._currentFlight);
  88. });
  89. this._switchToPerspective = createCommand(function () {
  90. if (that.sceneMode === SceneMode.SCENE2D) {
  91. return;
  92. }
  93. that._scene.camera.switchToPerspectiveFrustum();
  94. that._orthographic = false;
  95. that.dropDownVisible = false;
  96. });
  97. this._switchToOrthographic = createCommand(function () {
  98. if (that.sceneMode === SceneMode.SCENE2D) {
  99. return;
  100. }
  101. that._scene.camera.switchToOrthographicFrustum();
  102. that._orthographic = true;
  103. that.dropDownVisible = false;
  104. });
  105. //Used by knockout
  106. this._sceneMode = SceneMode;
  107. }
  108. Object.defineProperties(ProjectionPickerViewModel.prototype, {
  109. /**
  110. * Gets the scene
  111. * @memberof ProjectionPickerViewModel.prototype
  112. * @type {Scene}
  113. */
  114. scene: {
  115. get: function () {
  116. return this._scene;
  117. },
  118. },
  119. /**
  120. * Gets the command to toggle the drop down box.
  121. * @memberof ProjectionPickerViewModel.prototype
  122. *
  123. * @type {Command}
  124. */
  125. toggleDropDown: {
  126. get: function () {
  127. return this._toggleDropDown;
  128. },
  129. },
  130. /**
  131. * Gets the command to switch to a perspective projection.
  132. * @memberof ProjectionPickerViewModel.prototype
  133. *
  134. * @type {Command}
  135. */
  136. switchToPerspective: {
  137. get: function () {
  138. return this._switchToPerspective;
  139. },
  140. },
  141. /**
  142. * Gets the command to switch to orthographic projection.
  143. * @memberof ProjectionPickerViewModel.prototype
  144. *
  145. * @type {Command}
  146. */
  147. switchToOrthographic: {
  148. get: function () {
  149. return this._switchToOrthographic;
  150. },
  151. },
  152. /**
  153. * Gets whether the scene is currently using an orthographic projection.
  154. * @memberof ProjectionPickerViewModel.prototype
  155. *
  156. * @type {Command}
  157. */
  158. isOrthographicProjection: {
  159. get: function () {
  160. return this._orthographic;
  161. },
  162. },
  163. });
  164. /**
  165. * @returns {boolean} true if the object has been destroyed, false otherwise.
  166. */
  167. ProjectionPickerViewModel.prototype.isDestroyed = function () {
  168. return false;
  169. };
  170. /**
  171. * Destroys the view model.
  172. */
  173. ProjectionPickerViewModel.prototype.destroy = function () {
  174. this._eventHelper.removeAll();
  175. destroyObject(this);
  176. };
  177. export default ProjectionPickerViewModel;