Source: Widgets/HomeButton/HomeButtonViewModel.js

  1. /*global define*/
  2. define([
  3. '../../Core/Cartesian3',
  4. '../../Core/defaultValue',
  5. '../../Core/defined',
  6. '../../Core/defineProperties',
  7. '../../Core/DeveloperError',
  8. '../../Core/Matrix4',
  9. '../../Core/Rectangle',
  10. '../../Scene/Camera',
  11. '../../Scene/SceneMode',
  12. '../../ThirdParty/knockout',
  13. '../createCommand'
  14. ], function(
  15. Cartesian3,
  16. defaultValue,
  17. defined,
  18. defineProperties,
  19. DeveloperError,
  20. Matrix4,
  21. Rectangle,
  22. Camera,
  23. SceneMode,
  24. knockout,
  25. createCommand) {
  26. 'use strict';
  27. /**
  28. * The view model for {@link HomeButton}.
  29. * @alias HomeButtonViewModel
  30. * @constructor
  31. *
  32. * @param {Scene} scene The scene instance to use.
  33. * @param {Number} [duration] The duration of the camera flight in seconds.
  34. */
  35. function HomeButtonViewModel(scene, duration) {
  36. //>>includeStart('debug', pragmas.debug);
  37. if (!defined(scene)) {
  38. throw new DeveloperError('scene is required.');
  39. }
  40. //>>includeEnd('debug');
  41. this._scene = scene;
  42. this._duration = duration;
  43. var that = this;
  44. this._command = createCommand(function() {
  45. that._scene.camera.flyHome(that._duration);
  46. });
  47. /**
  48. * Gets or sets the tooltip. This property is observable.
  49. *
  50. * @type {String}
  51. */
  52. this.tooltip = 'View Home';
  53. knockout.track(this, ['tooltip']);
  54. }
  55. defineProperties(HomeButtonViewModel.prototype, {
  56. /**
  57. * Gets the scene to control.
  58. * @memberof HomeButtonViewModel.prototype
  59. *
  60. * @type {Scene}
  61. */
  62. scene : {
  63. get : function() {
  64. return this._scene;
  65. }
  66. },
  67. /**
  68. * Gets the Command that is executed when the button is clicked.
  69. * @memberof HomeButtonViewModel.prototype
  70. *
  71. * @type {Command}
  72. */
  73. command : {
  74. get : function() {
  75. return this._command;
  76. }
  77. },
  78. /**
  79. * Gets or sets the the duration of the camera flight in seconds.
  80. * A value of zero causes the camera to instantly switch to home view.
  81. * The duration will be computed based on the distance when undefined.
  82. * @memberof HomeButtonViewModel.prototype
  83. *
  84. * @type {Number|undefined}
  85. */
  86. duration : {
  87. get : function() {
  88. return this._duration;
  89. },
  90. set : function(value) {
  91. //>>includeStart('debug', pragmas.debug);
  92. if (defined(value) && value < 0) {
  93. throw new DeveloperError('value must be positive.');
  94. }
  95. //>>includeEnd('debug');
  96. this._duration = value;
  97. }
  98. }
  99. });
  100. return HomeButtonViewModel;
  101. });