HomeButtonViewModel.js 2.6 KB

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