SceneModePickerViewModel.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import defaultValue from '../../Core/defaultValue.js';
  2. import defined from '../../Core/defined.js';
  3. import defineProperties from '../../Core/defineProperties.js';
  4. import destroyObject from '../../Core/destroyObject.js';
  5. import DeveloperError from '../../Core/DeveloperError.js';
  6. import EventHelper from '../../Core/EventHelper.js';
  7. import SceneMode from '../../Scene/SceneMode.js';
  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. var that = this;
  26. var 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 = defaultValue(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, ['sceneMode', 'dropDownVisible', 'tooltip2D', 'tooltip3D', 'tooltipColumbusView']);
  63. /**
  64. * Gets the currently active tooltip. This property is observable.
  65. * @type {String}
  66. */
  67. this.selectedTooltip = undefined;
  68. knockout.defineProperty(this, 'selectedTooltip', function() {
  69. var mode = that.sceneMode;
  70. if (mode === SceneMode.SCENE2D) {
  71. return that.tooltip2D;
  72. }
  73. if (mode === SceneMode.SCENE3D) {
  74. return that.tooltip3D;
  75. }
  76. return that.tooltipColumbusView;
  77. });
  78. this._toggleDropDown = createCommand(function() {
  79. that.dropDownVisible = !that.dropDownVisible;
  80. });
  81. this._morphTo2D = createCommand(function() {
  82. scene.morphTo2D(that._duration);
  83. });
  84. this._morphTo3D = createCommand(function() {
  85. scene.morphTo3D(that._duration);
  86. });
  87. this._morphToColumbusView = createCommand(function() {
  88. scene.morphToColumbusView(that._duration);
  89. });
  90. //Used by knockout
  91. this._sceneMode = SceneMode;
  92. }
  93. defineProperties(SceneModePickerViewModel.prototype, {
  94. /**
  95. * Gets the scene
  96. * @memberof SceneModePickerViewModel.prototype
  97. * @type {Scene}
  98. */
  99. scene : {
  100. get : function() {
  101. return this._scene;
  102. }
  103. },
  104. /**
  105. * Gets or sets the the duration of scene mode transition animations in seconds.
  106. * A value of zero causes the scene to instantly change modes.
  107. * @memberof SceneModePickerViewModel.prototype
  108. * @type {Number}
  109. */
  110. duration : {
  111. get : function() {
  112. return this._duration;
  113. },
  114. set : function(value) {
  115. //>>includeStart('debug', pragmas.debug);
  116. if (value < 0.0) {
  117. throw new DeveloperError('duration value must be positive.');
  118. }
  119. //>>includeEnd('debug');
  120. this._duration = value;
  121. }
  122. },
  123. /**
  124. * Gets the command to toggle the drop down box.
  125. * @memberof SceneModePickerViewModel.prototype
  126. *
  127. * @type {Command}
  128. */
  129. toggleDropDown : {
  130. get : function() {
  131. return this._toggleDropDown;
  132. }
  133. },
  134. /**
  135. * Gets the command to morph to 2D.
  136. * @memberof SceneModePickerViewModel.prototype
  137. *
  138. * @type {Command}
  139. */
  140. morphTo2D : {
  141. get : function() {
  142. return this._morphTo2D;
  143. }
  144. },
  145. /**
  146. * Gets the command to morph to 3D.
  147. * @memberof SceneModePickerViewModel.prototype
  148. *
  149. * @type {Command}
  150. */
  151. morphTo3D : {
  152. get : function() {
  153. return this._morphTo3D;
  154. }
  155. },
  156. /**
  157. * Gets the command to morph to Columbus View.
  158. * @memberof SceneModePickerViewModel.prototype
  159. *
  160. * @type {Command}
  161. */
  162. morphToColumbusView : {
  163. get : function() {
  164. return this._morphToColumbusView;
  165. }
  166. }
  167. });
  168. /**
  169. * @returns {Boolean} true if the object has been destroyed, false otherwise.
  170. */
  171. SceneModePickerViewModel.prototype.isDestroyed = function() {
  172. return false;
  173. };
  174. /**
  175. * Destroys the view model.
  176. */
  177. SceneModePickerViewModel.prototype.destroy = function() {
  178. this._eventHelper.removeAll();
  179. destroyObject(this);
  180. };
  181. export default SceneModePickerViewModel;