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

SceneModePickerViewModel.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import {
  2. defined,
  3. destroyObject,
  4. DeveloperError,
  5. EventHelper,
  6. SceneMode,
  7. } from "@cesium/engine";
  8. import knockout from "../ThirdParty/knockout.js";
  9. import createCommand from "../createCommand.js";
  10. /**
  11. * The view model for {@link SceneModePicker}.
  12. * @alias SceneModePickerViewModel
  13. * @constructor
  14. *
  15. * @param {Scene} scene The Scene to morph
  16. * @param {number} [duration=2.0] The duration of scene morph animations, in seconds
  17. */
  18. function SceneModePickerViewModel(scene, duration) {
  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. const that = this;
  26. const morphStart = function (transitioner, oldMode, newMode, isMorphing) {
  27. that.sceneMode = newMode;
  28. that.dropDownVisible = false;
  29. };
  30. this._eventHelper = new EventHelper();
  31. this._eventHelper.add(scene.morphStart, morphStart);
  32. this._duration = duration ?? 2.0;
  33. /**
  34. * Gets or sets the current SceneMode. This property is observable.
  35. * @type {SceneMode}
  36. */
  37. this.sceneMode = scene.mode;
  38. /**
  39. * Gets or sets whether the button drop-down is currently visible. This property is observable.
  40. * @type {boolean}
  41. * @default false
  42. */
  43. this.dropDownVisible = false;
  44. /**
  45. * Gets or sets the 2D tooltip. This property is observable.
  46. * @type {string}
  47. * @default '2D'
  48. */
  49. this.tooltip2D = "2D";
  50. /**
  51. * Gets or sets the 3D tooltip. This property is observable.
  52. * @type {string}
  53. * @default '3D'
  54. */
  55. this.tooltip3D = "3D";
  56. /**
  57. * Gets or sets the Columbus View tooltip. This property is observable.
  58. * @type {string}
  59. * @default 'Columbus View'
  60. */
  61. this.tooltipColumbusView = "Columbus View";
  62. knockout.track(this, [
  63. "sceneMode",
  64. "dropDownVisible",
  65. "tooltip2D",
  66. "tooltip3D",
  67. "tooltipColumbusView",
  68. ]);
  69. /**
  70. * Gets the currently active tooltip. This property is observable.
  71. * @type {string}
  72. */
  73. this.selectedTooltip = undefined;
  74. knockout.defineProperty(this, "selectedTooltip", function () {
  75. const mode = that.sceneMode;
  76. if (mode === SceneMode.SCENE2D) {
  77. return that.tooltip2D;
  78. }
  79. if (mode === SceneMode.SCENE3D) {
  80. return that.tooltip3D;
  81. }
  82. return that.tooltipColumbusView;
  83. });
  84. this._toggleDropDown = createCommand(function () {
  85. that.dropDownVisible = !that.dropDownVisible;
  86. });
  87. this._morphTo2D = createCommand(function () {
  88. scene.morphTo2D(that._duration);
  89. });
  90. this._morphTo3D = createCommand(function () {
  91. scene.morphTo3D(that._duration);
  92. });
  93. this._morphToColumbusView = createCommand(function () {
  94. scene.morphToColumbusView(that._duration);
  95. });
  96. //Used by knockout
  97. this._sceneMode = SceneMode;
  98. }
  99. Object.defineProperties(SceneModePickerViewModel.prototype, {
  100. /**
  101. * Gets the scene
  102. * @memberof SceneModePickerViewModel.prototype
  103. * @type {Scene}
  104. */
  105. scene: {
  106. get: function () {
  107. return this._scene;
  108. },
  109. },
  110. /**
  111. * Gets or sets the the duration of scene mode transition animations in seconds.
  112. * A value of zero causes the scene to instantly change modes.
  113. * @memberof SceneModePickerViewModel.prototype
  114. * @type {number}
  115. */
  116. duration: {
  117. get: function () {
  118. return this._duration;
  119. },
  120. set: function (value) {
  121. //>>includeStart('debug', pragmas.debug);
  122. if (value < 0.0) {
  123. throw new DeveloperError("duration value must be positive.");
  124. }
  125. //>>includeEnd('debug');
  126. this._duration = value;
  127. },
  128. },
  129. /**
  130. * Gets the command to toggle the drop down box.
  131. * @memberof SceneModePickerViewModel.prototype
  132. *
  133. * @type {Command}
  134. */
  135. toggleDropDown: {
  136. get: function () {
  137. return this._toggleDropDown;
  138. },
  139. },
  140. /**
  141. * Gets the command to morph to 2D.
  142. * @memberof SceneModePickerViewModel.prototype
  143. *
  144. * @type {Command}
  145. */
  146. morphTo2D: {
  147. get: function () {
  148. return this._morphTo2D;
  149. },
  150. },
  151. /**
  152. * Gets the command to morph to 3D.
  153. * @memberof SceneModePickerViewModel.prototype
  154. *
  155. * @type {Command}
  156. */
  157. morphTo3D: {
  158. get: function () {
  159. return this._morphTo3D;
  160. },
  161. },
  162. /**
  163. * Gets the command to morph to Columbus View.
  164. * @memberof SceneModePickerViewModel.prototype
  165. *
  166. * @type {Command}
  167. */
  168. morphToColumbusView: {
  169. get: function () {
  170. return this._morphToColumbusView;
  171. },
  172. },
  173. });
  174. /**
  175. * @returns {boolean} true if the object has been destroyed, false otherwise.
  176. */
  177. SceneModePickerViewModel.prototype.isDestroyed = function () {
  178. return false;
  179. };
  180. /**
  181. * Destroys the view model.
  182. */
  183. SceneModePickerViewModel.prototype.destroy = function () {
  184. this._eventHelper.removeAll();
  185. destroyObject(this);
  186. };
  187. export default SceneModePickerViewModel;