SceneModePickerViewModel.js 6.1 KB

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